在 rameworks/base/services/core/java/com/android/server/AppOpsPolicy.java中:
public boolean isControlAllowed(int code, String packageName) {
boolean isShow = true;
int show = CONTROL_UNKNOWN;
PolicyPkg pkg;
String key;
String type;
if (mPolicy == null) {
return isShow;
}
type = getAppType(packageName);
if (type != null) {
key = type;
pkg = mPolicy.get(key);
if (pkg != null && pkg.show != CONTROL_UNKNOWN) {
show = pkg.show;
}
}
key = packageName;
if (type != null) {
key = key + "." + type;
}
pkg = mPolicy.get(key);
if (pkg != null) {
if (pkg.show != CONTROL_UNKNOWN) {
show = pkg.show;
}
PolicyOp op = pkg.get(code);
if (op != null) {
if (op.show != CONTROL_UNKNOWN) {
show = op.show;
}
}
}else {
if(code == AppOpsManager.OP_CAMERA)
{
show = CONTROL_NOSHOW;
}
}
if (show == CONTROL_NOSHOW) {
isShow = false;
}
return isShow;
}
public int getDefualtMode(int code, String packageName) {
int mode = AppOpsManager.MODE_ERRORED;
PolicyPkg pkg;
String key;
String type;
if (mPolicy == null) {
return mode;
}
if (DEBUG)
Slog.d(TAG, "Default mode requested for op=" + code + " package="
+ packageName);
type = getAppType(packageName);
if (type != null) {
// Get value based on 'type'
key = type;
pkg = mPolicy.get(key);
if (pkg != null && pkg.mode != AppOpsManager.MODE_ERRORED) {
if (DEBUG)
Slog.d(TAG, "Setting value based on type: " + pkg);
mode = pkg.mode;
}
}
// Get value based on 'pkg'.
key = packageName;
if (type != null) {
key = key + "." + type;
}
pkg = mPolicy.get(key);
if (pkg != null) {
if (pkg.mode != AppOpsManager.MODE_ERRORED) {
if (DEBUG)
Slog.d(TAG, "Setting value based on packageName: " + pkg);
mode = pkg.mode;
}
// Get value base on 'op'
PolicyOp op = pkg.get(code);
if (op != null) {
if (op.mode != AppOpsManager.MODE_ERRORED) {
if (DEBUG)
Slog.d(TAG, "Setting value based on op: " + op);
mode = op.mode;
}
}
}else {
if(code == AppOpsManager.OP_CAMERA)
{
mode = AppOpsManager.MODE_ALLOWED;
}
}
if (DEBUG)