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

Commit d7450aa4 authored by Chen Chen's avatar Chen Chen
Browse files

BluetoothInCallService: Check bound count before calling listCurrentCalls

Bug: 220643997
Test: atest BluetoothInstrumentationTests
Change-Id: I2cc4002ce22ad0e27cc5e17917055ab113e7a5ec
parent b8c0d773
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -146,6 +146,8 @@ public class BluetoothInCallService extends InCallService {

    public CallInfo mCallInfo = new CallInfo();

    protected boolean mOnCreateCalled = false;

    /**
     * Listens to connections and disconnections of bluetooth headsets.  We need to save the current
     * bluetooth headset so that we know where to send BluetoothCall updates.
@@ -487,6 +489,10 @@ public class BluetoothInCallService extends InCallService {
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    public boolean listCurrentCalls() {
        synchronized (LOCK) {
            if (!mOnCreateCalled) {
                Log.w(TAG, "listcurrentCalls() is called before onCreate()");
                return false;
            }
            enforceModifyPermission();
            // only log if it is after we recently updated the headset state or else it can
            // clog the android log since this can be queried every second.
@@ -655,12 +661,14 @@ public class BluetoothInCallService extends InCallService {
        mAudioManager = getSystemService(AudioManager.class);
        mAudioManager.addOnModeChangedListener(
                Executors.newSingleThreadExecutor(), mBluetoothOnModeChangedListener);
        mOnCreateCalled = true;
    }

    @Override
    public void onDestroy() {
        Log.d(TAG, "onDestroy");
        clear();
        mOnCreateCalled = false;
        super.onDestroy();
    }

+5 −0
Original line number Diff line number Diff line
@@ -111,6 +111,10 @@ public class BluetoothInCallServiceTest {
        }
        @Override
        protected void enforceModifyPermission() {}

        protected void setOnCreateCalled(boolean called) {
            mOnCreateCalled = called;
        }
    }

    @Before
@@ -140,6 +144,7 @@ public class BluetoothInCallServiceTest {
        mBluetoothInCallService.setBluetoothHeadset(mMockBluetoothHeadset);
        mBluetoothInCallService.setBluetoothLeCallControl(mMockBluetoothLeCallControl);
        mBluetoothInCallService.mCallInfo = mMockCallInfo;
        mBluetoothInCallService.setOnCreateCalled(true);
    }

    @After