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

Commit f7865b0c authored by William Escande's avatar William Escande
Browse files

Encapsulate call to beginBroadcast in synchronized

beginBroadcast cannot be called concurrently.
When shuting down the profile, multiple profiles can try to broadcast
their state to proxies which can create a crash.
There was a attempt to prevent that with a boolean, I am replacing it
with a synchronized block

Bug: 272430969
Test: atest ServiceBluetoothTests
Change-Id: Ie840cbf303c1f44d1aa254da798c8ff30d7d0fc9
parent 5643875c
Loading
Loading
Loading
Loading
+37 −46
Original line number Diff line number Diff line
@@ -1740,7 +1740,6 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
        IBinder mService;
        ComponentName mClassName;
        Intent mIntent;
        boolean mInvokingProxyCallbacks = false;

        ProfileServiceConnections(Intent intent) {
            mService = null;
@@ -1832,12 +1831,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                Log.e(TAG, "Unable to linkToDeath", e);
            }

            if (mInvokingProxyCallbacks) {
                Log.e(TAG, "Proxy callbacks already in progress.");
                return;
            }
            mInvokingProxyCallbacks = true;

            synchronized (mProxies) {
                final int n = mProxies.beginBroadcast();
                try {
                    for (int i = 0; i < n; i++) {
@@ -1849,7 +1843,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                    }
                } finally {
                    mProxies.finishBroadcast();
                mInvokingProxyCallbacks = false;
                }
            }
        }

@@ -1866,24 +1860,19 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
            mService = null;
            mClassName = null;

            if (mInvokingProxyCallbacks) {
                Log.e(TAG, "Proxy callbacks already in progress.");
                return;
            }
            mInvokingProxyCallbacks = true;

            synchronized (mProxies) {
                final int n = mProxies.beginBroadcast();
                try {
                    for (int i = 0; i < n; i++) {
                        try {
                            mProxies.getBroadcastItem(i).onServiceDisconnected(className);
                        } catch (RemoteException e) {
                        Log.e(TAG, "Unable to disconnect from proxy", e);
                            Log.e(TAG, "Unable to disconnect from proxy #" + i, e);
                        }
                    }
                } finally {
                    mProxies.finishBroadcast();
                mInvokingProxyCallbacks = false;
                }
            }
        }

@@ -1901,6 +1890,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
    }

    private void sendBluetoothStateCallback(boolean isUp) {
        synchronized (mStateChangeCallbacks) {
            try {
                int n = mStateChangeCallbacks.beginBroadcast();
                if (DBG) {
@@ -1918,6 +1908,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
                mStateChangeCallbacks.finishBroadcast();
            }
        }
    }

    /**
     * Inform BluetoothAdapter instances that Adapter service is up