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

Commit 8f473d60 authored by jasonwshsu's avatar jasonwshsu
Browse files

Fix crash when toggling ambient collapse button in hearing device dialog

Root Cause: mAmbientController.start() in onStart() might execute before mAmbientController is
initialized in onCreate(). Race condition between background executor in onCreate() and onStart()

Solution: Move task in onStart() to onCreate() to make sure it will be executed in order.

Bug: 397635040
Test: manual test, connect one of hearing aids then open hearing device dialog
Flag: EXEMPT bugfix
Change-Id: Ic9e6f1805789fbf26437ae54b5c68dcec8e17d7a
parent 238c473c
Loading
Loading
Loading
Loading
+4 −15
Original line number Diff line number Diff line
@@ -289,6 +289,8 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
            List<DeviceItem> hearingDeviceItemList = getHearingDeviceItemList();
            CachedBluetoothDevice activeHearingDevice = getActiveHearingDevice(
                    hearingDeviceItemList);
            mLocalBluetoothManager.getEventManager().registerCallback(this);

            mMainExecutor.execute(() -> {
                setupDeviceListView(dialog, hearingDeviceItemList);
                setupPairNewDeviceButton(dialog);
@@ -301,21 +303,6 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
        });
    }

    @Override
    public void onStart(@NonNull SystemUIDialog dialog) {
        mBgExecutor.execute(() -> {
            if (mLocalBluetoothManager != null) {
                mLocalBluetoothManager.getEventManager().registerCallback(this);
            }
            if (mPresetController != null) {
                mPresetController.registerHapCallback();
            }
            if (mAmbientController != null) {
                mAmbientController.start();
            }
        });
    }

    @Override
    public void onStop(@NonNull SystemUIDialog dialog) {
        mBgExecutor.execute(() -> {
@@ -378,6 +365,7 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,

        mPresetLayout = dialog.requireViewById(R.id.preset_layout);
        mPresetLayout.setVisibility(mPresetController.isPresetControlAvailable() ? VISIBLE : GONE);
        mBgExecutor.execute(() -> mPresetController.registerHapCallback());
    }

    private void setupAmbientControls(CachedBluetoothDevice activeHearingDevice) {
@@ -387,6 +375,7 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
                mDialog.getContext(), mLocalBluetoothManager, ambientLayout);
        mAmbientController.setShowUiWhenLocalDataExist(false);
        mAmbientController.loadDevice(activeHearingDevice);
        mBgExecutor.execute(() -> mAmbientController.start());
    }

    private void setupPairNewDeviceButton(SystemUIDialog dialog) {