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

Commit 49628640 authored by David Duarte's avatar David Duarte
Browse files

HearingAidService: Cache service in getService

If cleanup is callled at the same time than getService, mService
will become null and call to methods expecting the argument to not
be null will fail.

mService being null is checked by `Utils.checkServiceAvailable`,
to avoid the subsequent `Utils.check` calls failure, cache the
value to ensure that it will not change.

Bug: 327929337
Fix: 327929337
Test: m Bluetooth
Flag: Exempt, strict null check
Change-Id: I8a533e0c5df2bd7f39a493f5247e2198272682ba
parent 93732559
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -954,15 +954,17 @@ public class HearingAidService extends ProfileService {

        @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
        private HearingAidService getService(AttributionSource source) {
            // Cache mService because it can change while getService is called b/327929337
            HearingAidService service = mService;
            if (mIsTesting) {
                return mService;
                return service;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
            if (!Utils.checkServiceAvailable(service, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(service, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return null;
            }
            return mService;
            return service;
        }

        BluetoothHearingAidBinder(HearingAidService svc) {