概述
默认授权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);
}
}
最后
以上就是丰富橘子为你收集整理的Android11系统默认给第三方应用授权方法的全部内容,希望文章能够帮你解决Android11系统默认给第三方应用授权方法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复