Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ea11bdb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Prevent infinite rebind"

parents 635050b8 00294a78
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ 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

    /**
@@ -1469,7 +1470,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                }

                psc = new ProfileServiceConnections(intent);
                if (!psc.bindService()) {
                if (!psc.bindService(DEFAULT_REBIND_COUNT)) {
                    return false;
                }

@@ -1598,7 +1599,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            mIntent = intent;
        }

        private boolean bindService() {
        private boolean bindService(int rebindCount) {
            int state = BluetoothAdapter.STATE_OFF;
            try {
                mBluetoothLock.readLock().lock();
@@ -1621,6 +1622,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    UserHandle.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;
            }
@@ -1640,6 +1642,7 @@ 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);
                }
            }
@@ -2193,7 +2196,10 @@ 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: {