11ebd3d54Sopenharmony_ci/*
21ebd3d54Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
31ebd3d54Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
41ebd3d54Sopenharmony_ci * you may not use this file except in compliance with the License.
51ebd3d54Sopenharmony_ci * You may obtain a copy of the License at
61ebd3d54Sopenharmony_ci *
71ebd3d54Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
81ebd3d54Sopenharmony_ci *
91ebd3d54Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
101ebd3d54Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
111ebd3d54Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121ebd3d54Sopenharmony_ci * See the License for the specific language governing permissions and
131ebd3d54Sopenharmony_ci * limitations under the License.
141ebd3d54Sopenharmony_ci */
151ebd3d54Sopenharmony_ci
161ebd3d54Sopenharmony_ci#include "fuzztest_helper.h"
171ebd3d54Sopenharmony_ci
181ebd3d54Sopenharmony_ci#include "accesstoken_kit.h"
191ebd3d54Sopenharmony_ci#include "nativetoken_kit.h"
201ebd3d54Sopenharmony_ci#include "token_setproc.h"
211ebd3d54Sopenharmony_ci
221ebd3d54Sopenharmony_cinamespace OHOS {
231ebd3d54Sopenharmony_cinamespace BackgroundTaskMgr {
241ebd3d54Sopenharmony_ciFuzztestHelper::FuzztestHelper() {}
251ebd3d54Sopenharmony_ci
261ebd3d54Sopenharmony_ciFuzztestHelper::~FuzztestHelper() {}
271ebd3d54Sopenharmony_ci
281ebd3d54Sopenharmony_civoid FuzztestHelper::NativeTokenGet()
291ebd3d54Sopenharmony_ci{
301ebd3d54Sopenharmony_ci    if (isPermissionSet_) {
311ebd3d54Sopenharmony_ci        return;
321ebd3d54Sopenharmony_ci    }
331ebd3d54Sopenharmony_ci    uint64_t tokenId;
341ebd3d54Sopenharmony_ci    static const char *perms[] = {
351ebd3d54Sopenharmony_ci        "ohos.permission.KEEP_BACKGROUND_RUNNING",
361ebd3d54Sopenharmony_ci    };
371ebd3d54Sopenharmony_ci
381ebd3d54Sopenharmony_ci    NativeTokenInfoParams infoInstance = {
391ebd3d54Sopenharmony_ci        .dcapsNum = 0,
401ebd3d54Sopenharmony_ci        .permsNum = 1,
411ebd3d54Sopenharmony_ci        .aclsNum = 0,
421ebd3d54Sopenharmony_ci        .dcaps = nullptr,
431ebd3d54Sopenharmony_ci        .perms = perms,
441ebd3d54Sopenharmony_ci        .acls = nullptr,
451ebd3d54Sopenharmony_ci        .aplStr = "system_basic",
461ebd3d54Sopenharmony_ci    };
471ebd3d54Sopenharmony_ci
481ebd3d54Sopenharmony_ci    infoInstance.processName = "BgTaskOnRemoteRequestFuzzTest";
491ebd3d54Sopenharmony_ci    tokenId = GetAccessTokenId(&infoInstance);
501ebd3d54Sopenharmony_ci    SetSelfTokenID(tokenId);
511ebd3d54Sopenharmony_ci    OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
521ebd3d54Sopenharmony_ci    isPermissionSet_ = true;
531ebd3d54Sopenharmony_ci}
541ebd3d54Sopenharmony_ci}
551ebd3d54Sopenharmony_ci}