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

Commit 0cb6ebe9 authored by Chen Chen's avatar Chen Chen
Browse files

HeadsetPhoneState: Synchronize constructor with phone state listening functions.

Bug: 241871296

The bug is that mSignalStrengthUpdateRequest is null when bt calls mTelephonyManager.clearSignalStrengthUpdateRequest(mSignalStrengthUpdateRequest).

mSignalStrengthUpdateRequest is created at constructor. So the only explanation is that there is a race condition between the constructor and stopListenForPhoneState() who calls clearSignalStrengthUpdateRequest();

Test: atest BluetoothInstrumentationTests
Change-Id: I0d456a4a7981e1befe291d2045b926a4da4b6bf5
parent 624e50d9
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ public class HeadsetPhoneState {
    private final Object mPhoneStateListenerLock = new Object();

    HeadsetPhoneState(HeadsetService headsetService) {
        synchronized (mPhoneStateListenerLock) {
            Objects.requireNonNull(headsetService, "headsetService is null");
            mHeadsetService = headsetService;
            mTelephonyManager = mHeadsetService.getSystemService(TelephonyManager.class);
@@ -87,13 +88,14 @@ public class HeadsetPhoneState {
            // Initialize subscription on the handler thread
            mHandler = new Handler(headsetService.getStateMachinesThreadLooper());
            mOnSubscriptionsChangedListener = new HeadsetPhoneStateOnSubscriptionChangedListener();
        mSubscriptionManager.addOnSubscriptionsChangedListener(command -> mHandler.post(command),
                mOnSubscriptionsChangedListener);
            mSubscriptionManager.addOnSubscriptionsChangedListener(
                    command -> mHandler.post(command), mOnSubscriptionsChangedListener);
            mSignalStrengthUpdateRequest = new SignalStrengthUpdateRequest.Builder()
                    .setSignalThresholdInfos(Collections.EMPTY_LIST)
                    .setSystemThresholdReportingRequestedWhileIdle(true)
                    .build();
        }
    }

    /**
     * Cleanup this instance. Instance can no longer be used after calling this method.