• 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_types
18  * @{
19  *
20  * @brief Defines variables and data structures used by the permission management module.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file pms_types.h
28  *
29  * @brief Declares variables and data structures used by the permission management module.
30  *
31  * To use permission management APIs, you must obtain this file.
32  *
33  * @since 1.0
34  * @version 1.0
35  */
36 
37 #ifndef INTERFACES_KITS_PERMISSION_LITE_PMS_TYPES_H
38 #define INTERFACES_KITS_PERMISSION_LITE_PMS_TYPES_H
39 
40 #ifdef __cplusplus
41 #if __cplusplus
42 extern "C" {
43 #endif
44 #endif /* __cplusplus */
45 
46 /**
47  * @brief Indicates the length of a permission name.
48  *
49  * The default length is 64 bytes, including the terminating null byte <b>'\0'</b>.
50  */
51 #define PERM_NAME_LEN 64
52 /**
53  * @brief Indicates the length of a permission description.
54  *
55  * The default length is 128 bytes, including the terminating null byte <b>'\0'</b>.
56  */
57 #define PERM_DESC_LEN 128
58 /**
59  * @brief Indicates the length of udid.
60  *
61  * The default length is 64 bytes, do not contain the terminating null byte <b>'\0'</b>.
62  */
63 #define UDID_FINAL_BYTES 64
64 
65 /**
66  * @brief Enumerates granting statuses of the permission.
67  *
68  */
69 enum IsGranted {
70     /** Not granted */
71     NOT_GRANTED = 0,
72     /** Granted */
73     GRANTED = 1,
74 };
75 
76 /**
77  * @brief Defines the permission flag bits.
78  *
79  */
80 enum PmsFlagDef {
81     /**
82     * Permission flag: The default value of permission flag.
83     */
84     PMS_FLAG_DEFAULT = 0,
85 
86     /**
87     * Permission flag[bit1]: The permission is set in its current state by the user and it is fixed,
88     * i.e. apps can no longer request this permission.
89     */
90     PMS_FLAG_USER_FIXED = 1 << 1,
91 
92     /**
93     * Permission flag mask: Indicates the valid flag definition.
94     */
95     PMS_FLAG_VALID_MASK = 0x2,
96 };
97 
98 /**
99  * @brief Defines the permission, including the name, description, and whether the permission is granted.
100  *
101  */
102 typedef struct {
103     /** Permission name. For details about its length, see {@link PERM_NAME_LEN}. */
104     char name[PERM_NAME_LEN];
105     /** Permission description. For details about its length, see {@link PERM_DESC_LEN}. */
106     char desc[PERM_DESC_LEN];
107     /** Whether the permission is granted */
108     enum IsGranted granted;
109     /** Permission flags */
110     int flags;
111 } PermissionSaved;
112 
113 /**
114  * @brief Enumerates error codes of the permission management module.
115  *
116  */
117 enum PmsErrorCode {
118     /** Success */
119     PERM_ERRORCODE_SUCCESS = 0,
120     /** Invalid parameters */
121     PERM_ERRORCODE_INVALID_PARAMS = 10,
122     /** Invalid permission name */
123     PERM_ERRORCODE_INVALID_PERMNAME,
124     /** Failed to allocate memory using the <b>malloc</b> function. */
125     PERM_ERRORCODE_MALLOC_FAIL,
126     /** Failed to open the file descriptor. */
127     PERM_ERRORCODE_OPENFD_FAIL,
128     /** Failed to read the file descriptor. */
129     PERM_ERRORCODE_READFD_FAIL,
130     /** Failed to write the file descriptor. */
131     PERM_ERRORCODE_WRITEFD_FAIL,
132     /** Failed to parse the JSON string. */
133     PERM_ERRORCODE_JSONPARSE_FAIL,
134     /** Failed to copy the string. */
135     PERM_ERRORCODE_COPY_ERROR,
136     /** The permission name or description is too long. */
137     PERM_ERRORCODE_FIELD_TOO_LONG,
138     /** The permission does not exist. */
139     PERM_ERRORCODE_PERM_NOT_EXIST,
140     /** Failed to delete the permission file. */
141     PERM_ERRORCODE_UNLINK_ERROR,
142     /** The file does not exist. */
143     PERM_ERRORCODE_FILE_NOT_EXIST,
144     /** Failed to set memory using the <b>memset</b> function. */
145     PERM_ERRORCODE_MEMSET_FAIL,
146     /** Failed to obtain information about the named file using the <b>stat</b>
147      * function.
148      */
149     PERM_ERRORCODE_STAT_FAIL,
150     /** Invalid path */
151     PERM_ERRORCODE_PATH_INVALID,
152     /** Too many permissions */
153     PERM_ERRORCODE_TOO_MUCH_PERM,
154     /** The process ID does not exist. */
155     PERM_ERRORCODE_TASKID_NOT_EXIST,
156     /** Abnormal number of permissions */
157     PERM_ERRORCODE_PERM_NUM_ERROR,
158     /** Failed to generate udid */
159     PERM_ERRORCODE_GENERATE_UDID_FAILED,
160     /** Failed to format data using the <b>sprintf_s</b> function. */
161     PERM_ERRORCODE_SPRINTFS_FAIL,
162 };
163 
164 #ifdef __cplusplus
165 #if __cplusplus
166 }
167 #endif
168 #endif
169 #endif // INTERFACES_KITS_PERMISSION_LITE_PMS_TYPES_H
170