1 /* 2 * Copyright (c) 2023 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 UNITTEST_OHOS_ABILITY_RUNTIME_IS_SA_CALL_TEST_H 17 #define UNITTEST_OHOS_ABILITY_RUNTIME_IS_SA_CALL_TEST_H 18 19 #include "accesstoken_kit.h" 20 #include "nativetoken_kit.h" 21 #include "token_setproc.h" 22 23 namespace OHOS::AAFwk { 24 class IsMockSaCall { 25 public: IsMockSaCallWithPermission()26 static void IsMockSaCallWithPermission() 27 { 28 uint64_t tokenId; 29 const char* perms[] = { 30 perms[0] = "ohos.permission.ACCESS_DLP_FILE", 31 perms[1] = "ohos.permission.CLEAN_APPLICATION_DATA", 32 perms[2] = "ohos.permission.CLEAN_BACKGROUND_PROCESSES", 33 perms[3] = "ohos.permission.GET_RUNNING_INFO", 34 perms[4] = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS", 35 perms[5] = "ohos.permission.MANAGE_MISSIONS", 36 perms[6] = "ohos.permission.RUNNING_STATE_OBSERVER", 37 perms[7] = "ohos.permission.SET_ABILITY_CONTROLLER", 38 perms[8] = "ohos.permission.UPDATE_CONFIGURATION", 39 perms[9] = "ohos.permission.INSTALL_BUNDLE", 40 perms[10] = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", 41 perms[11] = "ohos.permission.START_INVISIBLE_ABILITY", 42 perms[12] = "ohos.permission.START_ABILITIES_FROM_BACKGROUND", 43 perms[13] = "ohos.permission.START_ABILIIES_FROM_BACKGROUND", 44 perms[14] = "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION", 45 perms[15] = "ohos.permission.MANAGER_ABILITY_FROM_GATEWAY", 46 perms[16] = "ohos.permission.PROXY_AUTHORIZATION_URI", 47 perms[17] = "ohos.permission.EXEMPT_AS_CALLER", 48 perms[18] = "ohos.permission.EXEMPT_AS_TARGET", 49 perms[19] = "ohos.permission.PREPARE_APP_TERMINATE", 50 perms[20] = "ohos.permission.START_ABILITY_WITH_ANIMATION", 51 perms[21] = "ohos.permission.MANAGE_APP_BOOT_INTERNAL", 52 perms[22] = "ohos.permission.CONNECT_UI_EXTENSION_ABILITY", 53 perms[23] = "ohos.permission.START_RECENT_ABILITY" 54 }; 55 56 NativeTokenInfoParams infoInstance = { 57 .dcapsNum = 0, 58 .permsNum = static_cast<int32_t>(sizeof(perms)/sizeof(perms[0])), 59 .aclsNum = 0, 60 .dcaps = nullptr, 61 .perms = perms, 62 .acls = nullptr, 63 .aplStr = "system_core", 64 }; 65 infoInstance.processName = "distributedsched"; 66 tokenId = GetAccessTokenId(&infoInstance); 67 SetSelfTokenID(tokenId); 68 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); 69 } 70 IsMockCheckObserverCallerPermission()71 static void IsMockCheckObserverCallerPermission() 72 { 73 uint64_t tokenId; 74 const char* perms[] = { 75 perms[0] = "ohos.permission.RUNNING_STATE_OBSERVER", 76 }; 77 78 NativeTokenInfoParams infoInstance = { 79 .dcapsNum = 0, 80 .permsNum = static_cast<int32_t>(sizeof(perms)/sizeof(perms[0])), 81 .aclsNum = 0, 82 .dcaps = nullptr, 83 .perms = perms, 84 .acls = nullptr, 85 .aplStr = "system_core", 86 }; 87 infoInstance.processName = "memmgrservice"; 88 tokenId = GetAccessTokenId(&infoInstance); 89 SetSelfTokenID(tokenId); 90 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); 91 } 92 IsMockProcessCachePermission()93 static void IsMockProcessCachePermission() 94 { 95 uint64_t tokenId; 96 const char* perms[] = { 97 perms[0] = "ohos.permission.SET_PROCESS_CACHE_STATE", 98 }; 99 100 NativeTokenInfoParams infoInstance = { 101 .dcapsNum = 0, 102 .permsNum = static_cast<int32_t>(sizeof(perms)/sizeof(perms[0])), 103 .aclsNum = 0, 104 .dcaps = nullptr, 105 .perms = perms, 106 .acls = nullptr, 107 .aplStr = "system_core", 108 }; 109 infoInstance.processName = "distributedsched"; 110 tokenId = GetAccessTokenId(&infoInstance); 111 SetSelfTokenID(tokenId); 112 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); 113 } 114 }; 115 } // namespace OHOS::AAFwk 116 #endif // UNITTEST_OHOS_ABILITY_RUNTIME_IS_SA_CALL_TEST_H