diff options
| author | 2012-10-10 12:03:41 -0700 | |
|---|---|---|
| committer | 2012-10-10 12:03:41 -0700 | |
| commit | d677054ca63f55abaa1c478ea3c50f6be665a979 (patch) | |
| tree | c27e68851c9140ad650d84245e9758625cfec0d5 | |
| parent | a8a6b0848d1c11c3ed0fcb846e3d6c39b91536a0 (diff) | |
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
| -rw-r--r-- | core/jni/android_media_AudioSystem.cpp | 11 | ||||
| -rw-r--r-- | media/java/android/media/AudioManager.java | 10 | ||||
| -rw-r--r-- | media/java/android/media/AudioSystem.java | 7 | ||||
| -rwxr-xr-x | services/java/com/android/server/NotificationManagerService.java | 5 |
4 files changed, 30 insertions, 3 deletions
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp index 56db116b6506..631cdaea806f 100644 --- a/core/jni/android_media_AudioSystem.cpp +++ b/core/jni/android_media_AudioSystem.cpp @@ -75,6 +75,14 @@ android_media_AudioSystem_isStreamActive(JNIEnv *env, jobject thiz, jint stream, return state; } +static jboolean +android_media_AudioSystem_isSourceActive(JNIEnv *env, jobject thiz, jint source) +{ + bool state = false; + AudioSystem::isSourceActive((audio_source_t) source, &state); + return state; +} + static int android_media_AudioSystem_setParameters(JNIEnv *env, jobject thiz, jstring keyValuePairs) { @@ -261,7 +269,8 @@ static JNINativeMethod gMethods[] = { {"getParameters", "(Ljava/lang/String;)Ljava/lang/String;", (void *)android_media_AudioSystem_getParameters}, {"muteMicrophone", "(Z)I", (void *)android_media_AudioSystem_muteMicrophone}, {"isMicrophoneMuted", "()Z", (void *)android_media_AudioSystem_isMicrophoneMuted}, - {"isStreamActive", "(II)Z", (void *)android_media_AudioSystem_isStreamActive}, + {"isStreamActive", "(II)Z", (void *)android_media_AudioSystem_isStreamActive}, + {"isSourceActive", "(I)Z", (void *)android_media_AudioSystem_isSourceActive}, {"setDeviceConnectionState", "(IILjava/lang/String;)I", (void *)android_media_AudioSystem_setDeviceConnectionState}, {"getDeviceConnectionState", "(ILjava/lang/String;)I", (void *)android_media_AudioSystem_getDeviceConnectionState}, {"setPhoneState", "(I)I", (void *)android_media_AudioSystem_setPhoneState}, diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index ee17bd3df596..035b2824b465 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -1526,6 +1526,16 @@ public class AudioManager { /** * @hide + * Checks whether speech recognition is active + * @return true if a recording with source {@link MediaRecorder.AudioSource#VOICE_RECOGNITION} + * is underway. + */ + public boolean isSpeechRecognitionActive() { + return AudioSystem.isSourceActive(MediaRecorder.AudioSource.VOICE_RECOGNITION); + } + + /** + * @hide * If the stream is active locally or remotely, adjust its volume according to the enforced * priority rules. * Note: only AudioManager.STREAM_MUSIC is supported at the moment diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 103e817b3ac5..260ddc7a4b56 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -111,6 +111,13 @@ public class AudioSystem public static native boolean isStreamActive(int stream, int inPastMs); /* + * Checks whether the specified audio source is active. + * + * return true if any recorder using this source is currently recording + */ + public static native boolean isSourceActive(int source); + + /* * Sets a group generic audio configuration parameters. The use of these parameters * are platform dependent, see libaudio * diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java index 85b488c9e1a2..2e7a54ba1571 100755 --- a/services/java/com/android/server/NotificationManagerService.java +++ b/services/java/com/android/server/NotificationManagerService.java @@ -1066,8 +1066,9 @@ public class NotificationManagerService extends INotificationManager.Stub } mSoundNotification = r; // do not play notifications if stream volume is 0 - // (typically because ringer mode is silent). - if (audioManager.getStreamVolume(audioStreamType) != 0) { + // (typically because ringer mode is silent) or if speech recognition is active. + if ((audioManager.getStreamVolume(audioStreamType) != 0) + && !audioManager.isSpeechRecognitionActive()) { final long identity = Binder.clearCallingIdentity(); try { final IRingtonePlayer player = mAudioService.getRingtonePlayer(); |