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

Commit bf481664 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge "Cancel scan when PendingIntent is cancelled"

parents ffa976d6 e1c945aa
Loading
Loading
Loading
Loading
+14 −2
Original line number Original line 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.
     * List of our registered scanners.
     */
     */
@@ -515,7 +523,7 @@ public class GattService extends ProfileService {
            if (service == null) {
            if (service == null) {
                return;
                return;
            }
            }
            service.stopScan(intent, callingPackage);
            service.stopScan(intent);
        }
        }


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


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

        pendingIntent.registerCancelListener(mScanIntentCancelListener);

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


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