1d95e75fdSopenharmony_ci/* 2d95e75fdSopenharmony_ci * Copyright (C) 2021-2023 Huawei Device Co., Ltd. 3d95e75fdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4d95e75fdSopenharmony_ci * you may not use this file except in compliance with the License. 5d95e75fdSopenharmony_ci * You may obtain a copy of the License at 6d95e75fdSopenharmony_ci * 7d95e75fdSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8d95e75fdSopenharmony_ci * 9d95e75fdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10d95e75fdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11d95e75fdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12d95e75fdSopenharmony_ci * See the License for the specific language governing permissions and 13d95e75fdSopenharmony_ci * limitations under the License. 14d95e75fdSopenharmony_ci */ 15d95e75fdSopenharmony_ci 16d95e75fdSopenharmony_ci#ifndef TELEPHONY_CS_TEST_H 17d95e75fdSopenharmony_ci#define TELEPHONY_CS_TEST_H 18d95e75fdSopenharmony_ci#include <securec.h> 19d95e75fdSopenharmony_ci#include <iostream> 20d95e75fdSopenharmony_ci#include <random> 21d95e75fdSopenharmony_ci 22d95e75fdSopenharmony_ci#include "accesstoken_kit.h" 23d95e75fdSopenharmony_ci#include "call_manager_errors.h" 24d95e75fdSopenharmony_ci#include "cellular_call_data_struct.h" 25d95e75fdSopenharmony_ci#include "cellular_call_interface.h" 26d95e75fdSopenharmony_ci#include "cellular_call_ipc_interface_code.h" 27d95e75fdSopenharmony_ci#include "gtest/gtest.h" 28d95e75fdSopenharmony_ci#include "iservice_registry.h" 29d95e75fdSopenharmony_ci#include "system_ability_definition.h" 30d95e75fdSopenharmony_ci#include "token_setproc.h" 31d95e75fdSopenharmony_ci 32d95e75fdSopenharmony_cinamespace OHOS { 33d95e75fdSopenharmony_cinamespace Telephony { 34d95e75fdSopenharmony_ciusing namespace Security::AccessToken; 35d95e75fdSopenharmony_ciusing Security::AccessToken::AccessTokenID; 36d95e75fdSopenharmony_ci 37d95e75fdSopenharmony_ciinline HapInfoParams testInfoParams = { 38d95e75fdSopenharmony_ci .bundleName = "tel_cellular_call_cs_gtest", 39d95e75fdSopenharmony_ci .userID = 1, 40d95e75fdSopenharmony_ci .instIndex = 0, 41d95e75fdSopenharmony_ci .appIDDesc = "test", 42d95e75fdSopenharmony_ci}; 43d95e75fdSopenharmony_ci 44d95e75fdSopenharmony_ciinline PermissionDef testPermPlaceCallDef = { 45d95e75fdSopenharmony_ci .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE", 46d95e75fdSopenharmony_ci .bundleName = "tel_cellular_call_cs_gtest", 47d95e75fdSopenharmony_ci .grantMode = 1, // SYSTEM_GRANT 48d95e75fdSopenharmony_ci .label = "label", 49d95e75fdSopenharmony_ci .labelId = 1, 50d95e75fdSopenharmony_ci .description = "Test cellular call", 51d95e75fdSopenharmony_ci .descriptionId = 1, 52d95e75fdSopenharmony_ci .availableLevel = APL_SYSTEM_BASIC, 53d95e75fdSopenharmony_ci}; 54d95e75fdSopenharmony_ci 55d95e75fdSopenharmony_ciinline PermissionStateFull testPlaceCallState = { 56d95e75fdSopenharmony_ci .grantFlags = { 2 }, // PERMISSION_USER_SET 57d95e75fdSopenharmony_ci .grantStatus = { PermissionState::PERMISSION_GRANTED }, 58d95e75fdSopenharmony_ci .isGeneral = true, 59d95e75fdSopenharmony_ci .permissionName = "ohos.permission.CONNECT_CELLULAR_CALL_SERVICE", 60d95e75fdSopenharmony_ci .resDeviceID = { "local" }, 61d95e75fdSopenharmony_ci}; 62d95e75fdSopenharmony_ci 63d95e75fdSopenharmony_ciinline HapPolicyParams testPolicyParams = { 64d95e75fdSopenharmony_ci .apl = APL_SYSTEM_BASIC, 65d95e75fdSopenharmony_ci .domain = "test.domain", 66d95e75fdSopenharmony_ci .permList = { testPermPlaceCallDef }, 67d95e75fdSopenharmony_ci .permStateList = { testPlaceCallState }, 68d95e75fdSopenharmony_ci}; 69d95e75fdSopenharmony_ci 70d95e75fdSopenharmony_ciclass AccessToken { 71d95e75fdSopenharmony_cipublic: 72d95e75fdSopenharmony_ci AccessToken() 73d95e75fdSopenharmony_ci { 74d95e75fdSopenharmony_ci currentID_ = GetSelfTokenID(); 75d95e75fdSopenharmony_ci AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams); 76d95e75fdSopenharmony_ci accessID_ = tokenIdEx.tokenIdExStruct.tokenID; 77d95e75fdSopenharmony_ci SetSelfTokenID(accessID_); 78d95e75fdSopenharmony_ci } 79d95e75fdSopenharmony_ci ~AccessToken() 80d95e75fdSopenharmony_ci { 81d95e75fdSopenharmony_ci AccessTokenKit::DeleteToken(accessID_); 82d95e75fdSopenharmony_ci SetSelfTokenID(currentID_); 83d95e75fdSopenharmony_ci } 84d95e75fdSopenharmony_ci 85d95e75fdSopenharmony_ciprivate: 86d95e75fdSopenharmony_ci AccessTokenID currentID_ = 0; 87d95e75fdSopenharmony_ci AccessTokenID accessID_ = 0; 88d95e75fdSopenharmony_ci}; 89d95e75fdSopenharmony_ci 90d95e75fdSopenharmony_ciclass CsTest : public testing::Test { 91d95e75fdSopenharmony_cipublic: 92d95e75fdSopenharmony_ci static void SetUpTestCase(); 93d95e75fdSopenharmony_ci static void TearDownTestCase(); 94d95e75fdSopenharmony_ci void SetUp(); 95d95e75fdSopenharmony_ci void TearDown(); 96d95e75fdSopenharmony_ci 97d95e75fdSopenharmony_ci int32_t Dial(const sptr<CellularCallInterface> &telephonyService) const; 98d95e75fdSopenharmony_ci int32_t HangUp(const sptr<CellularCallInterface> &telephonyService) const; 99d95e75fdSopenharmony_ci int32_t Answer(const sptr<CellularCallInterface> &telephonyService) const; 100d95e75fdSopenharmony_ci int32_t Reject(const sptr<CellularCallInterface> &telephonyService) const; 101d95e75fdSopenharmony_ci int32_t HoldCall(const sptr<CellularCallInterface> &telephonyService) const; 102d95e75fdSopenharmony_ci int32_t UnHoldCall(const sptr<CellularCallInterface> &telephonyService) const; 103d95e75fdSopenharmony_ci int32_t SwitchCall(const sptr<CellularCallInterface> &telephonyService) const; 104d95e75fdSopenharmony_ci int32_t IsEmergencyPhoneNumber(const sptr<CellularCallInterface> &telephonyService) const; 105d95e75fdSopenharmony_ci int32_t CombineConference(const sptr<CellularCallInterface> &telephonyService) const; 106d95e75fdSopenharmony_ci int32_t SeparateConference(const sptr<CellularCallInterface> &telephonyService) const; 107d95e75fdSopenharmony_ci int32_t InviteToConference(const sptr<CellularCallInterface> &telephonyService) const; 108d95e75fdSopenharmony_ci int32_t KickOutFromConference(const sptr<CellularCallInterface> &telephonyService) const; 109d95e75fdSopenharmony_ci int32_t HangUpAllConnection(const sptr<CellularCallInterface> &telephonyService) const; 110d95e75fdSopenharmony_ci int32_t UpdateImsCallMode(const sptr<CellularCallInterface> &telephonyService) const; 111d95e75fdSopenharmony_ci int32_t RegisterCallBack(const sptr<CellularCallInterface> &telephonyService) const; 112d95e75fdSopenharmony_ci int32_t UnRegisterCallBack(const sptr<CellularCallInterface> &telephonyService) const; 113d95e75fdSopenharmony_ci int32_t StartDtmf(const sptr<CellularCallInterface> &telephonyService) const; 114d95e75fdSopenharmony_ci int32_t StopDtmf(const sptr<CellularCallInterface> &telephonyService) const; 115d95e75fdSopenharmony_ci int32_t SendDtmf(const sptr<CellularCallInterface> &telephonyService) const; 116d95e75fdSopenharmony_ci int32_t StartRtt(const sptr<CellularCallInterface> &telephonyService) const; 117d95e75fdSopenharmony_ci int32_t StopRtt(const sptr<CellularCallInterface> &telephonyService) const; 118d95e75fdSopenharmony_ci int32_t SetCallTransferInfo(const sptr<CellularCallInterface> &telephonyService) const; 119d95e75fdSopenharmony_ci int32_t GetCallTransferInfo(const sptr<CellularCallInterface> &telephonyService) const; 120d95e75fdSopenharmony_ci int32_t SetCallWaiting(const sptr<CellularCallInterface> &telephonyService) const; 121d95e75fdSopenharmony_ci int32_t GetCallWaiting(const sptr<CellularCallInterface> &telephonyService) const; 122d95e75fdSopenharmony_ci int32_t SetCallRestriction(const sptr<CellularCallInterface> &telephonyService) const; 123d95e75fdSopenharmony_ci int32_t GetCallRestriction(const sptr<CellularCallInterface> &telephonyService) const; 124d95e75fdSopenharmony_ci int32_t SetCallRestrictionPassword(const sptr<CellularCallInterface> &telephonyService) const; 125d95e75fdSopenharmony_ci int32_t SetMute(const sptr<CellularCallInterface> &telephonyService) const; 126d95e75fdSopenharmony_ci int32_t GetMute(const sptr<CellularCallInterface> &telephonyService) const; 127d95e75fdSopenharmony_ci int32_t InputNumForInterface(const sptr<CellularCallInterface> &telephonyService) const; 128d95e75fdSopenharmony_ci void JudgeIsEmergencyPhoneNumber(); 129d95e75fdSopenharmony_ci bool HasSimCard(int32_t slotId); 130d95e75fdSopenharmony_ci int32_t InitCellularCallInfo(int32_t accountId, std::string phonenumber, CellularCallInfo &callInfo) 131d95e75fdSopenharmony_ci { 132d95e75fdSopenharmony_ci callInfo.accountId = accountId; 133d95e75fdSopenharmony_ci callInfo.slotId = accountId; 134d95e75fdSopenharmony_ci callInfo.index = accountId; 135d95e75fdSopenharmony_ci callInfo.callType = CallType::TYPE_CS; 136d95e75fdSopenharmony_ci callInfo.videoState = 0; // 0 means audio 137d95e75fdSopenharmony_ci if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) { 138d95e75fdSopenharmony_ci return TELEPHONY_ERR_MEMSET_FAIL; 139d95e75fdSopenharmony_ci } 140d95e75fdSopenharmony_ci if (phonenumber.length() > static_cast<size_t>(kMaxNumberLen)) { 141d95e75fdSopenharmony_ci return CALL_ERR_NUMBER_OUT_OF_RANGE; 142d95e75fdSopenharmony_ci } 143d95e75fdSopenharmony_ci if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, phonenumber.c_str(), phonenumber.length()) != EOK) { 144d95e75fdSopenharmony_ci return TELEPHONY_ERR_MEMCPY_FAIL; 145d95e75fdSopenharmony_ci } 146d95e75fdSopenharmony_ci return TELEPHONY_SUCCESS; 147d95e75fdSopenharmony_ci }; 148d95e75fdSopenharmony_ci 149d95e75fdSopenharmony_ci int32_t TestDialCallByCs(int32_t slotId, std::string code) 150d95e75fdSopenharmony_ci { 151d95e75fdSopenharmony_ci AccessToken token; 152d95e75fdSopenharmony_ci auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 153d95e75fdSopenharmony_ci if (systemAbilityMgr == nullptr) { 154d95e75fdSopenharmony_ci return TELEPHONY_ERR_FAIL; 155d95e75fdSopenharmony_ci } 156d95e75fdSopenharmony_ci auto remote = systemAbilityMgr->CheckSystemAbility(TELEPHONY_CELLULAR_CALL_SYS_ABILITY_ID); 157d95e75fdSopenharmony_ci if (remote == nullptr) { 158d95e75fdSopenharmony_ci return TELEPHONY_ERR_FAIL; 159d95e75fdSopenharmony_ci } 160d95e75fdSopenharmony_ci auto telephonyService = iface_cast<CellularCallInterface>(remote); 161d95e75fdSopenharmony_ci if (telephonyService == nullptr) { 162d95e75fdSopenharmony_ci return TELEPHONY_ERR_FAIL; 163d95e75fdSopenharmony_ci } 164d95e75fdSopenharmony_ci CellularCallInfo callInfo; 165d95e75fdSopenharmony_ci int32_t ret = TELEPHONY_SUCCESS; 166d95e75fdSopenharmony_ci ret = InitCellularCallInfo(slotId, code, callInfo); 167d95e75fdSopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 168d95e75fdSopenharmony_ci return ret; 169d95e75fdSopenharmony_ci } 170d95e75fdSopenharmony_ci // close ims, make this time use cs to test 171d95e75fdSopenharmony_ci ret = telephonyService->SetImsSwitchStatus(slotId, false); 172d95e75fdSopenharmony_ci if (ret != TELEPHONY_SUCCESS) { 173d95e75fdSopenharmony_ci return ret; 174d95e75fdSopenharmony_ci } 175d95e75fdSopenharmony_ci ret = telephonyService->Dial(callInfo); 176d95e75fdSopenharmony_ci return ret; 177d95e75fdSopenharmony_ci }; 178d95e75fdSopenharmony_ci 179d95e75fdSopenharmony_ciprivate: 180d95e75fdSopenharmony_ci int32_t InitCallInfo(CellularCallInfo &callInfo) const; 181d95e75fdSopenharmony_ci 182d95e75fdSopenharmony_ciprivate: 183d95e75fdSopenharmony_ci using RequestFuncType = int32_t (CsTest::*)(const sptr<CellularCallInterface> &telephonyService) const; 184d95e75fdSopenharmony_ci std::map<int32_t, RequestFuncType> requestFuncMap_; 185d95e75fdSopenharmony_ci}; 186d95e75fdSopenharmony_ci} // namespace Telephony 187d95e75fdSopenharmony_ci} // namespace OHOS 188d95e75fdSopenharmony_ci#endif // TELEPHONY_CS_TEST_H 189