【CTA认证】Android8实现android6以下的应用运行时也要申请权限

2023-12-03 08:36

本文主要是介绍【CTA认证】Android8实现android6以下的应用运行时也要申请权限,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

需求

CTA入网认证,要求低版本比如Android6以下的应用,运行时,也需要有运行时权限(Runtime Permission)功能,不能默认就取到权限,必须人工在设置中打开才可。

环境

Android 8

实现

frameworks
修改思路是所有APP都统一处理,支持运行时权限,
把所有版本相关的判断去掉,检测是否支持运行时权限的判断去掉。

diff --git a/base/services/core/java/com/android/server/pm/PackageInstallerService.java b/base/services/core/java/com/android/server/pm/PackageInstallerService.java
index 1fa37b91..3a3433c9 100644
--- a/base/services/core/java/com/android/server/pm/PackageInstallerService.java
+++ b/base/services/core/java/com/android/server/pm/PackageInstallerService.java
@@ -436,6 +436,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub {params.installFlags |= PackageManager.INSTALL_FROM_ADB;} else {
+            mAppOps = mContext.getSystemService(AppOpsManager.class);mAppOps.checkPackage(callingUid, installerPackageName);params.installFlags &= ~PackageManager.INSTALL_FROM_ADB;
@@ -705,6 +706,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub {@Overridepublic ParceledListSlice<SessionInfo> getMySessions(String installerPackageName, int userId) {mPm.enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false, "getMySessions");
+        mAppOps = mContext.getSystemService(AppOpsManager.class);mAppOps.checkPackage(Binder.getCallingUid(), installerPackageName);final List<SessionInfo> result = new ArrayList<>();
diff --git a/base/services/core/java/com/android/server/pm/PackageManagerService.java b/base/services/core/java/com/android/server/pm/PackageManagerService.java
index aa43008b..5f0f66a4 100644
--- a/base/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/base/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -2279,8 +2279,9 @@ public class PackageManagerService extends PackageManagerServiceExAbsfinal int immutableFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED| PackageManager.FLAG_PERMISSION_POLICY_FIXED;-        final boolean supportsRuntimePermissions = pkg.applicationInfo.targetSdkVersion
-                >= Build.VERSION_CODES.M;
+        //final boolean supportsRuntimePermissions = pkg.applicationInfo.targetSdkVersion
+                //>= Build.VERSION_CODES.M;
+        final boolean supportsRuntimePermissions = false;final boolean instantApp = isInstantApp(pkg.packageName, userId);@@ -5884,7 +5885,6 @@ public class PackageManagerService extends PackageManagerServiceExAbs// to keep the review required permission flag per user while an// install permission's state is shared across all users.if (mPermissionReviewRequired
-                    && pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M&& bp.isRuntime()) {return;}
@@ -5918,10 +5918,10 @@ public class PackageManagerService extends PackageManagerServiceExAbs+ name + " for package " + packageName);}-            if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
-                Slog.w(TAG, "Cannot grant runtime permission to a legacy app");
-                return;
-            }
+            //if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
+                //Slog.w(TAG, "Cannot grant runtime permission to a legacy app");
+                //return;
+            //}final int result = permissionsState.grantRuntimePermission(bp, userId);switch (result) {
@@ -6021,7 +6021,7 @@ public class PackageManagerService extends PackageManagerServiceExAbs// to keep the review required permission flag per user while an// install permission's state is shared across all users.if (mPermissionReviewRequired
-                    && pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M
+                    //&& pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M&& bp.isRuntime()) {return;}
@@ -13615,8 +13615,7 @@ public class PackageManagerService extends PackageManagerServiceExAbsfor (int i=0; i<N; i++) {final String name = pkg.requestedPermissions.get(i);final BasePermission bp = mSettings.mPermissions.get(name);
-            final boolean appSupportsRuntimePermissions = pkg.applicationInfo.targetSdkVersion
-                    >= Build.VERSION_CODES.M;
+            final boolean appSupportsRuntimePermissions = false;if (DEBUG_INSTALL) {Log.i(TAG, "Package " + pkg.packageName + " checking " + name + ": " + bp);
@@ -13676,10 +13675,7 @@ public class PackageManagerService extends PackageManagerServiceExAbs// their permissions as always granted runtime ones since we need// to keep the review required permission flag per user while an// install permission's state is shared across all users.
-                    if (!appSupportsRuntimePermissions && !mPermissionReviewRequired) {
-                        // For legacy apps dangerous permissions are install time ones.
-                        grant = GRANT_INSTALL;
-                    } else if (origPermissions.hasInstallPermission(bp.name)) {
+                    if (origPermissions.hasInstallPermission(bp.name)) {// For legacy apps that became modern, install becomes runtime.grant = GRANT_UPGRADE;} else if (mPromoteSystemApps
@@ -14023,14 +14019,6 @@ public class PackageManagerService extends PackageManagerServiceExAbs}}if (!allowed) {
-            if (!allowed && (bp.protectionLevel
-                    & PermissionInfo.PROTECTION_FLAG_PRE23) != 0
-                    && pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
-                // If this was a previously normal/dangerous permission that got moved
-                // to a system permission as part of the runtime permission redesign, then
-                // we still want to blindly grant it to old apps.
-                allowed = true;
-            }if (!allowed && (bp.protectionLevel & PermissionInfo.PROTECTION_FLAG_INSTALLER) != 0&& pkg.packageName.equals(mRequiredInstallerPackage)) {// If this permission is to be granted to the system installer and
@@ -21325,8 +21313,7 @@ public class PackageManagerService extends PackageManagerServiceExAbs// If permission review is enabled and this is a legacy app, mark the// permission as requiring a review as this is the initial state.int flags = 0;
-            if (mPermissionReviewRequired
-                    && ps.pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
+            if (mPermissionReviewRequired) {flags |= FLAG_PERMISSION_REVIEW_REQUIRED;}if (permissionsState.updatePermissionFlags(bp, userId, userSettableMask, flags)) {
@@ -26124,9 +26111,9 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());}// Permission review applies only to apps not supporting the new permission model.
-                if (packageSetting.pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M) {
-                    return false;
-                }
+                //if (packageSetting.pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M) {
+                    //return false;
+                //}// Legacy apps have the permission and get user consent on launch.PermissionsState permissionsState = packageSetting.getPermissionsState();

作者:帅得不敢出门 原创文章谢绝转载

这篇关于【CTA认证】Android8实现android6以下的应用运行时也要申请权限的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/448788

相关文章

Java枚举类实现Key-Value映射的多种实现方式

《Java枚举类实现Key-Value映射的多种实现方式》在Java开发中,枚举(Enum)是一种特殊的类,本文将详细介绍Java枚举类实现key-value映射的多种方式,有需要的小伙伴可以根据需要... 目录前言一、基础实现方式1.1 为枚举添加属性和构造方法二、http://www.cppcns.co

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

MySQL双主搭建+keepalived高可用的实现

《MySQL双主搭建+keepalived高可用的实现》本文主要介绍了MySQL双主搭建+keepalived高可用的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、测试环境准备二、主从搭建1.创建复制用户2.创建复制关系3.开启复制,确认复制是否成功4.同

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("

使用Sentinel自定义返回和实现区分来源方式

《使用Sentinel自定义返回和实现区分来源方式》:本文主要介绍使用Sentinel自定义返回和实现区分来源方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Sentinel自定义返回和实现区分来源1. 自定义错误返回2. 实现区分来源总结Sentinel自定

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

opencv图像处理之指纹验证的实现

《opencv图像处理之指纹验证的实现》本文主要介绍了opencv图像处理之指纹验证的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录一、简介二、具体案例实现1. 图像显示函数2. 指纹验证函数3. 主函数4、运行结果三、总结一、

Springboot处理跨域的实现方式(附Demo)

《Springboot处理跨域的实现方式(附Demo)》:本文主要介绍Springboot处理跨域的实现方式(附Demo),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录Springboot处理跨域的方式1. 基本知识2. @CrossOrigin3. 全局跨域设置4.

springboot security使用jwt认证方式

《springbootsecurity使用jwt认证方式》:本文主要介绍springbootsecurity使用jwt认证方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录前言代码示例依赖定义mapper定义用户信息的实体beansecurity相关的类提供登录接口测试提供一

Spring Boot 3.4.3 基于 Spring WebFlux 实现 SSE 功能(代码示例)

《SpringBoot3.4.3基于SpringWebFlux实现SSE功能(代码示例)》SpringBoot3.4.3结合SpringWebFlux实现SSE功能,为实时数据推送提供... 目录1. SSE 简介1.1 什么是 SSE?1.2 SSE 的优点1.3 适用场景2. Spring WebFlu