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 #define private public
17 #include "addcalltoken_fuzzer.h"
18 
19 #include "nativetoken_kit.h"
20 #include "token_setproc.h"
21 
22 using namespace OHOS::Telephony;
23 namespace OHOS {
24 const int PERMS_NUM = 6;
25 static bool g_isInited = false;
26 
IsServiceInited()27 bool IsServiceInited()
28 {
29     if (!g_isInited) {
30         DelayedSingleton<CallManagerService>::GetInstance()->OnStart();
31         if (DelayedSingleton<CallManagerService>::GetInstance()->GetServiceRunningState() ==
32             static_cast<int32_t>(CallManagerService::ServiceRunningState::STATE_RUNNING)) {
33             g_isInited = true;
34         }
35     }
36     return g_isInited;
37 }
38 
AddCallTokenFuzzer()39 AddCallTokenFuzzer::AddCallTokenFuzzer()
40 {
41     const char *perms[PERMS_NUM] = {
42         "ohos.permission.PLACE_CALL",
43         "ohos.permission.ANSWER_CALL",
44         "ohos.permission.SET_TELEPHONY_STATE",
45         "ohos.permission.GET_TELEPHONY_STATE",
46         "ohos.permission.READ_CALL_LOG",
47         "ohos.permission.WRITE_CALL_LOG",
48     };
49 
50     NativeTokenInfoParams testCallInfoParams = {
51         .dcapsNum = 0,
52         .permsNum = PERMS_NUM,
53         .aclsNum = 0,
54         .dcaps = nullptr,
55         .perms = perms,
56         .acls = nullptr,
57         .processName = "call_fuzzer",
58         .aplStr = "system_basic",
59     };
60     currentID_ = GetAccessTokenId(&testCallInfoParams);
61     SetSelfTokenID(currentID_);
62     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
63 }
64 
~AddCallTokenFuzzer()65 AddCallTokenFuzzer::~AddCallTokenFuzzer() {}
66 } // namespace OHOS