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