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 DEFAULT_PERMISSION_FLAGS = 0; 26 static const int FIRSTCALLER_TOKENID_DEFAULT = 0; 27 28 enum AccessTokenKitRet { 29 RET_FAILED = -1, 30 RET_SUCCESS = 0, 31 }; 32 33 typedef struct { 34 unsigned int tokenUniqueID : 24; 35 unsigned int res : 3; 36 unsigned int type : 2; 37 unsigned int version : 3; 38 } AccessTokenIDInner; 39 40 typedef enum TypeATokenTypeEnum { 41 TOKEN_INVALID = -1, 42 TOKEN_HAP = 0, 43 TOKEN_NATIVE, 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_USER_SET = 1 << 0, 72 PERMISSION_USER_FIXED = 1 << 1, 73 PERMISSION_SYSTEM_FIXED = 1 << 2, 74 } PermissionFlag; 75 76 class PermissionDef final { 77 public: 78 std::string permissionName; 79 std::string bundleName; 80 int grantMode; 81 TypeATokenAplEnum availableLevel; 82 bool provisionEnable; 83 bool distributedSceneEnable; 84 std::string label; 85 int labelId; 86 std::string description; 87 int descriptionId; 88 }; 89 90 class PermissionStateFull final { 91 public: 92 std::string permissionName; 93 bool isGeneral; 94 std::vector<std::string> resDeviceID; 95 std::vector<int> grantStatus; 96 std::vector<int> grantFlags; 97 }; 98 99 class HapInfoParams final { 100 public: 101 int userID; 102 std::string bundleName; 103 int instIndex; 104 std::string appIDDesc; 105 }; 106 107 class HapPolicyParams final { 108 public: 109 ATokenAplEnum apl; 110 std::string domain; 111 std::vector<PermissionDef> permList; 112 std::vector<PermissionStateFull> permStateList; 113 }; 114 } // namespace AccessToken 115 } // namespace Security 116 } // namespace OHOS 117 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_ACCESS_TOKEN_H