【轉】 android5.1裡面的user-app的預設許可權設定!
在 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,
<appops-policy version="1">
<user-app permission="ask" show="true"/>
<system-app permission="allowed" show="false"/>
<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>
</application>
</appops-policy>
以上是兩種設定預設許可權的方式!
轉自雨滴科技-活著