| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 36 | 33 | ||
| entry/ | 06-May-2025 | - | 1,158 | 1,057 | ||
| hvigor/ | 06-May-2025 | - | 24 | 22 | ||
| requestPermission/ | 06-May-2025 | - | 226 | 175 | ||
| screenshots/device/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 119 | 10 | 10 | |
| README.md | D | 06-May-2025 | 2.1 KiB | 49 | 24 | |
| README_zh.md | D | 06-May-2025 | 4.8 KiB | 88 | 56 | |
| build-profile.json5 | D | 06-May-2025 | 1.1 KiB | 45 | 44 | |
| hvigorfile.ts | D | 06-May-2025 | 158 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2.1 KiB | 64 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 823 | 27 | 25 | |
| ohosTest.md | D | 06-May-2025 | 768 | 12 | 9 |
README.md
1# Access Permission Control 2 3### Introduction 4 5This sample shows how `@ohos.abilityAccessCtrl` works to implement app permission control. The display effect is as follows: 6 7  8 9### Concepts 10 11Application access control: provides application permission management, including authentication, authorization, and authorization revocation. 12 13### Required Permissions 14 15- ohos.permission.GET_SENSITIVE_PERMISSIONS 16 17- ohos.permission.REVOKE_SENSITIVE_PERMISSIONS 18 19- ohos.permission.GRANT_SENSITIVE_PERMISSIONS 20 21- ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 22 23- ohos.permission.GET_BUNDLE_INFO 24 25- ohos.permission.MICROPHONE 26 27 28### Usage 29 301. Open the app. A dialog box is displayed, asking you whether to grant the permission. Touch **Cancel**. 31 322. The permission check screen is displayed. Touch the **Check Permission** button. A message is displayed, indicating that the permission is not granted. 33 343. Close the app and open it again. A dialog box is displayed, asking you whether to grant the permission. Touch **OK**. 35 364. The permission check screen is displayed. Touch the **Check Permission** button. A message is displayed, indicating that the permission has been granted. 37 385. Close the app and open it again. No dialog box is displayed. Touch the **Check Permission** button. A message is displayed, indicating that the permission has been granted. 39 40### Constraints 41 42- This sample can only be run on standard-system devices. 43 44- Before building a project, you need to run **Make Module 'entry'**. 45 46- This sample requires DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100) to compile and run. 47 48- The ohos.permission.GET_SENSITIVE_PERMISSIONS, ohos.permission.REVOKE_SENSITIVE_PERMISSIONS, and ohos.permission.GRANT_SENSITIVE_PERMISSIONS permissions used in this sample are of the system_core level. You need to configure signatures for these permissions. For details about the application permission level (APL), see [Permission List](https://gitee.com/openharmony/docs/blob/master/en/application-dev/security/AccessToken/permissions-for-system-apps.md). 49
README_zh.md
1# 访问权限控制(仅对系统应用开放) 2 3### 介绍 4 5本示例使用@ohos.abilityAccessCtrl,展示了应用申请权限场景。 6 7### 效果预览 8 9|主页|授权弹窗| 10|------------|-------------------| 11|| | 12 13使用说明 14 151.打开应用,页面出现弹窗,点击 **取消** 按钮。 16 172.页面跳转显示 **检测权限** 按钮,点击检测权限,出现提示信息“权限未授予”。 18 193.关闭应用再次打开,页面出现弹窗,点击 **确认** 按钮。 20 214.页面跳转显示 **检测权限** 按钮,点击**检测权限** 按钮,出现提示信息“权限已授予”。 22 235.关闭应用再次打开,页面不出现弹窗,点击 **检测权限** 按钮,点击检测权限,出现提示信息“权限已授予”。 24 25### 工程目录 26``` 27entry/src/main/ets/ 28|---entryability 29| |---EntryAbility.ets 30|---model 31| |---Logger.ts // 日志工具 32|---pages 33| |---Index.ets // 首页 34|---verifyability 35| |---VerifyAbility.ets 36| |---pages 37| | |---Index.ets // 检测权限 38``` 39### 具体实现 40 41* 该示例使用abilityAccessCtrl接口中abilityAccessCtrl方法获取访问控制模块对象,GrantStatus.PERMISSION_GRANTED方法表示已授权状态,bundleManager接口中getApplicationInfo方法根据包名获取ApplicationInfo等展示应用申请权限场景 42* 源码链接:[Index.ets](entry/src/main/ets/verifyability/pages/Index.ets) 43* 接口参考:[@ohos.abilityAccessCtrl](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-abilityAccessCtrl.md),[@ohos.bundle.bundleManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-bundleManager.md) 44 45### 相关权限 46 471.允许应用读取其他应用的敏感权限的状态权限:[ohos.permission.GET_SENSITIVE_PERMISSIONS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionget_sensitive_permissions) 48 492.允许应用撤销给其他应用授予的敏感信息权限:[ohos.permission.REVOKE_SENSITIVE_PERMISSIONS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionrevoke_sensitive_permissions) 50 513.允许应用为其他应用授予敏感权限:[ohos.permission.GRANT_SENSITIVE_PERMISSIONS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissiongrant_sensitive_permissions) 52 534.允许应用同时查询其他多个应用的信息权限:[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-enterprise-apps.md#ohospermissionget_bundle_info_privileged) 54 555.允许应用查询其他单个应用的信息权限:[ohos.permission.GET_BUNDLE_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionget_bundle_info) 56 576.允许应用使用麦克风权限:[ohos.permission.MICROPHONE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all-user.md#ohospermissionmicrophone) 58 59### 依赖 60 61不涉及。 62 63### 约束与限制 64 651.本示例仅支持在标准系统上运行。 66 672.本示例已适配API version 9版本SDK,版本号:3.2.11.9。 68 693.工程编译前需要先执行Make Module 'entry'。 70 714.本示例涉及使用系统接口:grantUserGrantedPermission(),需要手动替换Full SDK才能编译通过,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)。 72 735.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)及以上版本才可编译运行。 74 756.本示例所配置的权限ohos.permission.GET_SENSITIVE_PERMISSIONS、ohos.permission.REVOKE_SENSITIVE_PERMISSIONS、ohos.permission.GRANT_SENSITIVE_PERMISSIONS为system_core级别(相关权限级别可通过[权限定义列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md)查看),需要手动配置对应级别的权限签名(具体操作可查看[自动化签名方案](https://docs.openharmony.cn/pages/v3.2/zh-cn/application-dev/security/hapsigntool-overview.md/))。 76 77### 下载 78 79如需单独下载本工程,执行如下命令: 80``` 81git init 82git config core.sparsecheckout true 83echo code/SystemFeature/Security/AbilityAccessCtrl/ > .git/info/sparse-checkout 84git remote add origin https://gitee.com/openharmony/applications_app_samples.git 85git pull origin master 86 87``` 88