Android11系统默认给第三方应用授权方法

默认授权SYSTEM_ALERT_WINDOW权限,AppOpsManager.java里面支持的权限都可以使用该方法进行授权。

frameworks/base/services/core/java/com/android/server/wm/ActivityStarter.java

private int executeRequest(Request request) {

mInterceptor.setStates(userId, realCallingPid, realCallingUid, startFlags, callingPackage,
callingFeatureId);
if (mInterceptor.intercept(intent, rInfo, aInfo, resolvedType, inTask, callingPid,
callingUid, checkedOptions)) {
// activity start was intercepted, e.g. because the target user is currently in quiet
// mode (turn off work) or the target application is suspended
intent = mInterceptor.mIntent;
rInfo = mInterceptor.mRInfo;
aInfo = mInterceptor.mAInfo;
resolvedType = mInterceptor.mResolvedType;
inTask = mInterceptor.mInTask;
callingPid = mInterceptor.mCallingPid;
callingUid = mInterceptor.mCallingUid;
checkedOptions = mInterceptor.mActivityOptions;

        // The interception target shouldn't get any permission grants
        // intended for the original destination
        intentGrants = null;
    }
  • if(intent.getComponent().getPackageName()!=null){
  •                   +setPermissionAsUser(mService.mContext,intent.getComponent().getPackageName());
    
  •           }
    


}
}
//18682015156
public void setPermissionAsUser(Context context, String packageName) {
final boolean isSystemApp;
Context mContext = context;
AppOpsManager mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
try {
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(packageName,PackageManager.GET_DISABLED_COMPONENTS
|PackageManager.GET_UNINSTALLED_PACKAGES |PackageManager.GET_SIGNATURES);
if(packageInfo!=null){
isSystemApp = (packageInfo.applicationInfo.flags & (ApplicationInfo.FLAG_SYSTEM
|ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
if(!isSystemApp){
mAppOpsManager.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,packageInfo.applicationInfo.uid,
packageName, AppOpsManager.MODE_ALLOWED);
android.util.Log.i(“setPermissionAsUser”, “setPermissionAsUser packageName:”+packageName);
}
}else{
android.util.Log.i(“setPermissionAsUser”, “setPermissionAsUser packageName:”
+packageName+" packageInfo:" +packageInfo);
}
} catch (Exception e) {
android.util.Log.i(“setPermissionAsUser”, “Exception when retrieving package:”, e);
}
}

猜你喜欢

转载自blog.csdn.net/xiaoxiaowu520/article/details/128180823