diff options
author | Billy Lau <billylau@google.com> | 2015-08-07 22:22:19 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-08-07 22:22:19 +0000 |
commit | 5b2c66e4da749ca59d09776ec7831e20d1211909 (patch) | |
tree | e04c07ba014ba80cd0a3e35102ef7e26630573ae | |
parent | 7a3a453349fb51043d84adc21f87472ba34c49a8 (diff) | |
parent | a59f39fca65d0828b0e4ade95a8404282e858ba9 (diff) | |
download | packages_apps_Settings-5b2c66e4da749ca59d09776ec7831e20d1211909.zip packages_apps_Settings-5b2c66e4da749ca59d09776ec7831e20d1211909.tar.gz packages_apps_Settings-5b2c66e4da749ca59d09776ec7831e20d1211909.tar.bz2 |
am a59f39fc: Merge "Bug: 21588539 Move CHANGE_NETWORK_STATE to be in SYSTEM_SETTINGS" into mnc-dev
* commit 'a59f39fca65d0828b0e4ade95a8404282e858ba9':
Bug: 21588539 Move CHANGE_NETWORK_STATE to be in SYSTEM_SETTINGS
4 files changed, 41 insertions, 11 deletions
diff --git a/src/com/android/settings/applications/AppStateAppOpsBridge.java b/src/com/android/settings/applications/AppStateAppOpsBridge.java index 1a69322..ebff54e 100644 --- a/src/com/android/settings/applications/AppStateAppOpsBridge.java +++ b/src/com/android/settings/applications/AppStateAppOpsBridge.java @@ -34,8 +34,11 @@ import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.applications.ApplicationsState.AppEntry; import com.android.settingslib.applications.ApplicationsState.AppFilter; +import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; /* * Connects app ops info to the ApplicationsState. Makes use of AppOpsManager to @@ -54,7 +57,7 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { private final String[] mPermissions; public AppStateAppOpsBridge(Context context, ApplicationsState appState, Callback callback, - int appOpsOpCode, String permissionName) { + int appOpsOpCode, String[] permissions) { super(appState, callback); mContext = context; mIPackageManager = AppGlobals.getPackageManager(); @@ -62,7 +65,7 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { mProfiles = mUserManager.getUserProfiles(); mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); mAppOpsOpCodes = new int[] {appOpsOpCode}; - mPermissions = new String[] {permissionName}; + mPermissions = permissions; } private boolean isThisUserAProfileOfCurrentUser(final int userId) { @@ -77,6 +80,15 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { protected abstract void updateExtraInfo(AppEntry app, String pkg, int uid); + private boolean doesAnyPermissionMatch(String permissionToMatch, String[] permissions) { + for (String permission : permissions) { + if (permissionToMatch.equals(permission)) { + return true; + } + } + return false; + } + public PermissionState getPermissionInfo(String pkg, int uid) { PermissionState permissionState = new PermissionState(pkg, new UserHandle(UserHandle .getUserId(uid))); @@ -88,7 +100,7 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { int[] permissionFlags = permissionState.packageInfo.requestedPermissionsFlags; if (requestedPermissions != null) { for (int i = 0; i < requestedPermissions.length; i++) { - if (mPermissions[0].equals(requestedPermissions[i])) { + if (doesAnyPermissionMatch(requestedPermissions[i], mPermissions)) { permissionState.permissionDeclared = true; if ((permissionFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) { permissionState.staticPermissionGranted = true; @@ -133,9 +145,15 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { */ private SparseArray<ArrayMap<String, PermissionState>> getEntries() { try { - final String[] packages = mIPackageManager.getAppOpPermissionPackages(mPermissions[0]); + Set<String> packagesSet = new HashSet<>(); + for (String permission : mPermissions) { + String[] pkgs = mIPackageManager.getAppOpPermissionPackages(permission); + if (pkgs != null) { + packagesSet.addAll(Arrays.asList(pkgs)); + } + } - if (packages == null) { + if (packagesSet.isEmpty()) { // No packages are requesting permission as specified by mPermissions. return null; } @@ -147,7 +165,7 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { final ArrayMap<String, PermissionState> entriesForProfile = new ArrayMap<>(); final int profileId = profile.getIdentifier(); entries.put(profileId, entriesForProfile); - for (final String packageName : packages) { + for (final String packageName : packagesSet) { final boolean isAvailable = mIPackageManager.isPackageAvailable(packageName, profileId); if (!shouldIgnorePackage(packageName) && isAvailable) { @@ -193,7 +211,7 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { } } catch (RemoteException e) { Log.w(TAG, "PackageManager is dead. Can't get list of packages granted " - + mPermissions[0], e); + + mPermissions, e); return; } } @@ -223,7 +241,7 @@ public abstract class AppStateAppOpsBridge extends AppStateBaseBridge { if (pe == null) { Log.w(TAG, "AppOp permission exists for package " + packageOp.getPackageName() + " of user " + userId + " but package doesn't exist or did not request " - + mPermissions[0] + " access"); + + mPermissions + " access"); continue; } diff --git a/src/com/android/settings/applications/AppStateOverlayBridge.java b/src/com/android/settings/applications/AppStateOverlayBridge.java index c603028..71a6037 100644 --- a/src/com/android/settings/applications/AppStateOverlayBridge.java +++ b/src/com/android/settings/applications/AppStateOverlayBridge.java @@ -34,9 +34,12 @@ public class AppStateOverlayBridge extends AppStateAppOpsBridge { private static final String TAG = "AppStateOverlayBridge"; private static final int APP_OPS_OP_CODE = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; private static final String PM_SYSTEM_ALERT_WINDOW = Manifest.permission.SYSTEM_ALERT_WINDOW; + private static final String[] PM_PERMISSION = { + PM_SYSTEM_ALERT_WINDOW + }; public AppStateOverlayBridge(Context context, ApplicationsState appState, Callback callback) { - super(context, appState, callback, APP_OPS_OP_CODE, PM_SYSTEM_ALERT_WINDOW); + super(context, appState, callback, APP_OPS_OP_CODE, PM_PERMISSION); } @Override diff --git a/src/com/android/settings/applications/AppStateUsageBridge.java b/src/com/android/settings/applications/AppStateUsageBridge.java index ef5a2c7..70a3ae6 100644 --- a/src/com/android/settings/applications/AppStateUsageBridge.java +++ b/src/com/android/settings/applications/AppStateUsageBridge.java @@ -35,9 +35,12 @@ public class AppStateUsageBridge extends AppStateAppOpsBridge { private static final String PM_USAGE_STATS = Manifest.permission.PACKAGE_USAGE_STATS; private static final int APP_OPS_OP_CODE = AppOpsManager.OP_GET_USAGE_STATS; + private static final String[] PM_PERMISSION = { + PM_USAGE_STATS + }; public AppStateUsageBridge(Context context, ApplicationsState appState, Callback callback) { - super(context, appState, callback, APP_OPS_OP_CODE, PM_USAGE_STATS); + super(context, appState, callback, APP_OPS_OP_CODE, PM_PERMISSION); } @Override diff --git a/src/com/android/settings/applications/AppStateWriteSettingsBridge.java b/src/com/android/settings/applications/AppStateWriteSettingsBridge.java index 9dbe13b..7cdf7ea 100644 --- a/src/com/android/settings/applications/AppStateWriteSettingsBridge.java +++ b/src/com/android/settings/applications/AppStateWriteSettingsBridge.java @@ -34,10 +34,16 @@ public class AppStateWriteSettingsBridge extends AppStateAppOpsBridge { private static final String TAG = "AppStateWriteSettingsBridge"; private static final int APP_OPS_OP_CODE = AppOpsManager.OP_WRITE_SETTINGS; private static final String PM_WRITE_SETTINGS = Manifest.permission.WRITE_SETTINGS; + private static final String PM_CHANGE_NETWORK_STATE = Manifest.permission.CHANGE_NETWORK_STATE; + // CHANGE_NETWORK_STATE is now merged with WRITE_SETTINGS + private static final String[] PM_PERMISSIONS = { + PM_WRITE_SETTINGS, + PM_CHANGE_NETWORK_STATE + }; public AppStateWriteSettingsBridge(Context context, ApplicationsState appState, Callback callback) { - super(context, appState, callback, APP_OPS_OP_CODE, PM_WRITE_SETTINGS); + super(context, appState, callback, APP_OPS_OP_CODE, PM_PERMISSIONS); } @Override |