Improved audio focus handling for CARSM
Eliminates the REINITIALIZE message, which was originally written for
compatiblity with the old CallAudioManager. Resetting the audio route
back to the default state now occurs automatically whenever we lose
audio focus.
Also adds logging session support to InCallTonePlayer
Bug: 27555048
Change-Id: I4b7bb6c81aa2a38670fd3768dd65d4b3e24841eb
diff --git a/src/com/android/server/telecom/CallAudioManager.java b/src/com/android/server/telecom/CallAudioManager.java
index 97f8bc8..3028398 100644
--- a/src/com/android/server/telecom/CallAudioManager.java
+++ b/src/com/android/server/telecom/CallAudioManager.java
@@ -156,12 +156,6 @@
mCalls.remove(call);
onCallLeavingState(call, call.getState());
-
- if (mCallsManager.getCalls().isEmpty()) {
- Log.v(this, "all calls removed, resetting system audio to default state");
- mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
- CallAudioRouteStateMachine.REINITIALIZE);
- }
}
@Override
diff --git a/src/com/android/server/telecom/CallAudioRouteStateMachine.java b/src/com/android/server/telecom/CallAudioRouteStateMachine.java
index 1bb3e10..5f722dd 100644
--- a/src/com/android/server/telecom/CallAudioRouteStateMachine.java
+++ b/src/com/android/server/telecom/CallAudioRouteStateMachine.java
@@ -92,8 +92,6 @@
public static final int USER_SWITCH_SPEAKER = 1104;
public static final int USER_SWITCH_BASELINE_ROUTE = 1105;
- public static final int REINITIALIZE = 2001;
-
public static final int MUTE_ON = 3001;
public static final int MUTE_OFF = 3002;
public static final int TOGGLE_MUTE = 3003;
@@ -128,8 +126,6 @@
put(USER_SWITCH_SPEAKER, "USER_SWITCH_SPEAKER");
put(USER_SWITCH_BASELINE_ROUTE, "USER_SWITCH_BASELINE_ROUTE");
- put(REINITIALIZE, "REINITIALIZE");
-
put(MUTE_ON, "MUTE_ON");
put(MUTE_OFF, "MUTE_OFF");
put(TOGGLE_MUTE, "TOGGLE_MUTE");
@@ -212,15 +208,6 @@
case USER_SWITCH_BASELINE_ROUTE:
sendInternalMessage(calculateBaselineRouteMessage(true));
return HANDLED;
- case REINITIALIZE:
- CallAudioState initState = getInitialAudioState();
- mAvailableRoutes = initState.getSupportedRouteMask();
- mIsMuted = initState.isMuted();
- setMuteOn(mIsMuted);
- mWasOnSpeaker = initState.getRoute() == ROUTE_SPEAKER;
- mHasUserExplicitlyLeftBluetooth = false;
- transitionTo(mRouteCodeToQuiescentState.get(initState.getRoute()));
- return HANDLED;
default:
return NOT_HANDLED;
}
@@ -291,7 +278,7 @@
return HANDLED;
case SWITCH_FOCUS:
if (msg.arg1 == NO_FOCUS) {
- transitionTo(mQuiescentEarpieceRoute);
+ reinitialize();
}
return HANDLED;
default:
@@ -464,7 +451,7 @@
return HANDLED;
case SWITCH_FOCUS:
if (msg.arg1 == NO_FOCUS) {
- transitionTo(mQuiescentHeadsetRoute);
+ reinitialize();
}
return HANDLED;
default:
@@ -647,7 +634,7 @@
return HANDLED;
case SWITCH_FOCUS:
if (msg.arg1 == NO_FOCUS) {
- transitionTo(mQuiescentBluetoothRoute);
+ reinitialize();
}
return HANDLED;
default:
@@ -819,7 +806,7 @@
return HANDLED;
case SWITCH_FOCUS:
if (msg.arg1 == NO_FOCUS) {
- transitionTo(mQuiescentSpeakerRoute);
+ reinitialize();
}
return HANDLED;
default:
@@ -1029,7 +1016,7 @@
mLastKnownCallAudioState = initState;
mAvailableRoutes = initState.getSupportedRouteMask();
mIsMuted = initState.isMuted();
- mWasOnSpeaker = initState.getRoute() == ROUTE_SPEAKER;
+ mWasOnSpeaker = false;
mStatusBarNotifier.notifyMute(initState.isMuted());
mStatusBarNotifier.notifySpeakerphone(initState.getRoute() == CallAudioState.ROUTE_SPEAKER);
@@ -1283,4 +1270,14 @@
return isExplicitUserRequest ? USER_SWITCH_EARPIECE : SWITCH_EARPIECE;
}
}
+
+ private void reinitialize() {
+ CallAudioState initState = getInitialAudioState();
+ mAvailableRoutes = initState.getSupportedRouteMask();
+ mIsMuted = initState.isMuted();
+ setMuteOn(mIsMuted);
+ mWasOnSpeaker = false;
+ mHasUserExplicitlyLeftBluetooth = false;
+ transitionTo(mRouteCodeToQuiescentState.get(initState.getRoute()));
+ }
}
\ No newline at end of file
diff --git a/src/com/android/server/telecom/InCallTonePlayer.java b/src/com/android/server/telecom/InCallTonePlayer.java
index 78c1395..ca82673 100644
--- a/src/com/android/server/telecom/InCallTonePlayer.java
+++ b/src/com/android/server/telecom/InCallTonePlayer.java
@@ -105,6 +105,9 @@
/** Telecom lock object. */
private final TelecomSystem.SyncRoot mLock;
+ private Session mSession;
+ private final Object mSessionLock = new Object();
+
/**
* Initializes the tone player. Private; use the {@link Factory} to create tone players.
*
@@ -127,6 +130,12 @@
public void run() {
ToneGenerator toneGenerator = null;
try {
+ synchronized (mSessionLock) {
+ if (mSession != null) {
+ Log.continueSession(mSession, "ICTP.r");
+ mSession = null;
+ }
+ }
Log.d(this, "run(toneId = %s)", mToneId);
final int toneType; // Passed to ToneGenerator.startTone.
@@ -256,6 +265,13 @@
mCallAudioManager.setIsTonePlaying(true);
}
+ synchronized (mSessionLock) {
+ if (mSession != null) {
+ Log.cancelSubsession(mSession);
+ }
+ mSession = Log.createSubsession();
+ }
+
start();
}