OSDN Git Service

Drop uses-feature requirement for system process
authorEugene Susla <eugenesusla@google.com>
Tue, 25 Apr 2017 19:24:34 +0000 (12:24 -0700)
committerEugene Susla <eugenesusla@google.com>
Tue, 25 Apr 2017 19:57:23 +0000 (12:57 -0700)
Fixes: 37673382
Test: go through setup wizard and ensure no exception from bug report
  is present
Change-Id: I5a64586c1baec54ae579f47771546493f82b19df

services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java

index 9bb0f86..16b6ca8 100644 (file)
@@ -244,7 +244,7 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
         }
 
         private void checkCallerIsSystemOr(String pkg, int userId) throws RemoteException {
-            if (getCallingUserId() == UserHandle.USER_SYSTEM) {
+            if (isCallerSystem()) {
                 return;
             }
 
@@ -294,6 +294,11 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
         }
 
         private void checkUsesFeature(String pkg, int userId) {
+            if (isCallerSystem()) {
+                // Drop the requirement for calls from system process
+                return;
+            }
+
             FeatureInfo[] reqFeatures = getPackageInfo(pkg, userId).reqFeatures;
             String requiredFeature = PackageManager.FEATURE_COMPANION_DEVICE_SETUP;
             int numFeatures = ArrayUtils.size(reqFeatures);
@@ -306,10 +311,14 @@ public class CompanionDeviceManagerService extends SystemService implements Bind
         }
     }
 
-    private int getCallingUserId() {
+    private static int getCallingUserId() {
         return UserHandle.getUserId(Binder.getCallingUid());
     }
 
+    private static boolean isCallerSystem() {
+        return getCallingUserId() == UserHandle.USER_SYSTEM;
+    }
+
     private ServiceConnection createServiceConnection(
             final AssociationRequest request,
             final IFindDeviceCallback findDeviceCallback,