• 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 TypePermissionFlag {
74     PERMISSION_DEFAULT_FLAG = 0,
75     PERMISSION_USER_SET = 1 << 0,
76     PERMISSION_USER_FIXED = 1 << 1,
77     PERMISSION_SYSTEM_FIXED = 1 << 2,
78     PERMISSION_GRANTED_BY_POLICY = 1 << 3,
79 } PermissionFlag;
80 
81 class NativeTokenInfo final {
82 public:
83     ATokenTypeEnum apl;
84     std::string processName;
85     std::vector<std::string> dcap;
86     AccessTokenID tokenID;
87     AccessTokenAttr tokenAttr;
88     std::vector<std::string> nativeAcls;
89 };
90 
91 class PermissionDef final {
92 public:
93     std::string permissionName;
94     std::string bundleName;
95     int grantMode;
96     TypeATokenAplEnum availableLevel;
97     bool provisionEnable;
98     bool distributedSceneEnable;
99     std::string label;
100     int labelId;
101     std::string description;
102     int descriptionId;
103 };
104 
105 class PermissionStateFull final {
106 public:
107     std::string permissionName;
108     bool isGeneral;
109     std::vector<std::string> resDeviceID;
110     std::vector<int> grantStatus;
111     std::vector<int> grantFlags;
112 };
113 
114 class HapInfoParams final {
115 public:
116     int userID;
117     std::string bundleName;
118     int instIndex;
119     std::string appIDDesc;
120     int dlpType;
121     int32_t apiVersion;
122     bool isSystemApp;
123 };
124 
125 class HapPolicyParams final {
126 public:
127     ATokenAplEnum apl;
128     std::string domain;
129     std::vector<PermissionDef> permList;
130     std::vector<PermissionStateFull> permStateList;
131 };
132 } // namespace AccessToken
133 } // namespace Security
134 } // namespace OHOS
135 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H