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

Commit 42a5ff3b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check permissions when registering a scan pending intent" into oc-mr1-dev

parents d3ad1a63 31189ae6
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ import com.android.bluetooth.btservice.BluetoothProto;
        /** Flag to signal that transport is congested */
        Boolean isCongested = false;

        /** Whether the calling app has location permission */
        boolean hasLocationPermisson;

        /** Whether the calling app has peers mac address permission */
        boolean hasPeersMacAddressPermission;

        /** Internal callback info queue, waiting to be send on congestion clear */
        private List<CallbackInfo> congestionQueue = new ArrayList<CallbackInfo>();

@@ -151,7 +157,7 @@ import com.android.bluetooth.btservice.BluetoothProto;
    /**
     * Add an entry to the application context list.
     */
    void add(UUID uuid, WorkSource workSource, C callback, T info, GattService service) {
    App add(UUID uuid, WorkSource workSource, C callback, T info, GattService service) {
        int appUid = Binder.getCallingUid();
        String appName = service.getPackageManager().getNameForUid(appUid);
        if (appName == null) {
@@ -164,8 +170,10 @@ import com.android.bluetooth.btservice.BluetoothProto;
                appScanStats = new AppScanStats(appName, workSource, this, service);
                mAppScanStats.put(appUid, appScanStats);
            }
            mApps.add(new App(uuid, callback, info, appName, appScanStats));
            App app = new App(uuid, callback, info, appName, appScanStats);
            mApps.add(app);
            appScanStats.isRegistered = true;
            return app;
        }
    }

+24 −13
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.util.NumberUtils;
import com.android.internal.annotations.VisibleForTesting;

import java.security.Security;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -846,7 +847,7 @@ public class GattService extends ProfileService {
                if (cbApp.callback != null) {
                    cbApp.linkToDeath(new ScannerDeathRecipient(scannerId));
                } else {
                    continuePiStartScan(scannerId, cbApp.info);
                    continuePiStartScan(scannerId, cbApp);
                }
            } else {
                mScannerMap.remove(scannerId);
@@ -1629,26 +1630,36 @@ public class GattService extends ProfileService {
        piInfo.settings = settings;
        piInfo.filters = filters;
        piInfo.callingPackage = callingPackage;
        mScannerMap.add(uuid, null, null, piInfo, this);
        ScannerMap.App app = mScannerMap.add(uuid, null, null, piInfo, this);
        try {
            app.hasLocationPermisson =
                    Utils.checkCallerHasLocationPermission(this, mAppOps, callingPackage);
        } catch (SecurityException se) {
            // No need to throw here. Just mark as not granted.
            app.hasLocationPermisson = false;
        }
        try {
            app.hasPeersMacAddressPermission = Utils.checkCallerHasPeersMacAddressPermission(this);
        } catch (SecurityException se) {
            // No need to throw here. Just mark as not granted.
            app.hasPeersMacAddressPermission = false;
        }
        mScanManager.registerScanner(uuid);
    }

    void continuePiStartScan(int scannerId, PendingIntentInfo piInfo) {
    void continuePiStartScan(int scannerId, ScannerMap.App app) {
        final PendingIntentInfo piInfo = app.info;
        final ScanClient scanClient =
                new ScanClient(scannerId, piInfo.settings, piInfo.filters, null);
        scanClient.hasLocationPermission =
                true; // Utils.checkCallerHasLocationPermission(this, mAppOps,
        // piInfo.callingPackage);
        scanClient.hasPeersMacAddressPermission =
                true; // Utils.checkCallerHasPeersMacAddressPermission(
        // this);
        scanClient.hasLocationPermission = app.hasLocationPermisson;
        scanClient.hasPeersMacAddressPermission = app.hasPeersMacAddressPermission;
        scanClient.legacyForegroundApp = Utils.isLegacyForegroundApp(this, piInfo.callingPackage);

        AppScanStats app = mScannerMap.getAppScanStatsById(scannerId);
        if (app != null) {
            scanClient.stats = app;
        AppScanStats scanStats = mScannerMap.getAppScanStatsById(scannerId);
        if (scanStats != null) {
            scanClient.stats = scanStats;
            boolean isFilteredScan = (piInfo.filters != null) && !piInfo.filters.isEmpty();
            app.recordScanStart(piInfo.settings, isFilteredScan, scannerId);
            scanStats.recordScanStart(piInfo.settings, isFilteredScan, scannerId);
        }

        mScanManager.startScan(scanClient);