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

Commit e4aa3e92 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Prevent infinite rebind" am: 2ea11bdb

parents 3091f136 2ea11bdb
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -116,6 +116,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

    /**
@@ -1465,7 +1466,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                }

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

@@ -1594,7 +1595,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();
@@ -1617,6 +1618,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;
            }
@@ -1636,6 +1638,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);
                }
            }
@@ -2189,7 +2192,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: {