• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H
18 
19 #include <vector>
20 #include <string>
21 
22 namespace OHOS {
23 namespace Security {
24 namespace AccessToken {
25 typedef unsigned int AccessTokenID;
26 typedef unsigned int AccessTokenAttr;
27 static const int DEFAULT_TOKEN_VERSION = 1;
28 static const int FIRSTCALLER_TOKENID_DEFAULT = 0;
29 
30 enum AccessTokenKitRet {
31     RET_FAILED = -1,
32     RET_SUCCESS = 0,
33 };
34 
35 typedef struct {
36     unsigned int tokenUniqueID : 24;
37     unsigned int res : 3;
38     unsigned int type : 2;
39     unsigned int version : 3;
40 } AccessTokenIDInner;
41 
42 typedef enum TypeATokenTypeEnum {
43     TOKEN_INVALID = -1,
44     TOKEN_HAP = 0,
45     TOKEN_NATIVE,
46     TOKEN_SHELL,
47 } ATokenTypeEnum;
48 
49 typedef enum TypeATokenAplEnum {
50     APL_NORMAL = 1,
51     APL_SYSTEM_BASIC = 2,
52     APL_SYSTEM_CORE = 3,
53 } ATokenAplEnum;
54 
55 typedef union {
56     unsigned long long tokenIDEx;
57     struct {
58         AccessTokenID tokenID;
59         AccessTokenAttr tokenAttr;
60     } tokenIdExStruct;
61 } AccessTokenIDEx;
62 
63 typedef enum TypePermissionState {
64     PERMISSION_DENIED = -1,
65     PERMISSION_GRANTED = 0,
66 } PermissionState;
67 
68 typedef enum TypeGrantMode {
69     USER_GRANT = 0,
70     SYSTEM_GRANT = 1,
71 } GrantMode;
72 
73 typedef enum TypeATokenAvailableTypeEnum {
74     INVALID = 0,
75     NORMAL = 1,
76     MDM = 2,
77 } ATokenAvailableTypeEnum;
78 
79 typedef enum TypePermissionFlag {
80     PERMISSION_DEFAULT_FLAG = 0,
81     PERMISSION_USER_SET = 1 << 0,
82     PERMISSION_USER_FIXED = 1 << 1,
83     PERMISSION_SYSTEM_FIXED = 1 << 2,
84     PERMISSION_GRANTED_BY_POLICY = 1 << 3,
85 } PermissionFlag;
86 
87 class NativeTokenInfo final {
88 public:
89     ATokenTypeEnum apl;
90     std::string processName;
91     std::vector<std::string> dcap;
92     AccessTokenID tokenID;
93     AccessTokenAttr tokenAttr;
94     std::vector<std::string> nativeAcls;
95 };
96 
97 class PermissionDef final {
98 public:
99     std::string permissionName;
100     std::string bundleName;
101     int grantMode;
102     TypeATokenAplEnum availableLevel;
103     bool provisionEnable;
104     bool distributedSceneEnable;
105     std::string label;
106     int labelId;
107     std::string description;
108     int descriptionId;
109     ATokenAvailableTypeEnum availableType = ATokenAvailableTypeEnum::NORMAL;
110 };
111 
112 class PermissionStateFull final {
113 public:
114     std::string permissionName;
115     bool isGeneral;
116     std::vector<std::string> resDeviceID;
117     std::vector<int> grantStatus;
118     std::vector<int> grantFlags;
119 };
120 
121 class HapInfoParams final {
122 public:
123     int userID;
124     std::string bundleName;
125     int instIndex;
126     std::string appIDDesc;
127     int dlpType;
128     int32_t apiVersion;
129     bool isSystemApp;
130 };
131 
132 class HapPolicyParams final {
133 public:
134     ATokenAplEnum apl;
135     std::string domain;
136     std::vector<PermissionDef> permList;
137     std::vector<PermissionStateFull> permStateList;
138 };
139 } // namespace AccessToken
140 } // namespace Security
141 } // namespace OHOS
142 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H