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
This commit is contained in:
@ -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},
|
||||
|
@ -1524,6 +1524,16 @@ public class AudioManager {
|
||||
return AudioSystem.isStreamActive(STREAM_MUSIC, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
@ -110,6 +110,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
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user