summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFyodor Kupolov <fkupolov@google.com>2015-10-15 16:19:12 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-10-15 16:19:12 +0000
commit80a654ab3be8109bc427e27055b569127941215d (patch)
tree7d68da2cc2faeb00f63c8f868eb8d0728d7a24f7
parent836f7d384eea45c1cc29ab671be798e6b26da519 (diff)
parent4a9f9b0253fde7341bf9e12c5bd0e6f29fced4fc (diff)
downloadandroid_packages_apps_Bluetooth-80a654ab3be8109bc427e27055b569127941215d.tar.gz
android_packages_apps_Bluetooth-80a654ab3be8109bc427e27055b569127941215d.tar.bz2
android_packages_apps_Bluetooth-80a654ab3be8109bc427e27055b569127941215d.zip
am 4a9f9b02: Fix foreground scans for pre-M apps when location is disabled
* commit '4a9f9b0253fde7341bf9e12c5bd0e6f29fced4fc': Fix foreground scans for pre-M apps when location is disabled
-rw-r--r--src/com/android/bluetooth/Utils.java23
-rw-r--r--src/com/android/bluetooth/gatt/GattService.java15
-rw-r--r--src/com/android/bluetooth/gatt/ScanClient.java2
3 files changed, 25 insertions, 15 deletions
diff --git a/src/com/android/bluetooth/Utils.java b/src/com/android/bluetooth/Utils.java
index a16d3b9c4..6a467f9c3 100644
--- a/src/com/android/bluetooth/Utils.java
+++ b/src/com/android/bluetooth/Utils.java
@@ -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 {
@@ -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.
*
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index a5fdfea68..4847c53ce 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -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.
@@ -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);
}
diff --git a/src/com/android/bluetooth/gatt/ScanClient.java b/src/com/android/bluetooth/gatt/ScanClient.java
index d42df39d2..64d3e1ffc 100644
--- a/src/com/android/bluetooth/gatt/ScanClient.java
+++ b/src/com/android/bluetooth/gatt/ScanClient.java
@@ -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();