Loading android/app/src/com/android/bluetooth/Utils.java +15 −8 Original line number Diff line number Diff line Loading @@ -288,14 +288,7 @@ final public class Utils { return true; } // Enforce location permission for apps targeting M and later versions boolean enforceLocationPermission = true; try { enforceLocationPermission = context.getPackageManager().getApplicationInfo( callingPackage, 0).targetSdkVersion >= Build.VERSION_CODES.M; } catch (PackageManager.NameNotFoundException e) { // In case of exception, enforce permission anyway } if (enforceLocationPermission) { if (isMApp(context, callingPackage)) { throw new SecurityException("Need ACCESS_COARSE_LOCATION or " + "ACCESS_FINE_LOCATION permission to get scan results"); } else { Loading @@ -317,6 +310,20 @@ final public class Utils { android.Manifest.permission.PEERS_MAC_ADDRESS) == PackageManager.PERMISSION_GRANTED; } public static boolean isLegacyForegroundApp(Context context, String pkgName) { return !isMApp(context, pkgName) && isForegroundApp(context, pkgName); } private static boolean isMApp(Context context, String pkgName) { try { return context.getPackageManager().getApplicationInfo(pkgName, 0) .targetSdkVersion >= Build.VERSION_CODES.M; } catch (PackageManager.NameNotFoundException e) { // In case of exception, assume M app } return true; } /** * Return true if the specified package name is a foreground app. * Loading android/app/src/com/android/bluetooth/gatt/GattService.java +8 −7 Original line number Diff line number Diff line Loading @@ -641,12 +641,13 @@ public class GattService extends ProfileService { private boolean hasScanResultPermission(final ScanClient client) { final boolean requiresLocationEnabled = getResources().getBoolean(R.bool.strict_location_check); final boolean locationEnabled = Settings.Secure.getInt(getContentResolver(), final boolean locationEnabledSetting = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF) != Settings.Secure.LOCATION_MODE_OFF; return (client.hasPeersMacAddressPermission || (client.hasLocationPermission && (!requiresLocationEnabled || locationEnabled))); final boolean locationEnabled = !requiresLocationEnabled || locationEnabledSetting || client.legacyForegroundApp; return (client.hasPeersMacAddressPermission || (client.hasLocationPermission && locationEnabled)); } // Check if a scan record matches a specific filters. Loading Loading @@ -1378,12 +1379,12 @@ public class GattService extends ProfileService { if (needsPrivilegedPermissionForScan(settings)) { enforcePrivilegedPermission(); } boolean hasLocationPermission = Utils.checkCallerHasLocationPermission(this, mAppOps, callingPackage); final ScanClient scanClient = new ScanClient(appIf, isServer, settings, filters, storages); scanClient.hasLocationPermission = hasLocationPermission; scanClient.hasLocationPermission = Utils.checkCallerHasLocationPermission(this, mAppOps, callingPackage); scanClient.hasPeersMacAddressPermission = Utils.checkCallerHasPeersMacAddressPermission( this); scanClient.legacyForegroundApp = Utils.isLegacyForegroundApp(this, callingPackage); mScanManager.startScan(scanClient); } Loading android/app/src/com/android/bluetooth/gatt/ScanClient.java +2 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ import java.util.UUID; boolean appDied; boolean hasLocationPermission; boolean hasPeersMacAddressPermission; // Pre-M apps are allowed to get scan results even if location is disabled boolean legacyForegroundApp; private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); Loading Loading
android/app/src/com/android/bluetooth/Utils.java +15 −8 Original line number Diff line number Diff line Loading @@ -288,14 +288,7 @@ final public class Utils { return true; } // Enforce location permission for apps targeting M and later versions boolean enforceLocationPermission = true; try { enforceLocationPermission = context.getPackageManager().getApplicationInfo( callingPackage, 0).targetSdkVersion >= Build.VERSION_CODES.M; } catch (PackageManager.NameNotFoundException e) { // In case of exception, enforce permission anyway } if (enforceLocationPermission) { if (isMApp(context, callingPackage)) { throw new SecurityException("Need ACCESS_COARSE_LOCATION or " + "ACCESS_FINE_LOCATION permission to get scan results"); } else { Loading @@ -317,6 +310,20 @@ final public class Utils { android.Manifest.permission.PEERS_MAC_ADDRESS) == PackageManager.PERMISSION_GRANTED; } public static boolean isLegacyForegroundApp(Context context, String pkgName) { return !isMApp(context, pkgName) && isForegroundApp(context, pkgName); } private static boolean isMApp(Context context, String pkgName) { try { return context.getPackageManager().getApplicationInfo(pkgName, 0) .targetSdkVersion >= Build.VERSION_CODES.M; } catch (PackageManager.NameNotFoundException e) { // In case of exception, assume M app } return true; } /** * Return true if the specified package name is a foreground app. * Loading
android/app/src/com/android/bluetooth/gatt/GattService.java +8 −7 Original line number Diff line number Diff line Loading @@ -641,12 +641,13 @@ public class GattService extends ProfileService { private boolean hasScanResultPermission(final ScanClient client) { final boolean requiresLocationEnabled = getResources().getBoolean(R.bool.strict_location_check); final boolean locationEnabled = Settings.Secure.getInt(getContentResolver(), final boolean locationEnabledSetting = Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF) != Settings.Secure.LOCATION_MODE_OFF; return (client.hasPeersMacAddressPermission || (client.hasLocationPermission && (!requiresLocationEnabled || locationEnabled))); final boolean locationEnabled = !requiresLocationEnabled || locationEnabledSetting || client.legacyForegroundApp; return (client.hasPeersMacAddressPermission || (client.hasLocationPermission && locationEnabled)); } // Check if a scan record matches a specific filters. Loading Loading @@ -1378,12 +1379,12 @@ public class GattService extends ProfileService { if (needsPrivilegedPermissionForScan(settings)) { enforcePrivilegedPermission(); } boolean hasLocationPermission = Utils.checkCallerHasLocationPermission(this, mAppOps, callingPackage); final ScanClient scanClient = new ScanClient(appIf, isServer, settings, filters, storages); scanClient.hasLocationPermission = hasLocationPermission; scanClient.hasLocationPermission = Utils.checkCallerHasLocationPermission(this, mAppOps, callingPackage); scanClient.hasPeersMacAddressPermission = Utils.checkCallerHasPeersMacAddressPermission( this); scanClient.legacyForegroundApp = Utils.isLegacyForegroundApp(this, callingPackage); mScanManager.startScan(scanClient); } Loading
android/app/src/com/android/bluetooth/gatt/ScanClient.java +2 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ import java.util.UUID; boolean appDied; boolean hasLocationPermission; boolean hasPeersMacAddressPermission; // Pre-M apps are allowed to get scan results even if location is disabled boolean legacyForegroundApp; private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); Loading