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

Commit 8c10e8f2 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by android-build-merger
Browse files

Merge "Pipe featureId from app to noteOp in BT code"

am: fee9bbed

Change-Id: I868da2f757fab3e7a5ef614f7c05f7e4dfd82497
parents 024c0c44 fee9bbed
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.bluetooth;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AppOpsManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -386,7 +388,7 @@ public final class Utils {
     * OP_COARSE_LOCATION is allowed
     */
    public static boolean checkCallerHasCoarseLocation(Context context, AppOpsManager appOps,
            String callingPackage, UserHandle userHandle) {
            String callingPackage, @Nullable String callingFeatureId, UserHandle userHandle) {
        if (blockedByLocationOff(context, userHandle)) {
            Log.e(TAG, "Permission denial: Location is off.");
            return false;
@@ -396,7 +398,8 @@ public final class Utils {
        if (context.checkCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_COARSE_LOCATION)
                        == PackageManager.PERMISSION_GRANTED
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage)) {
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage,
                callingFeatureId)) {
            return true;
        }

@@ -411,7 +414,7 @@ public final class Utils {
     * OP_FINE_LOCATION is allowed
     */
    public static boolean checkCallerHasCoarseOrFineLocation(Context context, AppOpsManager appOps,
            String callingPackage, UserHandle userHandle) {
            String callingPackage, @Nullable String callingFeatureId, UserHandle userHandle) {
        if (blockedByLocationOff(context, userHandle)) {
            Log.e(TAG, "Permission denial: Location is off.");
            return false;
@@ -420,7 +423,8 @@ public final class Utils {
        if (context.checkCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_FINE_LOCATION)
                        == PackageManager.PERMISSION_GRANTED
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage)) {
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage,
                callingFeatureId)) {
            return true;
        }

@@ -428,7 +432,8 @@ public final class Utils {
        if (context.checkCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_COARSE_LOCATION)
                        == PackageManager.PERMISSION_GRANTED
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage)) {
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage,
                callingFeatureId)) {
            return true;
        }

@@ -442,7 +447,7 @@ public final class Utils {
     * OP_FINE_LOCATION is allowed
     */
    public static boolean checkCallerHasFineLocation(Context context, AppOpsManager appOps,
            String callingPackage, UserHandle userHandle) {
            String callingPackage, @Nullable String callingFeatureId, UserHandle userHandle) {
        if (blockedByLocationOff(context, userHandle)) {
            Log.e(TAG, "Permission denial: Location is off.");
            return false;
@@ -451,7 +456,8 @@ public final class Utils {
        if (context.checkCallingOrSelfPermission(
                android.Manifest.permission.ACCESS_FINE_LOCATION)
                        == PackageManager.PERMISSION_GRANTED
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage)) {
                && isAppOppAllowed(appOps, AppOpsManager.OPSTR_FINE_LOCATION, callingPackage,
                callingFeatureId)) {
            return true;
        }

@@ -487,7 +493,8 @@ public final class Utils {
        return true;
    }

    private static boolean isAppOppAllowed(AppOpsManager appOps, String op, String callingPackage) {
    private static boolean isAppOppAllowed(AppOpsManager appOps, String op, String callingPackage,
            @NonNull String callingFeatureId) {
        return appOps.noteOp(op, Binder.getCallingUid(), callingPackage)
                == AppOpsManager.MODE_ALLOWED;
    }
+8 −5
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.bluetooth.Utils.enforceBluetoothPrivilegedPermission;
import static com.android.bluetooth.Utils.enforceDumpPermission;
import static com.android.bluetooth.Utils.enforceLocalMacAddressPermission;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.AppOpsManager;
@@ -1284,7 +1285,7 @@ public class AdapterService extends Service {
        }

        @Override
        public boolean startDiscovery(String callingPackage) {
        public boolean startDiscovery(String callingPackage, String callingFeatureId) {
            AdapterService service = getService();
            if (service == null || !callerIsSystemOrActiveUser(TAG, "startDiscovery")) {
                return false;
@@ -1292,7 +1293,7 @@ public class AdapterService extends Service {

            enforceBluetoothAdminPermission(service);

            return service.startDiscovery(callingPackage);
            return service.startDiscovery(callingPackage, callingFeatureId);
        }

        @Override
@@ -2153,7 +2154,7 @@ public class AdapterService extends Service {
        }
    }

    boolean startDiscovery(String callingPackage) {
    boolean startDiscovery(String callingPackage, @Nullable String callingFeatureId) {
        UserHandle callingUser = UserHandle.of(UserHandle.getCallingUserId());
        debugLog("startDiscovery");
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
@@ -2164,12 +2165,14 @@ public class AdapterService extends Service {
        } else if (Utils.checkCallerHasNetworkSetupWizardPermission(this)) {
            permission = android.Manifest.permission.NETWORK_SETUP_WIZARD;
        } else if (isQApp) {
            if (!Utils.checkCallerHasFineLocation(this, mAppOps, callingPackage, callingUser)) {
            if (!Utils.checkCallerHasFineLocation(this, mAppOps, callingPackage, callingFeatureId,
                    callingUser)) {
                return false;
            }
            permission = android.Manifest.permission.ACCESS_FINE_LOCATION;
        } else {
            if (!Utils.checkCallerHasCoarseLocation(this, mAppOps, callingPackage, callingUser)) {
            if (!Utils.checkCallerHasCoarseLocation(this, mAppOps, callingPackage, callingFeatureId,
                    callingUser)) {
                return false;
            }
            permission = android.Manifest.permission.ACCESS_COARSE_LOCATION;
+17 −14
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.bluetooth.gatt;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.annotation.Nullable;
import android.app.AppOpsManager;
import android.app.PendingIntent;
import android.app.Service;
@@ -466,22 +467,25 @@ public class GattService extends ProfileService {

        @Override
        public void startScan(int scannerId, ScanSettings settings, List<ScanFilter> filters,
                List storages, String callingPackage) {
                List storages, String callingPackage, String callingFeatureId) {
            GattService service = getService();
            if (service == null) {
                return;
            }
            service.startScan(scannerId, settings, filters, storages, callingPackage);
            service.startScan(scannerId, settings, filters, storages, callingPackage,
                    callingFeatureId);
        }

        @Override
        public void startScanForIntent(PendingIntent intent, ScanSettings settings,
                List<ScanFilter> filters, String callingPackage) throws RemoteException {
                List<ScanFilter> filters, String callingPackage, String callingFeatureId)
                throws RemoteException {
            GattService service = getService();
            if (service == null) {
                return;
            }
            service.registerPiAndStartScan(intent, settings, filters, callingPackage);
            service.registerPiAndStartScan(intent, settings, filters, callingPackage,
                    callingFeatureId);
        }

        @Override
@@ -1933,7 +1937,8 @@ public class GattService extends ProfileService {
    }

    void startScan(int scannerId, ScanSettings settings, List<ScanFilter> filters,
            List<List<ResultStorageDescriptor>> storages, String callingPackage) {
            List<List<ResultStorageDescriptor>> storages, String callingPackage,
            @Nullable String callingFeatureId) {
        if (DBG) {
            Log.d(TAG, "start scan with filters");
        }
@@ -1947,13 +1952,11 @@ public class GattService extends ProfileService {
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        scanClient.isQApp = Utils.isQApp(this, callingPackage);
        if (scanClient.isQApp) {
            scanClient.hasLocationPermission =
                    Utils.checkCallerHasFineLocation(
                            this, mAppOps, callingPackage, scanClient.userHandle);
            scanClient.hasLocationPermission = Utils.checkCallerHasFineLocation(this, mAppOps,
                    callingPackage, callingFeatureId, scanClient.userHandle);
        } else {
            scanClient.hasLocationPermission =
                    Utils.checkCallerHasCoarseOrFineLocation(
                            this, mAppOps, callingPackage, scanClient.userHandle);
            scanClient.hasLocationPermission = Utils.checkCallerHasCoarseOrFineLocation(this,
                    mAppOps, callingPackage, callingFeatureId, scanClient.userHandle);
        }
        scanClient.hasNetworkSettingsPermission =
                Utils.checkCallerHasNetworkSettingsPermission(this);
@@ -1976,7 +1979,7 @@ public class GattService extends ProfileService {
    }

    void registerPiAndStartScan(PendingIntent pendingIntent, ScanSettings settings,
            List<ScanFilter> filters, String callingPackage) {
            List<ScanFilter> filters, String callingPackage, @Nullable String callingFeatureId) {
        if (DBG) {
            Log.d(TAG, "start scan with filters, for PendingIntent");
        }
@@ -2008,10 +2011,10 @@ public class GattService extends ProfileService {
        try {
            if (app.mIsQApp) {
                app.hasLocationPermission = Utils.checkCallerHasFineLocation(
                      this, mAppOps, callingPackage, app.mUserHandle);
                      this, mAppOps, callingPackage, callingFeatureId, app.mUserHandle);
            } else {
                app.hasLocationPermission = Utils.checkCallerHasCoarseOrFineLocation(
                      this, mAppOps, callingPackage, app.mUserHandle);
                      this, mAppOps, callingPackage, callingFeatureId, app.mUserHandle);
            }
        } catch (SecurityException se) {
            // No need to throw here. Just mark as not granted.