在 frameworks/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)
Slog.d(TAG, "Returning mode=" + mode);
return mode;
}
可以设置所有的用户APP默认打开摄像头的权限。
如果是要设置为允许某个用户APP默认打开摄像头权限,请打开/device/qcom/common/appops/appops_policy.xml,
<application>
<!-- Example:
<pkg name="com.android.dialer" type="system-app">
<op name="android:call_phone" permission="ask" show="true"/>
</pkg>
-->
<pkg name="com.android.calendar" type="system-app">
<op name="android:read_contacts" permission="ask" show="true"/>
</pkg>
<pkg name="com.android.email" type="system-app">
<op name="android:read_contacts" permission="ask" show="true"/>
</pkg>
<pkg name="com.huayusoft.barcodeadmin" type="user-app">
<op name="android:camera" permission="allow" show="false"/>
</pkg>
以上是两种设置默认权限的方式!
转自雨滴科技-活着