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

Commit facf11fb authored by Kyunglyul Hyun's avatar Kyunglyul Hyun
Browse files

Fix potential NPE in SapService

It could throw NPE if mService is being cleaned up
while accessing the variable.

This also fixes SapServiceTest failed in the local enviornment.

Flag: EXEMPT, strict null check
Bug: 339695797
Test: atest SapServiceTest
Change-Id: Ib2b09cad6ff84f41e66f07cfb066bc33e3ad1c0c
parent 8ed8181b
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -907,12 +907,14 @@ public class SapService extends ProfileService implements AdapterService.Bluetoo


        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private SapService getService(AttributionSource source) {
        private SapService getService(AttributionSource source) {
            if (!Utils.checkServiceAvailable(mService, TAG)
            SapService sapService = mService;
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)

                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
            if (!Utils.checkServiceAvailable(sapService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(sapService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(sapService, source, TAG)) {
                return null;
                return null;
            }
            }
            return mService;
            return sapService;
        }
        }


        SapBinder(SapService service) {
        SapBinder(SapService service) {
+6 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Looper;


import androidx.test.filters.MediumTest;
import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.platform.app.InstrumentationRegistry;
@@ -62,6 +63,11 @@ public class SapServiceTest {
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        mTargetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        TestUtils.setAdapterService(mAdapterService);
        TestUtils.setAdapterService(mAdapterService);

        if (Looper.myLooper() == null) {
            Looper.prepare();
        }

        mService = new SapService(mTargetContext);
        mService = new SapService(mTargetContext);
        mService.start();
        mService.start();
        mService.setAvailable(true);
        mService.setAvailable(true);