diff options
author | 2024-10-14 23:46:46 +0000 | |
---|---|---|
committer | 2024-10-14 23:46:46 +0000 | |
commit | d2a8a229326e5e2d2b0584f2c23b3ccef6563c08 (patch) | |
tree | 10e507f6b3aada80407869058efde3078bce4efc | |
parent | 34daf84e313ed11259dfc341fa6c94b7bd1f1d34 (diff) | |
parent | 5dce646c08eaaff8e66533199034c4ee29513e4f (diff) |
Merge "AS: send the mute event to APM" into main
10 files changed, 328 insertions, 257 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index cab836e147c4..fa4fc43c3418 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -7319,6 +7319,7 @@ package android.media { field @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_APP_OPS = 8; // 0x8 field @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_CLIENT_VOLUME = 16; // 0x10 field @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_MASTER = 1; // 0x1 + field @FlaggedApi("android.media.audio.muted_by_port_volume_api") @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_PORT_VOLUME = 64; // 0x40 field @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_STREAM_MUTED = 4; // 0x4 field @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_STREAM_VOLUME = 2; // 0x2 field @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_VOLUME_SHAPER = 32; // 0x20 diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp index 9bccf5af7096..8eaa7aa99a2d 100644 --- a/core/jni/android_media_AudioSystem.cpp +++ b/core/jni/android_media_AudioSystem.cpp @@ -747,16 +747,12 @@ android_media_AudioSystem_initStreamVolume(JNIEnv *env, jobject thiz, jint strea indexMax)); } -static jint -android_media_AudioSystem_setStreamVolumeIndex(JNIEnv *env, - jobject thiz, - jint stream, - jint index, - jint device) -{ +static jint android_media_AudioSystem_setStreamVolumeIndex(JNIEnv *env, jobject thiz, jint stream, + jint index, jboolean muted, + jint device) { return check_AudioSystem_Command( AudioSystem::setStreamVolumeIndex(static_cast<audio_stream_type_t>(stream), index, - static_cast<audio_devices_t>(device))); + muted, static_cast<audio_devices_t>(device))); } static jint @@ -773,13 +769,9 @@ android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env, return index; } -static jint -android_media_AudioSystem_setVolumeIndexForAttributes(JNIEnv *env, - jobject thiz, - jobject jaa, - jint index, - jint device) -{ +static jint android_media_AudioSystem_setVolumeIndexForAttributes(JNIEnv *env, jobject thiz, + jobject jaa, jint index, + jboolean muted, jint device) { // read the AudioAttributes values JNIAudioAttributeHelper::UniqueAaPtr paa = JNIAudioAttributeHelper::makeUnique(); jint jStatus = JNIAudioAttributeHelper::nativeFromJava(env, jaa, paa.get()); @@ -787,7 +779,7 @@ android_media_AudioSystem_setVolumeIndexForAttributes(JNIEnv *env, return jStatus; } return check_AudioSystem_Command( - AudioSystem::setVolumeIndexForAttributes(*(paa.get()), index, + AudioSystem::setVolumeIndexForAttributes(*(paa.get()), index, muted, static_cast<audio_devices_t>(device))); } @@ -3448,182 +3440,179 @@ static void android_media_AudioSystem_triggerSystemPropertyUpdate(JNIEnv *env, #define MAKE_AUDIO_SYSTEM_METHOD(x) \ MAKE_JNI_NATIVE_METHOD_AUTOSIG(#x, android_media_AudioSystem_##x) -static const JNINativeMethod gMethods[] = - {MAKE_AUDIO_SYSTEM_METHOD(setParameters), - MAKE_AUDIO_SYSTEM_METHOD(getParameters), - MAKE_AUDIO_SYSTEM_METHOD(muteMicrophone), - MAKE_AUDIO_SYSTEM_METHOD(isMicrophoneMuted), - MAKE_AUDIO_SYSTEM_METHOD(isStreamActive), - MAKE_AUDIO_SYSTEM_METHOD(isStreamActiveRemotely), - MAKE_AUDIO_SYSTEM_METHOD(isSourceActive), - MAKE_AUDIO_SYSTEM_METHOD(newAudioSessionId), - MAKE_AUDIO_SYSTEM_METHOD(newAudioPlayerId), - MAKE_AUDIO_SYSTEM_METHOD(newAudioRecorderId), - MAKE_JNI_NATIVE_METHOD("setDeviceConnectionState", "(ILandroid/os/Parcel;I)I", - android_media_AudioSystem_setDeviceConnectionState), - MAKE_AUDIO_SYSTEM_METHOD(getDeviceConnectionState), - MAKE_AUDIO_SYSTEM_METHOD(handleDeviceConfigChange), - MAKE_AUDIO_SYSTEM_METHOD(setPhoneState), - MAKE_AUDIO_SYSTEM_METHOD(setForceUse), - MAKE_AUDIO_SYSTEM_METHOD(getForceUse), - MAKE_AUDIO_SYSTEM_METHOD(setDeviceAbsoluteVolumeEnabled), - MAKE_AUDIO_SYSTEM_METHOD(initStreamVolume), - MAKE_AUDIO_SYSTEM_METHOD(setStreamVolumeIndex), - MAKE_AUDIO_SYSTEM_METHOD(getStreamVolumeIndex), - MAKE_JNI_NATIVE_METHOD("setVolumeIndexForAttributes", - "(Landroid/media/AudioAttributes;II)I", - android_media_AudioSystem_setVolumeIndexForAttributes), - MAKE_JNI_NATIVE_METHOD("getVolumeIndexForAttributes", - "(Landroid/media/AudioAttributes;I)I", - android_media_AudioSystem_getVolumeIndexForAttributes), - MAKE_JNI_NATIVE_METHOD("getMinVolumeIndexForAttributes", - "(Landroid/media/AudioAttributes;)I", - android_media_AudioSystem_getMinVolumeIndexForAttributes), - MAKE_JNI_NATIVE_METHOD("getMaxVolumeIndexForAttributes", - "(Landroid/media/AudioAttributes;)I", - android_media_AudioSystem_getMaxVolumeIndexForAttributes), - MAKE_AUDIO_SYSTEM_METHOD(setMasterVolume), - MAKE_AUDIO_SYSTEM_METHOD(getMasterVolume), - MAKE_AUDIO_SYSTEM_METHOD(setMasterMute), - MAKE_AUDIO_SYSTEM_METHOD(getMasterMute), - MAKE_AUDIO_SYSTEM_METHOD(setMasterMono), - MAKE_AUDIO_SYSTEM_METHOD(getMasterMono), - MAKE_AUDIO_SYSTEM_METHOD(setMasterBalance), - MAKE_AUDIO_SYSTEM_METHOD(getMasterBalance), - MAKE_AUDIO_SYSTEM_METHOD(getPrimaryOutputSamplingRate), - MAKE_AUDIO_SYSTEM_METHOD(getPrimaryOutputFrameCount), - MAKE_AUDIO_SYSTEM_METHOD(getOutputLatency), - MAKE_AUDIO_SYSTEM_METHOD(setLowRamDevice), - MAKE_AUDIO_SYSTEM_METHOD(checkAudioFlinger), - MAKE_JNI_NATIVE_METHOD("setAudioFlingerBinder", "(Landroid/os/IBinder;)V", - android_media_AudioSystem_setAudioFlingerBinder), - MAKE_JNI_NATIVE_METHOD("listAudioPorts", "(Ljava/util/ArrayList;[I)I", - android_media_AudioSystem_listAudioPorts), - MAKE_JNI_NATIVE_METHOD("getSupportedDeviceTypes", "(ILandroid/util/IntArray;)I", - android_media_AudioSystem_getSupportedDeviceTypes), - MAKE_JNI_NATIVE_METHOD("createAudioPatch", - "([Landroid/media/AudioPatch;[Landroid/media/" - "AudioPortConfig;[Landroid/media/AudioPortConfig;)I", - android_media_AudioSystem_createAudioPatch), - MAKE_JNI_NATIVE_METHOD("releaseAudioPatch", "(Landroid/media/AudioPatch;)I", - android_media_AudioSystem_releaseAudioPatch), - MAKE_JNI_NATIVE_METHOD("listAudioPatches", "(Ljava/util/ArrayList;[I)I", - android_media_AudioSystem_listAudioPatches), - MAKE_JNI_NATIVE_METHOD("setAudioPortConfig", "(Landroid/media/AudioPortConfig;)I", - android_media_AudioSystem_setAudioPortConfig), - MAKE_JNI_NATIVE_METHOD("startAudioSource", - "(Landroid/media/AudioPortConfig;Landroid/media/AudioAttributes;)I", - android_media_AudioSystem_startAudioSource), - MAKE_AUDIO_SYSTEM_METHOD(stopAudioSource), - MAKE_AUDIO_SYSTEM_METHOD(getAudioHwSyncForSession), - MAKE_JNI_NATIVE_METHOD("registerPolicyMixes", "(Ljava/util/ArrayList;Z)I", - android_media_AudioSystem_registerPolicyMixes), - MAKE_JNI_NATIVE_METHOD("getRegisteredPolicyMixes", "(Ljava/util/List;)I", - android_media_AudioSystem_getRegisteredPolicyMixes), - MAKE_JNI_NATIVE_METHOD("updatePolicyMixes", - "([Landroid/media/audiopolicy/AudioMix;[Landroid/media/audiopolicy/" - "AudioMixingRule;)I", - android_media_AudioSystem_updatePolicyMixes), - MAKE_JNI_NATIVE_METHOD("setUidDeviceAffinities", "(I[I[Ljava/lang/String;)I", - android_media_AudioSystem_setUidDeviceAffinities), - MAKE_AUDIO_SYSTEM_METHOD(removeUidDeviceAffinities), - MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_dynamic_policy_callback", - android_media_AudioSystem_registerDynPolicyCallback), - MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_recording_callback", - android_media_AudioSystem_registerRecordingCallback), - MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_routing_callback", - android_media_AudioSystem_registerRoutingCallback), - MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_vol_range_init_req_callback", - android_media_AudioSystem_registerVolRangeInitReqCallback), - MAKE_AUDIO_SYSTEM_METHOD(systemReady), - MAKE_AUDIO_SYSTEM_METHOD(getStreamVolumeDB), - MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_get_offload_support", - android_media_AudioSystem_getOffloadSupport), - MAKE_JNI_NATIVE_METHOD("getMicrophones", "(Ljava/util/ArrayList;)I", - android_media_AudioSystem_getMicrophones), - MAKE_JNI_NATIVE_METHOD("getSurroundFormats", "(Ljava/util/Map;)I", - android_media_AudioSystem_getSurroundFormats), - MAKE_JNI_NATIVE_METHOD("getReportedSurroundFormats", "(Ljava/util/ArrayList;)I", - android_media_AudioSystem_getReportedSurroundFormats), - MAKE_AUDIO_SYSTEM_METHOD(setSurroundFormatEnabled), - MAKE_AUDIO_SYSTEM_METHOD(setAssistantServicesUids), - MAKE_AUDIO_SYSTEM_METHOD(setActiveAssistantServicesUids), - MAKE_AUDIO_SYSTEM_METHOD(setA11yServicesUids), - MAKE_AUDIO_SYSTEM_METHOD(isHapticPlaybackSupported), - MAKE_AUDIO_SYSTEM_METHOD(isUltrasoundSupported), - MAKE_JNI_NATIVE_METHOD( - "getHwOffloadFormatsSupportedForBluetoothMedia", "(ILjava/util/ArrayList;)I", - android_media_AudioSystem_getHwOffloadFormatsSupportedForBluetoothMedia), - MAKE_AUDIO_SYSTEM_METHOD(setSupportedSystemUsages), - MAKE_AUDIO_SYSTEM_METHOD(setAllowedCapturePolicy), - MAKE_AUDIO_SYSTEM_METHOD(setRttEnabled), - MAKE_AUDIO_SYSTEM_METHOD(setAudioHalPids), - MAKE_AUDIO_SYSTEM_METHOD(isCallScreeningModeSupported), - MAKE_JNI_NATIVE_METHOD("setDevicesRoleForStrategy", "(II[I[Ljava/lang/String;)I", - android_media_AudioSystem_setDevicesRoleForStrategy), - MAKE_JNI_NATIVE_METHOD("removeDevicesRoleForStrategy", "(II[I[Ljava/lang/String;)I", - android_media_AudioSystem_removeDevicesRoleForStrategy), - MAKE_AUDIO_SYSTEM_METHOD(clearDevicesRoleForStrategy), - MAKE_JNI_NATIVE_METHOD("getDevicesForRoleAndStrategy", "(IILjava/util/List;)I", - android_media_AudioSystem_getDevicesForRoleAndStrategy), - MAKE_JNI_NATIVE_METHOD("setDevicesRoleForCapturePreset", "(II[I[Ljava/lang/String;)I", - android_media_AudioSystem_setDevicesRoleForCapturePreset), - MAKE_JNI_NATIVE_METHOD("addDevicesRoleForCapturePreset", "(II[I[Ljava/lang/String;)I", - android_media_AudioSystem_addDevicesRoleForCapturePreset), - MAKE_JNI_NATIVE_METHOD("removeDevicesRoleForCapturePreset", "(II[I[Ljava/lang/String;)I", - android_media_AudioSystem_removeDevicesRoleForCapturePreset), - MAKE_AUDIO_SYSTEM_METHOD(clearDevicesRoleForCapturePreset), - MAKE_JNI_NATIVE_METHOD("getDevicesForRoleAndCapturePreset", "(IILjava/util/List;)I", - android_media_AudioSystem_getDevicesForRoleAndCapturePreset), - MAKE_JNI_NATIVE_METHOD("getDevicesForAttributes", - "(Landroid/media/AudioAttributes;[Landroid/media/" - "AudioDeviceAttributes;Z)I", - android_media_AudioSystem_getDevicesForAttributes), - MAKE_JNI_NATIVE_METHOD("setUserIdDeviceAffinities", "(I[I[Ljava/lang/String;)I", - android_media_AudioSystem_setUserIdDeviceAffinities), - MAKE_AUDIO_SYSTEM_METHOD(removeUserIdDeviceAffinities), - MAKE_AUDIO_SYSTEM_METHOD(setCurrentImeUid), - MAKE_JNI_NATIVE_METHOD("setVibratorInfos", "(Ljava/util/List;)I", - android_media_AudioSystem_setVibratorInfos), - MAKE_JNI_NATIVE_METHOD("nativeGetSpatializer", - "(Landroid/media/INativeSpatializerCallback;)Landroid/os/IBinder;", - android_media_AudioSystem_getSpatializer), - MAKE_JNI_NATIVE_METHOD("canBeSpatialized", - "(Landroid/media/AudioAttributes;Landroid/media/AudioFormat;" - "[Landroid/media/AudioDeviceAttributes;)Z", - android_media_AudioSystem_canBeSpatialized), - MAKE_JNI_NATIVE_METHOD("nativeGetSoundDose", - "(Landroid/media/ISoundDoseCallback;)Landroid/os/IBinder;", - android_media_AudioSystem_nativeGetSoundDose), - MAKE_JNI_NATIVE_METHOD("getDirectPlaybackSupport", - "(Landroid/media/AudioFormat;Landroid/media/AudioAttributes;)I", - android_media_AudioSystem_getDirectPlaybackSupport), - MAKE_JNI_NATIVE_METHOD("getDirectProfilesForAttributes", - "(Landroid/media/AudioAttributes;Ljava/util/ArrayList;)I", - android_media_AudioSystem_getDirectProfilesForAttributes), - MAKE_JNI_NATIVE_METHOD("getSupportedMixerAttributes", "(ILjava/util/List;)I", - android_media_AudioSystem_getSupportedMixerAttributes), - MAKE_JNI_NATIVE_METHOD("setPreferredMixerAttributes", - "(Landroid/media/AudioAttributes;IILandroid/media/" - "AudioMixerAttributes;)I", - android_media_AudioSystem_setPreferredMixerAttributes), - MAKE_JNI_NATIVE_METHOD("getPreferredMixerAttributes", - "(Landroid/media/AudioAttributes;ILjava/util/List;)I", - android_media_AudioSystem_getPreferredMixerAttributes), - MAKE_JNI_NATIVE_METHOD("clearPreferredMixerAttributes", - "(Landroid/media/AudioAttributes;II)I", - android_media_AudioSystem_clearPreferredMixerAttributes), - MAKE_AUDIO_SYSTEM_METHOD(supportsBluetoothVariableLatency), - MAKE_AUDIO_SYSTEM_METHOD(setBluetoothVariableLatencyEnabled), - MAKE_AUDIO_SYSTEM_METHOD(isBluetoothVariableLatencyEnabled), - MAKE_JNI_NATIVE_METHOD("listenForSystemPropertyChange", - "(Ljava/lang/String;Ljava/lang/Runnable;)J", - android_media_AudioSystem_listenForSystemPropertyChange), - MAKE_JNI_NATIVE_METHOD("triggerSystemPropertyUpdate", - "(J)V", - android_media_AudioSystem_triggerSystemPropertyUpdate), - - }; +static const JNINativeMethod gMethods[] = { + MAKE_AUDIO_SYSTEM_METHOD(setParameters), + MAKE_AUDIO_SYSTEM_METHOD(getParameters), + MAKE_AUDIO_SYSTEM_METHOD(muteMicrophone), + MAKE_AUDIO_SYSTEM_METHOD(isMicrophoneMuted), + MAKE_AUDIO_SYSTEM_METHOD(isStreamActive), + MAKE_AUDIO_SYSTEM_METHOD(isStreamActiveRemotely), + MAKE_AUDIO_SYSTEM_METHOD(isSourceActive), + MAKE_AUDIO_SYSTEM_METHOD(newAudioSessionId), + MAKE_AUDIO_SYSTEM_METHOD(newAudioPlayerId), + MAKE_AUDIO_SYSTEM_METHOD(newAudioRecorderId), + MAKE_JNI_NATIVE_METHOD("setDeviceConnectionState", "(ILandroid/os/Parcel;I)I", + android_media_AudioSystem_setDeviceConnectionState), + MAKE_AUDIO_SYSTEM_METHOD(getDeviceConnectionState), + MAKE_AUDIO_SYSTEM_METHOD(handleDeviceConfigChange), + MAKE_AUDIO_SYSTEM_METHOD(setPhoneState), + MAKE_AUDIO_SYSTEM_METHOD(setForceUse), + MAKE_AUDIO_SYSTEM_METHOD(getForceUse), + MAKE_AUDIO_SYSTEM_METHOD(setDeviceAbsoluteVolumeEnabled), + MAKE_AUDIO_SYSTEM_METHOD(initStreamVolume), + MAKE_AUDIO_SYSTEM_METHOD(setStreamVolumeIndex), + MAKE_AUDIO_SYSTEM_METHOD(getStreamVolumeIndex), + MAKE_JNI_NATIVE_METHOD("setVolumeIndexForAttributes", + "(Landroid/media/AudioAttributes;IZI)I", + android_media_AudioSystem_setVolumeIndexForAttributes), + MAKE_JNI_NATIVE_METHOD("getVolumeIndexForAttributes", "(Landroid/media/AudioAttributes;I)I", + android_media_AudioSystem_getVolumeIndexForAttributes), + MAKE_JNI_NATIVE_METHOD("getMinVolumeIndexForAttributes", + "(Landroid/media/AudioAttributes;)I", + android_media_AudioSystem_getMinVolumeIndexForAttributes), + MAKE_JNI_NATIVE_METHOD("getMaxVolumeIndexForAttributes", + "(Landroid/media/AudioAttributes;)I", + android_media_AudioSystem_getMaxVolumeIndexForAttributes), + MAKE_AUDIO_SYSTEM_METHOD(setMasterVolume), + MAKE_AUDIO_SYSTEM_METHOD(getMasterVolume), + MAKE_AUDIO_SYSTEM_METHOD(setMasterMute), + MAKE_AUDIO_SYSTEM_METHOD(getMasterMute), + MAKE_AUDIO_SYSTEM_METHOD(setMasterMono), + MAKE_AUDIO_SYSTEM_METHOD(getMasterMono), + MAKE_AUDIO_SYSTEM_METHOD(setMasterBalance), + MAKE_AUDIO_SYSTEM_METHOD(getMasterBalance), + MAKE_AUDIO_SYSTEM_METHOD(getPrimaryOutputSamplingRate), + MAKE_AUDIO_SYSTEM_METHOD(getPrimaryOutputFrameCount), + MAKE_AUDIO_SYSTEM_METHOD(getOutputLatency), + MAKE_AUDIO_SYSTEM_METHOD(setLowRamDevice), + MAKE_AUDIO_SYSTEM_METHOD(checkAudioFlinger), + MAKE_JNI_NATIVE_METHOD("setAudioFlingerBinder", "(Landroid/os/IBinder;)V", + android_media_AudioSystem_setAudioFlingerBinder), + MAKE_JNI_NATIVE_METHOD("listAudioPorts", "(Ljava/util/ArrayList;[I)I", + android_media_AudioSystem_listAudioPorts), + MAKE_JNI_NATIVE_METHOD("getSupportedDeviceTypes", "(ILandroid/util/IntArray;)I", + android_media_AudioSystem_getSupportedDeviceTypes), + MAKE_JNI_NATIVE_METHOD("createAudioPatch", + "([Landroid/media/AudioPatch;[Landroid/media/" + "AudioPortConfig;[Landroid/media/AudioPortConfig;)I", + android_media_AudioSystem_createAudioPatch), + MAKE_JNI_NATIVE_METHOD("releaseAudioPatch", "(Landroid/media/AudioPatch;)I", + android_media_AudioSystem_releaseAudioPatch), + MAKE_JNI_NATIVE_METHOD("listAudioPatches", "(Ljava/util/ArrayList;[I)I", + android_media_AudioSystem_listAudioPatches), + MAKE_JNI_NATIVE_METHOD("setAudioPortConfig", "(Landroid/media/AudioPortConfig;)I", + android_media_AudioSystem_setAudioPortConfig), + MAKE_JNI_NATIVE_METHOD("startAudioSource", + "(Landroid/media/AudioPortConfig;Landroid/media/AudioAttributes;)I", + android_media_AudioSystem_startAudioSource), + MAKE_AUDIO_SYSTEM_METHOD(stopAudioSource), + MAKE_AUDIO_SYSTEM_METHOD(getAudioHwSyncForSession), + MAKE_JNI_NATIVE_METHOD("registerPolicyMixes", "(Ljava/util/ArrayList;Z)I", + android_media_AudioSystem_registerPolicyMixes), + MAKE_JNI_NATIVE_METHOD("getRegisteredPolicyMixes", "(Ljava/util/List;)I", + android_media_AudioSystem_getRegisteredPolicyMixes), + MAKE_JNI_NATIVE_METHOD("updatePolicyMixes", + "([Landroid/media/audiopolicy/AudioMix;[Landroid/media/audiopolicy/" + "AudioMixingRule;)I", + android_media_AudioSystem_updatePolicyMixes), + MAKE_JNI_NATIVE_METHOD("setUidDeviceAffinities", "(I[I[Ljava/lang/String;)I", + android_media_AudioSystem_setUidDeviceAffinities), + MAKE_AUDIO_SYSTEM_METHOD(removeUidDeviceAffinities), + MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_dynamic_policy_callback", + android_media_AudioSystem_registerDynPolicyCallback), + MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_recording_callback", + android_media_AudioSystem_registerRecordingCallback), + MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_routing_callback", + android_media_AudioSystem_registerRoutingCallback), + MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_register_vol_range_init_req_callback", + android_media_AudioSystem_registerVolRangeInitReqCallback), + MAKE_AUDIO_SYSTEM_METHOD(systemReady), + MAKE_AUDIO_SYSTEM_METHOD(getStreamVolumeDB), + MAKE_JNI_NATIVE_METHOD_AUTOSIG("native_get_offload_support", + android_media_AudioSystem_getOffloadSupport), + MAKE_JNI_NATIVE_METHOD("getMicrophones", "(Ljava/util/ArrayList;)I", + android_media_AudioSystem_getMicrophones), + MAKE_JNI_NATIVE_METHOD("getSurroundFormats", "(Ljava/util/Map;)I", + android_media_AudioSystem_getSurroundFormats), + MAKE_JNI_NATIVE_METHOD("getReportedSurroundFormats", "(Ljava/util/ArrayList;)I", + android_media_AudioSystem_getReportedSurroundFormats), + MAKE_AUDIO_SYSTEM_METHOD(setSurroundFormatEnabled), + MAKE_AUDIO_SYSTEM_METHOD(setAssistantServicesUids), + MAKE_AUDIO_SYSTEM_METHOD(setActiveAssistantServicesUids), + MAKE_AUDIO_SYSTEM_METHOD(setA11yServicesUids), + MAKE_AUDIO_SYSTEM_METHOD(isHapticPlaybackSupported), + MAKE_AUDIO_SYSTEM_METHOD(isUltrasoundSupported), + MAKE_JNI_NATIVE_METHOD( + "getHwOffloadFormatsSupportedForBluetoothMedia", "(ILjava/util/ArrayList;)I", + android_media_AudioSystem_getHwOffloadFormatsSupportedForBluetoothMedia), + MAKE_AUDIO_SYSTEM_METHOD(setSupportedSystemUsages), + MAKE_AUDIO_SYSTEM_METHOD(setAllowedCapturePolicy), + MAKE_AUDIO_SYSTEM_METHOD(setRttEnabled), + MAKE_AUDIO_SYSTEM_METHOD(setAudioHalPids), + MAKE_AUDIO_SYSTEM_METHOD(isCallScreeningModeSupported), + MAKE_JNI_NATIVE_METHOD("setDevicesRoleForStrategy", "(II[I[Ljava/lang/String;)I", + android_media_AudioSystem_setDevicesRoleForStrategy), + MAKE_JNI_NATIVE_METHOD("removeDevicesRoleForStrategy", "(II[I[Ljava/lang/String;)I", + android_media_AudioSystem_removeDevicesRoleForStrategy), + MAKE_AUDIO_SYSTEM_METHOD(clearDevicesRoleForStrategy), + MAKE_JNI_NATIVE_METHOD("getDevicesForRoleAndStrategy", "(IILjava/util/List;)I", + android_media_AudioSystem_getDevicesForRoleAndStrategy), + MAKE_JNI_NATIVE_METHOD("setDevicesRoleForCapturePreset", "(II[I[Ljava/lang/String;)I", + android_media_AudioSystem_setDevicesRoleForCapturePreset), + MAKE_JNI_NATIVE_METHOD("addDevicesRoleForCapturePreset", "(II[I[Ljava/lang/String;)I", + android_media_AudioSystem_addDevicesRoleForCapturePreset), + MAKE_JNI_NATIVE_METHOD("removeDevicesRoleForCapturePreset", "(II[I[Ljava/lang/String;)I", + android_media_AudioSystem_removeDevicesRoleForCapturePreset), + MAKE_AUDIO_SYSTEM_METHOD(clearDevicesRoleForCapturePreset), + MAKE_JNI_NATIVE_METHOD("getDevicesForRoleAndCapturePreset", "(IILjava/util/List;)I", + android_media_AudioSystem_getDevicesForRoleAndCapturePreset), + MAKE_JNI_NATIVE_METHOD("getDevicesForAttributes", + "(Landroid/media/AudioAttributes;[Landroid/media/" + "AudioDeviceAttributes;Z)I", + android_media_AudioSystem_getDevicesForAttributes), + MAKE_JNI_NATIVE_METHOD("setUserIdDeviceAffinities", "(I[I[Ljava/lang/String;)I", + android_media_AudioSystem_setUserIdDeviceAffinities), + MAKE_AUDIO_SYSTEM_METHOD(removeUserIdDeviceAffinities), + MAKE_AUDIO_SYSTEM_METHOD(setCurrentImeUid), + MAKE_JNI_NATIVE_METHOD("setVibratorInfos", "(Ljava/util/List;)I", + android_media_AudioSystem_setVibratorInfos), + MAKE_JNI_NATIVE_METHOD("nativeGetSpatializer", + "(Landroid/media/INativeSpatializerCallback;)Landroid/os/IBinder;", + android_media_AudioSystem_getSpatializer), + MAKE_JNI_NATIVE_METHOD("canBeSpatialized", + "(Landroid/media/AudioAttributes;Landroid/media/AudioFormat;" + "[Landroid/media/AudioDeviceAttributes;)Z", + android_media_AudioSystem_canBeSpatialized), + MAKE_JNI_NATIVE_METHOD("nativeGetSoundDose", + "(Landroid/media/ISoundDoseCallback;)Landroid/os/IBinder;", + android_media_AudioSystem_nativeGetSoundDose), + MAKE_JNI_NATIVE_METHOD("getDirectPlaybackSupport", + "(Landroid/media/AudioFormat;Landroid/media/AudioAttributes;)I", + android_media_AudioSystem_getDirectPlaybackSupport), + MAKE_JNI_NATIVE_METHOD("getDirectProfilesForAttributes", + "(Landroid/media/AudioAttributes;Ljava/util/ArrayList;)I", + android_media_AudioSystem_getDirectProfilesForAttributes), + MAKE_JNI_NATIVE_METHOD("getSupportedMixerAttributes", "(ILjava/util/List;)I", + android_media_AudioSystem_getSupportedMixerAttributes), + MAKE_JNI_NATIVE_METHOD("setPreferredMixerAttributes", + "(Landroid/media/AudioAttributes;IILandroid/media/" + "AudioMixerAttributes;)I", + android_media_AudioSystem_setPreferredMixerAttributes), + MAKE_JNI_NATIVE_METHOD("getPreferredMixerAttributes", + "(Landroid/media/AudioAttributes;ILjava/util/List;)I", + android_media_AudioSystem_getPreferredMixerAttributes), + MAKE_JNI_NATIVE_METHOD("clearPreferredMixerAttributes", + "(Landroid/media/AudioAttributes;II)I", + android_media_AudioSystem_clearPreferredMixerAttributes), + MAKE_AUDIO_SYSTEM_METHOD(supportsBluetoothVariableLatency), + MAKE_AUDIO_SYSTEM_METHOD(setBluetoothVariableLatencyEnabled), + MAKE_AUDIO_SYSTEM_METHOD(isBluetoothVariableLatencyEnabled), + MAKE_JNI_NATIVE_METHOD("listenForSystemPropertyChange", + "(Ljava/lang/String;Ljava/lang/Runnable;)J", + android_media_AudioSystem_listenForSystemPropertyChange), + MAKE_JNI_NATIVE_METHOD("triggerSystemPropertyUpdate", "(J)V", + android_media_AudioSystem_triggerSystemPropertyUpdate), +}; static const JNINativeMethod gEventHandlerMethods[] = {MAKE_JNI_NATIVE_METHOD("native_setup", "(Ljava/lang/Object;)V", diff --git a/media/java/android/media/AudioPlaybackConfiguration.java b/media/java/android/media/AudioPlaybackConfiguration.java index 4d6ddfdaef2e..3cd5f5266ef2 100644 --- a/media/java/android/media/AudioPlaybackConfiguration.java +++ b/media/java/android/media/AudioPlaybackConfiguration.java @@ -18,7 +18,9 @@ package android.media; import static android.media.AudioAttributes.ALLOW_CAPTURE_BY_ALL; import static android.media.AudioAttributes.ALLOW_CAPTURE_BY_NONE; +import static android.media.audio.Flags.FLAG_MUTED_BY_PORT_VOLUME_API; +import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; @@ -291,12 +293,24 @@ public final class AudioPlaybackConfiguration implements Parcelable { @SystemApi @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) public static final int MUTED_BY_VOLUME_SHAPER = (1 << 5); + /** + * @hide + * Flag used when muted by the track's port volume. + * + * <p>Note: this will replace the stream volume mute when using the AudioFlinger port volume + * APIs + */ + @SystemApi + @FlaggedApi(FLAG_MUTED_BY_PORT_VOLUME_API) + @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING) + public static final int MUTED_BY_PORT_VOLUME = (1 << 6); /** @hide */ @IntDef( flag = true, value = {MUTED_BY_MASTER, MUTED_BY_STREAM_VOLUME, MUTED_BY_STREAM_MUTED, - MUTED_BY_APP_OPS, MUTED_BY_CLIENT_VOLUME, MUTED_BY_VOLUME_SHAPER}) + MUTED_BY_APP_OPS, MUTED_BY_CLIENT_VOLUME, MUTED_BY_VOLUME_SHAPER, + MUTED_BY_PORT_VOLUME}) @Retention(RetentionPolicy.SOURCE) public @interface PlayerMuteEvent { } @@ -858,6 +872,9 @@ public final class AudioPlaybackConfiguration implements Parcelable { if ((mMutedState & MUTED_BY_VOLUME_SHAPER) != 0) { apcToString.append("volumeShaper "); } + if ((mMutedState & MUTED_BY_PORT_VOLUME) != 0) { + apcToString.append("portVolume "); + } } apcToString.append(" ").append(mFormatInfo); } diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index a8b863bc67f9..bf09cb07a8ed 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -1698,12 +1698,12 @@ public class AudioSystem } /** @hide Wrapper for native methods called from AudioService */ - public static int setStreamVolumeIndexAS(int stream, int index, int device) { + public static int setStreamVolumeIndexAS(int stream, int index, boolean muted, int device) { if (DEBUG_VOLUME) { Log.i(TAG, "setStreamVolumeIndex: " + STREAM_NAMES[stream] - + " dev=" + Integer.toHexString(device) + " idx=" + index); + + " dev=" + Integer.toHexString(device) + " idx=" + index + " muted=" + muted); } - return setStreamVolumeIndex(stream, index, device); + return setStreamVolumeIndex(stream, index, muted, device); } // usage for AudioRecord.startRecordingSync(), must match AudioSystem::sync_event_t @@ -1774,7 +1774,8 @@ public class AudioSystem @UnsupportedAppUsage public static native int initStreamVolume(int stream, int indexMin, int indexMax); @UnsupportedAppUsage - private static native int setStreamVolumeIndex(int stream, int index, int device); + private static native int setStreamVolumeIndex(int stream, int index, boolean muted, + int device); /** @hide */ public static native int getStreamVolumeIndex(int stream, int device); /** @@ -1787,7 +1788,7 @@ public class AudioSystem * @return command completion status. */ public static native int setVolumeIndexForAttributes(@NonNull AudioAttributes attributes, - int index, int device); + int index, boolean muted, int device); /** * @hide * get the volume index for the given {@link AudioAttributes}. diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 020cef170e0c..37a2fba8fcb5 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -69,6 +69,7 @@ import static com.android.media.audio.Flags.disablePrescaleAbsoluteVolume; import static com.android.media.audio.Flags.equalScoLeaVcIndexRange; import static com.android.media.audio.Flags.replaceStreamBtSco; import static com.android.media.audio.Flags.ringerModeAffectsAlarm; +import static com.android.media.audio.Flags.ringMyCar; import static com.android.media.audio.Flags.setStreamVolumeOrder; import static com.android.media.audio.Flags.vgsVssSyncMuteOrder; import static com.android.server.audio.SoundDoseHelper.ACTION_CHECK_MUSIC_ACTIVE; @@ -761,7 +762,7 @@ public class AudioService extends IAudioService.Stub /** Streams that can be muted by system. Do not resolve to aliases when checking. * @see System#MUTE_STREAMS_AFFECTED */ - private int mMuteAffectedStreams; + protected int mMuteAffectedStreams; /** Streams that can be muted by user. Do not resolve to aliases when checking. * @see System#MUTE_STREAMS_AFFECTED */ @@ -1465,7 +1466,8 @@ public class AudioService extends IAudioService.Stub mPlaybackMonitor = new PlaybackActivityMonitor(context, MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM], - device -> onMuteAwaitConnectionTimeout(device)); + device -> onMuteAwaitConnectionTimeout(device), + stream -> isStreamMute(stream)); mPlaybackMonitor.registerPlaybackCallback(mPlaybackActivityMonitor, true); mMediaFocusControl = new MediaFocusControl(mContext, mPlaybackMonitor); @@ -4846,6 +4848,8 @@ public class AudioService extends IAudioService.Stub + replaceStreamBtSco()); pw.println("\tcom.android.media.audio.equalScoLeaVcIndexRange:" + equalScoLeaVcIndexRange()); + pw.println("\tcom.android.media.audio.ringMyCar:" + + ringMyCar()); } private void dumpAudioMode(PrintWriter pw) { @@ -8695,9 +8699,14 @@ public class AudioService extends IAudioService.Stub // Only set audio policy BT SCO stream volume to 0 when the stream is actually muted. // This allows RX path muting by the audio HAL only when explicitly muted but not when // index is just set to 0 to repect BT requirements + boolean muted = false; if (mHasValidStreamType && isVssMuteBijective(mPublicStreamType) && getVssForStreamOrDefault(mPublicStreamType).isFullyMuted()) { - index = 0; + if (ringMyCar()) { + muted = true; + } else { + index = 0; + } } else if (isStreamBluetoothSco(mPublicStreamType) && index == 0) { index = 1; } @@ -8707,13 +8716,14 @@ public class AudioService extends IAudioService.Stub / getVssForStreamOrDefault(mPublicStreamType).getIndexStepFactor()); } + if (DEBUG_VOL) { Log.d(TAG, "setVolumeIndexInt(" + mAudioVolumeGroup.getId() + ", " + index + ", " - + device + ")"); + + muted + ", " + device + ")"); } // Set the volume index - mAudioSystem.setVolumeIndexForAttributes(mAudioAttributes, index, device); + mAudioSystem.setVolumeIndexForAttributes(mAudioAttributes, index, muted, device); } @GuardedBy("AudioService.VolumeStreamState.class") @@ -9297,6 +9307,13 @@ public class AudioService extends IAudioService.Stub } } + /** + * Sends the new volume index on the given device to native. + * + * <p>Make sure the index is consistent with the muting state. When ringMyCar is enabled + * will send the non-zero index together with muted state. Otherwise, index 0 will be sent + * to native for signalising a muted stream. + **/ @GuardedBy("VolumeStreamState.class") private void setStreamVolumeIndex(int index, int device) { // Only set audio policy BT SCO stream volume to 0 when the stream is actually muted. @@ -9311,18 +9328,19 @@ public class AudioService extends IAudioService.Stub / 10; } + boolean muted = ringMyCar() ? isFullyMuted() : false; if (DEBUG_VOL) { - Log.d(TAG, "setStreamVolumeIndexAS(" + mStreamType + ", " + index + ", " + device - + ")"); + Log.d(TAG, "setStreamVolumeIndexAS(streamType=" + mStreamType + ", index=" + index + + ", muted=" + muted + ", device=" + device + ")"); } - mAudioSystem.setStreamVolumeIndexAS(mStreamType, index, device); + mAudioSystem.setStreamVolumeIndexAS(mStreamType, index, muted, device); } // must be called while synchronized VolumeStreamState.class @GuardedBy("VolumeStreamState.class") /*package*/ void applyDeviceVolume_syncVSS(int device) { int index; - if (isFullyMuted()) { + if (isFullyMuted() && !ringMyCar()) { index = 0; } else if (isAbsoluteVolumeDevice(device) || isA2dpAbsoluteVolumeDevice(device) @@ -9356,7 +9374,7 @@ public class AudioService extends IAudioService.Stub for (int i = 0; i < mIndexMap.size(); i++) { final int device = mIndexMap.keyAt(i); if (device != AudioSystem.DEVICE_OUT_DEFAULT) { - if (isFullyMuted()) { + if (isFullyMuted() && !ringMyCar()) { index = 0; } else if (isAbsoluteVolumeDevice(device) || isA2dpAbsoluteVolumeDevice(device) @@ -9391,7 +9409,7 @@ public class AudioService extends IAudioService.Stub } // apply default volume last: by convention , default device volume will be used // by audio policy manager if no explicit volume is present for a given device type - if (isFullyMuted()) { + if (isFullyMuted() && !ringMyCar()) { index = 0; } else { index = (getIndex(AudioSystem.DEVICE_OUT_DEFAULT) + 5)/10; diff --git a/services/core/java/com/android/server/audio/AudioSystemAdapter.java b/services/core/java/com/android/server/audio/AudioSystemAdapter.java index 5cabddea9c17..e86c34cab88a 100644 --- a/services/core/java/com/android/server/audio/AudioSystemAdapter.java +++ b/services/core/java/com/android/server/audio/AudioSystemAdapter.java @@ -547,13 +547,14 @@ public class AudioSystemAdapter implements AudioSystem.RoutingUpdateCallback, * @param device * @return */ - public int setStreamVolumeIndexAS(int stream, int index, int device) { - return AudioSystem.setStreamVolumeIndexAS(stream, index, device); + public int setStreamVolumeIndexAS(int stream, int index, boolean muted, int device) { + return AudioSystem.setStreamVolumeIndexAS(stream, index, muted, device); } /** Same as {@link AudioSystem#setVolumeIndexForAttributes(AudioAttributes, int, int)} */ - public int setVolumeIndexForAttributes(AudioAttributes attributes, int index, int device) { - return AudioSystem.setVolumeIndexForAttributes(attributes, index, device); + public int setVolumeIndexForAttributes(AudioAttributes attributes, int index, boolean muted, + int device) { + return AudioSystem.setVolumeIndexForAttributes(attributes, index, muted, device); } /** diff --git a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java index a734e73d213b..b63b07f0453e 100644 --- a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java +++ b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java @@ -72,6 +72,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Consumer; +import java.util.function.Function; /** * Class to receive and dispatch updates from AudioSystem about recording configurations. @@ -160,18 +161,22 @@ public final class PlaybackActivityMonitor private final Context mContext; private int mSavedAlarmVolume = -1; + private boolean mSavedAlarmMuted = false; + private final Function<Integer, Boolean> mIsStreamMutedCb; private final int mMaxAlarmVolume; private int mPrivilegedAlarmActiveCount = 0; private final Consumer<AudioDeviceAttributes> mMuteAwaitConnectionTimeoutCb; private final FadeOutManager mFadeOutManager = new FadeOutManager(); PlaybackActivityMonitor(Context context, int maxAlarmVolume, - Consumer<AudioDeviceAttributes> muteTimeoutCallback) { + Consumer<AudioDeviceAttributes> muteTimeoutCallback, + Function<Integer, Boolean> isStreamMutedCb) { mContext = context; mMaxAlarmVolume = maxAlarmVolume; PlayMonitorClient.sListenerDeathMonitor = this; AudioPlaybackConfiguration.sPlayerDeathMonitor = this; mMuteAwaitConnectionTimeoutCb = muteTimeoutCallback; + mIsStreamMutedCb = isStreamMutedCb; initEventHandler(); } @@ -332,8 +337,9 @@ public final class PlaybackActivityMonitor if (mPrivilegedAlarmActiveCount++ == 0) { mSavedAlarmVolume = AudioSystem.getStreamVolumeIndex( AudioSystem.STREAM_ALARM, AudioSystem.DEVICE_OUT_SPEAKER); + mSavedAlarmMuted = mIsStreamMutedCb.apply(AudioSystem.STREAM_ALARM); AudioSystem.setStreamVolumeIndexAS(AudioSystem.STREAM_ALARM, - mMaxAlarmVolume, AudioSystem.DEVICE_OUT_SPEAKER); + mMaxAlarmVolume, /*muted=*/false, AudioSystem.DEVICE_OUT_SPEAKER); } } else if (event != AudioPlaybackConfiguration.PLAYER_STATE_STARTED && apc.getPlayerState() == AudioPlaybackConfiguration.PLAYER_STATE_STARTED) { @@ -342,7 +348,8 @@ public final class PlaybackActivityMonitor AudioSystem.STREAM_ALARM, AudioSystem.DEVICE_OUT_SPEAKER) == mMaxAlarmVolume) { AudioSystem.setStreamVolumeIndexAS(AudioSystem.STREAM_ALARM, - mSavedAlarmVolume, AudioSystem.DEVICE_OUT_SPEAKER); + mSavedAlarmVolume, mSavedAlarmMuted, + AudioSystem.DEVICE_OUT_SPEAKER); } } } diff --git a/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java b/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java index 3e2949d60183..de5564cb7704 100644 --- a/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/audio/AudioDeviceVolumeManagerTest.java @@ -20,6 +20,8 @@ import static com.android.media.audio.Flags.FLAG_ABS_VOLUME_INDEX_FIX; import static com.android.media.audio.Flags.FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME; import static com.android.media.audio.Flags.absVolumeIndexFix; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -109,12 +111,13 @@ public class AudioDeviceVolumeManagerTest { mAudioService.setDeviceVolume(volMin, usbDevice, mPackageName); mTestLooper.dispatchAll(); verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - AudioManager.STREAM_MUSIC, minIndex, AudioSystem.DEVICE_OUT_USB_DEVICE); + eq(AudioManager.STREAM_MUSIC), eq(minIndex), anyBoolean(), + eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); mAudioService.setDeviceVolume(volMid, usbDevice, mPackageName); mTestLooper.dispatchAll(); verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - AudioManager.STREAM_MUSIC, midIndex, AudioSystem.DEVICE_OUT_USB_DEVICE); + AudioManager.STREAM_MUSIC, midIndex, false, AudioSystem.DEVICE_OUT_USB_DEVICE); } @Test @@ -151,7 +154,7 @@ public class AudioDeviceVolumeManagerTest { // Stream volume changes verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - AudioManager.STREAM_MUSIC, targetIndex, + AudioManager.STREAM_MUSIC, targetIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET); } @@ -162,7 +165,7 @@ public class AudioDeviceVolumeManagerTest { mTestLooper.dispatchAll(); verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - AudioManager.STREAM_MUSIC, maxIndex, + AudioManager.STREAM_MUSIC, maxIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET); } @@ -193,8 +196,8 @@ public class AudioDeviceVolumeManagerTest { } // Stream volume changes verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - AudioManager.STREAM_MUSIC, passedIndex, - AudioSystem.DEVICE_OUT_BLE_HEADSET); + AudioManager.STREAM_MUSIC, passedIndex, false, + AudioSystem.DEVICE_OUT_BLE_HEADSET); } // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:4) @@ -207,7 +210,7 @@ public class AudioDeviceVolumeManagerTest { passedIndex = 4; } verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - AudioManager.STREAM_MUSIC, passedIndex, - AudioSystem.DEVICE_OUT_BLE_HEADSET); + AudioManager.STREAM_MUSIC, passedIndex, false, + AudioSystem.DEVICE_OUT_BLE_HEADSET); } } diff --git a/services/tests/servicestests/src/com/android/server/audio/NoOpAudioSystemAdapter.java b/services/tests/servicestests/src/com/android/server/audio/NoOpAudioSystemAdapter.java index 96ac5d251ffd..ce59a86c6ca3 100644 --- a/services/tests/servicestests/src/com/android/server/audio/NoOpAudioSystemAdapter.java +++ b/services/tests/servicestests/src/com/android/server/audio/NoOpAudioSystemAdapter.java @@ -132,12 +132,13 @@ public class NoOpAudioSystemAdapter extends AudioSystemAdapter { } @Override - public int setStreamVolumeIndexAS(int stream, int index, int device) { + public int setStreamVolumeIndexAS(int stream, int index, boolean muted, int device) { return AudioSystem.AUDIO_STATUS_OK; } @Override - public int setVolumeIndexForAttributes(AudioAttributes attributes, int index, int device) { + public int setVolumeIndexForAttributes(AudioAttributes attributes, int index, boolean muted, + int device) { return AudioSystem.AUDIO_STATUS_OK; } diff --git a/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java b/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java index dc8c1b9c8a10..6b41c434b80f 100644 --- a/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java +++ b/services/tests/servicestests/src/com/android/server/audio/VolumeHelperTest.java @@ -18,6 +18,7 @@ package com.android.server.audio; import static android.media.AudioManager.ADJUST_LOWER; import static android.media.AudioManager.ADJUST_MUTE; import static android.media.AudioManager.ADJUST_RAISE; +import static android.media.AudioManager.ADJUST_UNMUTE; import static android.media.AudioManager.DEVICE_OUT_BLE_SPEAKER; import static android.media.AudioManager.DEVICE_OUT_BLUETOOTH_SCO; import static android.media.AudioManager.DEVICE_OUT_SPEAKER; @@ -41,13 +42,13 @@ import static android.view.KeyEvent.KEYCODE_VOLUME_UP; import static com.android.media.audio.Flags.FLAG_ABS_VOLUME_INDEX_FIX; import static com.android.media.audio.Flags.FLAG_DISABLE_PRESCALE_ABSOLUTE_VOLUME; +import static com.android.media.audio.Flags.FLAG_RING_MY_CAR; import static com.android.media.audio.Flags.absVolumeIndexFix; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; @@ -180,6 +181,10 @@ public class VolumeHelperTest { } return mStreamDevice.get(stream); } + + public void setMuteAffectedStreams(int muteAffectedStreams) { + mMuteAffectedStreams = muteAffectedStreams; + } } private static class TestDeviceVolumeBehaviorDispatcherStub @@ -223,6 +228,7 @@ public class VolumeHelperTest { mSettingsAdapter, mAudioVolumeGroupHelper, mMockAudioPolicy, mTestLooper.getLooper(), mMockAppOpsManager, mMockPermissionEnforcer, mMockPermissionProvider); + mAudioService.setMuteAffectedStreams(AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED); mTestLooper.dispatchAll(); prepareAudioServiceState(); @@ -258,6 +264,8 @@ public class VolumeHelperTest { for (int streamType : usedStreamTypes) { mAudioService.setStreamVolume(streamType, DEFAULT_STREAM_VOLUME, /*flags=*/0, mContext.getOpPackageName()); + mAudioService.adjustStreamVolume(streamType, ADJUST_UNMUTE, /*flags=*/0, + mContext.getOpPackageName()); } if (!mIsAutomotive) { @@ -301,7 +309,20 @@ public class VolumeHelperTest { mTestLooper.dispatchAll(); verify(mSpyAudioSystem).setStreamVolumeIndexAS( - eq(STREAM_MUSIC), eq(newIndex), eq(DEVICE_OUT_USB_DEVICE)); + STREAM_MUSIC, newIndex, /*muted=*/false, DEVICE_OUT_USB_DEVICE); + } + + @Test + @RequiresFlagsEnabled(FLAG_RING_MY_CAR) + public void adjustStreamVolume_adjustMute_callsASSetStreamVolumeIndex() throws Exception { + int currentIndex = mAudioService.getStreamVolume(STREAM_MUSIC); + + mAudioService.adjustStreamVolume(STREAM_MUSIC, ADJUST_MUTE, /*flags=*/0, + mContext.getOpPackageName()); + mTestLooper.dispatchAll(); + + verify(mSpyAudioSystem).setStreamVolumeIndexAS( + eq(STREAM_MUSIC), eq(currentIndex), /*muted=*/eq(true), anyInt()); } @Test @@ -325,7 +346,7 @@ public class VolumeHelperTest { mTestLooper.dispatchAll(); verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - eq(STREAM_MUSIC), anyInt(), eq(DEVICE_OUT_USB_DEVICE)); + eq(STREAM_MUSIC), anyInt(), anyBoolean(), eq(DEVICE_OUT_USB_DEVICE)); } @Test @@ -341,7 +362,7 @@ public class VolumeHelperTest { mTestLooper.dispatchAll(); verify(mSpyAudioSystem).setStreamVolumeIndexAS( - eq(STREAM_MUSIC), anyInt(), eq(DEVICE_OUT_USB_DEVICE)); + eq(STREAM_MUSIC), anyInt(), eq(false), eq(DEVICE_OUT_USB_DEVICE)); } // --------------- Volume Group APIs --------------- @@ -356,15 +377,15 @@ public class VolumeHelperTest { mAudioService.setDeviceForStream(STREAM_MUSIC, DEVICE_OUT_USB_DEVICE); mAudioService.setVolumeGroupVolumeIndex(mAudioMusicVolumeGroup.getId(), circularNoMinMaxIncrementVolume(STREAM_MUSIC), /*flags=*/0, - mContext.getOpPackageName(), /*attributionTag*/null); + mContext.getOpPackageName(), /*attributionTag*/null); mTestLooper.dispatchAll(); - verify(mSpyAudioSystem).setVolumeIndexForAttributes(any(), anyInt(), + verify(mSpyAudioSystem).setVolumeIndexForAttributes(any(), anyInt(), eq(false), eq(DEVICE_OUT_USB_DEVICE)); } @Test - public void adjustVolumeGroupVolume_callsASSetVolumeIndexForAttributes() throws Exception { + public void adjustVolumeGroupVolume_callsASSetStreamVolumeIndexAS() throws Exception { assumeNotNull(mAudioMusicVolumeGroup); mAudioService.setDeviceForStream(STREAM_MUSIC, DEVICE_OUT_USB_DEVICE); @@ -372,8 +393,24 @@ public class VolumeHelperTest { ADJUST_LOWER, /*flags=*/0, mContext.getOpPackageName()); mTestLooper.dispatchAll(); - verify(mSpyAudioSystem).setVolumeIndexForAttributes( - any(), anyInt(), eq(DEVICE_OUT_USB_DEVICE)); + // adjust calls setStreamVolumeIndexAS instead of setVolumeIndexForAttributes + verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( + anyInt(), anyInt(), anyBoolean(), eq(DEVICE_OUT_USB_DEVICE)); + } + + @Test + @RequiresFlagsEnabled(FLAG_RING_MY_CAR) + public void adjustVolumeGroupVolume_adjustMute_callsASSetStreamVolumeIndexAS() + throws Exception { + assumeNotNull(mAudioMusicVolumeGroup); + + mAudioService.adjustVolumeGroupVolume(mAudioMusicVolumeGroup.getId(), + ADJUST_MUTE, /*flags=*/0, mContext.getOpPackageName()); + mTestLooper.dispatchAll(); + + // adjust calls setStreamVolumeIndexAS instead of setVolumeIndexForAttributes + verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( + anyInt(), anyInt(), eq(true), anyInt()); } @Test @@ -437,7 +474,7 @@ public class VolumeHelperTest { @Test public void check_isStreamAffectedByMute() { - assertFalse(mAudioService.isStreamAffectedByMute(STREAM_VOICE_CALL)); + assertTrue(mAudioService.isStreamAffectedByMute(STREAM_VOICE_CALL)); } // --------------------- Volume Flag Check -------------------- @@ -452,14 +489,14 @@ public class VolumeHelperTest { mContext.getOpPackageName()); mTestLooper.dispatchAll(); verify(mSpyAudioSystem).setStreamVolumeIndexAS( - eq(STREAM_NOTIFICATION), anyInt(), eq(DEVICE_OUT_BLE_SPEAKER)); + eq(STREAM_NOTIFICATION), anyInt(), eq(false), eq(DEVICE_OUT_BLE_SPEAKER)); reset(mSpyAudioSystem); mAudioService.adjustStreamVolume(STREAM_NOTIFICATION, ADJUST_LOWER, FLAG_BLUETOOTH_ABS_VOLUME, mContext.getOpPackageName()); mTestLooper.dispatchAll(); verify(mSpyAudioSystem).setStreamVolumeIndexAS( - eq(STREAM_NOTIFICATION), anyInt(), eq(DEVICE_OUT_BLE_SPEAKER)); + eq(STREAM_NOTIFICATION), anyInt(), eq(false), eq(DEVICE_OUT_BLE_SPEAKER)); } @Test @@ -471,13 +508,13 @@ public class VolumeHelperTest { mContext.getOpPackageName()); mTestLooper.dispatchAll(); verify(mSpyAudioSystem, times(0)).setStreamVolumeIndexAS( - eq(STREAM_NOTIFICATION), eq(newIndex), eq(DEVICE_OUT_BLE_SPEAKER)); + eq(STREAM_NOTIFICATION), eq(newIndex), eq(false), eq(DEVICE_OUT_BLE_SPEAKER)); mAudioService.adjustStreamVolume(STREAM_NOTIFICATION, ADJUST_LOWER, FLAG_BLUETOOTH_ABS_VOLUME, mContext.getOpPackageName()); mTestLooper.dispatchAll(); verify(mSpyAudioSystem, times(0)).setStreamVolumeIndexAS( - eq(STREAM_NOTIFICATION), anyInt(), eq(DEVICE_OUT_BLE_SPEAKER)); + eq(STREAM_NOTIFICATION), anyInt(), eq(false), eq(DEVICE_OUT_BLE_SPEAKER)); } @Test @@ -523,7 +560,7 @@ public class VolumeHelperTest { mTestLooper.dispatchAll(); verify(mSpyAudioSystem, times(0)).setStreamVolumeIndexAS( - eq(STREAM_MUSIC), anyInt(), anyInt()); + eq(STREAM_MUSIC), anyInt(), eq(false), anyInt()); } @Test @@ -537,7 +574,7 @@ public class VolumeHelperTest { mTestLooper.dispatchAll(); verify(mSpyAudioSystem, times(0)).setStreamVolumeIndexAS( - eq(STREAM_VOICE_CALL), anyInt(), eq(DEVICE_OUT_USB_DEVICE)); + eq(STREAM_VOICE_CALL), anyInt(), eq(false), eq(DEVICE_OUT_USB_DEVICE)); mAudioService.setDeviceForStream(STREAM_BLUETOOTH_SCO, DEVICE_OUT_BLUETOOTH_SCO); mAudioService.adjustStreamVolume(STREAM_BLUETOOTH_SCO, ADJUST_MUTE, /*flags=*/0, @@ -545,7 +582,7 @@ public class VolumeHelperTest { mTestLooper.dispatchAll(); verify(mSpyAudioSystem, times(0)).setStreamVolumeIndexAS( - eq(STREAM_BLUETOOTH_SCO), anyInt(), eq(DEVICE_OUT_USB_DEVICE)); + eq(STREAM_BLUETOOTH_SCO), anyInt(), eq(false), eq(DEVICE_OUT_USB_DEVICE)); } // ----------------- AudioDeviceVolumeManager ----------------- @@ -568,18 +605,18 @@ public class VolumeHelperTest { mTestLooper.dispatchAll(); // there is a min/max index mismatch in automotive - assertEquals(volMin, mAudioService.getDeviceVolume(volMin, usbDevice, - mContext.getOpPackageName())); + assertEquals(volMin.getVolumeIndex(), mAudioService.getDeviceVolume(volMin, usbDevice, + mContext.getOpPackageName()).getVolumeIndex()); verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - eq(STREAM_MUSIC), anyInt(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); + eq(STREAM_MUSIC), anyInt(), anyBoolean(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); mAudioService.setDeviceVolume(volMid, usbDevice, mContext.getOpPackageName()); mTestLooper.dispatchAll(); // there is a min/max index mismatch in automotive - assertEquals(volMid, mAudioService.getDeviceVolume(volMid, usbDevice, - mContext.getOpPackageName())); + assertEquals(volMid.getVolumeIndex(), mAudioService.getDeviceVolume(volMid, usbDevice, + mContext.getOpPackageName()).getVolumeIndex()); verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - eq(STREAM_MUSIC), anyInt(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); + eq(STREAM_MUSIC), anyInt(), anyBoolean(), eq(AudioSystem.DEVICE_OUT_USB_DEVICE)); } @Test @@ -617,8 +654,7 @@ public class VolumeHelperTest { mAudioService.getDeviceVolume(volCur, bleDevice, mContext.getOpPackageName())); // Stream volume changes verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - STREAM_MUSIC, targetIndex, - AudioSystem.DEVICE_OUT_BLE_HEADSET); + STREAM_MUSIC, targetIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET); } // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:4) @@ -630,8 +666,7 @@ public class VolumeHelperTest { assertEquals(volIndex4, mAudioService.getDeviceVolume(volIndex4, bleDevice, mContext.getOpPackageName())); verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - STREAM_MUSIC, maxIndex, - AudioSystem.DEVICE_OUT_BLE_HEADSET); + STREAM_MUSIC, maxIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET); } @Test @@ -660,8 +695,7 @@ public class VolumeHelperTest { } // Stream volume changes verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - STREAM_MUSIC, passedIndex, - AudioSystem.DEVICE_OUT_BLE_HEADSET); + STREAM_MUSIC, passedIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET); } // Adjust stream volume with FLAG_ABSOLUTE_VOLUME set (index:4) @@ -674,8 +708,7 @@ public class VolumeHelperTest { passedIndex = 4; } verify(mSpyAudioSystem, atLeast(1)).setStreamVolumeIndexAS( - STREAM_MUSIC, passedIndex, - AudioSystem.DEVICE_OUT_BLE_HEADSET); + STREAM_MUSIC, passedIndex, false, AudioSystem.DEVICE_OUT_BLE_HEADSET); } // ---------------- DeviceVolumeBehaviorTest ---------------- |