diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-07-18 07:31:48 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-07-18 07:31:48 +0000 |
commit | 72afedf2b654d77ca6921b72263b35b9078fa02c (patch) | |
tree | db87cb89c5e58b47948a1590416762e532f1a591 | |
parent | 6216f468b8368f528c427cd29c4b0a30251fbe39 (diff) | |
parent | c8b268f1621e69ae3cc566b2356117608592dd0d (diff) | |
download | android_packages_services_Telecomm-72afedf2b654d77ca6921b72263b35b9078fa02c.tar.gz android_packages_services_Telecomm-72afedf2b654d77ca6921b72263b35b9078fa02c.tar.bz2 android_packages_services_Telecomm-72afedf2b654d77ca6921b72263b35b9078fa02c.zip |
release-request-e04bb055-13fc-41a1-8a9f-7fb10894ec3d-for-git_oc-mr1-release-4189380 snap-temp-L90600000083186678
Change-Id: I9150b1fea42346dbb59ce5f4f620066488c92422
-rw-r--r-- | src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java index 1ee7de55..0e07922d 100644 --- a/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java +++ b/src/com/android/server/telecom/bluetooth/BluetoothRouteManager.java @@ -147,6 +147,8 @@ public class BluetoothRouteManager extends StateMachine { // arg2: Runnable public static final int RUN_RUNNABLE = 9001; + private static final int MAX_CONNECTION_RETRIES = 2; + // States private final class AudioOffState extends State { @Override @@ -213,7 +215,7 @@ public class BluetoothRouteManager extends StateMachine { break; case RETRY_HFP_CONNECTION: Log.i(LOG_TAG, "Retrying HFP connection to %s", (String) args.arg2); - String retryAddress = connectHfpAudio((String) args.arg2, false); + String retryAddress = connectHfpAudio((String) args.arg2, args.argi1); if (retryAddress != null) { mListener.onBluetoothStateChange(BLUETOOTH_DEVICE_CONNECTED, @@ -339,7 +341,7 @@ public class BluetoothRouteManager extends StateMachine { if (Objects.equals(address, mDeviceAddress)) { Log.d(LOG_TAG, "Retry message came through while connecting."); } else { - String retryAddress = connectHfpAudio(address, false); + String retryAddress = connectHfpAudio(address, args.argi1); if (retryAddress != null) { transitionTo(getConnectingStateForAddress(retryAddress, "AudioConnecting/RETRY_HFP_CONNECTION")); @@ -473,7 +475,7 @@ public class BluetoothRouteManager extends StateMachine { if (Objects.equals(address, mDeviceAddress)) { Log.d(LOG_TAG, "Retry message came through while connected."); } else { - String retryAddress = connectHfpAudio(address, false); + String retryAddress = connectHfpAudio(address, args.argi1); if (retryAddress != null) { mListener.onBluetoothStateChange(BLUETOOTH_AUDIO_CONNECTED, BLUETOOTH_AUDIO_PENDING); @@ -648,15 +650,15 @@ public class BluetoothRouteManager extends StateMachine { } private String connectHfpAudio(String address) { - return connectHfpAudio(address, true, null); + return connectHfpAudio(address, 0, null); } - private String connectHfpAudio(String address, boolean shouldRetry) { - return connectHfpAudio(address, shouldRetry, null); + private String connectHfpAudio(String address, int retryCount) { + return connectHfpAudio(address, retryCount, null); } private String connectHfpAudio(String address, String excludeAddress) { - return connectHfpAudio(address, true, excludeAddress); + return connectHfpAudio(address, 0, excludeAddress); } /** @@ -664,13 +666,12 @@ public class BluetoothRouteManager extends StateMachine { * Note: This method is not synchronized on the Telecom lock, so don't try and call back into * Telecom from within it. * @param address The address that should be tried first. May be null. - * @param shouldRetry true if there should be a retry-with-backoff if connection is - * immediately unsuccessful, false otherwise. + * @param retryCount The number of times this connection attempt has been retried. * @param excludeAddress Don't connect to this address. * @return The address of the device that's actually being connected to, or null if no * connection was successful. */ - private String connectHfpAudio(String address, boolean shouldRetry, String excludeAddress) { + private String connectHfpAudio(String address, int retryCount, String excludeAddress) { BluetoothHeadsetProxy bluetoothHeadset = mDeviceManager.getHeadsetService(); if (bluetoothHeadset == null) { Log.i(this, "connectHfpAudio: no headset service available."); @@ -688,12 +689,14 @@ public class BluetoothRouteManager extends StateMachine { address, actualAddress); } if (actualAddress != null && !connectAudio(actualAddress)) { - Log.w(LOG_TAG, "Could not connect to %s. Will %s", - actualAddress, shouldRetry ? "retry" : "not retry"); + boolean shouldRetry = retryCount < MAX_CONNECTION_RETRIES; + Log.w(LOG_TAG, "Could not connect to %s. Will %s", actualAddress, + shouldRetry ? "retry" : "not retry"); if (shouldRetry) { SomeArgs args = SomeArgs.obtain(); args.arg1 = Log.createSubsession(); args.arg2 = actualAddress; + args.argi1 = retryCount + 1; sendMessageDelayed(RETRY_HFP_CONNECTION, args, mTimeoutsAdapter.getRetryBluetoothConnectAudioBackoffMillis( mContext.getContentResolver())); |