Loading android/app/src/com/android/bluetooth/Utils.java +15 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; } Loading @@ -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; Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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; } Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +8 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -1292,7 +1293,7 @@ public class AdapterService extends Service { enforceBluetoothAdminPermission(service); return service.startDiscovery(callingPackage); return service.startDiscovery(callingPackage, callingFeatureId); } @Override Loading Loading @@ -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); Loading @@ -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; Loading android/app/src/com/android/bluetooth/gatt/GattService.java +17 −14 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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"); } Loading @@ -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); Loading @@ -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"); } Loading Loading @@ -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. Loading Loading
android/app/src/com/android/bluetooth/Utils.java +15 −8 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -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; } Loading @@ -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; Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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; } Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +8 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading @@ -1292,7 +1293,7 @@ public class AdapterService extends Service { enforceBluetoothAdminPermission(service); return service.startDiscovery(callingPackage); return service.startDiscovery(callingPackage, callingFeatureId); } @Override Loading Loading @@ -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); Loading @@ -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; Loading
android/app/src/com/android/bluetooth/gatt/GattService.java +17 −14 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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"); } Loading @@ -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); Loading @@ -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"); } Loading Loading @@ -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. Loading