• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 TELEPHONY_CS_TEST_H
17 #define TELEPHONY_CS_TEST_H
18 #include <securec.h>
19 
20 #include "accesstoken_kit.h"
21 #include "call_manager_errors.h"
22 #include "cellular_call_data_struct.h"
23 #include "cellular_call_interface.h"
24 #include "cellular_call_ipc_interface_code.h"
25 #include "gtest/gtest.h"
26 #include "iservice_registry.h"
27 #include "system_ability_definition.h"
28 #include "token_setproc.h"
29 
30 namespace OHOS {
31 namespace Telephony {
32 using namespace Security::AccessToken;
33 using Security::AccessToken::AccessTokenID;
34 
35 HapInfoParams testInfoParams = {
36     .bundleName = "tel_cellular_call_cs_gtest",
37     .userID = 1,
38     .instIndex = 0,
39     .appIDDesc = "test",
40 };
41 
42 PermissionDef testPermPlaceCallDef = {
43     .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE",
44     .bundleName = "tel_cellular_call_cs_gtest",
45     .grantMode = 1, // SYSTEM_GRANT
46     .label = "label",
47     .labelId = 1,
48     .description = "Test cellular call",
49     .descriptionId = 1,
50     .availableLevel = APL_SYSTEM_BASIC,
51 };
52 
53 PermissionStateFull testPlaceCallState = {
54     .grantFlags = { 2 }, // PERMISSION_USER_SET
55     .grantStatus = { PermissionState::PERMISSION_GRANTED },
56     .isGeneral = true,
57     .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE",
58     .resDeviceID = { "local" },
59 };
60 
61 HapPolicyParams testPolicyParams = {
62     .apl = APL_SYSTEM_BASIC,
63     .domain = "test.domain",
64     .permList = { testPermPlaceCallDef },
65     .permStateList = { testPlaceCallState },
66 };
67 
68 class AccessToken {
69 public:
AccessToken()70     AccessToken()
71     {
72         currentID_ = GetSelfTokenID();
73         AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
74         accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
75         SetSelfTokenID(accessID_);
76     }
~AccessToken()77     ~AccessToken()
78     {
79         AccessTokenKit::DeleteToken(accessID_);
80         SetSelfTokenID(currentID_);
81     }
82 
83 private:
84     AccessTokenID currentID_ = 0;
85     AccessTokenID accessID_ = 0;
86 };
87 
88 class CsTest : public testing::Test {
89 public:
90     static void SetUpTestCase();
91     static void TearDownTestCase();
92     void SetUp();
93     void TearDown();
94 
95     int32_t Dial(const sptr<CellularCallInterface> &telephonyService) const;
96     int32_t HangUp(const sptr<CellularCallInterface> &telephonyService) const;
97     int32_t Answer(const sptr<CellularCallInterface> &telephonyService) const;
98     int32_t Reject(const sptr<CellularCallInterface> &telephonyService) const;
99     int32_t HoldCall(const sptr<CellularCallInterface> &telephonyService) const;
100     int32_t UnHoldCall(const sptr<CellularCallInterface> &telephonyService) const;
101     int32_t SwitchCall(const sptr<CellularCallInterface> &telephonyService) const;
102     int32_t IsEmergencyPhoneNumber(const sptr<CellularCallInterface> &telephonyService) const;
103     int32_t CombineConference(const sptr<CellularCallInterface> &telephonyService) const;
104     int32_t SeparateConference(const sptr<CellularCallInterface> &telephonyService) const;
105     int32_t InviteToConference(const sptr<CellularCallInterface> &telephonyService) const;
106     int32_t KickOutFromConference(const sptr<CellularCallInterface> &telephonyService) const;
107     int32_t HangUpAllConnection(const sptr<CellularCallInterface> &telephonyService) const;
108     int32_t UpdateImsCallMode(const sptr<CellularCallInterface> &telephonyService) const;
109     int32_t RegisterCallBack(const sptr<CellularCallInterface> &telephonyService) const;
110     int32_t UnRegisterCallBack(const sptr<CellularCallInterface> &telephonyService) const;
111     int32_t StartDtmf(const sptr<CellularCallInterface> &telephonyService) const;
112     int32_t StopDtmf(const sptr<CellularCallInterface> &telephonyService) const;
113     int32_t SendDtmf(const sptr<CellularCallInterface> &telephonyService) const;
114     int32_t StartRtt(const sptr<CellularCallInterface> &telephonyService) const;
115     int32_t StopRtt(const sptr<CellularCallInterface> &telephonyService) const;
116     int32_t SetCallTransferInfo(const sptr<CellularCallInterface> &telephonyService) const;
117     int32_t GetCallTransferInfo(const sptr<CellularCallInterface> &telephonyService) const;
118     int32_t SetCallWaiting(const sptr<CellularCallInterface> &telephonyService) const;
119     int32_t GetCallWaiting(const sptr<CellularCallInterface> &telephonyService) const;
120     int32_t SetCallRestriction(const sptr<CellularCallInterface> &telephonyService) const;
121     int32_t GetCallRestriction(const sptr<CellularCallInterface> &telephonyService) const;
122     int32_t SetCallRestrictionPassword(const sptr<CellularCallInterface> &telephonyService) const;
123     int32_t SetMute(const sptr<CellularCallInterface> &telephonyService) const;
124     int32_t GetMute(const sptr<CellularCallInterface> &telephonyService) const;
125     int32_t InputNumForInterface(const sptr<CellularCallInterface> &telephonyService) const;
126     void JudgeIsEmergencyPhoneNumber();
127     bool HasSimCard(int32_t slotId);
InitCellularCallInfo(int32_t accountId,std::string phonenumber,CellularCallInfo & callInfo)128     int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo)
129     {
130         callInfo.accountId = accountId;
131         callInfo.slotId = accountId;
132         callInfo.index = accountId;
133         callInfo.callType = CallType::TYPE_CS;
134         callInfo.videoState = 0; // 0 means audio
135         if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
136             return TELEPHONY_ERR_MEMSET_FAIL;
137         }
138         if (phonenumber.length() > static_cast<size_t>(kMaxNumberLen)) {
139             return CALL_ERR_NUMBER_OUT_OF_RANGE;
140         }
141         if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) {
142             return TELEPHONY_ERR_MEMCPY_FAIL;
143         }
144         return TELEPHONY_SUCCESS;
145     };
146 
TestDialCallByCs(int32_t slotId,std::string code)147     int32_t TestDialCallByCs(int32_t slotId, std::string code)
148     {
149         AccessToken token;
150         auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
151         if (systemAbilityMgr == nullptr) {
152             return TELEPHONY_ERR_FAIL;
153         }
154         auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID);
155         if (remote == nullptr) {
156             return TELEPHONY_ERR_FAIL;
157         }
158         auto telephonyService = iface_cast<CellularCallInterface>(remote);
159         if (telephonyService == nullptr) {
160             return TELEPHONY_ERR_FAIL;
161         }
162         CellularCallInfo callInfo;
163         int32_t ret = TELEPHONY_SUCCESS;
164         ret = InitCellularCallInfo(slotId, code, callInfo);
165         if (ret != TELEPHONY_SUCCESS) {
166             return ret;
167         }
168         // close ims, make this time use cs to test
169         ret = telephonyService->SetImsSwitchStatus(slotId, false);
170         if (ret != TELEPHONY_SUCCESS) {
171             return ret;
172         }
173         ret = telephonyService->Dial(callInfo);
174         return ret;
175     };
176 
177 private:
178     using RequestFuncType = int32_t (CsTest::*)(const sptr<CellularCallInterface> &telephonyService) const;
179     std::map<int32_t, RequestFuncType> requestFuncMap_;
180 };
181 } // namespace Telephony
182 } // namespace OHOS
183 #endif // TELEPHONY_CS_TEST_H
184