Merge "Limit the retry attemps on restarting Bluetooth"

am: 46af84f892

Change-Id: Ic3a92b10076eeebd332fd8cb2581b508e642e345
This commit is contained in:
Ugo Yu
2019-11-25 20:40:07 -08:00
committed by android-build-merger

View File

@@ -98,7 +98,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
private static final int TIMEOUT_BIND_MS = 3000; //Maximum msec to wait for a bind private static final int TIMEOUT_BIND_MS = 3000; //Maximum msec to wait for a bind
//Maximum msec to wait for service restart //Maximum msec to wait for service restart
private static final int SERVICE_RESTART_TIME_MS = 200; private static final int SERVICE_RESTART_TIME_MS = 400;
//Maximum msec to wait for restart due to error //Maximum msec to wait for restart due to error
private static final int ERROR_RESTART_TIME_MS = 3000; private static final int ERROR_RESTART_TIME_MS = 3000;
//Maximum msec to delay MESSAGE_USER_SWITCHED //Maximum msec to delay MESSAGE_USER_SWITCHED
@@ -1635,13 +1635,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
// ActivityManager detects it. // ActivityManager detects it.
// The waiting for (b) and (c) is accomplished by // The waiting for (b) and (c) is accomplished by
// delaying the MESSAGE_RESTART_BLUETOOTH_SERVICE // delaying the MESSAGE_RESTART_BLUETOOTH_SERVICE
// message. On slower devices, that delay needs to be // message. The delay time is backed off if Bluetooth
// on the order of (2 * SERVICE_RESTART_TIME_MS). // continuously failed to turn on itself.
// //
waitForOnOff(false, true); waitForOnOff(false, true);
Message restartMsg = Message restartMsg =
mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
mHandler.sendMessageDelayed(restartMsg, 2 * SERVICE_RESTART_TIME_MS); mHandler.sendMessageDelayed(restartMsg, getServiceRestartMs());
} }
break; break;
@@ -1820,7 +1820,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
waitForOnOff(false, true); waitForOnOff(false, true);
Message restartMsg = Message restartMsg =
mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
mHandler.sendMessageDelayed(restartMsg, 2 * SERVICE_RESTART_TIME_MS); mHandler.sendMessageDelayed(restartMsg, getServiceRestartMs());
} }
} }
if (newState == BluetoothAdapter.STATE_ON if (newState == BluetoothAdapter.STATE_ON
@@ -1863,7 +1863,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
// Send a Bluetooth Restart message // Send a Bluetooth Restart message
Message restartMsg = Message restartMsg =
mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
mHandler.sendMessageDelayed(restartMsg, SERVICE_RESTART_TIME_MS); mHandler.sendMessageDelayed(restartMsg, getServiceRestartMs());
} }
sendBluetoothServiceDownCallback(); sendBluetoothServiceDownCallback();
@@ -1886,14 +1886,20 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
break; break;
} }
case MESSAGE_RESTART_BLUETOOTH_SERVICE: { case MESSAGE_RESTART_BLUETOOTH_SERVICE: {
Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE"); mErrorRecoveryRetryCounter++;
/* Enable without persisting the setting as Slog.d(TAG, "MESSAGE_RESTART_BLUETOOTH_SERVICE: retry count="
it doesnt change when IBluetooth + mErrorRecoveryRetryCounter);
service restarts */ if (mErrorRecoveryRetryCounter < MAX_ERROR_RESTART_RETRIES) {
mEnable = true; /* Enable without persisting the setting as
addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_RESTARTED, it doesnt change when IBluetooth
mContext.getPackageName(), true); service restarts */
handleEnable(mQuietEnable); mEnable = true;
addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_RESTARTED,
mContext.getPackageName(), true);
handleEnable(mQuietEnable);
} else {
Slog.e(TAG, "Reach maximum retry to restart Bluetooth!");
}
break; break;
} }
case MESSAGE_TIMEOUT_BIND: { case MESSAGE_TIMEOUT_BIND: {
@@ -2332,13 +2338,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mEnable = false; mEnable = false;
if (mErrorRecoveryRetryCounter++ < MAX_ERROR_RESTART_RETRIES) { // Send a Bluetooth Restart message to reenable bluetooth
// Send a Bluetooth Restart message to reenable bluetooth Message restartMsg = mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE);
Message restartMsg = mHandler.obtainMessage(MESSAGE_RESTART_BLUETOOTH_SERVICE); mHandler.sendMessageDelayed(restartMsg, ERROR_RESTART_TIME_MS);
mHandler.sendMessageDelayed(restartMsg, ERROR_RESTART_TIME_MS);
} else {
// todo: notify user to power down and power up phone to make bluetooth work.
}
} }
private boolean isBluetoothDisallowed() { private boolean isBluetoothDisallowed() {
@@ -2374,6 +2376,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
} }
} }
private int getServiceRestartMs() {
return (mErrorRecoveryRetryCounter + 1) * SERVICE_RESTART_TIME_MS;
}
@Override @Override
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) { public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) { if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) {