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

Commit 1c68f9f9 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
Change-Id: Ib4211bc8feed856d8ac37078efbee0f46e140493
parent e28852a6
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -165,6 +165,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, getAttributionSource());
                }
            };

    /**
     * List of our registered scanners.
     */
@@ -2342,6 +2350,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 =
@@ -2447,6 +2458,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, attributionSource);
            // Also unregister the scanner