我是靠谱客的博主 丰富橘子,最近开发中收集的这篇文章主要介绍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);
}
}

最后

以上就是丰富橘子为你收集整理的Android11系统默认给第三方应用授权方法的全部内容,希望文章能够帮你解决Android11系统默认给第三方应用授权方法所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部