Fix volume controls show media instead of call volume during a call. am: 188ab32778

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21610510

Change-Id: I8b6e130b00213224011aea8b4ebfb0cff462b07f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Bishoy Gendy
2023-03-03 17:40:23 +00:00
committed by Automerger Merge Worker

View File

@@ -1950,9 +1950,9 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_MUTE: {
// If we have a session send it the volume command, otherwise
// use the suggested stream.
if (mMediaController != null) {
// If we have a session and no active phone call send it the volume command,
// otherwise use the suggested stream.
if (mMediaController != null && !isActivePhoneCallKnown()) {
getMediaSessionManager().dispatchVolumeKeyEventToSessionAsSystemService(event,
mMediaController.getSessionToken());
} else {
@@ -2003,6 +2003,18 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
return false;
}
private boolean isActivePhoneCallKnown() {
boolean isActivePhoneCallKnown = false;
AudioManager audioManager =
(AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
int audioManagerMode = audioManager.getMode();
if (audioManagerMode == AudioManager.MODE_IN_CALL
|| audioManagerMode == AudioManager.MODE_IN_COMMUNICATION) {
isActivePhoneCallKnown = true;
}
return isActivePhoneCallKnown;
}
private KeyguardManager getKeyguardManager() {
if (mKeyguardManager == null) {
mKeyguardManager = (KeyguardManager) getContext().getSystemService(