Loading src/com/android/server/telecom/CallAudioRouteController.java +36 −21 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { private int mFocusType; private int mCallSupportedRouteMask = -1; private boolean mIsScoAudioConnected; private boolean mAvailableRoutesUpdated; private final Object mLock = new Object(); private final TelecomSystem.SyncRoot mTelecomLock; private final BroadcastReceiver mSpeakerPhoneChangeReceiver = new BroadcastReceiver() { Loading Loading @@ -359,7 +360,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.w(this, "Can't find available audio device info for route TYPE_SPEAKER"); } else { mTypeRoutes.put(AudioRoute.TYPE_SPEAKER, mSpeakerDockRoute); mAvailableRoutes.add(mSpeakerDockRoute); updateAvailableRoutes(mSpeakerDockRoute, true); } } Loading @@ -371,7 +372,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.w(this, "Can't find available audio device info for route TYPE_WIRED_HEADSET"); } else { mTypeRoutes.put(AudioRoute.TYPE_WIRED, mEarpieceWiredRoute); mAvailableRoutes.add(mEarpieceWiredRoute); updateAvailableRoutes(mEarpieceWiredRoute, true); } } else if ((supportMask & CallAudioState.ROUTE_EARPIECE) != 0) { // Create earpiece routes Loading @@ -381,7 +382,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.w(this, "Can't find available audio device info for route TYPE_EARPIECE"); } else { mTypeRoutes.put(AudioRoute.TYPE_EARPIECE, mEarpieceWiredRoute); mAvailableRoutes.add(mEarpieceWiredRoute); updateAvailableRoutes(mEarpieceWiredRoute, true); } } Loading Loading @@ -546,8 +547,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { } if (wiredHeadsetRoute != null) { mAvailableRoutes.add(wiredHeadsetRoute); mAvailableRoutes.remove(mEarpieceWiredRoute); updateAvailableRoutes(wiredHeadsetRoute, true); updateAvailableRoutes(mEarpieceWiredRoute, false); mTypeRoutes.put(AudioRoute.TYPE_WIRED, wiredHeadsetRoute); mEarpieceWiredRoute = wiredHeadsetRoute; routeTo(mIsActive, wiredHeadsetRoute); Loading @@ -559,12 +560,12 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { // Update audio route states AudioRoute wiredHeadsetRoute = mTypeRoutes.remove(AudioRoute.TYPE_WIRED); if (wiredHeadsetRoute != null) { mAvailableRoutes.remove(wiredHeadsetRoute); updateAvailableRoutes(wiredHeadsetRoute, false); mEarpieceWiredRoute = null; } AudioRoute earpieceRoute = mTypeRoutes.get(AudioRoute.TYPE_EARPIECE); if (earpieceRoute != null) { mAvailableRoutes.add(earpieceRoute); updateAvailableRoutes(earpieceRoute, true); mEarpieceWiredRoute = earpieceRoute; } onAvailableRoutesChanged(); Loading @@ -585,8 +586,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { } if (dockRoute != null) { mAvailableRoutes.add(dockRoute); mAvailableRoutes.remove(mSpeakerDockRoute); updateAvailableRoutes(dockRoute, true); updateAvailableRoutes(mSpeakerDockRoute, false); mTypeRoutes.put(AudioRoute.TYPE_DOCK, dockRoute); mSpeakerDockRoute = dockRoute; routeTo(mIsActive, dockRoute); Loading @@ -598,12 +599,12 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { // Update audio route states AudioRoute dockRoute = mTypeRoutes.get(AudioRoute.TYPE_DOCK); if (dockRoute != null) { mAvailableRoutes.remove(dockRoute); updateAvailableRoutes(dockRoute, false); mSpeakerDockRoute = null; } AudioRoute speakerRoute = mTypeRoutes.get(AudioRoute.TYPE_SPEAKER); if (speakerRoute != null) { mAvailableRoutes.add(speakerRoute); updateAvailableRoutes(speakerRoute, true); mSpeakerDockRoute = speakerRoute; } onAvailableRoutesChanged(); Loading Loading @@ -691,7 +692,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { + AudioRoute.DEVICE_TYPE_STRINGS.get(type)); } else { Log.i(this, "bluetooth route added: " + bluetoothRoute); mAvailableRoutes.add(bluetoothRoute); updateAvailableRoutes(bluetoothRoute, true); mBluetoothRoutes.put(bluetoothRoute, bluetoothDevice); onAvailableRoutesChanged(); } Loading @@ -712,7 +713,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { if (bluetoothRoute != null) { Log.i(this, "bluetooth route removed: " + bluetoothRoute); mBluetoothRoutes.remove(bluetoothRoute); mAvailableRoutes.remove(bluetoothRoute); updateAvailableRoutes(bluetoothRoute, false); onAvailableRoutesChanged(); } Loading Loading @@ -811,7 +812,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.i(this, "handleSwitchFocus (ACTIVE_FOCUS): mBluetoothAddressForRinging = " + "%s, mCurrentRoute = %s", mBluetoothAddressForRinging, mCurrentRoute); AudioRoute audioRoute = mBluetoothAddressForRinging != null && mBluetoothAddressForRinging.equals(mCurrentRoute.getBluetoothAddress()) && mBluetoothAddressForRinging.equals( mCurrentRoute.getBluetoothAddress()) ? mCurrentRoute : getBaseRoute(true, null); routeTo(true, audioRoute); Loading Loading @@ -1042,6 +1044,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { private boolean updateCallSupportedAudioRoutes() { int availableRouteMask = 0; Call foregroundCall = mCallsManager.getForegroundCall(); mCallSupportedRoutes.clear(); if (foregroundCall != null) { int foregroundCallSupportedRouteMask = foregroundCall.getSupportedAudioRoutes(); for (AudioRoute route : getAvailableRoutes()) { Loading @@ -1054,7 +1057,6 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { mCallSupportedRouteMask = availableRouteMask & foregroundCallSupportedRouteMask; return true; } else { mCallSupportedRoutes.clear(); mCallSupportedRouteMask = -1; return false; } Loading Loading @@ -1193,6 +1195,10 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { if (mCurrentRoute.equals(mStreamingRoute)) { return mStreamingRoutes; } else { if (mAvailableRoutesUpdated) { updateCallSupportedAudioRoutes(); mAvailableRoutesUpdated = false; } return mCallSupportedRoutes.isEmpty() ? mAvailableRoutes : mCallSupportedRoutes; } } Loading Loading @@ -1420,6 +1426,15 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { } } private void updateAvailableRoutes(AudioRoute route, boolean includeRoute) { if (includeRoute) { mAvailableRoutes.add(route); } else { mAvailableRoutes.remove(route); } mAvailableRoutesUpdated = true; } @VisibleForTesting public void setActive(boolean active) { if (active) { Loading Loading
src/com/android/server/telecom/CallAudioRouteController.java +36 −21 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { private int mFocusType; private int mCallSupportedRouteMask = -1; private boolean mIsScoAudioConnected; private boolean mAvailableRoutesUpdated; private final Object mLock = new Object(); private final TelecomSystem.SyncRoot mTelecomLock; private final BroadcastReceiver mSpeakerPhoneChangeReceiver = new BroadcastReceiver() { Loading Loading @@ -359,7 +360,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.w(this, "Can't find available audio device info for route TYPE_SPEAKER"); } else { mTypeRoutes.put(AudioRoute.TYPE_SPEAKER, mSpeakerDockRoute); mAvailableRoutes.add(mSpeakerDockRoute); updateAvailableRoutes(mSpeakerDockRoute, true); } } Loading @@ -371,7 +372,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.w(this, "Can't find available audio device info for route TYPE_WIRED_HEADSET"); } else { mTypeRoutes.put(AudioRoute.TYPE_WIRED, mEarpieceWiredRoute); mAvailableRoutes.add(mEarpieceWiredRoute); updateAvailableRoutes(mEarpieceWiredRoute, true); } } else if ((supportMask & CallAudioState.ROUTE_EARPIECE) != 0) { // Create earpiece routes Loading @@ -381,7 +382,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.w(this, "Can't find available audio device info for route TYPE_EARPIECE"); } else { mTypeRoutes.put(AudioRoute.TYPE_EARPIECE, mEarpieceWiredRoute); mAvailableRoutes.add(mEarpieceWiredRoute); updateAvailableRoutes(mEarpieceWiredRoute, true); } } Loading Loading @@ -546,8 +547,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { } if (wiredHeadsetRoute != null) { mAvailableRoutes.add(wiredHeadsetRoute); mAvailableRoutes.remove(mEarpieceWiredRoute); updateAvailableRoutes(wiredHeadsetRoute, true); updateAvailableRoutes(mEarpieceWiredRoute, false); mTypeRoutes.put(AudioRoute.TYPE_WIRED, wiredHeadsetRoute); mEarpieceWiredRoute = wiredHeadsetRoute; routeTo(mIsActive, wiredHeadsetRoute); Loading @@ -559,12 +560,12 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { // Update audio route states AudioRoute wiredHeadsetRoute = mTypeRoutes.remove(AudioRoute.TYPE_WIRED); if (wiredHeadsetRoute != null) { mAvailableRoutes.remove(wiredHeadsetRoute); updateAvailableRoutes(wiredHeadsetRoute, false); mEarpieceWiredRoute = null; } AudioRoute earpieceRoute = mTypeRoutes.get(AudioRoute.TYPE_EARPIECE); if (earpieceRoute != null) { mAvailableRoutes.add(earpieceRoute); updateAvailableRoutes(earpieceRoute, true); mEarpieceWiredRoute = earpieceRoute; } onAvailableRoutesChanged(); Loading @@ -585,8 +586,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { } if (dockRoute != null) { mAvailableRoutes.add(dockRoute); mAvailableRoutes.remove(mSpeakerDockRoute); updateAvailableRoutes(dockRoute, true); updateAvailableRoutes(mSpeakerDockRoute, false); mTypeRoutes.put(AudioRoute.TYPE_DOCK, dockRoute); mSpeakerDockRoute = dockRoute; routeTo(mIsActive, dockRoute); Loading @@ -598,12 +599,12 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { // Update audio route states AudioRoute dockRoute = mTypeRoutes.get(AudioRoute.TYPE_DOCK); if (dockRoute != null) { mAvailableRoutes.remove(dockRoute); updateAvailableRoutes(dockRoute, false); mSpeakerDockRoute = null; } AudioRoute speakerRoute = mTypeRoutes.get(AudioRoute.TYPE_SPEAKER); if (speakerRoute != null) { mAvailableRoutes.add(speakerRoute); updateAvailableRoutes(speakerRoute, true); mSpeakerDockRoute = speakerRoute; } onAvailableRoutesChanged(); Loading Loading @@ -691,7 +692,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { + AudioRoute.DEVICE_TYPE_STRINGS.get(type)); } else { Log.i(this, "bluetooth route added: " + bluetoothRoute); mAvailableRoutes.add(bluetoothRoute); updateAvailableRoutes(bluetoothRoute, true); mBluetoothRoutes.put(bluetoothRoute, bluetoothDevice); onAvailableRoutesChanged(); } Loading @@ -712,7 +713,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { if (bluetoothRoute != null) { Log.i(this, "bluetooth route removed: " + bluetoothRoute); mBluetoothRoutes.remove(bluetoothRoute); mAvailableRoutes.remove(bluetoothRoute); updateAvailableRoutes(bluetoothRoute, false); onAvailableRoutesChanged(); } Loading Loading @@ -811,7 +812,8 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { Log.i(this, "handleSwitchFocus (ACTIVE_FOCUS): mBluetoothAddressForRinging = " + "%s, mCurrentRoute = %s", mBluetoothAddressForRinging, mCurrentRoute); AudioRoute audioRoute = mBluetoothAddressForRinging != null && mBluetoothAddressForRinging.equals(mCurrentRoute.getBluetoothAddress()) && mBluetoothAddressForRinging.equals( mCurrentRoute.getBluetoothAddress()) ? mCurrentRoute : getBaseRoute(true, null); routeTo(true, audioRoute); Loading Loading @@ -1042,6 +1044,7 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { private boolean updateCallSupportedAudioRoutes() { int availableRouteMask = 0; Call foregroundCall = mCallsManager.getForegroundCall(); mCallSupportedRoutes.clear(); if (foregroundCall != null) { int foregroundCallSupportedRouteMask = foregroundCall.getSupportedAudioRoutes(); for (AudioRoute route : getAvailableRoutes()) { Loading @@ -1054,7 +1057,6 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { mCallSupportedRouteMask = availableRouteMask & foregroundCallSupportedRouteMask; return true; } else { mCallSupportedRoutes.clear(); mCallSupportedRouteMask = -1; return false; } Loading Loading @@ -1193,6 +1195,10 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { if (mCurrentRoute.equals(mStreamingRoute)) { return mStreamingRoutes; } else { if (mAvailableRoutesUpdated) { updateCallSupportedAudioRoutes(); mAvailableRoutesUpdated = false; } return mCallSupportedRoutes.isEmpty() ? mAvailableRoutes : mCallSupportedRoutes; } } Loading Loading @@ -1420,6 +1426,15 @@ public class CallAudioRouteController implements CallAudioRouteAdapter { } } private void updateAvailableRoutes(AudioRoute route, boolean includeRoute) { if (includeRoute) { mAvailableRoutes.add(route); } else { mAvailableRoutes.remove(route); } mAvailableRoutesUpdated = true; } @VisibleForTesting public void setActive(boolean active) { if (active) { Loading