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

Commit da9f10b8 authored by Aritra Sen's avatar Aritra Sen
Browse files

Deleting Handler and dropping queued messages to prevent any crash during stop...

Deleting Handler and dropping queued messages to prevent any crash during stop of state machine/services.

Bug: 299045927
Bug: 298898621
Bug: 296932947
Test: atest BluetoothInstrumentationTests
Change-Id: I1848663789fffe5d6d665da25b7d33423943d8ac
parent 7745538e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -259,6 +259,11 @@ public class A2dpService extends ProfileService {
                // Do not rethrow as we are shutting down anyway
            }
        }
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }

        // Step 2: Reset maximum number of connected audio devices
        mMaxConnectedAudioDevices = 1;

+11 −3
Original line number Diff line number Diff line
@@ -302,6 +302,10 @@ public class BassClientService extends ProfileService {
        mDatabaseManager = Objects.requireNonNull(mAdapterService.getDatabase(),
                "DatabaseManager cannot be null when BassClientService starts");
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

        // Setup Handler to handle local broadcast use cases.
        mHandler = new Handler(Looper.getMainLooper());

        mStateMachines.clear();
        mStateMachinesThread = new HandlerThread("BassClientService.StateMachines");
        mStateMachinesThread.start();
@@ -309,9 +313,6 @@ public class BassClientService extends ProfileService {
        mCallbackHandlerThread.start();
        mCallbacks = new Callbacks(mCallbackHandlerThread.getLooper());

        // Setup Handler to handle local broadcast use cases.
        mHandler = new Handler(Looper.getMainLooper());

        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
@@ -349,6 +350,7 @@ public class BassClientService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "stop()");
        }

        synchronized (mStateMachines) {
            for (BassClientStateMachine sm : mStateMachines.values()) {
                BassObjectsFactory.getInstance().destroyStateMachine(sm);
@@ -364,6 +366,12 @@ public class BassClientService extends ProfileService {
            mStateMachinesThread = null;
        }

        // Unregister Handler and stop all queued messages.
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }

        if (mIntentReceiver != null) {
            unregisterReceiver(mIntentReceiver);
            mIntentReceiver = null;
+7 −0
Original line number Diff line number Diff line
@@ -275,6 +275,13 @@ class AdapterProperties {
    public void cleanup() {
        mRemoteDevices = null;
        mProfileConnectionState.clear();

        // Unregister Handler and stop all queued messages.
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }

        if (mReceiverRegistered) {
            mService.unregisterReceiver(mReceiver);
            mReceiverRegistered = false;
+5 −0
Original line number Diff line number Diff line
@@ -180,6 +180,11 @@ public class RemoteDevices {
            mSdpTracker.clear();
        }

        // Unregister Handler and stop all queued messages.
        if (mMainHandler != null) {
            mMainHandler.removeCallbacksAndMessages(null);
        }

        synchronized (mDevices) {
            if (mDevices != null) {
                debugLog("reset(): Broadcasting ACL_DISCONNECTED");
+6 −0
Original line number Diff line number Diff line
@@ -214,6 +214,12 @@ public class CsipSetCoordinatorService extends ProfileService {
            }
        }

        // Unregister Handler and stop all queued messages.
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }

        mDeviceGroupIdRankMap.clear();
        mCallbacks.clear();
        mFoundSetMemberToGroupId.clear();
Loading