diff options
author | Hall Liu <hallliu@google.com> | 2017-08-25 19:42:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-08-25 19:42:22 +0000 |
commit | db86aa5bc50f8c6440dce1672864e29aaeba4a5d (patch) | |
tree | 6b5b1aacac14df34d8e710b3cb03f560f59cf25a | |
parent | 1cfe6e63dc492f92fdb6ad0b1c1420260c780678 (diff) | |
parent | 629ea10deba347f47ff4b79d1afc14c22d700d68 (diff) | |
download | android_packages_services_Telecomm-db86aa5bc50f8c6440dce1672864e29aaeba4a5d.tar.gz android_packages_services_Telecomm-db86aa5bc50f8c6440dce1672864e29aaeba4a5d.tar.bz2 android_packages_services_Telecomm-db86aa5bc50f8c6440dce1672864e29aaeba4a5d.zip |
Merge "Include Bluetooth in baseline route calculations" into oc-mr1-dev
3 files changed, 30 insertions, 14 deletions
diff --git a/src/com/android/server/telecom/CallAudioManager.java b/src/com/android/server/telecom/CallAudioManager.java index ddce98e4..705d5a85 100644 --- a/src/com/android/server/telecom/CallAudioManager.java +++ b/src/com/android/server/telecom/CallAudioManager.java @@ -408,7 +408,8 @@ public class CallAudioManager extends CallsManagerListenerBase { return; case CallAudioState.ROUTE_WIRED_OR_EARPIECE: mCallAudioRouteStateMachine.sendMessageWithSessionInfo( - CallAudioRouteStateMachine.USER_SWITCH_BASELINE_ROUTE); + CallAudioRouteStateMachine.USER_SWITCH_BASELINE_ROUTE, + CallAudioRouteStateMachine.NO_INCLUDE_BLUETOOTH_IN_BASELINE); return; default: Log.wtf(this, "Invalid route specified: %d", route); diff --git a/src/com/android/server/telecom/CallAudioRouteStateMachine.java b/src/com/android/server/telecom/CallAudioRouteStateMachine.java index 2e98ac97..c6952447 100644 --- a/src/com/android/server/telecom/CallAudioRouteStateMachine.java +++ b/src/com/android/server/telecom/CallAudioRouteStateMachine.java @@ -116,6 +116,10 @@ public class CallAudioRouteStateMachine extends StateMachine { public static final int ACTIVE_FOCUS = 2; public static final int RINGING_FOCUS = 3; + /** Valid values for the argument for SWITCH_BASELINE_ROUTE */ + public static final int NO_INCLUDE_BLUETOOTH_IN_BASELINE = 0; + public static final int INCLUDE_BLUETOOTH_IN_BASELINE = 1; + @VisibleForTesting public static final SparseArray<String> AUDIO_ROUTE_TO_LOG_EVENT = new SparseArray<String>() {{ put(CallAudioState.ROUTE_BLUETOOTH, LogUtils.Events.AUDIO_ROUTE_BT); @@ -232,10 +236,12 @@ public class CallAudioRouteStateMachine extends StateMachine { removedRoutes |= ROUTE_BLUETOOTH; break; case SWITCH_BASELINE_ROUTE: - sendInternalMessage(calculateBaselineRouteMessage(false)); + sendInternalMessage(calculateBaselineRouteMessage(false, + msg.arg1 == INCLUDE_BLUETOOTH_IN_BASELINE)); return HANDLED; case USER_SWITCH_BASELINE_ROUTE: - sendInternalMessage(calculateBaselineRouteMessage(true)); + sendInternalMessage(calculateBaselineRouteMessage(true, + msg.arg1 == INCLUDE_BLUETOOTH_IN_BASELINE)); return HANDLED; case SWITCH_FOCUS: mAudioFocusType = msg.arg1; @@ -611,7 +617,7 @@ public class CallAudioRouteStateMachine extends StateMachine { if (mWasOnSpeaker) { sendInternalMessage(SWITCH_SPEAKER); } else { - sendInternalMessage(SWITCH_BASELINE_ROUTE); + sendInternalMessage(SWITCH_BASELINE_ROUTE, INCLUDE_BLUETOOTH_IN_BASELINE); } return HANDLED; case BT_AUDIO_DISCONNECT: @@ -701,7 +707,7 @@ public class CallAudioRouteStateMachine extends StateMachine { } return HANDLED; case BT_AUDIO_DISCONNECT: - sendInternalMessage(SWITCH_BASELINE_ROUTE); + sendInternalMessage(SWITCH_BASELINE_ROUTE, NO_INCLUDE_BLUETOOTH_IN_BASELINE); return HANDLED; default: return NOT_HANDLED; @@ -782,7 +788,7 @@ public class CallAudioRouteStateMachine extends StateMachine { return HANDLED; case BT_AUDIO_DISCONNECT: // BT SCO might be connected when in-band ringing is enabled - sendInternalMessage(SWITCH_BASELINE_ROUTE); + sendInternalMessage(SWITCH_BASELINE_ROUTE, NO_INCLUDE_BLUETOOTH_IN_BASELINE); return HANDLED; default: return NOT_HANDLED; @@ -882,7 +888,7 @@ public class CallAudioRouteStateMachine extends StateMachine { // in the bluetooth route. return HANDLED; case DISCONNECT_BLUETOOTH: - sendInternalMessage(SWITCH_BASELINE_ROUTE); + sendInternalMessage(SWITCH_BASELINE_ROUTE, NO_INCLUDE_BLUETOOTH_IN_BASELINE); mWasOnSpeaker = false; return HANDLED; case DISCONNECT_WIRED_HEADSET: @@ -1091,7 +1097,7 @@ public class CallAudioRouteStateMachine extends StateMachine { // Nothing to do here return HANDLED; case DISCONNECT_DOCK: - sendInternalMessage(SWITCH_BASELINE_ROUTE); + sendInternalMessage(SWITCH_BASELINE_ROUTE, INCLUDE_BLUETOOTH_IN_BASELINE); return HANDLED; default: return NOT_HANDLED; @@ -1397,6 +1403,10 @@ public class CallAudioRouteStateMachine extends StateMachine { } private void sendInternalMessage(int messageCode) { + sendInternalMessage(messageCode, 0); + } + + private void sendInternalMessage(int messageCode, int arg1) { // Internal messages are messages which the state machine sends to itself in the // course of processing externally-sourced messages. We want to send these messages at // the front of the queue in order to make actions appear atomic to the user and to @@ -1411,9 +1421,9 @@ public class CallAudioRouteStateMachine extends StateMachine { // 7. State machine handler processes SWITCH_HEADSET. Session subsession = Log.createSubsession(); if(subsession != null) { - sendMessageAtFrontOfQueue(messageCode, subsession); + sendMessageAtFrontOfQueue(messageCode, arg1, 0, subsession); } else { - sendMessageAtFrontOfQueue(messageCode); + sendMessageAtFrontOfQueue(messageCode, arg1); } } @@ -1466,7 +1476,8 @@ public class CallAudioRouteStateMachine extends StateMachine { return true; } - private int calculateBaselineRouteMessage(boolean isExplicitUserRequest) { + private int calculateBaselineRouteMessage(boolean isExplicitUserRequest, + boolean includeBluetooth) { boolean isSkipEarpiece = false; if (!isExplicitUserRequest) { synchronized (mLock) { @@ -1475,7 +1486,11 @@ public class CallAudioRouteStateMachine extends StateMachine { isSkipEarpiece = mCallsManager.hasVideoCall(); } } - if ((mAvailableRoutes & ROUTE_EARPIECE) != 0 && !isSkipEarpiece) { + if ((mAvailableRoutes & ROUTE_BLUETOOTH) != 0 + && !mHasUserExplicitlyLeftBluetooth + && includeBluetooth) { + return isExplicitUserRequest ? USER_SWITCH_BLUETOOTH : SWITCH_BLUETOOTH; + } else if ((mAvailableRoutes & ROUTE_EARPIECE) != 0 && !isSkipEarpiece) { return isExplicitUserRequest ? USER_SWITCH_EARPIECE : SWITCH_EARPIECE; } else if ((mAvailableRoutes & ROUTE_WIRED_HEADSET) != 0) { return isExplicitUserRequest ? USER_SWITCH_HEADSET : SWITCH_HEADSET; @@ -1503,7 +1518,7 @@ public class CallAudioRouteStateMachine extends StateMachine { // Move to baseline route in the case the current route is no longer available. if ((mAvailableRoutes & currentState.getRoute()) == 0) { - sendInternalMessage(calculateBaselineRouteMessage(false)); + sendInternalMessage(calculateBaselineRouteMessage(false, true)); } } diff --git a/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java b/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java index 129d86e0..291152f7 100644 --- a/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java +++ b/tests/src/com/android/server/telecom/tests/CallAudioRouteStateMachineTest.java @@ -460,7 +460,7 @@ public class CallAudioRouteStateMachineTest NONE, // speakerInteraction NONE, // bluetoothInteraction CallAudioRouteStateMachine.DISCONNECT_WIRED_HEADSET, // action - CallAudioState.ROUTE_EARPIECE, // expectedRoute + CallAudioState.ROUTE_BLUETOOTH, // expectedRoute CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_BLUETOOTH, // expectedAvailable true, // doesDeviceSupportEarpiece shouldRunWithFocus |