• Home
Name Date Size #Lines LOC

..--

AppScope/12-May-2024-3633

entry/12-May-2024-985887

requestPermission/12-May-2024-214164

screenshots/device/12-May-2024-

.gitignoreD12-May-2024119 1010

README.mdD12-May-20242.1 KiB4924

README_zh.mdD12-May-20242.9 KiB5328

build-profile.json5D12-May-20241.1 KiB4544

hvigorfile.tsD12-May-2024158 21

package.jsonD12-May-2024381 1918

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![](screenshots/device/main_en.png) ![](screenshots/device/dialog_en.png)
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.0 Beta4 (Build Version: 3.0.0.992, built on July 14, 2022) 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/permission-list.md).
49

README_zh.md

1# 访问权限控制
2
3### 介绍
4
5本示例使用@ohos.abilityAccessCtrl,展示了应用申请权限场景。
6
7使用说明
8
91.打开应用,页面出现弹窗,点击 **取消** 按钮。
10
112.页面跳转显示 **检测权限** 按钮,点击检测权限,出现提示信息“权限未授予”。
12
133.关闭应用再次打开,页面出现弹窗,点击 **确认** 按钮。
14
154.页面跳转显示 **检测权限** 按钮,点击**检测权限** 按钮,出现提示信息“权限已授予”。
16
175.关闭应用再次打开,页面不出现弹窗,点击 **检测权限** 按钮,点击检测权限,出现提示信息“权限已授予”。
18
19### 效果预览
20
21|主页|授权弹窗|
22|------------|-------------------|
23|![](screenshots/device/main.png)| ![](screenshots/device/dialog.png)|
24
25### 相关权限
26
27[ohos.permission.GET_SENSITIVE_PERMISSIONS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionget_sensitive_permissions)
28
29[ohos.permission.REVOKE_SENSITIVE_PERMISSIONS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionrevoke_sensitive_permissions)
30
31[ohos.permission.GRANT_SENSITIVE_PERMISSIONS](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissiongrant_sensitive_permissions)
32
33[ohos.permission.GET_BUNDLE_INFO_PRIVILEGED](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionget_bundle_info_privileged)
34
35[ohos.permission.GET_BUNDLE_INFO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionget_bundle_info)
36
37[ohos.permission.MICROPHONE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionmicrophone)
38
39### 依赖
40
41不涉及。
42
43### 约束与限制
44
451.本示例仅支持在标准系统上运行。
46
472.工程编译前需要先执行Make Module 'entry'。
48
493.本示例涉及使用系统接口:grantUserGrantedPermission(),需要手动替换Full SDK才能编译通过,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/full-sdk-switch-guide.md)50
514.本示例需要使用DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100, built on November 3, 2022)才可编译运行。
52
535.本示例所配置的权限ohos.permission.GET_SENSITIVE_PERMISSIONSohos.permission.REVOKE_SENSITIVE_PERMISSIONSohos.permission.GRANT_SENSITIVE_PERMISSIONS为system_core级别(相关权限级别可通过[权限定义列表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md)查看),需要手动配置对应级别的权限签名(具体操作可查看[自动化签名方案](https://docs.openharmony.cn/pages/v3.2Beta/zh-cn/application-dev/security/hapsigntool-overview.md/))