OSDN Git Service

Fix PEERS_MAC_ADDRESS permission for Ble Scanning.
authorCalvin On <con@google.com>
Tue, 12 Apr 2016 22:43:59 +0000 (15:43 -0700)
committerCalvin On <con@google.com>
Tue, 12 Apr 2016 22:52:07 +0000 (15:52 -0700)
This changes the location permissions check to only throw a SecurityException
if *both* location and peers mac address permissions are missing.

Bug: 27837639
Change-Id: I5e10c8f0564d1f7edab23ad22dbd5aa5fdcbbf76

src/com/android/bluetooth/Utils.java

index e78341a..66d2172 100644 (file)
@@ -291,8 +291,13 @@ final public class Utils {
         }
         // Enforce location permission for apps targeting M and later versions
         if (isMApp(context, callingPackage)) {
-            throw new SecurityException("Need ACCESS_COARSE_LOCATION or "
-                    + "ACCESS_FINE_LOCATION permission to get scan results");
+            // PEERS_MAC_ADDRESS is another way to get scan results without
+            // requiring location permissions, so only throw an exception here
+            // if PEERS_MAC_ADDRESS permission is missing as well
+            if (!checkCallerHasPeersMacAddressPermission(context)) {
+                throw new SecurityException("Need ACCESS_COARSE_LOCATION or "
+                        + "ACCESS_FINE_LOCATION permission to get scan results");
+            }
         } else {
             // Pre-M apps running in the foreground should continue getting scan results
             if (isForegroundApp(context, callingPackage)) {