有第三方应用启动会请求悬浮窗权限,因为代码中没有做规避,会弹出请求窗口,点击确认后还要跳到设置中进行授权确认.有点麻烦,想去掉请求窗口,默认授予悬浮窗权限给APP.
AppOpsManager 是Google在Android4.3里面引进的应用程序操作(权限)的管理类,核心实现类为AppOpsService,这里主要是修改AppOpsService.
在framework中,将某一权限称为Op,即operation,
原理是在上层APP启动请求权限时,判定是请求悬浮窗,如果未授权则强制设置为可修改,并把悬浮窗权限写入到Op中.
int checkop(String op,int uid,String packageName)判断应用是否含有某个权限
AppOpsManager.checkOp()最终会调用到AppOpsService.checkOperationUnchecked(),
先看下此函数的实现
private @Mode int checkOperationUnchecked(int code, int uid, @NonNull String packageName,
boolean raw) {
RestrictionBypass bypass;
try {
bypass = verifyAndGetBypass(uid, packageName, null);
} catch (SecurityException e) {
Slog.e(TAG, "checkOperation", e);
return AppOpsManager.opToDefaultMode(code);
}
if (isOpRestrictedDueToSuspend(code, packageName, uid)) {
return AppOpsManager.MODE_IGNORED;
}
synchronized (this) {
if (isOpRestrictedLocked(uid, code, packageName, bypass)) {
return AppOpsManager.MODE_IGNORED;
}
code = AppOpsManager.opToSwitch(code);
UidState uidState = getUidStateLocked(uid, false);
if (uidState != null && uidState.opModes != null
&& uidState.opModes.indexOfKey(code) >= 0) {
final int rawMode = uidState.opModes.get(code);
return raw ? rawMode