• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup PMS
18  * @{
19  *
20  * @brief Manages permissions.
21  *
22  * This module provides interfaces for managing permissions of third-party applications.
23  *
24  * @since 1.0
25  * @version 1.0
26  */
27 
28 /**
29  * @file pms_interface.h
30  *
31  * @brief Declares interfaces for managing permissions.
32  *
33  * The interfaces can be used to authenticate native APIs, query, grant, and revoke permissions,
34  * and grant runtime permissions.
35  *
36  *
37  * @since 1.0
38  * @version 1.0
39  */
40 
41 #ifndef INTERFACES_KITS_PERMISSION_LITE_OHOS_PERMISSIONMANAGESERVICE_INTERFACE_H
42 #define INTERFACES_KITS_PERMISSION_LITE_OHOS_PERMISSIONMANAGESERVICE_INTERFACE_H
43 
44 #include "pms_types.h"
45 
46 #ifdef __cplusplus
47 #if __cplusplus
48 extern "C" {
49 #endif
50 #endif /* __cplusplus */
51 
52 /**
53  * @brief Checks whether the caller (generally a third-party application) has a specified permission
54  * of a system service API.
55  *
56  * @param uid Indicates the UID of the caller. The range is [0, INT_MAX].
57  * @param permissionName Indicates the pointer to the permission name.
58  * @return Returns <b>1</b> if the application has the given permission; returns <b>0</b> otherwise.
59  *
60  * @since 1.0
61  * @version 1.0
62  */
63 int CheckPermission(int uid, const char *permissionName);
64 
65 /**
66  * @brief Checks whether the caller (generally a third-party application) has a specified permission
67  * of a system service API.
68  *
69  * @param permissionName Indicates the pointer to the permission name.
70  * @return Returns <b>1</b> if the caller has the permission; returns <b>0</b> otherwise.
71  *
72  * @since 2.0
73  * @version 1.0
74  */
75 int CheckSelfPermission(const char *permissionName);
76 
77 /**
78  * @brief Queries all permissions requested by the application and checks whether these permissions are granted.
79  *
80  * @param identifier Indicates the pointer to the application bundle name.
81  * @param permissions Indicates the double pointer to the array of permissions. You need to pass the
82  * {@link PermissionSaved} pointer and release it after finishing using it.
83  * @param permNum Indicates the pointer to the number of permissions in the array, which is an integer.
84  * @return Returns <b>0</b> if the operation is successful; returns an error code defined in
85  * {@link PmsErrorCode} otherwise.
86  *
87  * @since 1.0
88  * @version 1.0
89  *
90  */
91 int QueryPermission(const char *identifier, PermissionSaved **permissions, int *permNum);
92 
93 /**
94  * @brief Grants a specified permission to the application.
95  *
96  * @param identifier Indicates the pointer to the application bundle name.
97  * @param permName Indicates the pointer to the permission name.
98  * @return Returns <b>0</b> if the permission is successfully granted; returns an error code defined in
99  * {@link PmsErrorCode} otherwise.
100  *
101  * @since 1.0
102  * @version 1.0
103  *
104  */
105 int GrantPermission(const char *identifier, const char *permName);
106 
107 /**
108  * @brief Revokes a specified permission from the application.
109  *
110  * @param identifier Indicates the pointer to the application bundle name.
111  * @param permName Indicates the pointer to the permission name.
112  * @return Returns <b>0</b> if the permission is successfully revoked; returns an error code defined in
113  * {@link PmsErrorCode} otherwise.
114  *
115  * @since 1.0
116  * @version 1.0
117  *
118  */
119 int RevokePermission(const char *identifier, const char *permName);
120 
121 
122 /**
123  * @brief Update a specified runtime permission flags.
124  *
125  * @param uid Indicates the user ID of the application. The range is [0, INT_MAX].
126  * @param permissionName Indicates the pointer to the permission name.
127  * @param flags Indicates the permission flags of the permission.
128  * @return Returns <b>0</b> if the permission flags is successfully updated; returns an error code defined in
129  * {@link PmsErrorCode} otherwise.
130  *
131  * @since 1.0
132  * @version 1.0
133  *
134  */
135 int UpdatePermissionFlags(const char *identifier, const char *permissionName, const int flags);
136 
137 /**
138  * @brief Grants a specified runtime permission to an application.
139  *
140  * This function applies to sensitive permissions that can be granted to the application only when the
141  * application is running.
142  *
143  * @param uid Indicates the user ID of the application. The range is [0, INT_MAX].
144  * @param permissionName Indicates the pointer to the permission name.
145  * @return Returns <b>0</b> if the permission is successfully granted; returns an error code defined in
146  * {@link PmsErrorCode} otherwise.
147  *
148  * @since 1.0
149  * @version 1.0
150  *
151  */
152 int GrantRuntimePermission(int uid, const char *permissionName);
153 
154 /**
155  * @brief Revokes a specified runtime permission from an application.
156  *
157  * This function applies to sensitive permissions that can be revoked from the application only when the
158  * application is running.
159  *
160  * @param uid Indicates the user ID of the application. The range is [0, INT_MAX].
161  * @param permissionName Indicates the pointer to the permission name.
162  * @return Returns <b>0</b> if the permission is successfully granted; returns an error code defined in
163  * {@link PmsErrorCode} otherwise.
164  *
165  * @since 2.0
166  * @version 1.0
167  *
168  */
169 int RevokeRuntimePermission(int uid, const char *permissionName);
170 
171 #ifdef __cplusplus
172 #if __cplusplus
173 }
174 #endif
175 #endif
176 #endif // INTERFACES_KITS_PERMISSION_LITE_OHOS_PERMISSIONMANAGESERVICE_INTERFACE_H
177