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

Commit d150d363 authored by Satish Kodishala's avatar Satish Kodishala Committed by Steve Kondik
Browse files

Bluetooth: Adding synchronization to handle multiple threads

If binder dies in the middle while OnserviceDisconnected is
being processed,there is a chance that other thread through
onbinderdied will also enter to onServiceDisconnected before
service is moved to NULL. Extending the synchronization to
OnServiceConnected to avoid simultaneous calls from addproxy
and removerproxy in corner cases which gets called from
different thread context.

Change-Id: Ib0e2f97ea1b98afc4e83dcfc1df21577485f86ca
parent 96a2c341
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -697,6 +697,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        public void onServiceConnected(ComponentName className, IBinder service) {
            // remove timeout message
            mHandler.removeMessages(MESSAGE_BIND_PROFILE_SERVICE, this);
            synchronized (this) {
                mService = service;
                mClassName = className;
                try {
@@ -704,6 +705,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                } catch (RemoteException e) {
                    Log.e(TAG, "Unable to linkToDeath", e);
                }
            }
            int n = mProxies.beginBroadcast();
            for (int i = 0; i < n; i++) {
                try {
@@ -717,12 +719,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {

        @Override
        public void onServiceDisconnected(ComponentName className) {
            synchronized (this) {
                if (mService == null) {
                    Log.e(TAG, "onServiceDisconnected: service is already NULL");
                    return;
                }
                mService.unlinkToDeath(this, 0);
                mService = null;
                mClassName = null;
            }
            int n = mProxies.beginBroadcast();
            for (int i = 0; i < n; i++) {
                try {