summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSungsoo Lim <sungsoo@google.com>2022-06-14 13:17:15 +0000
committerSungsoo Lim <sungsoo@google.com>2022-06-14 23:18:14 +0000
commitba63875cdefdc4f2b73b1668322668ee24501edc (patch)
treef9f14c0bd642e5000b515673c37eaa568075e198
parenta409e029a7e868285bb788c80326c97047c8bc3a (diff)
Prevent infinite rebind
Bug: 235495968 Tag: #refactor Test: manual Change-Id: Icfe55340b26c40111df0b2babbdfc40bf026dac0 (cherry picked from commit 00294a7805ec1ad337d331929370d464b2b6deaa)
-rw-r--r--service/java/com/android/server/bluetooth/BluetoothManagerService.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
index 0d415cae45..5e2fb8949d 100644
--- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java
+++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java
@@ -115,6 +115,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
private static final int ACTIVE_LOG_MAX_SIZE = 20;
private static final int CRASH_LOG_MAX_SIZE = 100;
+ private static final int DEFAULT_REBIND_COUNT = 3;
private static final int TIMEOUT_BIND_MS = 3000; //Maximum msec to wait for a bind
/**
@@ -1461,7 +1462,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
}
psc = new ProfileServiceConnections(intent);
- if (!psc.bindService()) {
+ if (!psc.bindService(DEFAULT_REBIND_COUNT)) {
return false;
}
@@ -1590,7 +1591,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
mIntent = intent;
}
- private boolean bindService() {
+ private boolean bindService(int rebindCount) {
int state = BluetoothAdapter.STATE_OFF;
try {
mBluetoothLock.readLock().lock();
@@ -1613,6 +1614,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
&& doBind(mIntent, this, 0, USER_HANDLE_CURRENT_OR_SELF)) {
Message msg = mHandler.obtainMessage(MESSAGE_BIND_PROFILE_SERVICE);
msg.obj = this;
+ msg.arg1 = rebindCount;
mHandler.sendMessageDelayed(msg, TIMEOUT_BIND_MS);
return true;
}
@@ -1632,6 +1634,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
if (!mHandler.hasMessages(MESSAGE_BIND_PROFILE_SERVICE, this)) {
Message msg = mHandler.obtainMessage(MESSAGE_BIND_PROFILE_SERVICE);
msg.obj = this;
+ msg.arg1 = DEFAULT_REBIND_COUNT;
mHandler.sendMessage(msg);
}
}
@@ -2185,7 +2188,10 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
if (psc == null) {
break;
}
- psc.bindService();
+ if (msg.arg1 > 0) {
+ mContext.unbindService(psc);
+ psc.bindService(msg.arg1 - 1);
+ }
break;
}
case MESSAGE_BLUETOOTH_SERVICE_CONNECTED: {