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#include "fuzztest_helper.h" 17 18#include "accesstoken_kit.h" 19#include "nativetoken_kit.h" 20#include "token_setproc.h" 21 22namespace OHOS { 23namespace DeviceUsageStats { 24FuzztestHelper::FuzztestHelper() {} 25 26FuzztestHelper::~FuzztestHelper() {} 27 28void FuzztestHelper::NativeTokenGet() 29{ 30 if (isPermissionSet_) { 31 return; 32 } 33 uint64_t tokenId; 34 static const char *perms[] = { 35 "ohos.permission.BUNDLE_ACTIVE_INFO", 36 }; 37 38 NativeTokenInfoParams infoInstance = { 39 .dcapsNum = 0, 40 .permsNum = 1, 41 .aclsNum = 0, 42 .dcaps = nullptr, 43 .perms = perms, 44 .acls = nullptr, 45 .aplStr = "system_basic", 46 }; 47 48 infoInstance.processName = "BundleActiveOnRemoteRequestFuzzTest"; 49 tokenId = GetAccessTokenId(&infoInstance); 50 SetSelfTokenID(tokenId); 51 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); 52 isPermissionSet_ = true; 53} 54} 55}