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

Commit e1c945aa authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Cancel scan when PendingIntent is cancelled

Currently, the scan is not stopped. This might cause unnecessary battery
drain.

Bug: 191844514
Merged-In: Ib4211bc8feed856d8ac37078efbee0f46e140493
Change-Id: Ib4211bc8feed856d8ac37078efbee0f46e140493
parent a1b3696c
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -147,6 +147,14 @@ public class GattService extends ProfileService {
        }
    }

    private final PendingIntent.CancelListener mScanIntentCancelListener =
            new PendingIntent.CancelListener(){
                public void onCancelled(PendingIntent intent) {
                    Log.d(TAG, "scanning PendingIntent cancelled");
                    stopScan(intent);
                }
            };

    /**
     * List of our registered scanners.
     */
@@ -515,7 +523,7 @@ public class GattService extends ProfileService {
            if (service == null) {
                return;
            }
            service.stopScan(intent, callingPackage);
            service.stopScan(intent);
        }

        @Override
@@ -2174,6 +2182,9 @@ public class GattService extends ProfileService {
        }

        ScannerMap.App app = mScannerMap.add(uuid, null, null, piInfo, this);

        pendingIntent.registerCancelListener(mScanIntentCancelListener);

        app.mUserHandle = UserHandle.of(UserHandle.getCallingUserId());
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        app.mEligibleForSanitizedExposureNotification =
@@ -2250,7 +2261,7 @@ public class GattService extends ProfileService {
        mScanManager.stopScan(scannerId);
    }

    void stopScan(PendingIntent intent, String callingPackage) {
    void stopScan(PendingIntent intent) {
        enforceAdminPermission();
        PendingIntentInfo pii = new PendingIntentInfo();
        pii.intent = intent;
@@ -2259,6 +2270,7 @@ public class GattService extends ProfileService {
            Log.d(TAG, "stopScan(PendingIntent): app found = " + app);
        }
        if (app != null) {
            intent.unregisterCancelListener(mScanIntentCancelListener);
            final int scannerId = app.id;
            stopScan(scannerId);
            // Also unregister the scanner