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

Commit 2fec02de authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

Merge "Cancel scan when PendingIntent is cancelled" am: bf481664

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1757489

Change-Id: Ibd6a71358d22f7ed0ae1cdade6c0671278c4f850
parents ab84959f bf481664
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