Merge "Add API to get app op for a permission" into mnc-dev

This commit is contained in:
Svet Ganov
2015-04-29 21:15:24 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 0 deletions

View File

@@ -3949,6 +3949,7 @@ package android.app {
method public void finishOp(java.lang.String, int, java.lang.String);
method public int noteOp(java.lang.String, int, java.lang.String);
method public int noteOpNoThrow(java.lang.String, int, java.lang.String);
method public static java.lang.String permissionToOp(java.lang.String);
method public int startOp(java.lang.String, int, java.lang.String);
method public int startOpNoThrow(java.lang.String, int, java.lang.String);
method public void startWatchingMode(java.lang.String, java.lang.String, android.app.AppOpsManager.OnOpChangedListener);

View File

@@ -726,6 +726,16 @@ public class AppOpsManager {
false
};
/**
* This is a mapping from a permission name to public app op name.
*/
private static final ArrayMap<String, String> sPermToOp = new ArrayMap<>();
static {
sPermToOp.put(Manifest.permission.ACCESS_COARSE_LOCATION, OPSTR_COARSE_LOCATION);
sPermToOp.put(Manifest.permission.ACCESS_FINE_LOCATION, OPSTR_FINE_LOCATION);
sPermToOp.put(Manifest.permission.PACKAGE_USAGE_STATS, OPSTR_GET_USAGE_STATS);
}
private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
static {
@@ -1065,6 +1075,21 @@ public class AppOpsManager {
}
}
/**
* Gets the app op name associated with a given permission.
* The app op name is one of the public constants defined
* in this class such as {@link #OPSTR_COARSE_LOCATION}.
*
* @param permission The permission.
* @return The app op associated with the permission or null.
*
* @hide
*/
@SystemApi
public static String permissionToOp(String permission) {
return sPermToOp.get(permission);
}
/**
* Monitor for changes to the operating mode for the given op in the given app package.
* @param op The operation to monitor, one of OPSTR_*.