Skip to content

Commit d677054

Browse files
committed
Don't play notifications during speech recognition
Add support for querying AudioManager to know whether speech recognition is currently underway. Don't play a notification if speech recognition is underway. Bug 7314859 Change-Id: I1bd013a3168cfe1a6b6dcfd28565e1c3c512eb6a
1 parent a8a6b08 commit d677054

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

core/jni/android_media_AudioSystem.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ android_media_AudioSystem_isStreamActive(JNIEnv *env, jobject thiz, jint stream,
7575
return state;
7676
}
7777

78+
static jboolean
79+
android_media_AudioSystem_isSourceActive(JNIEnv *env, jobject thiz, jint source)
80+
{
81+
bool state = false;
82+
AudioSystem::isSourceActive((audio_source_t) source, &state);
83+
return state;
84+
}
85+
7886
static int
7987
android_media_AudioSystem_setParameters(JNIEnv *env, jobject thiz, jstring keyValuePairs)
8088
{
@@ -261,7 +269,8 @@ static JNINativeMethod gMethods[] = {
261269
{"getParameters", "(Ljava/lang/String;)Ljava/lang/String;", (void *)android_media_AudioSystem_getParameters},
262270
{"muteMicrophone", "(Z)I", (void *)android_media_AudioSystem_muteMicrophone},
263271
{"isMicrophoneMuted", "()Z", (void *)android_media_AudioSystem_isMicrophoneMuted},
264-
{"isStreamActive", "(II)Z", (void *)android_media_AudioSystem_isStreamActive},
272+
{"isStreamActive", "(II)Z", (void *)android_media_AudioSystem_isStreamActive},
273+
{"isSourceActive", "(I)Z", (void *)android_media_AudioSystem_isSourceActive},
265274
{"setDeviceConnectionState", "(IILjava/lang/String;)I", (void *)android_media_AudioSystem_setDeviceConnectionState},
266275
{"getDeviceConnectionState", "(ILjava/lang/String;)I", (void *)android_media_AudioSystem_getDeviceConnectionState},
267276
{"setPhoneState", "(I)I", (void *)android_media_AudioSystem_setPhoneState},

media/java/android/media/AudioManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,16 @@ public boolean isMusicActive() {
15241524
return AudioSystem.isStreamActive(STREAM_MUSIC, 0);
15251525
}
15261526

1527+
/**
1528+
* @hide
1529+
* Checks whether speech recognition is active
1530+
* @return true if a recording with source {@link MediaRecorder.AudioSource#VOICE_RECOGNITION}
1531+
* is underway.
1532+
*/
1533+
public boolean isSpeechRecognitionActive() {
1534+
return AudioSystem.isSourceActive(MediaRecorder.AudioSource.VOICE_RECOGNITION);
1535+
}
1536+
15271537
/**
15281538
* @hide
15291539
* If the stream is active locally or remotely, adjust its volume according to the enforced

media/java/android/media/AudioSystem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ public class AudioSystem
110110
*/
111111
public static native boolean isStreamActive(int stream, int inPastMs);
112112

113+
/*
114+
* Checks whether the specified audio source is active.
115+
*
116+
* return true if any recorder using this source is currently recording
117+
*/
118+
public static native boolean isSourceActive(int source);
119+
113120
/*
114121
* Sets a group generic audio configuration parameters. The use of these parameters
115122
* are platform dependent, see libaudio

services/java/com/android/server/NotificationManagerService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,9 @@ public void enqueueNotificationInternal(String pkg, int callingUid, int callingP
10661066
}
10671067
mSoundNotification = r;
10681068
// do not play notifications if stream volume is 0
1069-
// (typically because ringer mode is silent).
1070-
if (audioManager.getStreamVolume(audioStreamType) != 0) {
1069+
// (typically because ringer mode is silent) or if speech recognition is active.
1070+
if ((audioManager.getStreamVolume(audioStreamType) != 0)
1071+
&& !audioManager.isSpeechRecognitionActive()) {
10711072
final long identity = Binder.clearCallingIdentity();
10721073
try {
10731074
final IRingtonePlayer player = mAudioService.getRingtonePlayer();

0 commit comments

Comments
 (0)