Merge branch 'master' of gitee.com:openharmony/telephony_core_service into master

Signed-off-by: 罗建贞 <luojianzhen1@huawei.com>
This commit is contained in:
罗建贞 2024-08-15 07:52:18 +00:00 committed by Gitee
commit b7cf564fec
83 changed files with 8015 additions and 360 deletions

View File

@ -103,6 +103,13 @@ struct AsyncStkCallSetupResult {
struct AsyncDsdsInfo {
AsyncContext<int32_t> asyncContext;
};
struct AsyncSimAuthInfo {
AsyncContext<napi_value> asyncContext;
int32_t authType = ERROR_DEFAULT;
std::string authData {};
SimAuthenticationResponse responseResult;
};
} // namespace Telephony
} // namespace OHOS
#endif // OHOS_NAPI_SIM_H

View File

@ -228,6 +228,7 @@ void NapiAsyncBaseCompleteCallback(
napi_value errorMessage = NapiUtil::CreateErrorMessage(env, error.errorMessage, error.errorCode);
NAPI_CALL_RETURN_VOID(env, napi_reject_deferred(env, context.deferred, errorMessage));
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, context.work));
TELEPHONY_LOGE("NapiAsyncBaseCompleteCallback deferred error and resolved is false");
return;
}
@ -236,6 +237,7 @@ void NapiAsyncBaseCompleteCallback(
(funcIgnoreReturnVal ? NapiUtil::CreateUndefined(env) : GetNapiValue(env, asyncContext.callbackVal));
NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, context.deferred, res));
NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, context.work));
TELEPHONY_LOGE("NapiAsyncBaseCompleteCallback deferred error and resolved is true");
return;
}
@ -332,6 +334,16 @@ napi_value DiallingNumbersConversion(napi_env env, const TelNumbersInfo &info)
return val;
}
napi_value SimAuthResultConversion(napi_env env, const SimAuthenticationResponse &responseResult)
{
napi_value val = nullptr;
napi_create_object(env, &val);
NapiUtil::SetPropertyInt32(env, val, "sw1", responseResult.sw1);
NapiUtil::SetPropertyInt32(env, val, "sw2", responseResult.sw2);
NapiUtil::SetPropertyStringUtf8(env, val, "response", responseResult.response);
return val;
}
void GetDiallingNumberInfo(const std::shared_ptr<DiallingNumbersInfo> &telNumber, const TelNumbersInfo &info)
{
telNumber->index_ = info.recordNumber;
@ -844,6 +856,67 @@ napi_value GetDsdsMode(napi_env env, napi_callback_info info)
return result;
}
void NativeGetSimAuthentication(napi_env env, void *data)
{
if (data == nullptr) {
return;
}
AsyncSimAuthInfo *asyncContext = static_cast<AsyncSimAuthInfo *>(data);
if (!IsValidSlotId(asyncContext->asyncContext.slotId)) {
TELEPHONY_LOGE("NativeGetSimAuthentication slotId is invalid");
asyncContext->asyncContext.context.errorCode = ERROR_SLOT_ID_INVALID;
return;
}
SimAuthenticationResponse response;
int32_t errorCode = DelayedRefSingleton<CoreServiceClient>::GetInstance().SimAuthentication(
asyncContext->asyncContext.slotId, static_cast<AuthType>(asyncContext->authType),
asyncContext->authData, response);
TELEPHONY_LOGI("NAPI NativeGetSimAuthentication %{public}d", errorCode);
if (errorCode == ERROR_NONE) {
asyncContext->responseResult = response;
asyncContext->asyncContext.context.resolved = true;
} else {
asyncContext->asyncContext.context.resolved = false;
}
asyncContext->asyncContext.context.errorCode = errorCode;
}
void GetSimAuthenticationCallback(napi_env env, napi_status status, void *data)
{
NAPI_CALL_RETURN_VOID(env, (data == nullptr ? napi_invalid_arg : napi_ok));
std::unique_ptr<AsyncSimAuthInfo> context(static_cast<AsyncSimAuthInfo *>(data));
AsyncContext<napi_value> &asyncContext = context->asyncContext;
if (asyncContext.context.resolved) {
asyncContext.callbackVal = SimAuthResultConversion(env, context->responseResult);
}
NapiAsyncPermissionCompleteCallback(
env, status, context->asyncContext, false, { "GetSimAuthentication", Permission::GET_TELEPHONY_STATE });
}
napi_value GetSimAuthentication(napi_env env, napi_callback_info info)
{
auto asyncContext = new AsyncSimAuthInfo();
BaseContext &context = asyncContext->asyncContext.context;
char authDataStr[ARRAY_SIZE] = {0};
auto initPara = std::make_tuple(&asyncContext->asyncContext.slotId, &asyncContext->authType, authDataStr,
&context.callbackRef);
AsyncPara para {
.funcName = "GetSimAuthentication",
.env = env,
.info = info,
.execute = NativeGetSimAuthentication,
.complete = GetSimAuthenticationCallback,
};
napi_value result = NapiCreateAsyncWork2<AsyncSimAuthInfo>(para, asyncContext, initPara);
if (result) {
asyncContext->authData = std::string(authDataStr);
NAPI_CALL(env, napi_queue_async_work_with_qos(env, context.work, napi_qos_default));
}
return result;
}
void NativeGetSimState(napi_env env, void *data)
{
if (data == nullptr) {
@ -3027,6 +3100,20 @@ napi_status InitEnumOperatorSimCard(napi_env env, napi_value exports)
return napi_define_properties(env, exports, arrSize, desc);
}
napi_status InitEnumAuthType(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
DECLARE_NAPI_STATIC_PROPERTY(
"SIM_AUTH_EAP_SIM_TYPE", GetNapiValue(env, static_cast<int32_t>(AuthType::SIM_AUTH_EAP_SIM_TYPE))),
DECLARE_NAPI_STATIC_PROPERTY(
"SIM_AUTH_EAP_AKA_TYPE", GetNapiValue(env, static_cast<int32_t>(AuthType::SIM_AUTH_EAP_AKA_TYPE))),
};
constexpr size_t arrSize = sizeof(desc) / sizeof(desc[0]);
NapiUtil::DefineEnumClassByName(env, exports, "AuthType", arrSize, desc);
return napi_define_properties(env, exports, arrSize, desc);
}
napi_status InitSimLockInterface(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
@ -3110,6 +3197,7 @@ napi_status InitSimInterface(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("getOpName", GetOpName),
DECLARE_NAPI_FUNCTION("getOpNameSync", GetOpNameSync),
DECLARE_NAPI_FUNCTION("getDsdsMode", GetDsdsMode),
DECLARE_NAPI_FUNCTION("getSimAuthentication", GetSimAuthentication),
};
return napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
}
@ -3130,6 +3218,7 @@ napi_value InitNapiSim(napi_env env, napi_value exports)
NAPI_CALL(env, InitEnumPersoLockType(env, exports));
NAPI_CALL(env, InitEnumOperatorConfigKey(env, exports));
NAPI_CALL(env, InitEnumOperatorSimCard(env, exports));
NAPI_CALL(env, InitEnumAuthType(env, exports));
return exports;
}
EXTERN_C_END

View File

@ -2460,6 +2460,15 @@ bool CoreManagerInner::IsSetPrimarySlotIdInProgress()
return simManager_->IsSetPrimarySlotIdInProgress();
}
int32_t CoreManagerInner::SavePrimarySlotId(int32_t slotId)
{
if (simManager_ == nullptr) {
TELEPHONY_LOGE("simManager_ is null!");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
return simManager_->SavePrimarySlotId(slotId);
}
/******************** simManager_ end ************************/
} // namespace Telephony
} // namespace OHOS

View File

@ -126,6 +126,14 @@ bool NetworkState::ReadParcelInt(Parcel &parcel)
return false;
}
nrState_ = static_cast<NrState>(rat);
if (!parcel.ReadInt32(rat)) {
return false;
}
lastPsRadioTech_ = static_cast<RadioTech>(rat);
if (!parcel.ReadInt32(rat)) {
return false;
}
lastCfgTech_ = static_cast<RadioTech>(rat);
return true;
}
@ -148,7 +156,17 @@ bool NetworkState::Marshalling(Parcel &parcel) const
if (!parcel.WriteBool(isEmergency_)) {
return false;
}
if (!MarshallingString(parcel)) {
return false;
}
if (!MarshallingInt(parcel)) {
return false;
}
return true;
}
bool NetworkState::MarshallingString(Parcel &parcel) const
{
if (!parcel.WriteString(psOperatorInfo_.fullName)) {
return false;
}
@ -167,6 +185,11 @@ bool NetworkState::Marshalling(Parcel &parcel) const
if (!parcel.WriteString(csOperatorInfo_.operatorNumeric)) {
return false;
}
return true;
}
bool NetworkState::MarshallingInt(Parcel &parcel) const
{
if (!parcel.WriteInt32(static_cast<int32_t>(csRoaming_))) {
return false;
}
@ -191,6 +214,12 @@ bool NetworkState::Marshalling(Parcel &parcel) const
if (!parcel.WriteInt32(static_cast<int32_t>(nrState_))) {
return false;
}
if (!parcel.WriteInt32(static_cast<int32_t>(lastPsRadioTech_))) {
return false;
}
if (!parcel.WriteInt32(static_cast<int32_t>(lastCfgTech_))) {
return false;
}
return true;
}

View File

@ -374,7 +374,7 @@ bool ResourceUtils::Init()
return false;
}
OHOS::sptr<OHOS::IRemoteObject> remoteObject =
systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
systemAbilityManager->CheckSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
sptr<AppExecFwk::IBundleMgr> iBundleMgr = OHOS::iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
if (iBundleMgr == nullptr) {

View File

@ -311,7 +311,7 @@ int32_t TelephonyStateRegistryProxy::RegisterStateChange(
if (callback == nullptr) {
return TELEPHONY_ERR_FAIL;
}
if (!in.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
if (!in.WriteRemoteObject(callback->AsObject())) {
return TELEPHONY_ERR_FAIL;
}
sptr<IRemoteObject> remote = Remote();
@ -346,6 +346,7 @@ int32_t TelephonyStateRegistryProxy::UnregisterStateChange(
if (remote == nullptr) {
return TELEPHONY_ERR_FAIL;
}
TELEPHONY_LOGI("UnregisterStateChange slotId:%{public}d mask:%{public}d", slotId, mask);
int result = remote->SendRequest(
static_cast<uint32_t>(StateNotifyInterfaceCode::REMOVE_OBSERVER), in, out, option);
if (result == ERR_NONE) {

View File

@ -320,6 +320,7 @@ public:
int32_t IsCTSimCard(int32_t slotId, bool &isCTSimCard);
bool IsSetActiveSimInProgress(int32_t slotId);
bool IsSetPrimarySlotIdInProgress();
int32_t SavePrimarySlotId(int32_t slotId);
/******************** simManager end *****************************/
private:
CoreManagerInner();

View File

@ -139,6 +139,7 @@ public:
virtual bool IsSetPrimarySlotIdInProgress() = 0;
virtual int32_t GetSimIO(int32_t slotId, int32_t command,
int32_t fileId, const std::string &data, const std::string &path, SimAuthenticationResponse &response) = 0;
virtual int32_t SavePrimarySlotId(int32_t slotId) = 0;
};
} // namespace Telephony
} // namespace OHOS

View File

@ -107,6 +107,12 @@ public:
*/
RadioTech GetLastCfgTech() const;
private:
bool ReadParcelString(Parcel &parcel);
bool ReadParcelInt(Parcel &parcel);
bool MarshallingString(Parcel &parcel) const;
bool MarshallingInt(Parcel &parcel) const;
private:
bool isEmergency_;
OperatorInformation psOperatorInfo_;
@ -121,8 +127,6 @@ private:
RadioTech csRadioTech_;
RadioTech cfgTech_;
NrState nrState_;
bool ReadParcelString(Parcel &parcel);
bool ReadParcelInt(Parcel &parcel);
};
} // namespace Telephony
} // namespace OHOS

View File

@ -190,6 +190,10 @@ struct DataProfile {
* Roaming protocol version
*/
std::string roamingProtocol = "";
/**
* Supported apn types bitmap
*/
int32_t supportedApnTypesBitmap = 0;
};
/**

View File

@ -25,7 +25,7 @@ namespace Telephony {
using SatelliteMessage = GsmSimMessageParam;
namespace {
const int32_t TELEPHONY_SATELLITE_SERVICE_ABILITY_ID = 4013;
const int32_t TELEPHONY_SATELLITE_SERVICE_ABILITY_ID = 4012;
}
enum SatelliteServiceProxyType {

View File

@ -2190,6 +2190,34 @@ declare namespace sim {
*/
function getDsdsMode(): Promise<DsdsMode>;
/**
* Performs SIM card authentication.
*
* @permission ohos.permission.GET_TELEPHONY_STATE
* @param { number } slotId - Sim slot id.
* @param { AuthType } authType - The authentication type.
* @param { string } authData - Ser password or other authentication information.
* @returns { Promise<SimAuthenticationResponse> } A string the response of authentication.This value will be null in
* the following cases: Authentication error, incorrect MAC Authentication error, security context not supported Key
* freshness failure Authentication error, no memory space available Authentication error, no memory space available
* in EFMUK.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 202 - Non-system applications use system APIs.
* @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
* 2. Incorrect parameter types.
* @throws { BusinessError } 8300001 - Invalid parameter value.
* @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
* @throws { BusinessError } 8300003 - System internal error.
* @throws { BusinessError } 8300004 - Do not have sim card.
* @throws { BusinessError } 8300999 - Unknown error code.
* @throws { BusinessError } 8301002 - SIM card operation error.
* @syscap SystemCapability.Telephony.CoreService.
* @systemapi Hide this for inner system use.
* @since 12
*/
function getSimAuthentication(slotId: number, authType: AuthType,
authData: string): Promise<SimAuthenticationResponse>;
/**
* Defines the carrier configuration.
*
@ -3034,6 +3062,74 @@ declare namespace sim {
*/
CHINA_TELECOM_CARD = 'china_telecom_card',
}
/**
* The authentication type.
*
* @enum { number }
* @syscap SystemCapability.Telephony.CoreService
* @systemapi Hide this for inner system use.
* @since 12
*/
export enum AuthType {
/**
* Authentication type is EAP-SIM. See RFC 4186
*
* @syscap SystemCapability.Telephony.CoreService
* @systemapi Hide this for inner system use.
* @since 12
*/
SIM_AUTH_EAP_SIM_TYPE = 128,
/**
* Authentication type is EAP-AKA. See RFC 4187
*
* @syscap SystemCapability.Telephony.CoreService
* @systemapi Hide this for inner system use.
* @since 12
*/
SIM_AUTH_EAP_AKA_TYPE = 129,
}
/**
* SIM card Authentication response.
*
* @interface SimAuthenticationResponse
* @syscap SystemCapability.Telephony.CoreService
* @systemapi Hide this for inner system use.
* @since 12
*/
export interface SimAuthenticationResponse {
/**
* Status word 1 of the SIM card, which is returned by the SIM card after command execution.
*
* @type { number }
* @syscap SystemCapability.Telephony.CoreService
* @systemapi Hide this for inner system use.
* @since 12
*/
sw1: number;
/**
* Status word 2 of the SIM card, which is returned by the SIM card after command execution.
*
* @type { number }
* @syscap SystemCapability.Telephony.CoreService
* @systemapi Hide this for inner system use.
* @since 12
*/
sw2: number;
/**
* A string the response of authentication.
*
* @type { string }
* @syscap SystemCapability.Telephony.CoreService
* @systemapi Hide this for inner system use.
* @since 12
*/
response: string;
}
}
export default sim;

View File

@ -59,7 +59,9 @@
"ohos.permission.UPDATE_CONFIGURATION",
"ohos.permission.MICROPHONE",
"ohos.permission.DISTRIBUTED_DATASYNC",
"ohos.permission.RECEIVE_UPDATE_MESSAGE"
"ohos.permission.RECEIVE_UPDATE_MESSAGE",
"ohos.permission.MANAGE_LOCAL_ACCOUNTS",
"ohos.permission.READ_CALL_LOG"
],
"secon" : "u:r:telephony_sa:s0"
}

View File

@ -19,7 +19,7 @@
"zh_Hant": "中國聯通"
},
{
"mcc_mnc_array": [46003,46011,46050,46051,46059],
"mcc_mnc_array": [46003,46011,46050,46051,46059,45502,45507],
"zh_CN": "中国电信",
"en_US": "China Telecom",
"zh_TW": "中國電信",

View File

@ -42,7 +42,6 @@ public:
void UpdateCfgTech();
void UpdateCellularCall(const RegServiceState &regStatus, const int32_t callType);
int32_t HandleRrcStateChanged(int32_t status);
RegServiceState GetRegServiceState() const;
enum class RilRegister {
REG_STATE_NOT_REG = 0,
@ -106,7 +105,6 @@ private:
bool isCsCapable_ = true;
std::string currentNrConfig_ = "";
std::string systemPropertiesConfig_ = "ConfigD";
RegServiceState regStatusResult_ = RegServiceState::REG_STATE_UNKNOWN;
};
} // namespace Telephony
} // namespace OHOS

View File

@ -97,13 +97,13 @@ public:
sptr<CellLocation> GetCellLocation();
void TimezoneRefresh();
void SetCellRequestMinInterval(uint32_t minInterval);
int32_t GetRegServiceState(RegServiceState &regState);
bool IsPowerOnPrimaryRadioWhenNoSim() const;
void ProcessSignalIntensity(int32_t slotId, const Rssi &signalIntensity);
void RadioOnState();
private:
void RadioOffOrUnavailableState(int32_t radioState) const;
void SetRadioOffWhenAirplaneIsOn();
void GetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event);
void SetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event);
void SimStateChange(const AppExecFwk::InnerEvent::Pointer &);
@ -153,6 +153,7 @@ private:
bool IsSatelliteOn() const;
void RadioOnWhenHasSim(std::shared_ptr<NetworkSearchManager> &networkSearchManager, int32_t radioState) const;
void UpdateNetworkState();
void GetDeviceId();
private:
std::weak_ptr<NetworkSearchManager> networkSearchManager_;

View File

@ -56,6 +56,7 @@ private:
RegServiceState regStatus, sptr<NetworkState> &networkState, int32_t spnRule, std::string &spn, bool &showSpn);
int32_t GetCurrentLac();
std::string GetCustomName(const std::string &numeric);
unsigned int GetSpnRule(sptr<NetworkState> &networkState);
unsigned int GetCustSpnRule(bool roaming);
std::string GetEons(const std::string &numeric, int32_t lac, bool longNameRequired);
std::string GetCustEons(const std::string &numeric, int32_t lac, bool roaming, bool longNameRequired);
@ -64,6 +65,7 @@ private:
void UpdateOplCust(const std::vector<std::string> &oplCust);
void UpdateOperatorConfig();
bool isDomesticRoaming(const std::string &simPlmn, const std::string &netPlmn);
bool IsChinaCard();
bool isCMCard(const std::string &numeric);
bool isCUCard(const std::string &numeric);
bool isCTCard(const std::string &numeric);

View File

@ -70,7 +70,6 @@ void NetworkRegister::UpdateNetworkSearchState(RegServiceState regStatus,
RoamingType roam,
DomainType type)
{
regStatusResult_ = regStatus;
networkSearchState_->SetNetworkState(regStatus, type);
networkSearchState_->SetEmergency(
(regStatus == RegServiceState::REG_STATE_EMERGENCY_ONLY) && isCsCapable_);
@ -387,11 +386,6 @@ RegServiceState NetworkRegister::ConvertRegFromRil(RilRegister code) const
}
}
RegServiceState NetworkRegister::GetRegServiceState() const
{
return regStatusResult_;
}
RadioTech NetworkRegister::ConvertTechFromRil(TelRilRadioTech code) const
{
switch (code) {

View File

@ -497,6 +497,23 @@ void NetworkSearchHandler::SimRecordsLoaded(const AppExecFwk::InnerEvent::Pointe
}
}
void NetworkSearchHandler::GetDeviceId()
{
auto networkSearchManager = networkSearchManager_.lock();
if (networkSearchManager == nullptr) {
TELEPHONY_LOGE("NetworkSearchHandler::GetDeviceId failed to get NetworkSearchManager");
return;
}
std::u16string meid = u"";
std::u16string imei = u"";
std::u16string imeiSv = u"";
std::string basebandVersion = "";
networkSearchManager->GetImei(slotId_, imei);
networkSearchManager->GetImeiSv(slotId_, imeiSv);
networkSearchManager->GetMeid(slotId_, meid);
networkSearchManager->GetBasebandVersion(slotId_, basebandVersion);
}
void NetworkSearchHandler::RadioStateChange(const AppExecFwk::InnerEvent::Pointer &event)
{
if (event == nullptr) {
@ -524,6 +541,7 @@ void NetworkSearchHandler::RadioStateChange(const AppExecFwk::InnerEvent::Pointe
case CORE_SERVICE_POWER_ON: {
firstInit_ = false;
InitGetNetworkSelectionMode();
SetRadioOffWhenAirplaneIsOn();
RadioOnState();
break;
}
@ -538,8 +556,7 @@ void NetworkSearchHandler::RadioStateChange(const AppExecFwk::InnerEvent::Pointe
inner->deviceStateHandler_->ProcessRadioState();
}
networkSearchManager->InitSimRadioProtocol(slotId_);
std::u16string imei = u"";
networkSearchManager->GetImei(slotId_, imei);
GetDeviceId();
} else {
networkSearchManager->SetRadioStateValue(slotId_, CORE_SERVICE_POWER_NOT_AVAILABLE);
}
@ -548,6 +565,19 @@ void NetworkSearchHandler::RadioStateChange(const AppExecFwk::InnerEvent::Pointe
}
}
void NetworkSearchHandler::SetRadioOffWhenAirplaneIsOn()
{
bool isAirplaneMode = false;
auto networkSearchManager = networkSearchManager_.lock();
if (networkSearchManager == nullptr) {
TELEPHONY_LOGE("NetworkSearchHandler::SetRadioOffWhenAirplaneIsOn failed to get NetworkSearchManager");
return;
}
if (networkSearchManager->GetAirplaneMode(isAirplaneMode) == TELEPHONY_SUCCESS && isAirplaneMode) {
networkSearchManager->SetRadioState(slotId_, static_cast<bool>(ModemPowerState::CORE_SERVICE_POWER_OFF), 0);
}
}
void NetworkSearchHandler::RadioRestrictedState(const AppExecFwk::InnerEvent::Pointer &event)
{
if (event == nullptr) {
@ -1191,19 +1221,10 @@ void NetworkSearchHandler::HandleDelayNotifyEvent(const AppExecFwk::InnerEvent::
TELEPHONY_LOGE("NetworkSearchHandler::NotifyStateChange networkRegister_ is nullptr!");
return;
}
RevertLastTechnology();
RadioOnState();
}
int32_t NetworkSearchHandler::GetRegServiceState(RegServiceState &regState)
{
if (networkRegister_ == nullptr) {
TELEPHONY_LOGE("NetworkSearchHandler::GetRegServiceState networkRegister_ is nullptr!");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
regState = networkRegister_->GetRegServiceState();
return TELEPHONY_ERR_SUCCESS;
}
int32_t NetworkSearchHandler::HandleRrcStateChanged(int32_t status)
{
TELEPHONY_LOGI("NetworkSearchHandler::HandleRrcStateChanged slotId:%{public}d", slotId_);

View File

@ -1458,8 +1458,7 @@ bool NetworkSearchManager::IsNeedDelayNotify(int32_t slotId)
TELEPHONY_LOGI("The NR switch is closed.");
return false;
}
RegServiceState regState = RegServiceState::REG_STATE_UNKNOWN;
inner->networkSearchHandler_->GetRegServiceState(regState);
RegServiceState regState = inner->networkSearchState_->GetNetworkStatus()->GetRegStatus();
if (regState == RegServiceState::REG_STATE_NO_SERVICE) {
TELEPHONY_LOGI("The reg state is no service.");
return false;

View File

@ -327,10 +327,10 @@ void NetworkSearchState::NotifyPsRoamingStatusChange()
return;
}
if (networkState_->GetPsRoamingStatus() > RoamingType::ROAMING_STATE_UNKNOWN &&
(processNetworkState_ || networkStateOld_->GetPsRoamingStatus() == RoamingType::ROAMING_STATE_UNKNOWN)) {
networkStateOld_->GetPsRoamingStatus() == RoamingType::ROAMING_STATE_UNKNOWN) {
networkSearchManager->NotifyPsRoamingOpenChanged(slotId_);
}
if ((processNetworkState_ || networkStateOld_->GetPsRoamingStatus() > RoamingType::ROAMING_STATE_UNKNOWN) &&
if (networkStateOld_->GetPsRoamingStatus() > RoamingType::ROAMING_STATE_UNKNOWN &&
networkState_->GetPsRoamingStatus() == RoamingType::ROAMING_STATE_UNKNOWN) {
networkSearchManager->NotifyPsRoamingCloseChanged(slotId_);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -263,31 +263,26 @@ void OperatorName::NotifyGsmSpnChanged(
TELEPHONY_LOGE("OperatorName::NotifyGsmSpnChanged networkState is nullptr slotId:%{public}d", slotId_);
return;
}
int32_t spnRule = 0;
std::string plmn = "";
std::string spn = "";
bool showPlmn = false;
bool showPlmnOld = false;
bool showSpn = false;
bool roaming = networkState->IsRoaming();
if (enableCust_ && displayConditionCust_ != SPN_INVALID) {
spnRule = GetCustSpnRule(roaming);
} else {
std::string numeric = networkState->GetPlmnNumeric();
if (simManager_ != nullptr) {
spnRule = simManager_->ObtainSpnCondition(slotId_, roaming, numeric);
}
}
UpdatePlmn(regStatus, networkState, spnRule, plmn, showPlmn);
UpdateSpn(regStatus, networkState, spnRule, spn, showSpn);
int32_t spnRule = static_cast<int32_t>(GetSpnRule(networkState));
if (slotId_ == static_cast<int32_t>(SimSlotType::VSIM_SLOT_ID)) {
UpdateVSimSpn(spn, spnRule, showSpn);
}
UpdatePlmn(regStatus, networkState, spnRule, plmn, showPlmn);
UpdateSpn(regStatus, networkState, spnRule, spn, showSpn);
showPlmnOld = showPlmn;
if (spn.empty() || !plmn.empty()) {
if (spn.empty() && !plmn.empty()) {
showPlmn = true;
}
if (showPlmn && spn == plmn) {
showSpn = false;
}
TELEPHONY_LOGI(
"OperatorName::NotifyGsmSpnChanged showSpn:%{public}d curSpn_:%{public}s spn:%{public}s showPlmn:%{public}d "
"curPlmn_:%{public}s plmn:%{public}s showPlmnOld:%{public}d enableCust_:%{public}d "
@ -420,6 +415,23 @@ std::string OperatorName::GetEons(const std::string &numeric, int32_t lac, bool
return Str16ToStr8(simManager_->GetSimEons(slotId_, numeric, lac, longNameRequired));
}
unsigned int OperatorName::GetSpnRule(sptr<NetworkState> &networkState)
{
int32_t spnRule = 0;
bool roaming = networkState->IsRoaming();
if (enableCust_ && displayConditionCust_ != SPN_INVALID) {
spnRule = static_cast<int32_t>(GetCustSpnRule(roaming));
} else if (!roaming && IsChinaCard()) {
spnRule = SPN_CONDITION_DISPLAY_PLMN;
} else {
std::string numeric = networkState->GetPlmnNumeric();
if (simManager_ != nullptr) {
spnRule = simManager_->ObtainSpnCondition(slotId_, roaming, numeric);
}
}
return spnRule;
}
unsigned int OperatorName::GetCustSpnRule(bool roaming)
{
unsigned int cond = 0;
@ -606,6 +618,17 @@ bool OperatorName::isCBDomestic(const std::string &numeric)
return false;
}
bool OperatorName::IsChinaCard()
{
std::string simPlmn = "";
if (simManager_ != nullptr) {
std::u16string operatorNumeric = u"";
simManager_->GetSimOperatorNumeric(slotId_, operatorNumeric);
simPlmn = Str16ToStr8(operatorNumeric);
}
return isCMCard(simPlmn) || isCUCard(simPlmn) || isCTCard(simPlmn) || isCBCard(simPlmn);
}
int32_t OperatorName::GetCurrentLac()
{
auto networkSearchManager = networkSearchManager_.lock();

View File

@ -69,7 +69,7 @@ void RadioInfo::ProcessGetRadioState(const AppExecFwk::InnerEvent::Pointer &even
} else {
bool isAirplaneModeOn = false;
nsm->GetAirplaneMode(isAirplaneModeOn);
if (nsm->GetRadioState(slotId_) != ModemPowerState::CORE_SERVICE_POWER_ON && !isAirplaneModeOn) {
if (nsm->GetRadioState(slotId_) == ModemPowerState::CORE_SERVICE_POWER_OFF && !isAirplaneModeOn) {
nsm->SetRadioState(slotId_, static_cast<bool>(ModemPowerState::CORE_SERVICE_POWER_ON), 0);
}
if (nsm->GetRadioState(slotId_) == ModemPowerState::CORE_SERVICE_POWER_ON) {

View File

@ -65,6 +65,7 @@ private:
bool hasEventDone_ = false;
bool hasQueryEventDone_ = true;
std::condition_variable processWait_;
void ProcessSimStateChanged();
void ProcessLoadDone(const AppExecFwk::InnerEvent::Pointer &event);
void ProcessUpdateDone(const AppExecFwk::InnerEvent::Pointer &event);
void ProcessWriteDone(const AppExecFwk::InnerEvent::Pointer &event);

View File

@ -76,6 +76,7 @@ public:
int32_t UpdateOpKeyInfo();
bool IsSetActiveSimInProgress(int32_t slotId);
bool IsSetPrimarySlotIdInProgress();
int32_t SavePrimarySlotId(int32_t slotId);
public:
int32_t unInitModemSlotId_ = INVALID_VALUE;
@ -115,6 +116,7 @@ private:
int32_t GetTargetIccId(int32_t slotId, std::string &iccId);
bool IsAllModemInitDone();
int32_t IsSatelliteSupported();
void UpdateSubState(int32_t slotId, int32_t enable);
private:
const int32_t IMS_SWITCH_STATUS_UNKNOWN = -1;

View File

@ -21,6 +21,7 @@
#include "common_event_subscriber.h"
#include "iservice_registry.h"
#include "multi_sim_controller.h"
#include "os_account_manager_wrapper.h"
#include "sim_constant.h"
#include "sim_file_manager.h"
#include "system_ability_definition.h"
@ -73,6 +74,7 @@ private:
std::list<SimAccountCallbackRecord> GetSimAccountCallbackRecords();
void InitListener();
void SubscribeDataShareReady();
void SubscribeUserSwitch();
void UnSubscribeListeners();
void CheckOpcNeedUpdata(const bool isDataShareError);
int32_t CheckUpdateOpcVersion();
@ -91,6 +93,16 @@ private:
MultiSimMonitor &handler_;
};
class UserSwitchEventSubscriber : public CommonEventSubscriber {
public:
explicit UserSwitchEventSubscriber(
const CommonEventSubscribeInfo &info, MultiSimMonitor &handler)
: CommonEventSubscriber(info), handler_(handler) {}
~UserSwitchEventSubscriber() = default;
void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
MultiSimMonitor &handler_;
};
class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
public:
explicit SystemAbilityStatusChangeListener(MultiSimMonitor &handler) : handler_(handler) {};
@ -110,11 +122,13 @@ private:
std::unique_ptr<ObserverHandler> observerHandler_ = nullptr;
std::list<SimAccountCallbackRecord> listSimAccountCallbackRecord_;
std::shared_ptr<DataShareEventSubscriber> dataShareSubscriber_ = nullptr;
std::shared_ptr<UserSwitchEventSubscriber> userSwitchSubscriber_ = nullptr;
sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
std::mutex mutexInner_;
std::mutex mutexForData_;
std::atomic<int32_t> remainCount_ = 30;
int32_t maxSlotCount_ = 0;
bool isDataShareReady_ = false;
};
} // namespace Telephony
} // namespace OHOS

View File

@ -29,6 +29,7 @@ public:
void ClearAllCache(int32_t slotId);
void ClearMemoryCache(int32_t slotId);
void ClearOperatorValue(int32_t slotId);
void ClearMemoryAndOpkey(int32_t slotId);
int32_t LoadOperatorConfig(int32_t slotId, OperatorConfig &poc, int32_t state = 0);
int32_t GetOperatorConfigs(int32_t slotId, OperatorConfig &poc);
int32_t UpdateOperatorConfigs(int32_t slotId);

View File

@ -287,6 +287,7 @@ enum CallForwardingStatus {
};
inline const std::string DATASHARE_READY_EVENT = "usual.event.DATA_SHARE_READY";
inline const std::string BUNDLE_SCAN_FINISHED_EVENT = "usual.event.BUNDLE_SCAN_FINISHED";
} // namespace Telephony
} // namespace OHOS
#endif // OHOS_SIM_CONSTANT_H

View File

@ -31,6 +31,12 @@
namespace OHOS {
namespace Telephony {
const int32_t SLOT_ID_ZERO = 0;
const int32_t SIM_IO_DATA_MIN_LEN = 6;
const int32_t SIM_IO_DATA_STR_LEN = 2;
const int32_t SIM_IO_DATA_P1_OFFSET = 0;
const int32_t SIM_IO_DATA_P2_OFFSET = 2;
const int32_t SIM_IO_DATA_P3_OFFSET = 4;
const int32_t SIM_IO_HEX_SIGN = 16;
class SimManager : public ISimManager {
public:
explicit SimManager(std::shared_ptr<ITelRilManager> telRilManager);
@ -147,6 +153,7 @@ public:
bool IsSetPrimarySlotIdInProgress() override;
int32_t GetSimIO(int32_t slotId, int32_t command, int32_t fileId,
const std::string &data, const std::string &path, SimAuthenticationResponse &response) override;
int32_t SavePrimarySlotId(int32_t slotId) override;
private:
bool IsValidSlotId(int32_t slotId);

View File

@ -146,7 +146,6 @@ public:
bool modemInitDone_ = false;
private:
void SyncCmdResponse();
void ObtainIccStatus(int32_t slotId);
void GetSimCardData(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event);
void GetSimLockState(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event);

View File

@ -57,11 +57,12 @@ public:
int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey);
bool IfModemInitDone();
int32_t GetSimIO(int32_t slotId, SimIoRequestInfo requestInfo, SimAuthenticationResponse &response);
void SyncCmdResponse();
public:
static bool responseReady_;
static std::mutex ctx_;
static std::condition_variable cv_;
bool responseReady_;
std::mutex ctx_;
std::condition_variable cv_;
private:
void RequestUnlock(UnlockCmd type);

View File

@ -18,25 +18,19 @@
#include <string>
#include "common_event_subscriber.h"
#include "iservice_registry.h"
#include "operator_config_cache.h"
#include "operator_config_loader.h"
#include "system_ability_definition.h"
#include "system_ability_status_change_stub.h"
#include "telephony_log_wrapper.h"
namespace OHOS {
namespace Telephony {
using namespace OHOS::EventFwk;
using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo;
using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber;
class SimStateTracker : public TelEventHandler {
public:
SimStateTracker(std::weak_ptr<SimFileManager> simFileManager,
std::shared_ptr<OperatorConfigCache> operatorConfigCache, int32_t slotId);
~SimStateTracker();
void InitListener();
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
bool RegisterForIccLoaded();
bool RegisterOpkeyLoaded();
@ -57,34 +51,6 @@ private:
void ProcessSimRecordLoad(const AppExecFwk::InnerEvent::Pointer &event);
void ProcessSimOpkeyLoad(const AppExecFwk::InnerEvent::Pointer &event);
void ProcessOperatorCacheDel(const AppExecFwk::InnerEvent::Pointer &event);
private:
class UserSwitchEventSubscriber : public CommonEventSubscriber {
public:
explicit UserSwitchEventSubscriber(
const CommonEventSubscribeInfo &info, int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader)
: CommonEventSubscriber(info), slotId_(slotId), configLoader_(configLoader)
{}
~UserSwitchEventSubscriber() = default;
void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
private:
const int32_t slotId_;
std::shared_ptr<OperatorConfigLoader> configLoader_ = nullptr;
};
class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
public:
explicit SystemAbilityStatusChangeListener(int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader);
~SystemAbilityStatusChangeListener() = default;
virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
private:
const int32_t slotId_;
std::shared_ptr<OperatorConfigLoader> configLoader_ = nullptr;
std::shared_ptr<UserSwitchEventSubscriber> userSwitchSubscriber_ = nullptr;
bool isUserSwitchSubscribered = false;
};
};
} // namespace Telephony
} // namespace OHOS

View File

@ -16,8 +16,13 @@
#ifndef OHOS_STK_CONTROLLER_H
#define OHOS_STK_CONTROLLER_H
#include "system_ability_definition.h"
#include "system_ability_status_change_stub.h"
#include "common_event_subscriber.h"
#include "telephony_state_registry_client.h"
#include "i_tel_ril_manager.h"
#include "inner_event.h"
#include "sim_constant.h"
#include "sim_state_manager.h"
#include "tel_event_handler.h"
#include "want.h"
@ -32,11 +37,14 @@
namespace OHOS {
namespace Telephony {
using namespace OHOS::EventFwk;
using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo;
using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber;
class StkController : public TelEventHandler {
public:
explicit StkController(const std::weak_ptr<Telephony::ITelRilManager> &telRilManager,
const std::weak_ptr<Telephony::SimStateManager> &simStateManager, int32_t slotId);
virtual ~StkController() = default;
~StkController();
void Init();
std::string initStkBudleName();
int32_t SendTerminalResponseCmd(const std::string &strCmd);
@ -66,6 +74,32 @@ private:
bool CheckIsBipCmd(const std::string &cmdData);
sptr<OHOS::IRemoteObject> GetBundleMgr();
void RetrySendRilProactiveCommand();
void UnSubscribeListeners();
void InitListener();
void SubscribeBundleScanFinished();
void OnReceiveBms();
private:
class BundleScanFinishedEventSubscriber : public CommonEventSubscriber {
public:
explicit BundleScanFinishedEventSubscriber(
const CommonEventSubscribeInfo &info, StkController &handler)
: CommonEventSubscriber(info), handler_(handler) {}
~BundleScanFinishedEventSubscriber() = default;
void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
StkController &handler_;
};
class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
public:
explicit SystemAbilityStatusChangeListener(StkController &handler) : handler_(handler) {};
~SystemAbilityStatusChangeListener() = default;
virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
private:
StkController &handler_;
};
private:
std::weak_ptr<Telephony::ITelRilManager> telRilManager_;
@ -81,6 +115,9 @@ private:
std::condition_variable stkCv_;
AAFwk::Want retryWant_;
int32_t remainTryCount_ = 0;
bool isProactiveCommandSucc = false;
std::shared_ptr<BundleScanFinishedEventSubscriber> bundleScanFinishedSubscriber_ = nullptr;
sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
};
} // namespace Telephony
} // namespace OHOS

View File

@ -211,7 +211,9 @@ void IccDiallingNumbersCache::UpdateDiallingNumberToIcc(int fileId,
infor.isDel = isDel;
AppExecFwk::InnerEvent::Pointer event =
BuildCallerInfo(MSG_SIM_CHANGE_DIALLING_NUMBERS_DONE, fileId, index, diallingNumberInfor, caller);
diallingNumbersHandler_->UpdateDiallingNumbers(infor, event);
if (diallingNumbersHandler_ != nullptr) {
diallingNumbersHandler_->UpdateDiallingNumbers(infor, event);
}
}
bool IccDiallingNumbersCache::CheckValueAndOperation(
@ -282,11 +284,15 @@ void IccDiallingNumbersCache::ObtainAllDiallingNumberFiles(
if (fileId == ELEMENTARY_FILE_PBR) {
TELEPHONY_LOGI("ObtainAllDiallingNumberFiles start usim adn");
AppExecFwk::InnerEvent::Pointer pointer = CreateUsimPointer(MSG_SIM_OBTAIN_PBR_DETAILS_DONE, fileId, caller);
usimDiallingNumberSrv_->ObtainUsimElementaryFiles(pointer);
if (usimDiallingNumberSrv_ != nullptr) {
usimDiallingNumberSrv_->ObtainUsimElementaryFiles(pointer);
}
} else {
AppExecFwk::InnerEvent::Pointer event = BuildCallerInfo(
MSG_SIM_OBTAIN_ADN_DETAILS_DONE, fileId, 0, nullptr, caller);
diallingNumbersHandler_->GetAllDiallingNumbers(fileId, extFileId, event);
if (diallingNumbersHandler_ != nullptr) {
diallingNumbersHandler_->GetAllDiallingNumbers(fileId, extFileId, event);
}
}
}
@ -310,7 +316,15 @@ void IccDiallingNumbersCache::SendBackResult(const AppExecFwk::InnerEvent::Point
auto owner = callPointer->GetOwner();
uint32_t id = callPointer->GetInnerEventId();
std::unique_ptr<ResultObtain> fd = callPointer->GetUniqueObject<ResultObtain>();
if (fd == nullptr) {
TELEPHONY_LOGE("fd is nullptr!");
return;
}
std::unique_ptr<ResponseResult> data = std::make_unique<ResponseResult>(fd.get());
if (data == nullptr) {
TELEPHONY_LOGE("data is nullptr!");
return;
}
data->result = static_cast<std::shared_ptr<void>>(ar);
data->exception = object;
if (owner != nullptr) {

View File

@ -52,7 +52,7 @@ void IccDiallingNumbersManager::Init()
stateDiallingNumbers_ = HandleRunningState::STATE_RUNNING;
diallingNumbersCache_->Init();
simFileManager->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_RECORDS_LOADED);
simFileManager->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_CHANGE);
TELEPHONY_LOGI("Init() end");
}
@ -77,11 +77,26 @@ void IccDiallingNumbersManager::ProcessEvent(const AppExecFwk::InnerEvent::Point
case MSG_SIM_DIALLING_NUMBERS_DELETE_DONE:
ProcessDeleteDone(event);
break;
case RadioEvent::RADIO_SIM_STATE_CHANGE:
ProcessSimStateChanged();
break;
default:
break;
}
}
void IccDiallingNumbersManager::ProcessSimStateChanged()
{
if (simStateManager_ == nullptr || diallingNumbersCache_ == nullptr) {
TELEPHONY_LOGE("IccDiallingNumbersManager::ProcessSimStateChanged simStateManager_ is nullptr");
return;
}
if (simStateManager_->GetSimState() == SimState::SIM_STATE_NOT_PRESENT) {
TELEPHONY_LOGI("IccDiallingNumbersManager::ProcessSimStateChanged clear data when sim is absent");
diallingNumbersCache_->ClearDiallingNumberCache();
}
}
void IccDiallingNumbersManager::ProcessLoadDone(const AppExecFwk::InnerEvent::Pointer &event)
{
TELEPHONY_LOGI("IccDiallingNumbersManager::ProcessLoadDone: start");
@ -308,7 +323,7 @@ void IccDiallingNumbersManager::FillResults(
diallingNumbersList_.push_back(item);
}
}
TELEPHONY_LOGI("IccDiallingNumbersManager::FillResults end");
TELEPHONY_LOGI("IccDiallingNumbersManager::FillResults %{public}zu", diallingNumbersList_.size());
}
bool IccDiallingNumbersManager::IsValidType(int type)

View File

@ -514,6 +514,15 @@ bool MultiSimController::IsSimActive(int32_t slotId)
return localCacheInfo_[slotId].isActive == ACTIVE ? true : false;
}
void MultiSimController::UpdateSubState(int32_t slotId, int32_t enable)
{
if (TELEPHONY_EXT_WRAPPER.updateSubState_) {
TELEPHONY_LOGI("TELEPHONY_EXT_WRAPPER UpdateSubState slotId: %{public}d enable: %{public}d", slotId, enable);
TELEPHONY_EXT_WRAPPER.updateSubState_(slotId, enable);
}
isSetActiveSimInProgress_[slotId] = 0;
}
int32_t MultiSimController::SetActiveSim(int32_t slotId, int32_t enable, bool force)
{
TELEPHONY_LOGI("enable = %{public}d slotId = %{public}d", enable, slotId);
@ -536,7 +545,7 @@ int32_t MultiSimController::SetActiveSim(int32_t slotId, int32_t enable, bool fo
}
if (force) {
TELEPHONY_LOGD("no need to update cache");
isSetActiveSimInProgress_[slotId] = 0;
UpdateSubState(slotId, enable);
return TELEPHONY_ERR_SUCCESS;
}
if (simDbHelper_ == nullptr) {
@ -561,8 +570,8 @@ int32_t MultiSimController::SetActiveSim(int32_t slotId, int32_t enable, bool fo
}
localCacheInfo_[slotId].isActive = enable;
lock.unlock();
UpdateSubState(slotId, enable);
CheckIfNeedSwitchMainSlotId();
isSetActiveSimInProgress_[slotId] = 0;
return TELEPHONY_ERR_SUCCESS;
}
@ -1015,10 +1024,6 @@ int32_t MultiSimController::GetShowNumber(int32_t slotId, std::u16string &showNu
if (!showNumber.empty()) {
return TELEPHONY_ERR_SUCCESS;
}
showNumber = Str8ToStr16(TelAesCryptoUtils::ObtainDecryptString(PHONE_NUMBER_PREF, curSimId, ""));
if (!showNumber.empty()) {
return TELEPHONY_ERR_SUCCESS;
}
return GetSimTelephoneNumber(slotId, showNumber);
}
@ -1137,13 +1142,6 @@ int32_t MultiSimController::GetSimTelephoneNumber(int32_t slotId, std::u16string
telephoneNumber = Str8ToStr16(result);
TELEPHONY_LOGI("impu result is empty:%{public}s, slotId:%{public}d", (telephoneNumber.empty() ? "true" : "false"),
slotId);
if (!telephoneNumber.empty()) {
int curSimId = GetSimId(slotId);
if (curSimId != INVALID_VALUE) {
TelAesCryptoUtils::SaveEncryptString(PHONE_NUMBER_PREF, curSimId, result);
TELEPHONY_LOGI("SaveEncryptString, slotId:%{public}d, curSimId:%{public}d", slotId, curSimId);
}
}
return TELEPHONY_ERR_SUCCESS;
}
@ -1303,5 +1301,17 @@ bool MultiSimController::IsSetPrimarySlotIdInProgress()
return isSetPrimarySlotIdInProgress_;
}
int32_t MultiSimController::SavePrimarySlotId(int32_t slotId)
{
if (!IsValidSlotId(slotId)) {
TELEPHONY_LOGE("SavePrimarySlotId invalid slotId: %{public}d", slotId);
return TELEPHONY_ERR_ARGUMENT_INVALID;
}
TELEPHONY_LOGI("SavePrimarySlotId: %{public}d", slotId);
SavePrimarySlotIdInfo(slotId);
return TELEPHONY_ERR_SUCCESS;
}
} // namespace Telephony
} // namespace OHOS

View File

@ -29,6 +29,7 @@
namespace OHOS {
namespace Telephony {
const int64_t DELAY_TIME = 1000;
const int32_t ACTIVE_USER_ID = 100;
MultiSimMonitor::MultiSimMonitor(const std::shared_ptr<MultiSimController> &controller,
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager,
std::vector<std::weak_ptr<Telephony::SimFileManager>> simFileManager)
@ -249,6 +250,10 @@ void MultiSimMonitor::UnSubscribeListeners()
dataShareSubscriber_ = nullptr;
TELEPHONY_LOGI("Unsubscribe datashare ready success");
}
if (userSwitchSubscriber_ != nullptr && CommonEventManager::UnSubscribeCommonEvent(userSwitchSubscriber_)) {
userSwitchSubscriber_ = nullptr;
TELEPHONY_LOGI("Unsubscribe UserSwitch success");
}
if (statusChangeListener_ != nullptr) {
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy != nullptr) {
@ -279,6 +284,7 @@ void MultiSimMonitor::SystemAbilityStatusChangeListener::OnAddSystemAbility(int3
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID is running");
handler_.SubscribeDataShareReady();
handler_.SubscribeUserSwitch();
break;
}
default:
@ -293,6 +299,7 @@ void MultiSimMonitor::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(i
switch (systemAbilityId) {
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID stopped");
handler_.UnSubscribeListeners();
break;
}
default:
@ -318,7 +325,25 @@ void MultiSimMonitor::SubscribeDataShareReady()
dataShareSubscriber_ = nullptr;
TELEPHONY_LOGE("Subscribe datashare ready fail");
}
CheckDataShareError();
}
void MultiSimMonitor::SubscribeUserSwitch()
{
if (userSwitchSubscriber_ != nullptr) {
TELEPHONY_LOGW("UserSwitch has Subscribed");
return;
}
MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
subscriberInfo.SetThreadMode(CommonEventSubscribeInfo::COMMON);
userSwitchSubscriber_ = std::make_shared<UserSwitchEventSubscriber>(subscriberInfo, *this);
if (CommonEventManager::SubscribeCommonEvent(userSwitchSubscriber_)) {
TELEPHONY_LOGI("Subscribe UserSwitch success");
} else {
userSwitchSubscriber_ = nullptr;
TELEPHONY_LOGE("Subscribe UserSwitch fail");
}
}
void MultiSimMonitor::DataShareEventSubscriber::OnReceiveEvent(const CommonEventData &data)
@ -326,8 +351,27 @@ void MultiSimMonitor::DataShareEventSubscriber::OnReceiveEvent(const CommonEvent
OHOS::EventFwk::Want want = data.GetWant();
std::string action = want.GetAction();
TELEPHONY_LOGI("action = %{public}s", action.c_str());
std::vector<int32_t> activeList = { 0 };
DelayedSingleton<AppExecFwk::OsAccountManagerWrapper>::GetInstance()->QueryActiveOsAccountIds(activeList);
if (action == DATASHARE_READY_EVENT) {
handler_.CheckDataShareError();
handler_.isDataShareReady_ = true;
if (activeList[0] == ACTIVE_USER_ID) {
handler_.CheckDataShareError();
}
}
}
void MultiSimMonitor::UserSwitchEventSubscriber::OnReceiveEvent(const CommonEventData &data)
{
OHOS::EventFwk::Want want = data.GetWant();
std::string action = want.GetAction();
TELEPHONY_LOGI("action = %{public}s", action.c_str());
if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
int32_t userId = data.GetCode();
TELEPHONY_LOGI("current user id is :%{public}d", userId);
if (userId == ACTIVE_USER_ID && handler_.isDataShareReady_) {
handler_.CheckDataShareError();
}
}
}

View File

@ -43,6 +43,14 @@ void OperatorConfigCache::ClearAllCache(int32_t slotId)
lock.unlock();
}
void OperatorConfigCache::ClearMemoryAndOpkey(int32_t slotId)
{
std::unique_lock<std::mutex> lock(mutex_);
ClearOperatorValue(slotId);
ClearMemoryCache(slotId);
lock.unlock();
}
void OperatorConfigCache::ClearOperatorValue(int32_t slotId)
{
auto simFileManager = simFileManager_.lock();
@ -139,13 +147,14 @@ int32_t OperatorConfigCache::LoadOperatorConfig(int32_t slotId, OperatorConfig &
int32_t OperatorConfigCache::GetOperatorConfigs(int32_t slotId, OperatorConfig &poc)
{
std::unique_lock<std::mutex> lock(mutex_);
if (opc_.configValue.size() > 0) {
TELEPHONY_LOGD("get from memory");
std::unique_lock<std::mutex> lock(mutex_);
CopyOperatorConfig(opc_, poc);
lock.unlock();
return TELEPHONY_ERR_SUCCESS;
}
lock.unlock();
TELEPHONY_LOGI("reload operator config");
return LoadOperatorConfig(slotId, poc);
}
@ -328,7 +337,7 @@ bool OperatorConfigCache::IsNeedOperatorLoad(int32_t slotId)
return true;
}
std::string iccid = Str16ToStr8(simFileManager->GetSimIccId());
std::string filename = EncryptIccId(iccid) + ".json";
std::string filename = EncryptIccId(iccid + opkey) + ".json";
std::string path = parser_.GetOperatorConfigFilePath(filename);
std::ifstream f(path.c_str());
return !f.good();

View File

@ -1870,7 +1870,6 @@ void SimFile::InitPlmnMemberFunc()
int SimFile::ObtainSpnCondition(bool roaming, const std::string &operatorNum)
{
unsigned int cond = 0;
unsigned int condTemp = 0;
if (displayConditionOfSpn_ <= SPN_INVALID) {
return cond;
}
@ -1880,15 +1879,14 @@ int SimFile::ObtainSpnCondition(bool roaming, const std::string &operatorNum)
cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_SPN);
}
} else {
condTemp = SPN_CONDITION_DISPLAY_SPN;
cond = SPN_CONDITION_DISPLAY_SPN;
if ((static_cast<unsigned int>(displayConditionOfSpn_) & static_cast<unsigned int>(SPN_COND_PLMN)) ==
SPN_COND_PLMN) {
condTemp |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_PLMN);
cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_PLMN);
}
cond = SPN_CONDITION_DISPLAY_PLMN;
}
TELEPHONY_LOGI("displayConditionOfSpn_:%{public}d, roaming:%{public}d, cond:%{public}d, condTemp:%{public}d",
displayConditionOfSpn_, roaming, cond, condTemp);
TELEPHONY_LOGI("displayConditionOfSpn_:%{public}d, roaming:%{public}d, cond:%{public}d",
displayConditionOfSpn_, roaming, cond);
return cond;
}

View File

@ -133,15 +133,18 @@ bool SimFileManager::InitSimFile(SimFileManager::IccType type)
if (iccFileIt == iccFileCache_.end()) {
if (type == SimFileManager::IccType::ICC_TYPE_CDMA) {
simFile_ = std::make_shared<RuimFile>(simStateManager_.lock());
iccFileCache_.insert(std::make_pair(SimFileManager::IccType::ICC_TYPE_CDMA, simFile_));
} else if (type == SimFileManager::IccType::ICC_TYPE_IMS) {
simFile_ = std::make_shared<IsimFile>(simStateManager_.lock());
iccFileCache_.insert(std::make_pair(SimFileManager::IccType::ICC_TYPE_IMS, simFile_));
} else {
simFile_ = std::make_shared<SimFile>(simStateManager_.lock());
iccFileCache_.insert(std::make_pair(SimFileManager::IccType::ICC_TYPE_USIM, simFile_));
iccFileCache_.insert(std::make_pair(SimFileManager::IccType::ICC_TYPE_GSM, simFile_));
}
if (simFile_ != nullptr) {
simFile_->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_RECORDS_LOADED);
}
iccFileCache_.insert(std::make_pair(type, simFile_));
} else {
simFile_ = iccFileIt->second;
}
@ -885,9 +888,7 @@ void SimFileManager::ChangeSimFileByCardType(SimFileManager::IccType type)
TELEPHONY_LOGI("SimFileManager handle new icc invalid type received %{public}d", type);
return;
}
if (type == iccType_ || (iccType_ == SimFileManager::IccType::ICC_TYPE_USIM && type ==
SimFileManager::IccType::ICC_TYPE_GSM) || (iccType_ == SimFileManager::IccType::ICC_TYPE_GSM &&
type == SimFileManager::IccType::ICC_TYPE_USIM)) {
if (type == iccType_) {
TELEPHONY_LOGI("SimFileManager same type as ready");
return;
}

View File

@ -1222,12 +1222,29 @@ int32_t SimManager::GetSimIO(int32_t slotId, int32_t command,
TELEPHONY_LOGE("SimAuthentication has no sim card!");
return TELEPHONY_ERR_NO_SIM_CARD;
}
if (data.length() < SIM_IO_DATA_MIN_LEN) {
TELEPHONY_LOGE("SIM IO input data length invalid");
return TELEPHONY_ERR_FAIL;
}
SimIoRequestInfo requestInfo;
requestInfo.p1 = stoi(data.substr(SIM_IO_DATA_P1_OFFSET, SIM_IO_DATA_STR_LEN), nullptr, SIM_IO_HEX_SIGN);
requestInfo.p2 = stoi(data.substr(SIM_IO_DATA_P2_OFFSET, SIM_IO_DATA_STR_LEN), nullptr, SIM_IO_HEX_SIGN);
requestInfo.p3 = stoi(data.substr(SIM_IO_DATA_P3_OFFSET, SIM_IO_DATA_STR_LEN), nullptr, SIM_IO_HEX_SIGN);
requestInfo.command = command;
requestInfo.fileId = fileId;
requestInfo.data = data;
requestInfo.data = data.substr(SIM_IO_DATA_MIN_LEN, data.length() - SIM_IO_DATA_MIN_LEN);
requestInfo.path = path;
return simStateManager_[slotId]->GetSimIO(slotId, requestInfo, response);
}
int32_t SimManager::SavePrimarySlotId(int32_t slotId)
{
if (!IsValidSlotId(slotId) || multiSimController_ == nullptr) {
TELEPHONY_LOGE("slotId: %{public}d is invalid or multiSimController_ is nullptr", slotId);
return TELEPHONY_ERR_ARGUMENT_INVALID;
}
return multiSimController_->SavePrimarySlotId(slotId);
}
} // namespace Telephony
} // namespace OHOS

View File

@ -17,6 +17,7 @@
#include "sim_data.h"
#include "telephony_errors.h"
#include "telephony_ext_wrapper.h"
#include "telephony_types.h"
namespace OHOS {
@ -550,8 +551,13 @@ int32_t SimRdbHelper::ForgetAllData(int32_t slotId)
DataShare::DataSharePredicates predicates;
predicates.EqualTo(SimData::SLOT_INDEX, std::to_string(slotId));
DataShare::DataShareValuesBucket value;
DataShare::DataShareValueObject valueObj(ACTIVE);
value.Put(SimData::IS_ACTIVE, valueObj);
if (TELEPHONY_EXT_WRAPPER.isVSimEnabled_ && TELEPHONY_EXT_WRAPPER.isVSimEnabled_() &&
slotId != static_cast<int32_t>(SimSlotType::VSIM_SLOT_ID)) {
TELEPHONY_LOGI("vsim enabled, not change slotId: %{public}d IS_ACTIVE state", slotId);
} else {
DataShare::DataShareValueObject valueObj(ACTIVE);
value.Put(SimData::IS_ACTIVE, valueObj);
}
DataShare::DataShareValueObject valueIndex(INVALID_VALUE);
value.Put(SimData::SLOT_INDEX, valueIndex);
std::shared_ptr<DataShare::DataShareHelper> dataShareHelper = CreateDataHelper();

View File

@ -38,9 +38,6 @@
using namespace OHOS::EventFwk;
namespace OHOS {
namespace Telephony {
std::mutex SimStateManager::ctx_;
bool SimStateManager::responseReady_ = false;
std::condition_variable SimStateManager::cv_;
const std::map<uint32_t, SimStateHandle::Func> SimStateHandle::memberFuncMap_ = {
{ MSG_SIM_UNLOCK_PIN_DONE,
[](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
@ -663,14 +660,6 @@ LockStatusResponse SimStateHandle::GetSimlockResponse()
return simlockRespon_;
}
void SimStateHandle::SyncCmdResponse()
{
std::unique_lock<std::mutex> lck(SimStateManager::ctx_);
SimStateManager::responseReady_ = true;
TELEPHONY_LOGI("SimStateHandle::SyncCmdResponse(), responseReady_ = %{public}d", SimStateManager::responseReady_);
SimStateManager::cv_.notify_one();
}
bool SimStateHandle::PublishSimStateEvent(std::string event, int32_t eventCode, std::string eventData)
{
AAFwk::Want want;
@ -700,7 +689,12 @@ void SimStateHandle::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
if (memberFunc != nullptr) {
memberFunc(this, slotId_, event);
}
SyncCmdResponse();
auto simStateManager = simStateManager_.lock();
if (simStateManager == nullptr) {
TELEPHONY_LOGE("simStateManager nullptr");
return;
}
simStateManager->SyncCmdResponse();
return;
}

View File

@ -135,6 +135,14 @@ int32_t SimStateManager::SetModemInit(bool state)
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
void SimStateManager::SyncCmdResponse()
{
std::unique_lock<std::mutex> lck(ctx_);
responseReady_ = true;
TELEPHONY_LOGI("SimStateManager::SyncCmdResponse(), responseReady_ = %{public}d", responseReady_);
cv_.notify_one();
}
int32_t SimStateManager::UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response)
{
if (simStateHandle_ == nullptr) {

View File

@ -18,7 +18,6 @@
#include "common_event_manager.h"
#include "common_event_support.h"
#include "core_manager_inner.h"
#include "os_account_manager_wrapper.h"
#include "radio_event.h"
#include "telephony_ext_wrapper.h"
#include "thread"
@ -26,7 +25,6 @@
namespace OHOS {
namespace Telephony {
constexpr int32_t OPKEY_VMSG_LENTH = 3;
const int32_t ACTIVE_USER_ID = 100;
SimStateTracker::SimStateTracker(std::weak_ptr<SimFileManager> simFileManager,
std::shared_ptr<OperatorConfigCache> operatorConfigCache, int32_t slotId)
: TelEventHandler("SimStateTracker"), simFileManager_(simFileManager), operatorConfigCache_(operatorConfigCache),
@ -36,7 +34,6 @@ SimStateTracker::SimStateTracker(std::weak_ptr<SimFileManager> simFileManager,
TELEPHONY_LOGE("can not make OperatorConfigLoader");
}
operatorConfigLoader_ = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
InitListener();
}
SimStateTracker::~SimStateTracker()
@ -51,20 +48,6 @@ SimStateTracker::~SimStateTracker()
}
}
void SimStateTracker::InitListener()
{
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(slotId_, operatorConfigLoader_);
if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
TELEPHONY_LOGE("samgrProxy or statusChangeListener_ is nullptr");
return;
}
int32_t ret = samgrProxy->SubscribeSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, statusChangeListener_);
TELEPHONY_LOGI("SubscribeSystemAbility SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN result:%{public}d", ret);
ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
TELEPHONY_LOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d", ret);
}
void SimStateTracker::ProcessSimRecordLoad(const AppExecFwk::InnerEvent::Pointer &event)
{
TELEPHONY_LOGI("SimStateTracker::Refresh config");
@ -134,8 +117,7 @@ void SimStateTracker::ProcessOperatorCacheDel(const AppExecFwk::InnerEvent::Poin
TELEPHONY_LOGE("operatorConfigCache is nullptr");
return;
}
operatorConfigCache_->ClearOperatorValue(slotId);
operatorConfigCache_->ClearMemoryCache(slotId);
operatorConfigCache_->ClearMemoryAndOpkey(slotId);
}
void SimStateTracker::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
@ -232,92 +214,5 @@ bool SimStateTracker::UnregisterOperatorCacheDel()
simFileManager->UnRegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_OPERATOR_CACHE_DELETE);
return true;
}
SimStateTracker::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
int32_t slotId, std::shared_ptr<OperatorConfigLoader> configLoader)
: slotId_(slotId), configLoader_(configLoader)
{}
void SimStateTracker::SystemAbilityStatusChangeListener::OnAddSystemAbility(
int32_t systemAbilityId, const std::string &deviceId)
{
if (configLoader_ == nullptr) {
TELEPHONY_LOGE("configLoader_ is nullptr.");
return;
}
switch (systemAbilityId) {
case SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN: {
TELEPHONY_LOGI("SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN running");
std::vector<int32_t> activeList = { 0 };
DelayedSingleton<AppExecFwk::OsAccountManagerWrapper>::GetInstance()->QueryActiveOsAccountIds(activeList);
TELEPHONY_LOGI("current active user id is :%{public}d", activeList[0]);
if (activeList[0] == ACTIVE_USER_ID) {
configLoader_->LoadOperatorConfig(slotId_);
}
break;
}
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID running, isUserSwitchSubscribered is :%{public}d",
isUserSwitchSubscribered);
if (isUserSwitchSubscribered) {
return;
}
MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
subscriberInfo.SetThreadMode(CommonEventSubscribeInfo::COMMON);
userSwitchSubscriber_ = std::make_shared<UserSwitchEventSubscriber>(subscriberInfo, slotId_, configLoader_);
if (CommonEventManager::SubscribeCommonEvent(userSwitchSubscriber_)) {
isUserSwitchSubscribered = true;
TELEPHONY_LOGI("Subscribe user switched success");
}
break;
}
default:
TELEPHONY_LOGE("systemAbilityId is invalid");
break;
}
}
void SimStateTracker::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
int32_t systemAbilityId, const std::string &deviceId)
{
switch (systemAbilityId) {
case SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN: {
TELEPHONY_LOGE("SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN stopped");
break;
}
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID stopped, isUserSwitchSubscribered is :%{public}d",
isUserSwitchSubscribered);
if (!isUserSwitchSubscribered) {
return;
}
if (userSwitchSubscriber_ != nullptr && CommonEventManager::UnSubscribeCommonEvent(userSwitchSubscriber_)) {
userSwitchSubscriber_ = nullptr;
isUserSwitchSubscribered = false;
TELEPHONY_LOGI("Unsubscribe user switched success");
}
break;
}
default:
TELEPHONY_LOGE("systemAbilityId is invalid");
break;
}
}
void SimStateTracker::UserSwitchEventSubscriber::OnReceiveEvent(const CommonEventData &data)
{
OHOS::EventFwk::Want want = data.GetWant();
std::string action = data.GetWant().GetAction();
TELEPHONY_LOGI("action = %{public}s", action.c_str());
if (action == CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
int32_t userId = data.GetCode();
TELEPHONY_LOGI("current user id is :%{public}d", userId);
if (userId == ACTIVE_USER_ID) {
configLoader_->LoadOperatorConfig(slotId_);
}
}
}
} // namespace Telephony
} // namespace OHOS

View File

@ -233,6 +233,9 @@ std::u16string SIMUtils::UcsConvertToString(unsigned char *data, int length, int
if (len > length - START_POS) {
len = length - START_POS;
}
if (len <= 0) {
return u"";
}
unsigned char* dataUsc = new unsigned char[len * HALF_LEN]{ FF_DATA };
int index = 0;
int base = 0;
@ -269,6 +272,9 @@ std::u16string SIMUtils::UcsWideConvertToString(unsigned char *data, int length,
if (len > length - END_POS) {
len = length - END_POS;
}
if (len <= 0) {
return u"";
}
int base = (data[offset + UCS_BASE_POS] << BYTE_BIT) + data[offset + UCS_BASE_POS + 1];
unsigned char* dataUsc = new unsigned char[len * HALF_LEN]{ FF_DATA };
int dataOffset = UCS_WIDE_OFFSET;

View File

@ -58,6 +58,11 @@ StkController::StkController(const std::weak_ptr<Telephony::ITelRilManager> &tel
slotId_(slotId)
{}
StkController::~StkController()
{
UnSubscribeListeners();
}
void StkController::Init()
{
stkBundleName_ = initStkBudleName();
@ -65,6 +70,108 @@ void StkController::Init()
if (TELEPHONY_EXT_WRAPPER.initBip_ != nullptr) {
TELEPHONY_EXT_WRAPPER.initBip_(slotId_);
}
InitListener();
}
void StkController::UnSubscribeListeners()
{
if (bundleScanFinishedSubscriber_ != nullptr &&
CommonEventManager::UnSubscribeCommonEvent(bundleScanFinishedSubscriber_)) {
bundleScanFinishedSubscriber_ = nullptr;
TELEPHONY_LOGI("Unsubscribe Bundle Scan Finished success");
}
if (statusChangeListener_ != nullptr) {
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy != nullptr) {
samgrProxy->UnSubscribeSystemAbility(OHOS::COMMON_EVENT_SERVICE_ID, statusChangeListener_);
statusChangeListener_ = nullptr;
TELEPHONY_LOGI("Unsubscribe COMMON_EVENT_SERVICE_ID success");
}
}
}
void StkController::InitListener()
{
auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(*this);
if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
TELEPHONY_LOGE("samgrProxy or statusChangeListener_ is nullptr");
return;
}
auto ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
TELEPHONY_LOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result is %{public}d", ret);
}
void StkController::SystemAbilityStatusChangeListener::OnAddSystemAbility(int32_t systemAbilityId,
const std::string &deviceId)
{
switch (systemAbilityId) {
case COMMON_EVENT_SERVICE_ID: {
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID is running");
handler_.SubscribeBundleScanFinished();
break;
}
default:
TELEPHONY_LOGE("systemAbilityId is invalid");
break;
}
}
void StkController::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(int32_t systemAbilityId,
const std::string &deviceId)
{
switch (systemAbilityId) {
case COMMON_EVENT_SERVICE_ID: {
handler_.UnSubscribeListeners();
TELEPHONY_LOGI("COMMON_EVENT_SERVICE_ID stopped");
break;
}
default:
TELEPHONY_LOGE("systemAbilityId is invalid");
break;
}
}
void StkController::SubscribeBundleScanFinished()
{
if (bundleScanFinishedSubscriber_ != nullptr) {
TELEPHONY_LOGW("Bundle Scan Finished has Subscribed");
return;
}
MatchingSkills matchingSkills;
matchingSkills.AddEvent(BUNDLE_SCAN_FINISHED_EVENT);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
subscriberInfo.SetThreadMode(CommonEventSubscribeInfo::COMMON);
bundleScanFinishedSubscriber_ = std::make_shared<BundleScanFinishedEventSubscriber>(subscriberInfo, *this);
if (CommonEventManager::SubscribeCommonEvent(bundleScanFinishedSubscriber_)) {
TELEPHONY_LOGI("Subscribe Bundle Scan Finished success");
} else {
bundleScanFinishedSubscriber_ = nullptr;
TELEPHONY_LOGE("Subscribe Bundle Scan Finished fail");
}
}
void StkController::BundleScanFinishedEventSubscriber::OnReceiveEvent(const CommonEventData &data)
{
OHOS::EventFwk::Want want = data.GetWant();
std::string action = want.GetAction();
TELEPHONY_LOGI("action = %{public}s", action.c_str());
if (action == BUNDLE_SCAN_FINISHED_EVENT) {
handler_.OnReceiveBms();
}
}
void StkController::OnReceiveBms()
{
if (!retryWant_.GetStringParam(PARAM_MSG_CMD).empty() && !isProactiveCommandSucc) {
if (remainTryCount_ == 0) {
remainTryCount_ = MAX_RETRY_COUNT;
TELEPHONY_LOGI("OnReceiveBms retry send stkdata");
SendEvent(StkController::RETRY_SEND_RIL_PROACTIVE_COMMAND, 0, DELAY_TIME);
} else {
remainTryCount_ = MAX_RETRY_COUNT;
}
}
}
std::string StkController::initStkBudleName()
@ -266,6 +373,7 @@ void StkController::OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Poin
SendEvent(StkController::RETRY_SEND_RIL_PROACTIVE_COMMAND, 0, DELAY_TIME);
return;
}
isProactiveCommandSucc = true;
remainTryCount_ = 0;
}
@ -279,6 +387,7 @@ void StkController::RetrySendRilProactiveCommand()
return;
}
TELEPHONY_LOGI("StkController[%{public}d] retry sucess", slotId_);
isProactiveCommandSucc = true;
remainTryCount_ = 0;
return;
}

View File

@ -324,6 +324,10 @@ void UsimDiallingNumbersService::StorePbrDetailInfo(
void UsimDiallingNumbersService::SendBackResult(
const std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> &diallingnumbers)
{
if (callerPointer_ == nullptr) {
TELEPHONY_LOGE("callerPointer_ is nullptr");
return;
}
auto owner = callerPointer_->GetOwner();
if (owner == nullptr) {
TELEPHONY_LOGE("owner is nullptr");

View File

@ -29,6 +29,7 @@ public:
~TelRilData() = default;
HDI::Ril::V1_1::DataProfileDataInfo ChangeDPToHalDataProfile(DataProfile dataProfile);
HDI::Ril::V1_3::DataProfileDataInfoWithApnTypes ChangeDPToHalDataProfileWithApnTypes(DataProfile dataProfile);
int32_t DeactivatePdpContext(int32_t cid, int32_t reason, const AppExecFwk::InnerEvent::Pointer &response);
int32_t DeactivatePdpContextResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo);
int32_t SetInitApnInfo(const DataProfile &dataProfile, const AppExecFwk::InnerEvent::Pointer &response);

View File

@ -39,6 +39,21 @@ HDI::Ril::V1_1::DataProfileDataInfo TelRilData::ChangeDPToHalDataProfile(DataPro
return dataProfileInfo;
}
HDI::Ril::V1_3::DataProfileDataInfoWithApnTypes TelRilData::ChangeDPToHalDataProfileWithApnTypes(
DataProfile dataProfile)
{
HDI::Ril::V1_3::DataProfileDataInfoWithApnTypes dataProfileInfoWithApnTypes;
dataProfileInfoWithApnTypes.profileId = dataProfile.profileId;
dataProfileInfoWithApnTypes.password = dataProfile.password;
dataProfileInfoWithApnTypes.authenticationType = dataProfile.verType;
dataProfileInfoWithApnTypes.userName = dataProfile.userName;
dataProfileInfoWithApnTypes.apn = dataProfile.apn;
dataProfileInfoWithApnTypes.protocol = dataProfile.protocol;
dataProfileInfoWithApnTypes.roamingProtocol = dataProfile.roamingProtocol;
dataProfileInfoWithApnTypes.supportedApnTypesBitmap = dataProfile.supportedApnTypesBitmap;
return dataProfileInfoWithApnTypes;
}
int32_t TelRilData::DeactivatePdpContext(int32_t cid, int32_t reason, const AppExecFwk::InnerEvent::Pointer &response)
{
HDI::Ril::V1_1::UniInfo uniInfo;
@ -55,12 +70,13 @@ int32_t TelRilData::DeactivatePdpContextResponse(const HDI::Ril::V1_1::RilRadioR
int32_t TelRilData::ActivatePdpContext(int32_t radioTechnology, DataProfile dataProfile, bool isRoaming,
bool allowRoaming, const AppExecFwk::InnerEvent::Pointer &response)
{
HDI::Ril::V1_1::DataCallInfo dataCallInfo;
dataCallInfo.radioTechnology = radioTechnology;
dataCallInfo.dataProfileInfo = ChangeDPToHalDataProfile(dataProfile);
dataCallInfo.roamingAllowed = allowRoaming;
dataCallInfo.isRoaming = isRoaming;
return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_1::IRil::ActivatePdpContext, dataCallInfo);
HDI::Ril::V1_3::DataCallInfoWithApnTypes dataCallInfoWithApnTypes;
dataCallInfoWithApnTypes.radioTechnology = radioTechnology;
dataCallInfoWithApnTypes.dataProfileInfo = ChangeDPToHalDataProfileWithApnTypes(dataProfile);
dataCallInfoWithApnTypes.roamingAllowed = allowRoaming;
dataCallInfoWithApnTypes.isRoaming = isRoaming;
return Request(TELEPHONY_LOG_FUNC_NAME, response, &HDI::Ril::V1_3::IRil::ActivatePdpContextWithApnTypes,
dataCallInfoWithApnTypes);
}
int32_t TelRilData::ActivatePdpContextResponse(const HDI::Ril::V1_1::RilRadioResponseInfo &responseInfo,

View File

@ -189,6 +189,10 @@ std::shared_ptr<TelRilModem> TelRilManager::GetTelRilModem(int32_t slotId)
std::shared_ptr<ObserverHandler> TelRilManager::GetObserverHandler(int32_t slotId)
{
if (slotId < 0 || static_cast<size_t>(slotId) >= observerHandler_.size()) {
TELEPHONY_LOGE("observerHandler_ slotId %{public}d is valid", slotId);
return nullptr;
}
return observerHandler_[slotId];
}

View File

@ -89,9 +89,11 @@ public:
typedef bool (*GET_SIM_ID_EXT)(int32_t slotId, int32_t &simId);
typedef bool (*GET_SLOT_ID_EXT)(int32_t simId, int32_t &slotId);
typedef bool (*IS_HANDLE_VSIM)(void);
typedef bool (*IS_VSIM_ENABLED)(void);
typedef void (*UPDATE_SUB_STATE)(int32_t slotId, int32_t subState);
/* add for vsim end */
typedef bool (*SEND_EVENT)(std::shared_ptr<std::string> cmdData, int32_t slotId);
typedef bool (*INIT_BIP)(int32_t slotId);
/* add for vsim end */
typedef bool (*IS_ALLOWED_INSERT_APN)(std::string &value);
typedef void (*GET_TARGET_OPKEY)(int32_t slotId, std::u16string &opkey);
typedef void (*SORT_SIGNAL_INFO_LIST_EXT)(
@ -142,9 +144,11 @@ public:
GET_SIM_ID_EXT getSimIdExt_ = nullptr;
GET_SLOT_ID_EXT getSlotIdExt_ = nullptr;
IS_HANDLE_VSIM isHandleVSim_ = nullptr;
IS_VSIM_ENABLED isVSimEnabled_ = nullptr;
UPDATE_SUB_STATE updateSubState_ = nullptr;
/* add for vsim end */
SEND_EVENT sendEvent_ = nullptr;
INIT_BIP initBip_ = nullptr;
/* add for vsim end */
IS_ALLOWED_INSERT_APN isAllowedInsertApn_ = nullptr;
GET_TARGET_OPKEY getTargetOpkey_ = nullptr;
SORT_SIGNAL_INFO_LIST_EXT sortSignalInfoListExt_ = nullptr;

View File

@ -168,10 +168,13 @@ void TelephonyExtWrapper::InitTelephonyExtWrapperForVSim()
getSimIdExt_ = (GET_SIM_ID_EXT) dlsym(telephonyVSimWrapperHandle_, "GetSimIdExt");
getSlotIdExt_ = (GET_SLOT_ID_EXT) dlsym(telephonyVSimWrapperHandle_, "GetSlotIdExt");
isHandleVSim_ = (IS_HANDLE_VSIM) dlsym(telephonyVSimWrapperHandle_, "IsHandleVSim");
isVSimEnabled_ = (IS_VSIM_ENABLED) dlsym(telephonyVSimWrapperHandle_, "IsVSimEnabled");
updateSubState_ = (UPDATE_SUB_STATE) dlsym(telephonyVSimWrapperHandle_, "UpdateSubState");
bool hasFuncNull = (isVSimInStatus_ == nullptr || getVSimSlotId_ == nullptr || onAllFilesFetchedExt_ == nullptr ||
putVSimExtraInfo_ == nullptr || changeSpnAndRuleExt_ == nullptr || getVSimCardState_ == nullptr ||
getSimIdExt_ == nullptr || getSlotIdExt_ == nullptr || isHandleVSim_ == nullptr);
getSimIdExt_ == nullptr || getSlotIdExt_ == nullptr || isHandleVSim_ == nullptr || isVSimEnabled_ == nullptr ||
updateSubState_ == nullptr);
if (hasFuncNull) {
TELEPHONY_LOGE("[VSIM] telephony ext wrapper symbol failed, error: %{public}s", dlerror());
return;

View File

@ -17,8 +17,21 @@ group("unittest") {
testonly = true
deps = []
deps += [
"unittest/core_service_gtest:tel_core_service_common_test",
"unittest/core_service_gtest:tel_core_service_gtest",
"unittest/core_service_gtest:tel_core_service_native_branch_gtest",
"unittest/core_service_gtest:tel_core_service_test",
"unittest/core_service_gtest:tel_core_zero_branch_gtest",
"unittest/core_service_gtest:tel_network_search_branch_gtest",
"unittest/core_service_gtest:tel_network_search_gtest",
"unittest/core_service_gtest:tel_network_search_manager_gtest",
"unittest/core_service_gtest:tel_sim_file_manager_branch_gtest",
"unittest/core_service_gtest:tel_sim_gtest",
"unittest/core_service_gtest:tel_sim_zero_branch_gtest",
"unittest/icc_dialling_numbers_handler_gtest:icc_dialling_numbers_handler_gtest",
"unittest/sim_manager_gtest:sim_manager_gtest",
"unittest/sim_state_handle_gtest:sim_state_handle_gtest",
"unittest/tel_ril_gtest:tel_ril_gtest",
"unittest/utils_vcard_gtest:utils_vcard_gtest",
]
}

View File

@ -22,7 +22,6 @@ ohos_unittest("tel_core_service_gtest") {
module_out_path = part_name + "/" + test_module
sources = [
"network_search_test_callback_stub.cpp",
"satellite_service_test.cpp",
"security_token.cpp",
"zero_branch_test_core_service.cpp",
@ -112,23 +111,398 @@ ohos_unittest("tel_network_search_gtest") {
module_out_path = part_name + "/" + test_module
sources = [
# Depends files
"$SOURCE_DIR/frameworks/native/src/i_network_search_callback_stub.cpp",
"core_service_test_helper.cpp",
"ims_reg_info_callback_gtest.cpp",
"network_search_test.cpp",
"network_search_test_callback_stub.cpp",
"network_search_test_time_zone.cpp",
"security_token.cpp",
# Test cases
"network_search_test.cpp",
"network_search_test_time_zone.cpp",
]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_network_search_manager_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_manager_gtest"
module_out_path = part_name + "/" + test_module
sources = [
# Depends files
"$SOURCE_DIR/frameworks/native/src/i_network_search_callback_stub.cpp",
"core_service_test_helper.cpp",
"ims_reg_info_callback_gtest.cpp",
"network_search_test_callback_stub.cpp",
"security_token.cpp",
# Test cases
"network_search_manager_test.cpp",
]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_sim_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [
# Depends files
"core_service_test_helper.cpp",
"security_token.cpp",
"sim_operator_brocast_test.cpp",
"sim_test_util.cpp",
# Test cases
"sim_core_service_test.cpp",
"sim_elementary_file_test.cpp",
"sim_icc_test.cpp",
"sim_operator_brocast_test.cpp",
"sim_test.cpp",
"sim_test_util.cpp",
"sim_type_convert_test.cpp",
"vcard_test.cpp",
"vsim_test.cpp",
]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_core_zero_branch_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [
# Depends files
"core_service_test_helper.cpp",
"security_token.cpp",
"sim_operator_brocast_test.cpp",
"sim_test_util.cpp",
# Test cases
"zero_branch_test.cpp",
]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_sim_zero_branch_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [
# Depends files
"core_service_test_helper.cpp",
"security_token.cpp",
"sim_operator_brocast_test.cpp",
"sim_test_util.cpp",
# Test cases
"zero_branch_test_sim_ril.cpp",
]
@ -208,10 +582,464 @@ ohos_unittest("tel_network_search_gtest") {
]
}
ohos_unittest("tel_core_service_test") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [ "core_service_test.cpp" ]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_core_service_common_test") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [
"core_service_common_test.cpp",
"security_token.cpp",
]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"huks:libhukssdk",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_network_search_branch_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [
# Depends files
"core_service_test_helper.cpp",
"security_token.cpp",
"sim_operator_brocast_test.cpp",
"sim_test_util.cpp",
# Test cases
"network_search_branch_test.cpp",
]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_core_service_native_branch_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [
# Depends files
"core_service_test_helper.cpp",
"security_token.cpp",
"sim_operator_brocast_test.cpp",
"sim_test_util.cpp",
# Test cases
"core_service_native_branch_test.cpp",
]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
ohos_unittest("tel_sim_file_manager_branch_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "tel_network_search_gtest"
module_out_path = part_name + "/" + test_module
sources = [ "sim_file_manager_branch_test.cpp" ]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
group("unittest") {
testonly = true
deps = [
":tel_core_service_common_test",
":tel_core_service_gtest",
":tel_core_service_native_branch_gtest",
":tel_core_service_test",
":tel_core_zero_branch_gtest",
":tel_network_search_branch_gtest",
":tel_network_search_gtest",
":tel_sim_file_manager_branch_gtest",
":tel_sim_gtest",
":tel_sim_zero_branch_gtest",
]
}

View File

@ -0,0 +1,474 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include <gtest/gtest.h>
#include <string_ex.h>
#include "hks_api.h"
#include "tel_aes_crypto_util.h"
#include "common_event_manager.h"
#include "common_event_support.h"
#include "core_service.h"
#include "core_service_client.h"
#include "core_service_dump_helper.h"
#include "core_service_hisysevent.h"
#include "enum_convert.h"
#include "network_search_manager.h"
#include "operator_name.h"
#include "operator_name_utils.h"
#include "security_token.h"
#include "sim_manager.h"
#include "tel_ril_manager.h"
#include "telephony_config.h"
#include "telephony_log_wrapper.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
constexpr int32_t NR_NSA_OPTION_ONLY = 1;
static const int32_t SLEEP_TIME = 3;
static const uint32_t MODEM_CAP_MIN_VALUE = 0;
static const uint32_t MODEM_CAP_MAX_VALUE = 32;
class CoreServiceCommonTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void CoreServiceCommonTest::SetUpTestCase() {}
void CoreServiceCommonTest::TearDownTestCase()
{
sleep(SLEEP_TIME);
}
void CoreServiceCommonTest::SetUp() {}
void CoreServiceCommonTest::TearDown() {}
/**
* @tc.number CoreService_SetNrOptionMode_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_SetNrOptionMode_001, Function | MediumTest | Level1)
{
int32_t mode = NR_NSA_OPTION_ONLY;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetNrOptionMode(0, mode, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_PERMISSION_ERR);
}
/**
* @tc.number CoreService_SetNrOptionMode_002
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_SetNrOptionMode_002, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t mode = NR_NSA_OPTION_ONLY;
DelayedSingleton<CoreService>::GetInstance()->networkSearchManager_ = nullptr;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetNrOptionMode(0, mode, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number CoreService_GetCellInfoList_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetCellInfoList_001, Function | MediumTest | Level1)
{
SecurityToken token;
DelayedSingleton<CoreService>::GetInstance()->networkSearchManager_ = nullptr;
std::vector<sptr<CellInformation>> cellInfo;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetCellInfoList(0, cellInfo);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number CoreService_InitExtraModule_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_InitExtraModule_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->InitExtraModule(0);
ASSERT_EQ(result, TELEPHONY_ERROR);
}
/**
* @tc.number CoreService_GetNrSsbIdInfo_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetNrSsbIdInfo_001, Function | MediumTest | Level1)
{
std::shared_ptr<NrSsbInformation> nrSsbInformation;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetNrSsbIdInfo(0, nrSsbInformation);
ASSERT_EQ(result, TELEPHONY_ERR_PERMISSION_ERR);
}
/**
* @tc.number CoreService_GetNrSsbIdInfo_002
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetNrSsbIdInfo_002, Function | MediumTest | Level1)
{
SecurityToken token;
DelayedSingleton<CoreService>::GetInstance()->networkSearchManager_ = nullptr;
std::shared_ptr<NrSsbInformation> nrSsbInformation;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetNrSsbIdInfo(0, nrSsbInformation);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number CoreService_GetNrSsbIdInfo_003
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetNrSsbIdInfo_003, Function | MediumTest | Level1)
{
SecurityToken token;
std::shared_ptr<NrSsbInformation> nrSsbInformation;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetNrSsbIdInfo(0, nrSsbInformation);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number CoreService_IsAllowedInsertApn_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_IsAllowedInsertApn_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::string value = "";
auto result = DelayedSingleton<CoreService>::GetInstance()->IsAllowedInsertApn(value);
ASSERT_EQ(result, true);
}
/**
* @tc.number CoreService_GetTargetOpkey_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetTargetOpkey_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string value = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetTargetOpkey(0, value);
ASSERT_EQ(result, TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number CoreService_GetOpkeyVersion_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetOpkeyVersion_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::string versionInfo = "";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetOpkeyVersion(versionInfo);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number CoreService_GetSimIO_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetSimIO_001, Function | MediumTest | Level1)
{
int32_t command = 0;
int32_t fileId = 0;
std::string data = "";
std::string path = "";
SimAuthenticationResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetSimIO(0, command, fileId, data, path, response);
ASSERT_EQ(result, TELEPHONY_ERR_PERMISSION_ERR);
}
/**
* @tc.number CoreService_GetSimIO_002
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetSimIO_002, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t command = 0;
int32_t fileId = 0;
std::string data = "";
std::string path = "";
SimAuthenticationResponse response;
DelayedSingleton<CoreService>::GetInstance()->simManager_ = nullptr;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetSimIO(0, command, fileId, data, path, response);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number CoreService_GetSimIO_003
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, CoreService_GetSimIO_003, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t command = 0;
int32_t fileId = 0;
std::string data = "";
std::string path = "";
SimAuthenticationResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetSimIO(0, command, fileId, data, path, response);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number Enum_convert_GetCellularDataConnectionState_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, Enum_convert_GetCellularDataConnectionState_001, Function | MediumTest | Level1)
{
int32_t state = static_cast<int32_t>(TelephonyDataConnectionStatus::DATA_STATE_DISCONNECTED);
std::string result = GetCellularDataConnectionState(state);
ASSERT_STREQ(result.c_str(), "DATA_STATE_DISCONNECTED");
state = static_cast<int32_t>(TelephonyDataConnectionStatus::DATA_STATE_CONNECTING);
result = GetCellularDataConnectionState(state);
ASSERT_STREQ(result.c_str(), "DATA_STATE_CONNECTING");
state = static_cast<int32_t>(TelephonyDataConnectionStatus::DATA_STATE_CONNECTED);
result = GetCellularDataConnectionState(state);
ASSERT_STREQ(result.c_str(), "DATA_STATE_CONNECTED");
state = static_cast<int32_t>(TelephonyDataConnectionStatus::DATA_STATE_SUSPENDED);
result = GetCellularDataConnectionState(state);
ASSERT_STREQ(result.c_str(), "DATA_STATE_SUSPENDED");
}
/**
* @tc.number TelAesCryptoUtils_HexToDec_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelAesCryptoUtils_HexToDec_001, Function | MediumTest | Level1)
{
uint8_t decodeValue;
bool result = TelAesCryptoUtils::HexToDec('5', decodeValue);
EXPECT_TRUE(result);
EXPECT_EQ(decodeValue, 5);
}
/**
* @tc.number TelAesCryptoUtils_HexToDec_002
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelAesCryptoUtils_HexToDec_002, Function | MediumTest | Level1)
{
uint8_t decodeValue;
bool result = TelAesCryptoUtils::HexToDec('a', decodeValue);
EXPECT_TRUE(result);
EXPECT_EQ(decodeValue, 10);
}
/**
* @tc.number TelAesCryptoUtils_HexToDec_003
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelAesCryptoUtils_HexToDec_003, Function | MediumTest | Level1)
{
uint8_t decodeValue;
bool result = TelAesCryptoUtils::HexToDec('g', decodeValue);
EXPECT_FALSE(result);
}
/**
* @tc.number TelAesCryptoUtils_DecToHexString_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelAesCryptoUtils_DecToHexString_001, Function | MediumTest | Level1)
{
const uint8_t *data = nullptr;
size_t len = 10;
std::string result = TelAesCryptoUtils::DecToHexString(data, len);
ASSERT_EQ(result, "");
}
/**
* @tc.number TelAesCryptoUtils_DecToHexString_002
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelAesCryptoUtils_DecToHexString_002, Function | MediumTest | Level1)
{
uint8_t data[10] = {0};
size_t len = 0;
std::string result = TelAesCryptoUtils::DecToHexString(data, len);
ASSERT_EQ(result, "");
}
/**
* @tc.number TelAesCryptoUtils_DecToHexString_003
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelAesCryptoUtils_DecToHexString_003, Function | MediumTest | Level1)
{
uint8_t data[10] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA};
size_t len = 10;
std::string result = TelAesCryptoUtils::DecToHexString(data, len);
ASSERT_EQ(result, "0102030405060708090a");
}
/**
* @tc.number TelAesCryptoUtils_HexToDecString_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelAesCryptoUtils_HexToDecString_001, Function | MediumTest | Level1)
{
std::string hexString = "";
auto result = TelAesCryptoUtils::HexToDecString(hexString);
ASSERT_EQ(result.first, nullptr);
hexString = "12345";
result = TelAesCryptoUtils::HexToDecString(hexString);
ASSERT_EQ(result.first, nullptr);
hexString = "123456";
result = TelAesCryptoUtils::HexToDecString(hexString);
ASSERT_NE(result.first, nullptr);
hexString = "123456";
result = TelAesCryptoUtils::HexToDecString(hexString);
ASSERT_NE(result.first, nullptr);
hexString = "123456";
result = TelAesCryptoUtils::HexToDecString(hexString);
ASSERT_NE(result.first, nullptr);
}
/**
* @tc.number TelephonyConfig_IsCapabilitySupport_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelephonyConfig_IsCapabilitySupport_001, Function | MediumTest | Level1)
{
TelephonyConfig telephonyConfig;
uint32_t capablity = MODEM_CAP_MIN_VALUE - 1;
EXPECT_FALSE(telephonyConfig.IsCapabilitySupport(capablity));
capablity = MODEM_CAP_MAX_VALUE;
EXPECT_FALSE(telephonyConfig.IsCapabilitySupport(capablity));
}
/**
* @tc.number TelephonyConfig_ConvertCharToInt_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelephonyConfig_ConvertCharToInt_001, Function | MediumTest | Level1)
{
TelephonyConfig telephonyConfig;
uint32_t retValue = 0;
std::string maxCap = "1234567890";
uint32_t index = 11;
int32_t result = telephonyConfig.ConvertCharToInt(retValue, maxCap, index);
ASSERT_EQ(result, -1);
}
/**
* @tc.number TelephonyConfig_ConvertCharToInt_002
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelephonyConfig_ConvertCharToInt_002, Function | MediumTest | Level1)
{
TelephonyConfig telephonyConfig;
uint32_t retValue = 0;
std::string maxCap = "12345678901";
uint32_t index = 10;
int32_t result = telephonyConfig.ConvertCharToInt(retValue, maxCap, index);
ASSERT_EQ(result, 0);
}
/**
* @tc.number TelephonyConfig_ConvertCharToInt_003
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelephonyConfig_ConvertCharToInt_003, Function | MediumTest | Level1)
{
TelephonyConfig telephonyConfig;
uint32_t retValue = 0;
std::string maxCap = "1234567890";
uint32_t index = 0;
int32_t result = telephonyConfig.ConvertCharToInt(retValue, maxCap, index);
ASSERT_EQ(result, 0);
ASSERT_EQ(retValue, 1);
}
/**
* @tc.number TelephonyConfig_ConvertCharToInt_004
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelephonyConfig_ConvertCharToInt_004, Function | MediumTest | Level1)
{
TelephonyConfig telephonyConfig;
uint32_t retValue = 0;
std::string maxCap = "abcdef";
uint32_t index = 0;
int32_t result = telephonyConfig.ConvertCharToInt(retValue, maxCap, index);
ASSERT_EQ(result, 0);
ASSERT_EQ(retValue, 10);
}
/**
* @tc.number TelephonyConfig_ConvertCharToInt_005
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelephonyConfig_ConvertCharToInt_005, Function | MediumTest | Level1)
{
TelephonyConfig telephonyConfig;
uint32_t retValue = 0;
std::string maxCap = "ABCDEF";
uint32_t index = 0;
int32_t result = telephonyConfig.ConvertCharToInt(retValue, maxCap, index);
ASSERT_EQ(result, 0);
ASSERT_EQ(retValue, 10);
}
/**
* @tc.number TelephonyConfig_ConvertCharToInt_006
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceCommonTest, TelephonyConfig_ConvertCharToInt_006, Function | MediumTest | Level1)
{
TelephonyConfig telephonyConfig;
uint32_t retValue = 0;
std::string maxCap = "!@#$%^&*()";
uint32_t index = 0;
int32_t result = telephonyConfig.ConvertCharToInt(retValue, maxCap, index);
ASSERT_EQ(result, -1);
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,470 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include "gtest/gtest.h"
#include "core_manager_inner.h"
#include "core_service_proxy.h"
#include "network_search_manager.h"
#include "resource_utils.h"
#include "sim_manager.h"
#include "tel_ril_manager.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
namespace {
constexpr int32_t INVALID_SLOTID = -1;
constexpr int32_t INVALID_DEFAULT_SLOTID = -2;
} // namespace
class CoreServiceNativeBranchTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void CoreServiceNativeBranchTest::TearDownTestCase() {}
void CoreServiceNativeBranchTest::SetUp() {}
void CoreServiceNativeBranchTest::TearDown() {}
void CoreServiceNativeBranchTest::SetUpTestCase() {}
class TestIRemoteObject : public IRemoteObject {
public:
uint32_t requestCode_ = -1;
int32_t result_ = 0;
public:
TestIRemoteObject() : IRemoteObject(u"test_remote_object") {}
~TestIRemoteObject() {}
int32_t GetObjectRefCount() override
{
return 0;
}
int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override
{
TELEPHONY_LOGI("Mock SendRequest");
requestCode_ = code;
reply.WriteInt32(result_);
return 0;
}
bool IsProxyObject() const override
{
return true;
}
bool CheckObjectLegality() const override
{
return true;
}
bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override
{
return true;
}
bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override
{
return true;
}
bool Marshalling(Parcel &parcel) const override
{
return true;
}
sptr<IRemoteBroker> AsInterface() override
{
return nullptr;
}
int Dump(int fd, const std::vector<std::u16string> &args) override
{
return 0;
}
std::u16string GetObjectDescriptor() const
{
std::u16string descriptor = std::u16string();
return descriptor;
}
};
HWTEST_F(CoreServiceNativeBranchTest, Telephony_ResourceUtils, Function | MediumTest | Level1)
{
ResourceUtils resourceUtils;
resourceUtils.beSourceAdd_ = true;
EXPECT_TRUE(resourceUtils.Init());
resourceUtils.beSourceAdd_ = false;
resourceUtils.resourceManager_ = nullptr;
EXPECT_FALSE(resourceUtils.Init());
std::string strValue = "";
int intValue = 0;
bool boolValue = false;
std::vector<std::string> strVector;
std::vector<int32_t> intVector;
resourceUtils.resourceManager_ =
std::unique_ptr<Global::Resource::ResourceManager>(Global::Resource::CreateResourceManager());
ASSERT_NE(resourceUtils.resourceManager_, nullptr);
EXPECT_FALSE(resourceUtils.GetStringByName("testName", strValue));
EXPECT_FALSE(resourceUtils.GetIntegerByName("testName", intValue));
EXPECT_FALSE(resourceUtils.GetBooleanByName("testName", boolValue));
EXPECT_FALSE(resourceUtils.GetStringArrayByName("testName", strVector));
EXPECT_FALSE(resourceUtils.GetIntArrayByName("testName", intVector));
std::string name = "name";
EXPECT_TRUE(resourceUtils.GetCallFailedMessageName(-1, name));
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreServiceProxy_001, Function | MediumTest | Level1)
{
sptr<TestIRemoteObject> remote = new (std::nothrow) TestIRemoteObject();
CoreServiceProxy coreServiceProxy(remote);
SimState simState = SimState::SIM_STATE_UNKNOWN;
EXPECT_EQ(coreServiceProxy.GetSimState(-1, simState), TELEPHONY_ERR_SLOTID_INVALID);
std::u16string testU16Str = u"";
EXPECT_EQ(coreServiceProxy.GetISOCountryCodeForSim(-1, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetSimOperatorNumeric(-1, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetSimSpn(-1, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetSimIccId(-1, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetIMSI(-1, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
bool isCTSimCard = false;
EXPECT_EQ(coreServiceProxy.IsCTSimCard(-1, isCTSimCard), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_FALSE(coreServiceProxy.IsSimActive(-1));
EXPECT_EQ(coreServiceProxy.GetSlotId(-1), -1);
EXPECT_EQ(coreServiceProxy.GetSimId(-1), -1);
EXPECT_EQ(coreServiceProxy.GetSimGid1(-1, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ((coreServiceProxy.GetSimGid2(-1)), u"");
std::string plmn = "";
EXPECT_EQ((coreServiceProxy.GetSimEons(-1, plmn, 0, false)), u"");
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreServiceProxy_002, Function | MediumTest | Level1)
{
sptr<TestIRemoteObject> remote = new (std::nothrow) TestIRemoteObject();
CoreServiceProxy coreServiceProxy(remote);
IccAccountInfo info;
EXPECT_EQ(coreServiceProxy.GetSimAccountInfo(INVALID_SLOTID, info), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.SetDefaultVoiceSlotId(INVALID_DEFAULT_SLOTID), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.SetPrimarySlotId(INVALID_SLOTID), TELEPHONY_ERR_SLOTID_INVALID);
std::u16string testU16Str = u"";
EXPECT_EQ(coreServiceProxy.SetShowNumber(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetShowNumber(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.SetShowName(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetShowName(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
OperatorConfig poc;
EXPECT_EQ(coreServiceProxy.GetOperatorConfigs(INVALID_SLOTID, poc), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_FALSE(coreServiceProxy.IsValidSlotIdEx(INVALID_SLOTID));
EXPECT_FALSE(coreServiceProxy.IsValidSlotIdForDefault(INVALID_DEFAULT_SLOTID));
EXPECT_EQ(coreServiceProxy.SetActiveSim(INVALID_SLOTID, -1), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetSimTelephoneNumber(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetSimTeleNumberIdentifier(INVALID_SLOTID), u"");
EXPECT_EQ(coreServiceProxy.GetVoiceMailIdentifier(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetVoiceMailNumber(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
int32_t voiceMailCount = 0;
EXPECT_EQ(coreServiceProxy.GetVoiceMailCount(INVALID_SLOTID, voiceMailCount), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.SetVoiceMailCount(INVALID_SLOTID, voiceMailCount), TELEPHONY_ERR_SLOTID_INVALID);
testU16Str = u"test";
EXPECT_TRUE(coreServiceProxy.IsValidStringLength(testU16Str));
testU16Str = u"testABCDEFGHIJKLMNOPQRSTUVWXYZtestabcdefg";
EXPECT_FALSE(coreServiceProxy.IsValidStringLength(testU16Str));
std::string number = "";
EXPECT_EQ(coreServiceProxy.SetVoiceCallForwarding(INVALID_SLOTID, false, number), TELEPHONY_ERR_SLOTID_INVALID);
std::vector<std::shared_ptr<DiallingNumbersInfo>> reslut = {};
EXPECT_EQ(coreServiceProxy.QueryIccDiallingNumbers(INVALID_SLOTID, 1, reslut), TELEPHONY_ERR_SLOTID_INVALID);
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreServiceProxy_003, Function | MediumTest | Level1)
{
sptr<TestIRemoteObject> remote = new (std::nothrow) TestIRemoteObject();
CoreServiceProxy coreServiceProxy(remote);
const std::shared_ptr<DiallingNumbersInfo> diallingNumber = nullptr;
EXPECT_EQ(coreServiceProxy.AddIccDiallingNumbers(INVALID_SLOTID, 1, diallingNumber), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.DelIccDiallingNumbers(INVALID_SLOTID, 1, diallingNumber), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.UpdateIccDiallingNumbers(INVALID_SLOTID, 1, diallingNumber),
TELEPHONY_ERR_SLOTID_INVALID);
std::u16string testU16Str = u"";
EXPECT_EQ(coreServiceProxy.SetVoiceMailInfo(INVALID_SLOTID, testU16Str, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetOpKey(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetOpKeyExt(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.GetOpName(INVALID_SLOTID, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
std::string cmd = "";
EXPECT_EQ(coreServiceProxy.SendEnvelopeCmd(INVALID_SLOTID, cmd), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.SendTerminalResponseCmd(INVALID_SLOTID, cmd), TELEPHONY_ERR_SLOTID_INVALID);
LockStatusResponse response;
PersoLockInfo lockInfo;
EXPECT_EQ(coreServiceProxy.UnlockSimLock(INVALID_SLOTID, lockInfo, response), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(coreServiceProxy.SendTerminalResponseCmd(INVALID_SLOTID, cmd), TELEPHONY_ERR_SLOTID_INVALID);
ImsServiceType imsSrvType = ImsServiceType::TYPE_VOICE;
ImsRegInfo info;
EXPECT_EQ(coreServiceProxy.GetImsRegStatus(INVALID_SLOTID, imsSrvType, info), TELEPHONY_ERR_SLOTID_INVALID);
sptr<ImsRegInfoCallback> callback = nullptr;
EXPECT_EQ(coreServiceProxy.RegisterImsRegInfoCallback(INVALID_SLOTID, imsSrvType, callback),
TELEPHONY_ERR_ARGUMENT_NULL);
EXPECT_EQ(coreServiceProxy.UnregisterImsRegInfoCallback(INVALID_SLOTID, imsSrvType), TELEPHONY_ERR_SLOTID_INVALID);
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_001, Function | MediumTest | Level1)
{
CoreManagerInner mInner;
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
std::shared_ptr<AppExecFwk::EventHandler> handler;
mInner.networkSearchManager_ = networkSearchManager;
EXPECT_EQ(mInner.RegisterCoreNotify(INVALID_SLOTID, handler, RadioEvent::RADIO_PS_CONNECTION_ATTACHED, nullptr),
TELEPHONY_SUCCESS);
EXPECT_EQ(mInner.UnRegisterCoreNotify(INVALID_SLOTID, handler, RadioEvent::RADIO_EMERGENCY_STATE_CLOSE),
TELEPHONY_SUCCESS);
mInner.simManager_ = simManager;
EXPECT_EQ(mInner.RegisterCoreNotify(INVALID_SLOTID, handler, RadioEvent::RADIO_SIM_STATE_CHANGE, nullptr),
TELEPHONY_SUCCESS);
EXPECT_EQ(mInner.UnRegisterCoreNotify(INVALID_SLOTID, handler, RadioEvent::RADIO_SIM_RECORDS_LOADED),
TELEPHONY_SUCCESS);
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_002, Function | MediumTest | Level1)
{
CoreManagerInner mInner;
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
mInner.networkSearchManager_ = networkSearchManager;
sptr<NetworkSearchCallBackBase> callback = nullptr;
mInner.RegisterCellularDataObject(callback);
mInner.UnRegisterCellularDataObject(callback);
mInner.RegisterCellularCallObject(callback);
mInner.UnRegisterCellularCallObject(callback);
simManager->multiSimMonitor_ = nullptr;
mInner.simManager_ = simManager;
sptr<SimAccountCallback> simAccountCallback;
EXPECT_EQ(mInner.RegisterSimAccountCallback(-1, simAccountCallback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UnregisterSimAccountCallback(-1), TELEPHONY_ERR_LOCAL_PTR_NULL);
mInner.telRilManager_ = nullptr;
std::shared_ptr<AppExecFwk::EventHandler> handler;
std::string testStr = "";
EXPECT_EQ(mInner.SetNetworkSelectionMode(-1, -1, 0, testStr, handler), TELEPHONY_ERR_LOCAL_PTR_NULL);
AppExecFwk::InnerEvent::Pointer response(nullptr, nullptr);
mInner.telRilManager_ = telRilManager;
EXPECT_EQ(mInner.GetClip(-1, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.SetClip(-1, -1, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetClir(-1, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.SetClir(-1, -1, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.SetCallWaiting(-1, -1, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
CallTransferParam param;
CallRestrictionParam reParam;
EXPECT_EQ(mInner.SetCallTransferInfo(-1, param, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetCallTransferInfo(-1, -1, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetCallWaiting(-1, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetCallRestriction(-1, testStr, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.SetCallRestriction(-1, reParam, response), TELEPHONY_ERR_LOCAL_PTR_NULL);
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_003, Function | MediumTest | Level1)
{
CoreManagerInner mInner;
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
AppExecFwk::InnerEvent::Pointer response(nullptr, nullptr);
mInner.telRilManager_ = telRilManager;
EXPECT_EQ(mInner.SetBarringPassword(-1, "", "", "", response), TELEPHONY_ERR_LOCAL_PTR_NULL);
int32_t testTech = 0;
mInner.networkSearchManager_ = networkSearchManager;
EXPECT_EQ(mInner.GetPsRadioTech(-1, testTech), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetCsRadioTech(-1, testTech), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetPsRegState(-1), TELEPHONY_ERROR);
EXPECT_EQ(mInner.GetCsRegState(-1), TELEPHONY_ERROR);
EXPECT_EQ(mInner.GetPsRoamingState(-1), TELEPHONY_ERROR);
sptr<INetworkSearchCallback> callback = nullptr;
networkSearchManager->eventSender_ = nullptr;
mInner.networkSearchManager_ = networkSearchManager;
std::vector<sptr<SignalInformation>> signals;
EXPECT_EQ(mInner.GetSignalInfoList(-1, signals), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetOperatorNumeric(-1), u"");
std::u16string testU16Str = u"";
EXPECT_EQ(mInner.GetOperatorName(-1, testU16Str), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(mInner.SetRadioState(-1, true, 0, callback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetRadioState(-1), ModemPowerState::CORE_SERVICE_POWER_NOT_AVAILABLE);
EXPECT_EQ(mInner.GetRadioState(-1, callback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetIsoCountryCodeForNetwork(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetImei(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetImeiSv(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetMeid(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetUniqueDeviceId(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetPhoneType(-1), PhoneType::PHONE_TYPE_IS_NONE);
EXPECT_EQ(mInner.GetCellLocation(-1), nullptr);
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_004, Function | MediumTest | Level1)
{
CoreManagerInner mInner;
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
networkSearchManager->eventSender_ = nullptr;
mInner.networkSearchManager_ = networkSearchManager;
sptr<INetworkSearchCallback> callback = nullptr;
std::vector<sptr<CellInformation>> cellInfoList;
EXPECT_EQ(mInner.GetNetworkSearchInformation(-1, callback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetNetworkSelectionMode(-1, callback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetCellInfoList(-1, cellInfoList), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.SendUpdateCellLocationRequest(-1), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetPreferredNetwork(-1, callback), TELEPHONY_ERR_LOCAL_PTR_NULL);
networkSearchManager->simManager_ = nullptr;
mInner.networkSearchManager_ = networkSearchManager;
EXPECT_EQ(mInner.SetPreferredNetwork(-1, -1, callback), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_FALSE(mInner.IsNrSupported(-1));
mInner.DcPhysicalLinkActiveUpdate(-1, true);
EXPECT_EQ(mInner.NotifyCallStatusToNetworkSearch(-1, -1), TELEPHONY_ERR_LOCAL_PTR_NULL);
NrMode mode = NrMode::NR_MODE_UNKNOWN;
EXPECT_EQ(mInner.GetNrOptionMode(-1, mode), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetFrequencyType(-1), FrequencyType::FREQ_TYPE_UNKNOWN);
EXPECT_EQ(mInner.GetNrState(-1), NrState::NR_STATE_NOT_SUPPORT);
ImsRegInfo info;
EXPECT_EQ(mInner.GetImsRegStatus(-1, ImsServiceType::TYPE_VOICE, info), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UpdateRadioOn(-1), TELEPHONY_ERROR);
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_005, Function | MediumTest | Level1)
{
CoreManagerInner mInner;
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
mInner.simManager_ = simManager;
EXPECT_EQ(mInner.ObtainSpnCondition(-1, false, ""), TELEPHONY_ERROR);
std::u16string testU16Str = u"";
EXPECT_EQ(mInner.GetSimSpn(-1, testU16Str), TELEPHONY_ERR_NO_SIM_CARD);
EXPECT_EQ(mInner.SetVoiceMailInfo(-1, testU16Str, testU16Str), TELEPHONY_ERR_NO_SIM_CARD);
std::vector<std::shared_ptr<DiallingNumbersInfo>> result;
EXPECT_EQ(mInner.QueryIccDiallingNumbers(-1, 0, result), TELEPHONY_ERR_LOCAL_PTR_NULL);
std::shared_ptr<DiallingNumbersInfo> diallingNumbers = std::make_shared<DiallingNumbersInfo>();
EXPECT_EQ(mInner.AddIccDiallingNumbers(-1, 0, diallingNumbers), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.DelIccDiallingNumbers(-1, 0, diallingNumbers), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.UpdateIccDiallingNumbers(-1, 0, diallingNumbers), TELEPHONY_ERR_LOCAL_PTR_NULL);
std::string testStr = "";
EXPECT_EQ(mInner.AddSmsToIcc(-1, 0, testStr, testStr), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(mInner.UpdateSmsIcc(-1, 0, 0, testStr, testStr), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ((mInner.ObtainAllSmsOfIcc(-1)).size(), 0);
EXPECT_EQ(mInner.DelSmsIcc(-1, 0), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_FALSE(mInner.IsSimActive(-1));
EXPECT_EQ(mInner.SetActiveSim(-1, 0), TELEPHONY_ERR_LOCAL_PTR_NULL);
IccAccountInfo info;
simManager->multiSimMonitor_ = nullptr;
mInner.simManager_ = simManager;
EXPECT_EQ(mInner.GetSimAccountInfo(-1, info), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.SetDefaultVoiceSlotId(INVALID_DEFAULT_SLOTID), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(mInner.SetDefaultSmsSlotId(INVALID_DEFAULT_SLOTID), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(mInner.SetDefaultCellularDataSlotId(-1), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(mInner.SetPrimarySlotId(-1), TELEPHONY_ERR_SLOTID_INVALID);
EXPECT_EQ(mInner.SetShowNumber(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
}
HWTEST_F(CoreServiceNativeBranchTest, Telephony_CoreManagerInner_006, Function | MediumTest | Level1)
{
CoreManagerInner mInner;
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
std::u16string testU16Str = u"";
mInner.simManager_ = nullptr;
EXPECT_EQ(mInner.SetShowNumber(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
simManager->multiSimMonitor_ = nullptr;
mInner.simManager_ = simManager;
EXPECT_EQ(mInner.SetShowName(-1, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
simManager->slotCount_ = 1;
mInner.simManager_ = simManager;
EXPECT_EQ(mInner.GetDefaultVoiceSlotId(), DEFAULT_SIM_SLOT_ID);
int32_t simId = 0;
EXPECT_EQ(mInner.GetDefaultVoiceSimId(simId), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetDefaultSmsSlotId(), DEFAULT_SIM_SLOT_ID);
EXPECT_EQ(mInner.GetDefaultSmsSimId(simId), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetDefaultCellularDataSlotId(), DEFAULT_SIM_SLOT_ID);
EXPECT_EQ(mInner.GetDefaultCellularDataSimId(simId), TELEPHONY_ERR_LOCAL_PTR_NULL);
int32_t dsdsMode = 0;
EXPECT_EQ(mInner.GetDsdsMode(dsdsMode), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(static_cast<DsdsMode>(dsdsMode), DsdsMode::DSDS_MODE_V2);
EXPECT_EQ(mInner.SetDsdsMode(dsdsMode), TELEPHONY_ERR_SUCCESS);
int32_t slotId = -1;
EXPECT_EQ(mInner.GetPrimarySlotId(slotId), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(slotId, 0);
EXPECT_EQ(mInner.GetShowNumber(slotId, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(mInner.GetShowName(slotId, testU16Str), TELEPHONY_ERR_LOCAL_PTR_NULL);
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,807 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include <gtest/gtest.h>
#include <string_ex.h>
#include "core_service_test.h"
#include "common_event_manager.h"
#include "common_event_support.h"
#include "core_service.h"
#include "core_service_client.h"
#include "core_service_dump_helper.h"
#include "core_service_hisysevent.h"
#include "network_search_manager.h"
#include "operator_name.h"
#include "operator_name_utils.h"
#include "sim_manager.h"
#include "tel_ril_manager.h"
#include "telephony_log_wrapper.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
constexpr int32_t NR_NSA_OPTION_ONLY = 1;
static const int32_t SLEEP_TIME = 3;
class CoreServiceTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void CoreServiceTest::SetUpTestCase() {}
void CoreServiceTest::TearDownTestCase()
{
sleep(SLEEP_TIME);
}
void CoreServiceTest::SetUp() {}
void CoreServiceTest::TearDown() {}
/**
* @tc.number CoreService_SetNetworkSelectionMode_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetNetworkSelectionMode_001, Function | MediumTest | Level1)
{
SecurityToken token;
sptr<NetworkInformation> networkInfo = new (std::nothrow) NetworkInformation();
networkInfo->SetOperateInformation("CHINA MOBILE", "CMCC", "46000",
static_cast<int32_t>(NetworkPlmnState::NETWORK_PLMN_STATE_AVAILABLE),
static_cast<int32_t>(NetworkRat::NETWORK_LTE));
auto result = DelayedSingleton<CoreService>::GetInstance()->SetNetworkSelectionMode(
0, static_cast<int32_t>(SelectionMode::MODE_TYPE_MANUAL), networkInfo, true, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetRadioState_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetRadioState_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetRadioState(0, true, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetImei_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetImei_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string imei = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetImei(0, imei);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetImeiSv_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetImeiSv_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string imeiSv = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetImeiSv(0, imeiSv);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetMeid_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetMeid_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string meid = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetMeid(0, meid);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetUniqueDeviceId_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetUniqueDeviceId_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string deviceId = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetUniqueDeviceId(0, deviceId);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetNrOptionMode_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetNrOptionMode_001, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t mode = NR_NSA_OPTION_ONLY;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetNrOptionMode(0, mode, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetNrOptionMode_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetNrOptionMode_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetNrOptionMode(0, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetDsdsMode_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetDsdsMode_001, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t dsdsMode;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetDsdsMode(dsdsMode);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetSimIccId_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetSimIccId_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string iccId = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetSimIccId(0, iccId);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetIMSI_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetIMSI_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string imsi = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetIMSI(0, imsi);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_IsCTSimCard_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_IsCTSimCard_001, Function | MediumTest | Level1)
{
SecurityToken token;
bool isCTSimCard = false;
auto result = DelayedSingleton<CoreService>::GetInstance()->IsCTSimCard(0, isCTSimCard);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetNetworkSearchInformation_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetNetworkSearchInformation_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetNetworkSearchInformation(0, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetSimGid1_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetSimGid1_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string gid1 = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetSimGid1(0, gid1);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetDefaultVoiceSlotId_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetDefaultVoiceSlotId_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetDefaultVoiceSlotId(0);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetPrimarySlotId_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetPrimarySlotId_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetPrimarySlotId(0);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetShowNumber_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetShowNumber_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string number = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->SetShowNumber(0, number);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetShowNumber_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetShowNumber_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string showNumber = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetShowNumber(0, showNumber);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetShowName_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetShowName_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string name = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->SetShowName(0, name);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetShowName_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetShowName_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string showName = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetShowName(0, showName);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetOperatorConfigs_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetOperatorConfigs_001, Function | MediumTest | Level1)
{
SecurityToken token;
OperatorConfig poc;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetOperatorConfigs(0, poc);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_UnlockPin_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_UnlockPin_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string pin = u"";
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->UnlockPin(0, pin, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_UnlockPuk_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_UnlockPuk_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string newPin = u"";
std::u16string puk = u"";
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->UnlockPuk(0, newPin, puk, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_AlterPin_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_AlterPin_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string newPin = u"";
std::u16string oldPin = u"";
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->AlterPin(0, newPin, oldPin, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_UnlockPin2_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_UnlockPin2_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string pin2 = u"";
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->UnlockPin2(0, pin2, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_UnlockPuk2_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_UnlockPuk2_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string newPin2 = u"";
std::u16string puk2 = u"";
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->UnlockPuk2(0, newPin2, puk2, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_AlterPin2_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_AlterPin2_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string newPin2 = u"";
std::u16string oldPin2 = u"";
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->AlterPin2(0, newPin2, oldPin2, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetLockState_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetLockState_001, Function | MediumTest | Level1)
{
SecurityToken token;
LockInfo options;
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetLockState(0, options, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetLockState_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetLockState_001, Function | MediumTest | Level1)
{
SecurityToken token;
LockType lockType = LockType::PIN_LOCK;
LockState lockState;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetLockState(0, lockType, lockState);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetActiveSim_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetActiveSim_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetActiveSim(0, true);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetPreferredNetwork_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetPreferredNetwork_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetPreferredNetwork(0, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetPreferredNetwork_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetPreferredNetwork_001, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t networkMode = 0;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetPreferredNetwork(0, networkMode, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetNetworkCapability_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetNetworkCapability_001, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t networkCapabilityType = 0;
int32_t networkCapabilityState = 0;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetNetworkCapability(0, networkCapabilityType,
networkCapabilityState);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetNetworkCapability_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetNetworkCapability_001, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t networkCapabilityType = 0;
int32_t networkCapabilityState = 0;
auto result = DelayedSingleton<CoreService>::GetInstance()->SetNetworkCapability(0, networkCapabilityType,
networkCapabilityState);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetSimTelephoneNumber_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetSimTelephoneNumber_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string telephoneNumber = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetSimTelephoneNumber(0, telephoneNumber);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetVoiceMailIdentifier_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetVoiceMailIdentifier_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string voiceMailIdentifier = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetVoiceMailIdentifier(0, voiceMailIdentifier);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetVoiceMailNumber_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetVoiceMailNumber_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string voiceMailNumber = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetVoiceMailNumber(0, voiceMailNumber);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetVoiceMailCount_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetVoiceMailCount_001, Function | MediumTest | Level1)
{
SecurityToken token;
int32_t voiceMailCount;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetVoiceMailCount(0, voiceMailCount);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_QueryIccDiallingNumbers_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_QueryIccDiallingNumbers_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::vector<std::shared_ptr<DiallingNumbersInfo>> diallingNumbersInfo;
auto result = DelayedSingleton<CoreService>::GetInstance()->QueryIccDiallingNumbers(0, 0, diallingNumbersInfo);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_AddIccDiallingNumbers_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_AddIccDiallingNumbers_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->AddIccDiallingNumbers(0, 0, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_DelIccDiallingNumbers_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_DelIccDiallingNumbers_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->DelIccDiallingNumbers(0, 0, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_UpdateIccDiallingNumbers_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_UpdateIccDiallingNumbers_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->UpdateIccDiallingNumbers(0, 0, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SetVoiceMailInfo_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SetVoiceMailInfo_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::u16string mailName = u"";
std::u16string mailNumber = u"";
auto result = DelayedSingleton<CoreService>::GetInstance()->SetVoiceMailInfo(0, mailName, mailNumber);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SendEnvelopeCmd_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SendEnvelopeCmd_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::string cmd = "";
auto result = DelayedSingleton<CoreService>::GetInstance()->SendEnvelopeCmd(0, cmd);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SendTerminalResponseCmd_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SendTerminalResponseCmd_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::string cmd = "";
auto result = DelayedSingleton<CoreService>::GetInstance()->SendTerminalResponseCmd(0, cmd);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SendCallSetupRequestResult_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SendCallSetupRequestResult_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->SendCallSetupRequestResult(0, true);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_UnlockSimLock_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_UnlockSimLock_001, Function | MediumTest | Level1)
{
SecurityToken token;
PersoLockInfo lockInfo;
LockStatusResponse response;
auto result = DelayedSingleton<CoreService>::GetInstance()->UnlockSimLock(0, lockInfo, response);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetImsRegStatus_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetImsRegStatus_001, Function | MediumTest | Level1)
{
SecurityToken token;
ImsServiceType imsSrvType = ImsServiceType::TYPE_VOICE;
ImsRegInfo info;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetImsRegStatus(0, imsSrvType, info);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetCellInfoList_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetCellInfoList_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::vector<sptr<CellInformation>> cellInfo;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetCellInfoList(0, cellInfo);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_SendUpdateCellLocationRequest_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_SendUpdateCellLocationRequest_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->SendUpdateCellLocationRequest(0);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_RegisterImsRegInfoCallback_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_RegisterImsRegInfoCallback_001, Function | MediumTest | Level1)
{
SecurityToken token;
ImsServiceType imsSrvType = ImsServiceType::TYPE_VOICE;
auto result = DelayedSingleton<CoreService>::GetInstance()->RegisterImsRegInfoCallback(0, imsSrvType, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_UnregisterImsRegInfoCallback_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_UnregisterImsRegInfoCallback_001, Function | MediumTest | Level1)
{
SecurityToken token;
ImsServiceType imsSrvType = ImsServiceType::TYPE_VOICE;
auto result = DelayedSingleton<CoreService>::GetInstance()->UnregisterImsRegInfoCallback(0, imsSrvType);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetBasebandVersion_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetBasebandVersion_001, Function | MediumTest | Level1)
{
SecurityToken token;
std::string version = "";
auto result = DelayedSingleton<CoreService>::GetInstance()->GetBasebandVersion(0, version);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_FactoryReset_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_FactoryReset_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->FactoryReset(0);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_InitExtraModule_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_InitExtraModule_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->InitExtraModule(0);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetNrSsbIdInfo_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetNrSsbIdInfo_001, Function | MediumTest | Level1)
{
SecurityToken token;
auto result = DelayedSingleton<CoreService>::GetInstance()->GetNrSsbIdInfo(0, nullptr);
ASSERT_EQ(result, TELEPHONY_ERR_ILLEGAL_USE_OF_SYSTEM_API);
}
/**
* @tc.number CoreService_GetResidentNetworkNumeric_001
* @tc.name test normal branch
* @tc.desc Function test
*/
HWTEST_F(CoreServiceTest, CoreService_GetResidentNetworkNumeric_001, Function | MediumTest | Level1)
{
auto result = DelayedSingleton<CoreService>::GetInstance()->GetResidentNetworkNumeric(0);
ASSERT_STREQ(result.c_str(), "");
DelayedSingleton<CoreService>::GetInstance()->networkSearchManager_ = nullptr;
result = DelayedSingleton<CoreService>::GetInstance()->GetResidentNetworkNumeric(0);
ASSERT_STREQ(result.c_str(), "");
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,155 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_CORE_SERVICE_TEST_H
#define OHOS_CORE_SERVICE_TEST_H
#include "security_token.h"
#include <iostream>
#include "nativetoken_kit.h"
#include "token_setproc.h"
namespace OHOS {
namespace Telephony {
using namespace Security::AccessToken;
using Security::AccessToken::AccessTokenID;
inline HapInfoParams testInfoParams = {
.bundleName = "tel_core_service_gtest",
.userID = 1,
.instIndex = 0,
.appIDDesc = "test",
.isSystemApp = false,
};
inline PermissionDef testPermGetTelephonyStateDef = {
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test core service",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testGetTelephonyState = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.resDeviceID = { "local" },
};
inline PermissionDef testPermSetTelephonyStateDef = {
.permissionName = "ohos.permission.SET_TELEPHONY_STATE",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test core service",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testSetTelephonyState = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.SET_TELEPHONY_STATE",
.resDeviceID = { "local" },
};
inline PermissionDef testPermGetNetworkInfoDef = {
.permissionName = "ohos.permission.GET_NETWORK_INFO",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test core service",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testPermGetNetworkInfo = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.GET_NETWORK_INFO",
.resDeviceID = { "local" },
};
inline PermissionDef testSimPermWriteContactsDef = {
.permissionName = "ohos.permission.WRITE_CONTACTS",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test core service",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testSimPermWriteContacts = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.WRITE_CONTACTS",
.resDeviceID = { "local" },
};
inline PermissionDef testSimPermReadContactsDef = {
.permissionName = "ohos.permission.READ_CONTACTS",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test core service",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testSimPermReadContacts = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.READ_CONTACTS",
.resDeviceID = { "local" },
};
inline HapPolicyParams testPolicyParams = {
.apl = APL_SYSTEM_BASIC,
.domain = "test.domain",
.permList = { testPermGetTelephonyStateDef, testPermSetTelephonyStateDef, testPermGetNetworkInfoDef,
testSimPermWriteContactsDef, testSimPermReadContactsDef },
.permStateList = { testGetTelephonyState, testSetTelephonyState, testPermGetNetworkInfo, testSimPermWriteContacts,
testSimPermReadContacts },
};
SecurityToken::SecurityToken()
{
currentID_ = GetSelfTokenID();
AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testInfoParams, testPolicyParams);
accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
SetSelfTokenID(tokenIdEx.tokenIDEx);
}
SecurityToken::~SecurityToken()
{
AccessTokenKit::DeleteToken(accessID_);
SetSelfTokenID(currentID_);
}
} // namespace Telephony
} // namespace OHOS
#endif // OHOS_CORE_SERVICE_TEST_H

View File

@ -0,0 +1,374 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include "gtest/gtest.h"
#include "device_state_observer.h"
#include "network_search_manager.h"
#include "sim_manager.h"
#include "tel_ril_manager.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
namespace {
constexpr int32_t INVALID_SLOTID = -1;
constexpr int32_t INVALID_YEAR = 1800;
constexpr int32_t TEST_YEAR = 2000;
constexpr int32_t TEST_MONTH = 2;
} // namespace
class NetworkSearchBranchTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void NetworkSearchBranchTest::TearDownTestCase() {}
void NetworkSearchBranchTest::SetUp() {}
void NetworkSearchBranchTest::TearDown() {}
void NetworkSearchBranchTest::SetUpTestCase() {}
HWTEST_F(NetworkSearchBranchTest, Telephony_NetworkType, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto networkType = std::make_unique<NetworkType>(networkSearchManager, INVALID_SLOTID);
AppExecFwk::InnerEvent::Pointer event(nullptr, nullptr);
networkType->ProcessSetPreferredNetwork(event);
event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_PREFERRED_NETWORK_MODE);
networkType->networkSearchManager_ = std::weak_ptr<NetworkSearchManager>();
ASSERT_TRUE(networkType->networkSearchManager_.expired());
networkType->ProcessSetPreferredNetwork(event);
std::shared_ptr<PreferredNetworkTypeInfo> preferredTypeInfo = std::make_shared<PreferredNetworkTypeInfo>();
std::shared_ptr<RadioResponseInfo> responseInfo = std::make_shared<RadioResponseInfo>();
MessageParcel data;
int64_t index = 0;
EXPECT_FALSE(networkType->WriteGetPreferredNetworkInfo(preferredTypeInfo, responseInfo, data, index));
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NetworkSelection, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto networkSelection = std::make_unique<NetworkSelection>(networkSearchManager, INVALID_SLOTID);
AppExecFwk::InnerEvent::Pointer event(nullptr, nullptr);
networkSelection->ProcessNetworkSearchResult(event);
networkSelection->ProcessGetNetworkSelectionMode(event);
networkSelection->ProcessSetNetworkSelectionMode(event);
event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_NETWORK_SEARCH_RESULT);
networkSelection->networkSearchManager_ = std::weak_ptr<NetworkSearchManager>();
ASSERT_TRUE(networkSelection->networkSearchManager_.expired());
networkSelection->ProcessNetworkSearchResult(event);
networkSelection->ProcessGetNetworkSelectionMode(event);
networkSelection->ProcessSetNetworkSelectionMode(event);
std::shared_ptr<AvailableNetworkList> availNetworkResult = std::make_shared<AvailableNetworkList>();
MessageParcel data;
int64_t index = 0;
EXPECT_FALSE(networkSelection->AvailNetworkResult(availNetworkResult, data, index));
std::shared_ptr<SetNetworkModeInfo> selectModeResult = std::make_shared<SetNetworkModeInfo>();
EXPECT_FALSE(networkSelection->SelectModeResult(selectModeResult, data, index));
networkSelection->networkSearchManager_ = networkSearchManager;
std::shared_ptr<NetworkSearchManager> nsm = networkSelection->networkSearchManager_.lock();
ASSERT_NE(nsm, nullptr);
EXPECT_TRUE(networkSelection->AvailNetworkResult(nullptr, data, index));
EXPECT_EQ(index, -1);
index = 0;
EXPECT_FALSE(networkSelection->SelectModeResult(nullptr, data, index));
EXPECT_EQ(index, 0);
EXPECT_TRUE(networkSelection->ResponseInfoOfResult(nullptr, data, index));
EXPECT_TRUE(networkSelection->ResponseInfoOfGet(nullptr, data, index));
MessageParcel data1;
std::shared_ptr<RadioResponseInfo> responseInfo = std::make_shared<RadioResponseInfo>();
responseInfo->error = ErrType::NONE;
EXPECT_TRUE(networkSelection->ResponseInfoOfSet(responseInfo, data1, index));
EXPECT_TRUE(data1.ReadBool());
EXPECT_EQ(data1.ReadInt32(), TELEPHONY_SUCCESS);
MessageParcel data2;
responseInfo->error = ErrType::ERR_INVALID_PARAMETER;
EXPECT_TRUE(networkSelection->ResponseInfoOfSet(responseInfo, data2, index));
EXPECT_FALSE(data2.ReadBool());
EXPECT_EQ(data2.ReadInt32(), static_cast<int32_t>(ErrType::ERR_INVALID_PARAMETER));
}
HWTEST_F(NetworkSearchBranchTest, Telephony_DeviceStateObserver, Function | MediumTest | Level1)
{
auto deviceStateObserver = std::make_shared<DeviceStateObserver>();
deviceStateObserver->subscriber_ = nullptr;
deviceStateObserver->sharingEventCallback_ = nullptr;
deviceStateObserver->StopEventSubscriber();
MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_ON);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_POWER_SAVE_MODE_CHANGED);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CHARGING);
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_DISCHARGING);
CommonEventSubscribeInfo subscriberInfo(matchingSkills);
subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
deviceStateObserver->subscriber_ = std::make_shared<DeviceStateEventSubscriber>(subscriberInfo);
deviceStateObserver->subscriber_->deviceStateHandler_ = nullptr;
CommonEventData data;
deviceStateObserver->subscriber_->OnReceiveEvent(data);
deviceStateObserver->subscriber_->ProcessWifiState(data);
deviceStateObserver->subscriber_->InitEventMap();
std::string event = "testEvent";
EXPECT_EQ(deviceStateObserver->subscriber_->GetDeviceStateEventIntValue(event),
DeviceStateEventIntValue::COMMON_EVENT_UNKNOWN);
event = CommonEventSupport::COMMON_EVENT_CHARGING;
EXPECT_EQ(deviceStateObserver->subscriber_->GetDeviceStateEventIntValue(event),
DeviceStateEventIntValue::COMMON_EVENT_CHARGING);
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NitzUpdate_001, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto nitzUpdate = std::make_unique<NitzUpdate>(networkSearchManager, INVALID_SLOTID);
AppExecFwk::InnerEvent::Pointer event(nullptr, nullptr);
nitzUpdate->ProcessNitzUpdate(event);
NitzUpdate::NetworkTime networkTime;
std::string nitzStr = "2023/01/01";
EXPECT_FALSE(nitzUpdate->NitzParse(nitzStr, networkTime));
nitzStr = "2023/01,12:00:00";
EXPECT_FALSE(nitzUpdate->NitzParse(nitzStr, networkTime));
nitzStr = "202/01/01,12:00:00";
EXPECT_FALSE(nitzUpdate->NitzParse(nitzStr, networkTime));
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NitzUpdate_002, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto nitzUpdate = std::make_unique<NitzUpdate>(networkSearchManager, INVALID_SLOTID);
NitzUpdate::NetworkTime networkTime;
std::string strTimeSubs = "-12:00:00-05-00-00";
EXPECT_FALSE(nitzUpdate->NitzTimeParse(strTimeSubs, networkTime));
strTimeSubs = "12:00:00";
EXPECT_FALSE(nitzUpdate->NitzTimeParse(strTimeSubs, networkTime));
strTimeSubs = "+12";
EXPECT_FALSE(nitzUpdate->NitzTimeParse(strTimeSubs, networkTime));
strTimeSubs = "+12:00:00:00";
EXPECT_FALSE(nitzUpdate->NitzTimeParse(strTimeSubs, networkTime));
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NitzUpdate_003, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto nitzUpdate = std::make_unique<NitzUpdate>(networkSearchManager, INVALID_SLOTID);
NitzUpdate::NetworkTime networkTime;
networkTime.year = INVALID_YEAR;
networkTime.month = 0;
nitzUpdate->ProcessTime(networkTime);
networkTime.month = TEST_MONTH;
nitzUpdate->ProcessTime(networkTime);
networkTime.year = TEST_YEAR;
networkTime.month = 0;
nitzUpdate->ProcessTime(networkTime);
nitzUpdate->networkSearchManager_ = std::weak_ptr<NetworkSearchManager>();
ASSERT_TRUE(nitzUpdate->networkSearchManager_.expired());
nitzUpdate->ProcessTimeZone();
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NetworkRegister_001, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto networkSearchState = std::make_shared<NetworkSearchState>(networkSearchManager, INVALID_SLOTID);
auto networkRegister = std::make_shared<NetworkRegister>(networkSearchState, networkSearchManager, INVALID_SLOTID);
networkRegister->networkSearchManager_ = std::weak_ptr<NetworkSearchManager>();
ASSERT_TRUE(networkRegister->networkSearchManager_.expired());
auto psRegInfo = std::make_shared<PsRegStatusResultInfo>();
auto csRegInfo = std::make_shared<CsRegStatusInfo>();
networkRegister->ProcessPsRegister(psRegInfo);
networkRegister->ProcessCsRegister(csRegInfo);
networkRegister->NotifyNrFrequencyChanged();
EXPECT_EQ(networkRegister->UpdateNsaState(static_cast<int32_t>(NrState::NR_STATE_NOT_SUPPORT)),
static_cast<int32_t>(NrState::NR_STATE_NOT_SUPPORT));
RegServiceState regStatus = RegServiceState::REG_STATE_IN_SERVICE;
networkRegister->UpdateCellularCall(regStatus, 0);
networkRegister->networkSearchManager_ = networkSearchManager;
networkRegister->networkSearchState_ = nullptr;
networkRegister->ProcessPsRegister(psRegInfo);
networkRegister->ProcessCsRegister(csRegInfo);
EXPECT_EQ(networkRegister->RevertLastTechnology(), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(networkRegister->NotifyStateChange(), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(networkRegister->UpdateNsaState(static_cast<int32_t>(NrState::NR_STATE_NOT_SUPPORT)),
static_cast<int32_t>(NrState::NR_STATE_NOT_SUPPORT));
auto netManager = networkRegister->networkSearchManager_.lock();
ASSERT_NE(netManager, nullptr);
netManager->cellularCallCallBack_ = nullptr;
networkRegister->UpdateCellularCall(regStatus, 0);
regStatus = RegServiceState::REG_STATE_EMERGENCY_ONLY;
networkRegister->UpdateCellularCall(regStatus, 0);
networkRegister->networkSearchState_ = networkSearchState;
networkRegister->networkSearchState_->networkState_ = nullptr;
EXPECT_EQ(networkRegister->RevertLastTechnology(), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(networkRegister->NotifyStateChange(), TELEPHONY_ERR_SUCCESS);
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NetworkRegister_002, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto networkSearchState = std::make_shared<NetworkSearchState>(networkSearchManager, INVALID_SLOTID);
auto networkRegister = std::make_shared<NetworkRegister>(networkSearchState, networkSearchManager, INVALID_SLOTID);
networkRegister->networkSearchManager_ = std::weak_ptr<NetworkSearchManager>();
ASSERT_TRUE(networkRegister->networkSearchManager_.expired());
int32_t rrcState = 0;
EXPECT_EQ(networkRegister->GetRrcConnectionState(rrcState), TELEPHONY_ERR_LOCAL_PTR_NULL);
networkRegister->networkSearchState_ = nullptr;
networkRegister->systemPropertiesConfig_ = "ConfigAD";
int32_t status = 1;
EXPECT_EQ(networkRegister->HandleRrcStateChanged(status), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(networkRegister->currentNrConfig_, "ConfigA");
status = 0;
EXPECT_EQ(networkRegister->HandleRrcStateChanged(status), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(networkRegister->currentNrConfig_, "ConfigD");
networkRegister->nrState_ = NrState::NR_NSA_STATE_NO_DETECT;
EXPECT_EQ(networkRegister->GetTechnologyByNrConfig(RadioTech::RADIO_TECHNOLOGY_LTE_CA),
RadioTech::RADIO_TECHNOLOGY_NR);
networkRegister->nrState_ = NrState::NR_NSA_STATE_CONNECTED_DETECT;
EXPECT_EQ(networkRegister->GetTechnologyByNrConfig(RadioTech::RADIO_TECHNOLOGY_LTE_CA),
RadioTech::RADIO_TECHNOLOGY_NR);
networkRegister->nrState_ = NrState::NR_NSA_STATE_IDLE_DETECT;
EXPECT_EQ(networkRegister->GetTechnologyByNrConfig(RadioTech::RADIO_TECHNOLOGY_LTE_CA),
RadioTech::RADIO_TECHNOLOGY_NR);
networkRegister->nrState_ = NrState::NR_NSA_STATE_DUAL_CONNECTED;
EXPECT_EQ(networkRegister->GetTechnologyByNrConfig(RadioTech::RADIO_TECHNOLOGY_LTE_CA),
RadioTech::RADIO_TECHNOLOGY_NR);
networkRegister->nrState_ = NrState::NR_NSA_STATE_SA_ATTACHED;
EXPECT_EQ(networkRegister->GetTechnologyByNrConfig(RadioTech::RADIO_TECHNOLOGY_LTE_CA),
RadioTech::RADIO_TECHNOLOGY_LTE_CA);
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NetworkSearchState_001, Function | MediumTest | Level1)
{
NetworkSearchNotify networkSearchNotify;
sptr<NetworkState> networkState = nullptr;
networkSearchNotify.NotifyNetworkStateUpdated(0, networkState);
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto networkSearchState = std::make_shared<NetworkSearchState>(networkSearchManager, INVALID_SLOTID);
networkSearchState->networkState_ = nullptr;
EXPECT_FALSE(networkSearchState->IsEmergency());
networkSearchState->imsRegStatus_ = false;
networkSearchState->SetImsStatus(false);
networkSearchState->imsRegStatus_ = true;
networkSearchState->imsServiceStatus_ = std::make_unique<ImsServiceStatus>();
ASSERT_NE(networkSearchState->imsServiceStatus_, nullptr);
networkSearchState->imsServiceStatus_->supportImsVoice = true;
EXPECT_EQ(networkSearchState->GetImsRegState(ImsServiceType::TYPE_VOICE), ImsRegState::IMS_REGISTERED);
networkSearchState->imsServiceStatus_->supportImsVideo = true;
EXPECT_EQ(networkSearchState->GetImsRegState(ImsServiceType::TYPE_VIDEO), ImsRegState::IMS_REGISTERED);
networkSearchState->imsServiceStatus_->supportImsUt = true;
EXPECT_EQ(networkSearchState->GetImsRegState(ImsServiceType::TYPE_UT), ImsRegState::IMS_REGISTERED);
networkSearchState->imsServiceStatus_->supportImsSms = true;
EXPECT_EQ(networkSearchState->GetImsRegState(ImsServiceType::TYPE_SMS), ImsRegState::IMS_REGISTERED);
}
HWTEST_F(NetworkSearchBranchTest, Telephony_NetworkSearchState_002, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto networkSearchState = std::make_shared<NetworkSearchState>(networkSearchManager, INVALID_SLOTID);
networkSearchState->networkState_ = std::make_unique<NetworkState>();
networkSearchState->networkState_->lastCfgTech_ = RadioTech::RADIO_TECHNOLOGY_LTE_CA;
RadioTech tech = RadioTech::RADIO_TECHNOLOGY_UNKNOWN;
EXPECT_EQ(networkSearchState->GetLastCfgTech(tech), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(tech, RadioTech::RADIO_TECHNOLOGY_LTE_CA);
networkSearchState->networkState_->lastPsRadioTech_ = RadioTech::RADIO_TECHNOLOGY_UNKNOWN;
EXPECT_EQ(networkSearchState->GetLastPsRadioTech(tech), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(tech, RadioTech::RADIO_TECHNOLOGY_UNKNOWN);
networkSearchState->networkSearchManager_ = std::weak_ptr<NetworkSearchManager>();
ASSERT_TRUE(networkSearchState->networkSearchManager_.expired());
ImsRegInfo info;
networkSearchState->NotifyPsRegStatusChange();
networkSearchState->NotifyPsRoamingStatusChange();
networkSearchState->NotifyPsRadioTechChange();
networkSearchState->NotifyEmergencyChange();
networkSearchState->NotifyNrStateChange();
networkSearchState->NotifyImsStateChange(ImsServiceType::TYPE_VOICE, info);
networkSearchState->CsRadioTechChange();
EXPECT_TRUE(networkSearchState->networkSearchManager_.expired());
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,170 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include "network_search_manager_test.h"
#include "cell_info.h"
#include "cell_location.h"
#include "common_event_manager.h"
#include "common_event_support.h"
#include "core_manager_inner.h"
#include "core_service_client.h"
#include "csim_file_controller.h"
#include "gtest/gtest.h"
#include "tel_ril_base_parcel.h"
#include "icc_file.h"
#include "icc_file_controller.h"
#include "icc_operator_rule.h"
#include "ims_core_service_callback_proxy.h"
#include "ims_core_service_callback_stub.h"
#include "ims_core_service_proxy.h"
#include "ims_reg_info_callback_proxy.h"
#include "isim_file_controller.h"
#include "multi_sim_controller.h"
#include "multi_sim_monitor.h"
#include "network_register.h"
#include "network_search_manager.h"
#include "network_search_state.h"
#include "operator_matching_rule.h"
#include "operator_name.h"
#include "radio_protocol_controller.h"
#include "ruim_file_controller.h"
#include "sim_file_controller.h"
#include "sim_file_manager.h"
#include "sim_manager.h"
#include "sim_number_decode.h"
#include "sim_rdb_helper.h"
#include "sim_sms_controller.h"
#include "sim_state_manager.h"
#include "sim_utils.h"
#include "stk_controller.h"
#include "stk_manager.h"
#include "tag_service.h"
#include "tel_ril_manager.h"
#include "telephony_errors.h"
#include "telephony_hisysevent.h"
#include "telephony_log_wrapper.h"
#include "usim_file_controller.h"
#include "telephony_data_helper.h"
#include "sim_data.h"
#include "accesstoken_kit.h"
#include "token_setproc.h"
#include "nativetoken_kit.h"
#include "ims_reg_info_callback_stub.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
namespace {
const int32_t SLOT_ID_0 = 0;
const int32_t INVALID_SLOTID = -1;
constexpr int32_t LTE_RSSI_GOOD = -80;
constexpr int32_t SLEEP_TIME_SECONDS = 3;
} // namespace
class NetworkSearchBranchTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void NetworkSearchBranchTest::TearDownTestCase()
{
sleep(SLEEP_TIME_SECONDS);
}
void NetworkSearchBranchTest::SetUp() {}
void NetworkSearchBranchTest::TearDown() {}
void NetworkSearchBranchTest::SetUpTestCase()
{
constexpr int permissionNum = 2;
const char *perms[permissionNum] = {"ohos.permission.GET_TELEPHONY_STATE",
"ohos.permission.SET_TELEPHONY_STATE"};
NativeTokenInfoParams infoInstance = {.dcapsNum = 0, .permsNum = permissionNum, .aclsNum = 0, .dcaps = nullptr,
.perms = perms, .acls = nullptr, .processName = "NetworkSearchBranchTest", .aplStr = "system_basic",
};
uint64_t tokenId = GetAccessTokenId(&infoInstance);
SetSelfTokenID(tokenId);
auto result = Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
EXPECT_EQ(result, Security::AccessToken::RET_SUCCESS);
}
class ImsRegInfoCallbackTest : public ImsRegInfoCallbackStub {
public:
int32_t OnImsRegInfoChanged(int32_t slotId, ImsServiceType imsSrvType, const ImsRegInfo &info) override;
};
int32_t ImsRegInfoCallbackTest::OnImsRegInfoChanged(int32_t slotId, ImsServiceType imsSrvType, const ImsRegInfo &info)
{
TELEPHONY_LOGI("slotId: %{public}d, imsSrvType: %{public}d, ImsRegState: %{public}d, ImsRegTech: %{public}d",
slotId, imsSrvType, info.imsRegState, info.imsRegTech);
return TELEPHONY_SUCCESS;
}
/**
* @tc.number Telephony_NetworkSearchManager2_001
* @tc.name test branch
* @tc.desc Function test
*/
HWTEST_F(NetworkSearchBranchTest, Telephony_NetworkSearchManager2_001, Function | MediumTest | Level1)
{
AccessToken token;
auto telRilManager = std::make_shared<TelRilManager>();
EXPECT_TRUE(telRilManager->OnInit());
CoreManagerInner::GetInstance().SetTelRilMangerObj(telRilManager);
auto &client = CoreServiceClient::GetInstance();
auto slotCount = client.GetMaxSimCount();
std::shared_ptr<SimManager> simManager = std::make_shared<SimManager>(telRilManager);
EXPECT_TRUE(simManager->OnInit(slotCount));
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
EXPECT_TRUE(networkSearchManager->OnInit());
std::shared_ptr<NetworkSearchManagerInner> inner = std::make_shared<NetworkSearchManagerInner>();
EXPECT_TRUE(networkSearchManager->InitPointer(inner, SLOT_ID_0));
EXPECT_EQ(networkSearchManager->InitTelExtraModule(INVALID_SLOTID), TELEPHONY_ERROR);
networkSearchManager->RegisterCellularDataObject(nullptr);
networkSearchManager->RegisterCellularCallObject(nullptr);
networkSearchManager->UnRegisterCellularCallObject(nullptr);
networkSearchManager->SavePreferredNetworkValue(SLOT_ID_0,
static_cast<int32_t>(PreferredNetworkMode::CORE_NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA_GSM_EVDO_CDMA));
EXPECT_EQ(networkSearchManager->UpdateRadioOn(SLOT_ID_0), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(networkSearchManager->GetNrSsbId(SLOT_ID_0, nullptr), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(networkSearchManager->GetNrSsbId(INVALID_SLOTID, nullptr), TELEPHONY_ERR_LOCAL_PTR_NULL);
Rssi signalIntensity;
signalIntensity.lte.rsrp = LTE_RSSI_GOOD;
EXPECT_EQ(networkSearchManager->ProcessSignalIntensity(SLOT_ID_0, signalIntensity), TELEPHONY_ERR_SUCCESS);
sptr<ImsRegInfoCallback> callback = new ImsRegInfoCallbackTest;
int32_t tokenId = 0;
EXPECT_EQ(networkSearchManager->RegisterImsRegInfoCallback(
SLOT_ID_0, ImsServiceType::TYPE_SMS, tokenId, callback), TELEPHONY_SUCCESS);
EXPECT_EQ(networkSearchManager->UnregisterImsRegInfoCallback(
SLOT_ID_0, ImsServiceType::TYPE_SMS, tokenId), TELEPHONY_SUCCESS);
EXPECT_EQ(networkSearchManager->StartRadioOnState(SLOT_ID_0), TELEPHONY_SUCCESS);
EXPECT_EQ(networkSearchManager->StartGetRilSignalIntensity(SLOT_ID_0), TELEPHONY_SUCCESS);
bool isGsm = false;
EXPECT_EQ(networkSearchManager->IsGsm(SLOT_ID_0, isGsm), TELEPHONY_SUCCESS);
EXPECT_EQ(networkSearchManager->IsCdma(SLOT_ID_0, isGsm), TELEPHONY_SUCCESS);
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,200 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NETWORK_SEARCH_MANAGER_TEST_H
#define NETWORK_SEARCH_MANAGER_TEST_H
#include <gtest/gtest.h>
#include <list>
#include "accesstoken_kit.h"
#include "core_service_client.h"
#include "core_manager_inner.h"
#include "token_setproc.h"
namespace OHOS {
namespace Telephony {
using namespace Security::AccessToken;
using Security::AccessToken::AccessTokenID;
inline HapInfoParams testNetInfoParams = {
.bundleName = "tel_core_service_gtest",
.userID = 1,
.instIndex = 0,
.appIDDesc = "test",
.isSystemApp = true,
};
inline PermissionDef testNetPermLocationDef = {
.permissionName = "ohos.permission.LOCATION",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test network search",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testNetPermLocation = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.LOCATION",
.resDeviceID = { "local" },
};
inline PermissionDef testNetPermGetTelephonyStateDef = {
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test network search",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testNetGetTelephonyState = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.resDeviceID = { "local" },
};
inline PermissionDef testNetPermSetTelephonyStateDef = {
.permissionName = "ohos.permission.SET_TELEPHONY_STATE",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test network search",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testNetSetTelephonyState = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.SET_TELEPHONY_STATE",
.resDeviceID = { "local" },
};
inline PermissionDef testNetPermGetNetworkInfoDef = {
.permissionName = "ohos.permission.GET_NETWORK_INFO",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test network search",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testNetPermGetNetworkInfo = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.GET_NETWORK_INFO",
.resDeviceID = { "local" },
};
inline PermissionDef testPermReadContactsDef = {
.permissionName = "ohos.permission.READ_CONTACTS",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test network search",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testPermReadContacts = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.READ_CONTACTS",
.resDeviceID = { "local" },
};
inline PermissionDef testPermWriteContactsDef = {
.permissionName = "ohos.permission.WRITE_CONTACTS",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test network search",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
inline PermissionStateFull testPermWriteContacts = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.WRITE_CONTACTS",
.resDeviceID = { "local" },
};
inline PermissionStateFull testPermSecureSettings = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.MANAGE_SECURE_SETTINGS",
.resDeviceID = { "local" },
};
inline PermissionStateFull testPermManagerSettings = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.MANAGE_SETTINGS",
.resDeviceID = { "local" },
};
inline HapPolicyParams testNetPolicyParams = {
.apl = APL_SYSTEM_BASIC,
.domain = "test.domain",
.permList = { testNetPermLocationDef, testNetPermGetTelephonyStateDef, testNetPermSetTelephonyStateDef,
testNetPermGetNetworkInfoDef, testPermReadContactsDef, testPermWriteContactsDef },
.permStateList = { testNetPermLocation, testNetGetTelephonyState, testNetSetTelephonyState,
testNetPermGetNetworkInfo, testPermReadContacts, testPermWriteContacts },
};
class AccessToken {
public:
AccessToken()
{
currentID_ = GetSelfTokenID();
AccessTokenIDEx tokenIdEx = AccessTokenKit::AllocHapToken(testNetInfoParams, testNetPolicyParams);
accessID_ = tokenIdEx.tokenIdExStruct.tokenID;
SetSelfTokenID(tokenIdEx.tokenIDEx);
}
~AccessToken()
{
AccessTokenKit::DeleteToken(accessID_);
SetSelfTokenID(currentID_);
}
private:
AccessTokenID currentID_ = 0;
AccessTokenID accessID_ = 0;
};
} // namespace Telephony
} // namespace OHOS
#endif // NETWORK_SEARCH_MANAGER_TEST_H

View File

@ -34,6 +34,44 @@ HapInfoParams testInfoParams = {
.isSystemApp = true,
};
PermissionDef testPermLocationDef = {
.permissionName = "ohos.permission.LOCATION",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test core service",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
PermissionStateFull testLocationState = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.LOCATION",
.resDeviceID = { "local" },
};
PermissionDef testPermCellLocationDef = {
.permissionName = "ohos.permission.CELL_LOCATION",
.bundleName = "tel_core_service_gtest",
.grantMode = 1, // SYSTEM_GRANT
.label = "label",
.labelId = 1,
.description = "Test core service",
.descriptionId = 1,
.availableLevel = APL_SYSTEM_BASIC,
};
PermissionStateFull testCellLocationState = {
.grantFlags = { 2 }, // PERMISSION_USER_SET
.grantStatus = { PermissionState::PERMISSION_GRANTED },
.isGeneral = true,
.permissionName = "ohos.permission.CELL_LOCATION",
.resDeviceID = { "local" },
};
PermissionDef testPermGetTelephonyStateDef = {
.permissionName = "ohos.permission.GET_TELEPHONY_STATE",
.bundleName = "tel_core_service_gtest",
@ -133,9 +171,9 @@ HapPolicyParams testPolicyParams = {
.apl = APL_SYSTEM_BASIC,
.domain = "test.domain",
.permList = { testPermGetTelephonyStateDef, testPermSetTelephonyStateDef, testPermGetNetworkInfoDef,
testSimPermWriteContactsDef, testSimPermReadContactsDef },
testSimPermWriteContactsDef, testSimPermReadContactsDef, testPermLocationDef, testPermCellLocationDef},
.permStateList = { testGetTelephonyState, testSetTelephonyState, testPermGetNetworkInfo, testSimPermWriteContacts,
testSimPermReadContacts },
testSimPermReadContacts, testLocationState, testCellLocationState},
};
} // namespace

View File

@ -0,0 +1,205 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include <string>
#include <unistd.h>
#include "common_event_manager.h"
#include "common_event_support.h"
#include "gtest/gtest.h"
#include "tel_ril_manager.h"
#include "sim_file_manager.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
class SimFileManagerBranchTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void SimFileManagerBranchTest::TearDownTestCase() {}
void SimFileManagerBranchTest::SetUp() {}
void SimFileManagerBranchTest::TearDown() {}
void SimFileManagerBranchTest::SetUpTestCase() {}
HWTEST_F(SimFileManagerBranchTest, Telephony_SimFileManager_001, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
SimFileManager simFileManager { subcribeInfo, std::weak_ptr<ITelRilManager>(telRilManager),
std::weak_ptr<SimStateManager>(simStateManager) };
int slotId = 1;
simFileManager.stateRecord_ = SimFileManager::HandleRunningState::STATE_RUNNING;
simFileManager.Init(slotId);
EXPECT_EQ(simFileManager.iccType_, SimFileManager::IccType::ICC_TYPE_USIM);
simFileManager.stateRecord_ = SimFileManager::HandleRunningState::STATE_NOT_START;
simFileManager.stateRecord_ = SimFileManager::HandleRunningState::STATE_RUNNING;
simFileManager.Init(slotId);
EXPECT_EQ(simFileManager.iccType_, SimFileManager::IccType::ICC_TYPE_USIM);
simFileManager.stateRecord_ = SimFileManager::HandleRunningState::STATE_NOT_START;
simFileManager.stateRecord_ = SimFileManager::HandleRunningState::STATE_NOT_START;
simFileManager.telRilManager_ = std::weak_ptr<TelRilManager>();
simFileManager.Init(slotId);
EXPECT_EQ(simFileManager.iccType_, SimFileManager::IccType::ICC_TYPE_USIM);
simFileManager.telRilManager_ = std::weak_ptr<ITelRilManager>(telRilManager);
simFileManager.simStateManager_ = std::weak_ptr<SimStateManager>();
simFileManager.Init(slotId);
EXPECT_EQ(simFileManager.iccType_, SimFileManager::IccType::ICC_TYPE_USIM);
}
HWTEST_F(SimFileManagerBranchTest, Telephony_SimFileManager_002, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
SimFileManager simFileManager { subcribeInfo, std::weak_ptr<ITelRilManager>(telRilManager),
std::weak_ptr<SimStateManager>(simStateManager) };
simFileManager.fileController_ = nullptr;
EXPECT_FALSE(simFileManager.InitSimFile(SimFileManager::IccType::ICC_TYPE_CDMA));
int slotId = 1;
simFileManager.fileController_ = std::make_shared<RuimFileController>(slotId);
simFileManager.diallingNumberHandler_ = nullptr;
EXPECT_FALSE(simFileManager.InitSimFile(SimFileManager::IccType::ICC_TYPE_CDMA));
simFileManager.fileController_ = nullptr;
simFileManager.iccFileControllerCache_.insert(std::make_pair(SimFileManager::IccType::ICC_TYPE_CDMA, nullptr));
EXPECT_FALSE(simFileManager.InitIccFileController(SimFileManager::IccType::ICC_TYPE_CDMA));
simFileManager.iccFileControllerCache_.clear();
EXPECT_TRUE(simFileManager.InitIccFileController(SimFileManager::IccType::ICC_TYPE_CDMA));
EXPECT_EQ(simFileManager.iccFileControllerCache_.size(), 1);
simFileManager.iccFileControllerCache_.clear();
EXPECT_TRUE(simFileManager.InitIccFileController(SimFileManager::IccType::ICC_TYPE_IMS));
EXPECT_EQ(simFileManager.iccFileControllerCache_.size(), 1);
simFileManager.iccFileControllerCache_.clear();
EXPECT_TRUE(simFileManager.InitIccFileController(SimFileManager::IccType::ICC_TYPE_GSM));
EXPECT_EQ(simFileManager.iccFileControllerCache_.size(), 1);
simFileManager.iccFileControllerCache_.clear();
EXPECT_TRUE(simFileManager.InitIccFileController(SimFileManager::IccType::ICC_TYPE_USIM));
EXPECT_EQ(simFileManager.iccFileControllerCache_.size(), 1);
}
HWTEST_F(SimFileManagerBranchTest, Telephony_SimFileManager_003, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
SimFileManager simFileManager { subcribeInfo, std::weak_ptr<ITelRilManager>(telRilManager),
std::weak_ptr<SimStateManager>(simStateManager) };
simFileManager.simFile_ = nullptr;
std::string number = "";
EXPECT_EQ(simFileManager.GetMCC(), u"");
EXPECT_EQ(simFileManager.GetMNC(), u"");
EXPECT_EQ(simFileManager.GetSimDecIccId(), u"");
EXPECT_EQ(simFileManager.GetVoiceMailCount(), UNKNOWN_VOICE_MAIL_COUNT);
EXPECT_FALSE(simFileManager.SetVoiceMailCount(0));
EXPECT_FALSE(simFileManager.SetVoiceCallForwarding(0, number));
simFileManager.simFile_ = std::make_shared<RuimFile>(simStateManager);
EXPECT_EQ(simFileManager.GetISOCountryCodeForSim(), u"");
EXPECT_EQ(simFileManager.GetSimSpn(), u"");
EXPECT_EQ(simFileManager.GetSimDecIccId(), u"");
EXPECT_EQ(simFileManager.GetSimGid1(), u"");
EXPECT_EQ(simFileManager.GetVoiceMailIdentifier(), u"");
EXPECT_EQ(simFileManager.GetVoiceMailCount(), DEFAULT_VOICE_MAIL_COUNT);
EXPECT_FALSE(simFileManager.SetVoiceMailCount(0));
EXPECT_FALSE(simFileManager.SetVoiceCallForwarding(0, number));
simFileManager.UnRegisterCoreNotify(nullptr, RadioEvent::RADIO_STK_SESSION_END);
simFileManager.SetImsi("testImsi");
std::u16string testU16Str = u"";
EXPECT_FALSE(simFileManager.SetSimTelephoneNumber(testU16Str, testU16Str));
simFileManager.simStateManager_ = std::weak_ptr<SimStateManager>();
EXPECT_EQ(simFileManager.GetSimIccId(), u"");
simFileManager.simFile_->SetVoiceMailNumber("testNum");
EXPECT_STREQ((simFileManager.simFile_->voiceMailNum_).c_str(), "testNum");
EXPECT_STREQ((simFileManager.GetVoiceMailNumberKey()).c_str(), "testNum");
}
HWTEST_F(SimFileManagerBranchTest, Telephony_SimFileManager_004, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
SimFileManager simFileManager { subcribeInfo, std::weak_ptr<ITelRilManager>(telRilManager),
std::weak_ptr<SimStateManager>(simStateManager) };
EXPECT_STREQ((simFileManager.EncryptImsi("")).c_str(), "");
EXPECT_STRNE((simFileManager.EncryptImsi("460001234567890")).c_str(), "");
simFileManager.simStateManager_ = std::weak_ptr<SimStateManager>();
EXPECT_FALSE(simFileManager.HasSimCard());
EXPECT_FALSE(simFileManager.IsCTSimCard());
simFileManager.fileController_ = nullptr;
EXPECT_FALSE(simFileManager.InitDiallingNumberHandler());
int slotId = 1;
simFileManager.fileController_ = std::make_shared<RuimFileController>(slotId);
simFileManager.diallingNumberHandler_ = std::make_shared<IccDiallingNumbersHandler>(simFileManager.fileController_);
EXPECT_TRUE(simFileManager.InitDiallingNumberHandler());
simFileManager.simFile_ = nullptr;
simFileManager.HandleSimRecordsLoaded();
simFileManager.HandleSimIccidLoaded("testIccid");
auto ril = std::weak_ptr<ITelRilManager>();
auto simState = std::weak_ptr<SimStateManager>();
EXPECT_EQ(ril.lock(), nullptr);
EXPECT_EQ(simFileManager.CreateInstance(ril, simState), nullptr);
ril = std::weak_ptr<ITelRilManager>(telRilManager);
EXPECT_NE(ril.lock(), nullptr);
EXPECT_EQ(simState.lock(), nullptr);
EXPECT_EQ(simFileManager.CreateInstance(ril, simState), nullptr);
EXPECT_EQ(simFileManager.GetIccTypeByCardType(CardType::SINGLE_MODE_ISIM_CARD),
SimFileManager::IccType::ICC_TYPE_IMS);
simFileManager.simFile_ = std::make_shared<IsimFile>(simStateManager);
EXPECT_EQ(simFileManager.GetSimIst(), u"");
}
} // namespace Telephony
} // namespace OHOS

View File

@ -20,9 +20,12 @@
#include "core_manager_inner.h"
#include "core_service.h"
#include "core_service_client.h"
#include "multi_sim_controller.h"
#include "operator_config_cache.h"
#include "sim_manager.h"
#include "sim_test_util.h"
#include "tel_ril_callback.h"
#include "tel_ril_manager.h"
#include "telephony_ext_wrapper.h"
namespace OHOS {
@ -165,6 +168,8 @@ HWTEST_F(SimTest, Telephony_VSim_Wrapper_0100, Function | MediumTest | Level1)
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.getSimIdExt_ != nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.getSlotIdExt_ != nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.isHandleVSim_ != nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.isVSimEnabled_ != nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.updateSubState_ != nullptr);
}
}
@ -186,9 +191,54 @@ HWTEST_F(SimTest, Telephony_VSim_Wrapper_0200, Function | MediumTest | Level1)
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.getSimIdExt_ == nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.getSlotIdExt_ == nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.isHandleVSim_ == nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.isVSimEnabled_ == nullptr);
EXPECT_TRUE(TELEPHONY_EXT_WRAPPER.updateSubState_ == nullptr);
}
}
/**
* @tc.number SavePrimarySlotId_0100
* @tc.name InitExtraModule
* @tc.desc Function test
*/
HWTEST_F(SimTest, SavePrimarySlotId_0100, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
CoreManagerInner::GetInstance().OnInit(nullptr, simManager, telRilManager);
int32_t result = CoreManagerInner::GetInstance().SavePrimarySlotId(0);
EXPECT_EQ(TELEPHONY_ERR_ARGUMENT_INVALID, result);
}
/**
* @tc.number SavePrimarySlotId_0200
* @tc.name InitExtraModule
* @tc.desc Function test
*/
HWTEST_F(SimTest, SavePrimarySlotId_0200, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { nullptr, nullptr };
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { nullptr, nullptr };
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
EXPECT_EQ(TELEPHONY_ERR_SUCCESS, multiSimController->SavePrimarySlotId(0));
}
/**
* @tc.number SavePrimarySlotId_0300
* @tc.name InitExtraModule
* @tc.desc Function test
*/
HWTEST_F(SimTest, SavePrimarySlotId_0300, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { nullptr, nullptr };
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { nullptr, nullptr };
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
EXPECT_EQ(TELEPHONY_ERR_ARGUMENT_INVALID, multiSimController->SavePrimarySlotId(4));
}
#else // TEL_TEST_UNSUPPORT
/**
* @tc.number Telephony_Sim_MockTest_0100
@ -202,7 +252,6 @@ HWTEST_F(SimTest, Telephony_Sim_MockTest_0100, Function | MediumTest | Level3)
}
EXPECT_TRUE(true);
}
#endif // TEL_TEST_UNSUPPORT
} // namespace Telephony
} // namespace OHOS

View File

@ -1340,6 +1340,79 @@ HWTEST_F(BranchTest, Telephony_MultiSimController_002, Function | MediumTest | L
EXPECT_NE(multiSimController->InsertData(0, testStr), TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number Telephony_MultiSimController_003
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(BranchTest, Telephony_MultiSimController_003, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { nullptr, nullptr };
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { nullptr, nullptr };
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
multiSimController->UpdateOpKeyInfo();
EXPECT_FALSE(multiSimController->IsValidData(-1));
}
/**
* @tc.number Telephony_MultiSimController_004
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(BranchTest, Telephony_MultiSimController_004, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { nullptr, nullptr};
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { nullptr, nullptr};
for (int32_t slotId = 0; slotId < 2; slotId++) {
simStateManager[slotId] = std::make_shared<SimStateManager>(telRilManager);
if (simStateManager[slotId] != nullptr) {
simStateManager[slotId]->Init(slotId);
}
simFileManager[slotId] = SimFileManager::CreateInstance(std::weak_ptr<ITelRilManager>(telRilManager),
std::weak_ptr<SimStateManager>(simStateManager[slotId]));
if (simFileManager[slotId] != nullptr) {
simFileManager[slotId]->Init(slotId);
}
}
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
multiSimController->Init();
telRilManager->InitTelExtraModule(2);
simStateManager.resize(3);
simFileManager.resize(3);
simStateManager[2] = std::make_shared<SimStateManager>(telRilManager);
if (simStateManager[2] != nullptr) {
simStateManager[2]->Init(2);
}
simFileManager[2] = SimFileManager::CreateInstance(std::weak_ptr<ITelRilManager>(telRilManager),
std::weak_ptr<SimStateManager>(simStateManager[2]));
if (simFileManager[2] != nullptr) {
simFileManager[2]->Init(2);
}
multiSimController->AddExtraManagers(simStateManager[2], simFileManager[2]);
multiSimController->ForgetAllData(0);
multiSimController->simStateManager_[0]->simStateHandle_->iccState_.simStatus_ = 1;
multiSimController->simStateManager_[0]->simStateHandle_->iccState_.simType_ = 2;
multiSimController->simStateManager_[0]->simStateHandle_->iccid_ = "898600520123F0102670";
multiSimController->simStateManager_[0]->simStateHandle_->externalType_ = CardType::SINGLE_MODE_USIM_CARD;
multiSimController->simStateManager_[0]->simStateHandle_->externalState_ = SimState::SIM_STATE_READY;
EXPECT_FALSE(multiSimController->InitData(0));
EXPECT_FALSE(multiSimController->InitData(0));
EXPECT_TRUE(multiSimController->InitShowNumber(0));
std::vector<IccAccountInfo> iccAccountInfoList;
EXPECT_GE(multiSimController->GetActiveSimAccountInfoList(false, iccAccountInfoList), TELEPHONY_ERR_SUCCESS);
EXPECT_GE(multiSimController->GetActiveSimAccountInfoList(true, iccAccountInfoList), TELEPHONY_ERR_SUCCESS);
EXPECT_GE(multiSimController->SaveImsSwitch(0, 1), TELEPHONY_ERR_SUCCESS);
int32_t imsSwitchValue;
EXPECT_GE(multiSimController->QueryImsSwitch(0, imsSwitchValue), TELEPHONY_ERR_SUCCESS);
EXPECT_FALSE(multiSimController->IsSetActiveSimInProgress(0));
EXPECT_FALSE(multiSimController->IsSetPrimarySlotIdInProgress());
}
/**
* @tc.number Telephony_SimManager_001
* @tc.name test error branch
@ -2377,13 +2450,11 @@ HWTEST_F(BranchTest, Telephony_NetworkSearchHandler_003, Function | MediumTest |
std::make_shared<NetworkSearchHandler>(networkSearchManager, telRilManager, simManager, INVALID_SLOTID);
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(RadioEvent::DELAY_NOTIFY_STATE_CHANGE);
event = nullptr;
RegServiceState regState = RegServiceState::REG_STATE_UNKNOWN;
int32_t status = RRC_IDLE_STATUS;
networkSearchHandler->HandleDelayNotifyEvent(event);
networkSearchHandler->NetworkSearchResult(event);
networkSearchHandler->RadioGetNeighboringCellInfo(event);
networkSearchHandler->RadioGetImeiSv(event);
EXPECT_EQ(networkSearchHandler->GetRegServiceState(regState), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(networkSearchHandler->HandleRrcStateChanged(status), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(networkSearchHandler->RevertLastTechnology(), TELEPHONY_ERR_LOCAL_PTR_NULL);
@ -2394,7 +2465,6 @@ HWTEST_F(BranchTest, Telephony_NetworkSearchHandler_003, Function | MediumTest |
networkSearchHandler->NetworkSearchResult(event);
event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_NEIGHBORING_CELL_INFO);
networkSearchHandler->RadioGetNeighboringCellInfo(event);
EXPECT_EQ(networkSearchHandler->GetRegServiceState(regState), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(networkSearchHandler->HandleRrcStateChanged(status), TELEPHONY_ERR_SUCCESS);
EXPECT_EQ(networkSearchHandler->RevertLastTechnology(), TELEPHONY_ERR_SUCCESS);
networkSearchHandler->IsPowerOnPrimaryRadioWhenNoSim();
@ -2977,6 +3047,147 @@ HWTEST_F(BranchTest, Telephony_MultiSimMonitor_001, Function | MediumTest | Leve
EXPECT_EQ(multiSimMonitor->UnregisterSimAccountCallback(tokenId), TELEPHONY_ERROR);
}
/**
* @tc.number Telephony_MultiSimMonitor_002
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(BranchTest, Telephony_MultiSimMonitor_002, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
auto simStateManagerPtr = std::make_shared<SimStateManager>(telRilManager);
auto telRilManagerWeak = std::weak_ptr<TelRilManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManagerPtr = std::make_shared<Telephony::SimFileManager>(
subcribeInfo, telRilManagerWeak, std::weak_ptr<Telephony::SimStateManager>(simStateManagerPtr));
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { simStateManagerPtr,
simStateManagerPtr };
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { simFileManagerPtr, simFileManagerPtr };
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
std::vector<std::weak_ptr<Telephony::SimFileManager>> simFileManagerWeak = {
std::weak_ptr<Telephony::SimFileManager>(simFileManagerPtr),
std::weak_ptr<Telephony::SimFileManager>(simFileManagerPtr)
};
auto multiSimMonitor = std::make_shared<MultiSimMonitor>(multiSimController, simStateManager, simFileManagerWeak);
multiSimMonitor->AddExtraManagers(simStateManagerPtr, simFileManagerPtr);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManagerPtr);
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SIM_STATE_READY, 0);
multiSimMonitor->ProcessEvent(event);
multiSimMonitor->RegisterCoreNotify(0, simStateHandle, RadioEvent::RADIO_SIM_ACCOUNT_LOADED);
multiSimMonitor->IsVSimSlotId(0);
multiSimMonitor->RegisterSimNotify(0);
multiSimMonitor->UnRegisterSimNotify();
}
/**
* @tc.number Telephony_MultiSimMonitor_003
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(BranchTest, Telephony_MultiSimMonitor_003, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
auto simStateManagerPtr = std::make_shared<SimStateManager>(telRilManager);
auto telRilManagerWeak = std::weak_ptr<TelRilManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManagerPtr = std::make_shared<Telephony::SimFileManager>(
subcribeInfo, telRilManagerWeak, std::weak_ptr<Telephony::SimStateManager>(simStateManagerPtr));
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { simStateManagerPtr,
simStateManagerPtr };
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { simFileManagerPtr, simFileManagerPtr };
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
std::vector<std::weak_ptr<Telephony::SimFileManager>> simFileManagerWeak = {
std::weak_ptr<Telephony::SimFileManager>(simFileManagerPtr),
std::weak_ptr<Telephony::SimFileManager>(simFileManagerPtr)
};
std::shared_ptr<MultiSimMonitor> multiSimMonitor =
std::make_shared<MultiSimMonitor>(multiSimController, simStateManager, simFileManagerWeak);
multiSimMonitor->AddExtraManagers(simStateManagerPtr, simFileManagerPtr);
EventFwk::MatchingSkills matchSkills;
matchingSkills.AddEvent(DATASHARE_READY_EVENT);
EventFwk::CommonEventSubscribeInfo subscriberInfo(matchSkills);
subscriberInfo.SetThreadMode(CommonEventSubscribeInfo::COMMON);
}
/**
* @tc.number Telephony_MultiSimMonitor_004
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(BranchTest, Telephony_MultiSimMonitor_004, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
auto simStateManagerPtr = std::make_shared<SimStateManager>(telRilManager);
auto telRilManagerWeak = std::weak_ptr<TelRilManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManagerPtr = std::make_shared<Telephony::SimFileManager>(
subcribeInfo, telRilManagerWeak, std::weak_ptr<Telephony::SimStateManager>(simStateManagerPtr));
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { simStateManagerPtr,
simStateManagerPtr };
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { simFileManagerPtr, simFileManagerPtr };
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
auto simFileManagerWeak = std::weak_ptr<Telephony::SimFileManager>(simFileManagerPtr);
std::vector<std::weak_ptr<Telephony::SimFileManager>> simFileManagerWeaks = {simFileManagerWeak,
simFileManagerWeak};
std::shared_ptr<MultiSimMonitor> multiSimMonitor =
std::make_shared<MultiSimMonitor>(nullptr, simStateManager, simFileManagerWeaks);
multiSimMonitor->RegisterSimNotify();
multiSimMonitor->InitData(0);
simStateManager = { nullptr, nullptr };
multiSimMonitor = std::make_shared<MultiSimMonitor>(multiSimController, simStateManager, simFileManagerWeaks);
multiSimMonitor->RegisterSimNotify(0);
multiSimMonitor->UnRegisterSimNotify();
simFileManagerWeak.reset();
simFileManagerWeaks = { simFileManagerWeak, simFileManagerWeak };
multiSimMonitor = std::make_shared<MultiSimMonitor>(multiSimController, simStateManager, simFileManagerWeaks);
multiSimMonitor->RegisterSimNotify(0);
multiSimMonitor->UnRegisterSimNotify();
multiSimMonitor->RefreshData(0);
multiSimMonitor->UpdateAllOpkeyConfigs();
multiSimMonitor->ClearAllOpcCache();
EXPECT_FALSE(multiSimMonitor->IsValidSlotId(-1));
}
/**
* @tc.number Telephony_MultiSimMonitor_005
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(BranchTest, Telephony_MultiSimMonitor_005, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
auto simStateManagerPtr = std::make_shared<SimStateManager>(telRilManager);
simStateManagerPtr->Init(0);
auto telRilManagerWeak = std::weak_ptr<TelRilManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManagerPtr = std::make_shared<Telephony::SimFileManager>(
subcribeInfo, telRilManagerWeak, std::weak_ptr<Telephony::SimStateManager>(simStateManagerPtr));
std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager = { simStateManagerPtr,
simStateManagerPtr };
std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager = { simFileManagerPtr, simFileManagerPtr };
std::shared_ptr<Telephony::MultiSimController> multiSimController =
std::make_shared<MultiSimController>(telRilManager, simStateManager, simFileManager);
std::vector<std::weak_ptr<Telephony::SimFileManager>> simFileManagerWeak = {
std::weak_ptr<Telephony::SimFileManager>(simFileManagerPtr),
std::weak_ptr<Telephony::SimFileManager>(simFileManagerPtr)
};
std::shared_ptr<MultiSimMonitor> multiSimMonitor =
std::make_shared<MultiSimMonitor>(multiSimController, simStateManager, simFileManagerWeak);
multiSimMonitor->Init();
}
/**
* @tc.number Telephony_ImsCoreServiceCallbackProxy_001
* @tc.name test error branch
@ -3070,18 +3281,70 @@ HWTEST_F(BranchTest, Telephony_SignalInformation_001, Function | MediumTest | Le
EXPECT_GE(gsmCellLocation->GetCellId(), 0);
}
/**
* @tc.number Telephony_RadioInfo_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(BranchTest, Telephony_RadioInfo_001, Function | MediumTest | Level1)
HWTEST_F(BranchTest, Telephony_NrSsbInfo, Function | MediumTest | Level1)
{
auto simManager = std::make_shared<SimManager>(nullptr);
auto nsm = std::make_shared<NetworkSearchManager>(nullptr, simManager);
auto radioInfo = std::make_shared<radioInfo>(nsm, SLOT_ID_0);
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto nrSsbInfo = std::make_shared<NrSsbInfo>(networkSearchManager, INVALID_SLOTID);
EXPECT_FALSE(nrSsbInfo->FillNrSsbIdInformation(nullptr));
std::shared_ptr<NrSsbInformation> nrCellSsbIdsInfo = std::make_shared<NrSsbInformation>();
EXPECT_TRUE(nrSsbInfo->FillNrSsbIdInformation(nrCellSsbIdsInfo));
AppExecFwk::InnerEvent::Pointer event(nullptr, nullptr);
EXPECT_FALSE(nrSsbInfo->ProcessGetNrSsbId(event));
EXPECT_FALSE(nrSsbInfo->UpdateNrSsbIdInfo(SLOT_ID_0, nullptr));
std::shared_ptr<NrCellSsbIds> nrCellSsbIds = std::make_shared<NrCellSsbIds>();
nrSsbInfo->nrCellSsbIdsInfo_ = nullptr;
EXPECT_FALSE(nrSsbInfo->UpdateNrSsbIdInfo(SLOT_ID_0, nrCellSsbIds));
nrSsbInfo->nrCellSsbIdsInfo_ = std::make_shared<NrCellSsbInfo>();
EXPECT_TRUE(nrSsbInfo->UpdateNrSsbIdInfo(SLOT_ID_0, nrCellSsbIds));
nrCellSsbIds->nbCellCount = 5;
EXPECT_FALSE(nrSsbInfo->UpdateNrSsbIdInfo(SLOT_ID_0, nrCellSsbIds));
}
HWTEST_F(BranchTest, Telephony_RadioInfo, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simManager = std::make_shared<SimManager>(telRilManager);
auto networkSearchManager = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
auto radioInfo = std::make_shared<RadioInfo>(networkSearchManager, INVALID_SLOTID);
AppExecFwk::InnerEvent::Pointer event(nullptr, nullptr);
radioInfo->ProcessGetRadioState(event);
radioInfo->ProcessSetRadioState(event);
std::shared_ptr<NetworkSearchManager> nsm = std::make_shared<NetworkSearchManager>(telRilManager, simManager);
radioInfo->RadioFirstPowerOn(nsm, ModemPowerState::CORE_SERVICE_POWER_OFF);
radioInfo->ProcessGetImei(event);
radioInfo->ProcessGetImeiSv(event);
radioInfo->ProcessGetMeid(event);
radioInfo->ProcessVoiceTechChange(event);
radioInfo->ProcessGetBasebandVersion(event);
radioInfo->ProcessGetRrcConnectionState(event);
radioInfo->ProcessSetNrOptionMode(event);
radioInfo->ProcessGetNrOptionMode(event);
EXPECT_EQ(radioInfo->RadioTechToPhoneType(RadioTech::RADIO_TECHNOLOGY_1XRTT, RadioTech::RADIO_TECHNOLOGY_LTE),
PhoneType::PHONE_TYPE_IS_CDMA);
EXPECT_EQ(radioInfo->RadioTechToPhoneType(RadioTech::RADIO_TECHNOLOGY_EVDO, RadioTech::RADIO_TECHNOLOGY_LTE),
PhoneType::PHONE_TYPE_IS_CDMA);
EXPECT_EQ(radioInfo->RadioTechToPhoneType(RadioTech::RADIO_TECHNOLOGY_EHRPD, RadioTech::RADIO_TECHNOLOGY_LTE),
PhoneType::PHONE_TYPE_IS_CDMA);
EXPECT_EQ(radioInfo->RadioTechToPhoneType(RadioTech::RADIO_TECHNOLOGY_UNKNOWN, RadioTech::RADIO_TECHNOLOGY_LTE),
PhoneType::PHONE_TYPE_IS_GSM);
EXPECT_EQ(radioInfo->RadioTechToPhoneType(RadioTech::RADIO_TECHNOLOGY_UNKNOWN, RadioTech::RADIO_TECHNOLOGY_LTE_CA),
PhoneType::PHONE_TYPE_IS_GSM);
EXPECT_EQ(radioInfo->RadioTechToPhoneType(RadioTech::RADIO_TECHNOLOGY_UNKNOWN, RadioTech::RADIO_TECHNOLOGY_NR),
PhoneType::PHONE_TYPE_IS_GSM);
radioInfo->SetRadioOnIfNeeded();
radioInfo->slotId_ = INVALID_SLOTID;
radioInfo->slotId_ = SLOT_ID_0;
radioInfo->SetRadioOnIfNeeded();
nsm->simManager_ = nullptr;
radioInfo->SetRadioOnIfNeeded();

View File

@ -24,7 +24,6 @@
#include "core_service_dump_helper.h"
#include "core_service_hisysevent.h"
#include "network_search_manager.h"
#include "network_search_test_callback_stub.h"
#include "operator_name.h"
#include "operator_name_utils.h"
#include "security_token.h"
@ -85,6 +84,7 @@ void CoreServiceBranchTest::TearDownTestCase()
telRilManager->DeInit();
DelayedSingleton<CoreService>::GetInstance()->Stop();
DelayedSingleton<CoreService>::DestroyInstance();
sleep(SLEEP_TIME_SECONDS);
}
void CoreServiceBranchTest::SetUp() {}
@ -106,9 +106,8 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_NetWork_001, Function | Me
networkInfo->SetOperateInformation("CHINA MOBILE", "CMCC", "46000",
static_cast<int32_t>(NetworkPlmnState::NETWORK_PLMN_STATE_AVAILABLE),
static_cast<int32_t>(NetworkRat::NETWORK_LTE));
sptr<NetworkSearchTestCallbackStub> callback(new NetworkSearchTestCallbackStub());
int32_t result = DelayedSingleton<CoreService>::GetInstance()->SetNetworkSelectionMode(
SLOT_ID, static_cast<int32_t>(SelectionMode::MODE_TYPE_MANUAL), networkInfo, true, callback);
SLOT_ID, static_cast<int32_t>(SelectionMode::MODE_TYPE_MANUAL), networkInfo, true, nullptr);
EXPECT_GE(result, TELEPHONY_ERR_SUCCESS);
std::vector<sptr<SignalInformation>> signals;
result = DelayedSingleton<CoreService>::GetInstance()->GetSignalInfoList(SLOT_ID, signals);
@ -119,8 +118,8 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_NetWork_001, Function | Me
EXPECT_GE(result, TELEPHONY_ERR_SUCCESS);
sptr<NetworkState> networkState = nullptr;
DelayedSingleton<CoreService>::GetInstance()->GetNetworkState(SLOT_ID, networkState);
DelayedSingleton<CoreService>::GetInstance()->SetRadioState(SLOT_ID, false, callback);
DelayedSingleton<CoreService>::GetInstance()->SetRadioState(SLOT_ID, false, callback);
DelayedSingleton<CoreService>::GetInstance()->SetRadioState(SLOT_ID, false, nullptr);
DelayedSingleton<CoreService>::GetInstance()->SetRadioState(SLOT_ID, false, nullptr);
EXPECT_GE(result, TELEPHONY_ERR_SUCCESS);
}
@ -132,9 +131,8 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_NetWork_001, Function | Me
HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_NetWork_002, Function | MediumTest | Level1)
{
SecurityToken token;
sptr<NetworkSearchTestCallbackStub> callback(new NetworkSearchTestCallbackStub());
DelayedSingleton<CoreService>::GetInstance()->GetPreferredNetwork(SLOT_ID, callback);
DelayedSingleton<CoreService>::GetInstance()->SetPreferredNetwork(SLOT_ID, 1, callback);
DelayedSingleton<CoreService>::GetInstance()->GetPreferredNetwork(SLOT_ID, nullptr);
DelayedSingleton<CoreService>::GetInstance()->SetPreferredNetwork(SLOT_ID, 1, nullptr);
int32_t networkCapabilityType = 1;
int32_t networkCapabilityState = 1;
DelayedSingleton<CoreService>::GetInstance()->GetNetworkCapability(
@ -152,11 +150,11 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_NetWork_002, Function | Me
DelayedSingleton<CoreService>::GetInstance()->GetMeid(SLOT_ID, u16Ret);
DelayedSingleton<CoreService>::GetInstance()->GetUniqueDeviceId(SLOT_ID, u16Ret);
DelayedSingleton<CoreService>::GetInstance()->IsNrSupported(SLOT_ID);
DelayedSingleton<CoreService>::GetInstance()->GetPreferredNetwork(SLOT_ID, callback);
DelayedSingleton<CoreService>::GetInstance()->SetNrOptionMode(SLOT_ID, NR_NSA_OPTION_ONLY, callback);
DelayedSingleton<CoreService>::GetInstance()->GetNetworkSearchInformation(SLOT_ID, callback);
DelayedSingleton<CoreService>::GetInstance()->GetNrOptionMode(SLOT_ID, callback);
DelayedSingleton<CoreService>::GetInstance()->GetNetworkSelectionMode(SLOT_ID, callback);
DelayedSingleton<CoreService>::GetInstance()->GetPreferredNetwork(SLOT_ID, nullptr);
DelayedSingleton<CoreService>::GetInstance()->SetNrOptionMode(SLOT_ID, NR_NSA_OPTION_ONLY, nullptr);
DelayedSingleton<CoreService>::GetInstance()->GetNetworkSearchInformation(SLOT_ID, nullptr);
DelayedSingleton<CoreService>::GetInstance()->GetNrOptionMode(SLOT_ID, nullptr);
DelayedSingleton<CoreService>::GetInstance()->GetNetworkSelectionMode(SLOT_ID, nullptr);
EXPECT_GE(result, TELEPHONY_ERR_SUCCESS);
}
@ -245,7 +243,7 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_Sim_002, Function | Medium
*/
HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_Stub_001, Function | MediumTest | Level1)
{
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::FACTORY_RESET);
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::GET_SIM_IO_DONE);
for (uint32_t code = 0; code <= maxCode; code++) {
if (code == static_cast<uint32_t>(CoreServiceInterfaceCode::HAS_OPERATOR_PRIVILEGES)) {
continue;
@ -270,7 +268,7 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_Stub_002, Function | Mediu
{
SecurityToken token;
int32_t slotId = SLOT_ID;
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::FACTORY_RESET);
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::GET_SIM_IO_DONE);
for (uint32_t code = 0; code <= maxCode; code++) {
MessageParcel data;
MessageParcel reply;
@ -293,8 +291,7 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_Stub_003, Function | Mediu
{
SecurityToken token;
int32_t slotId = SLOT_ID;
sptr<NetworkSearchTestCallbackStub> callback(new NetworkSearchTestCallbackStub());
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::FACTORY_RESET);
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::GET_SIM_IO_DONE);
for (uint32_t code = 0; code <= maxCode; code++) {
if (code == static_cast<uint32_t>(CoreServiceInterfaceCode::HAS_OPERATOR_PRIVILEGES)) {
continue;
@ -304,7 +301,7 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_Stub_003, Function | Mediu
MessageOption option;
data.WriteInterfaceToken(CoreServiceStub::GetDescriptor());
data.WriteInt32(slotId);
data.WriteRemoteObject(callback->AsObject().GetRefPtr());
data.WriteRemoteObject(nullptr);
DelayedSingleton<CoreService>::GetInstance()->OnRemoteRequest(code, data, reply, option);
}
std::string version;
@ -321,23 +318,22 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_Stub_004, Function | Mediu
{
SecurityToken token;
int32_t slotId = SLOT_ID;
sptr<NetworkSearchTestCallbackStub> callback(new NetworkSearchTestCallbackStub());
DelayedSingleton<CoreService>::GetInstance()->GetRadioState(slotId, callback);
DelayedSingleton<CoreService>::GetInstance()->GetRadioState(slotId, nullptr);
auto simManager = DelayedSingleton<CoreService>::GetInstance()->simManager_;
auto networkSearchManager_ = DelayedSingleton<CoreService>::GetInstance()->networkSearchManager_;
auto telRilManager_ = DelayedSingleton<CoreService>::GetInstance()->telRilManager_;
DelayedSingleton<CoreService>::GetInstance()->simManager_ = nullptr;
DelayedSingleton<CoreService>::GetInstance()->networkSearchManager_ = nullptr;
DelayedSingleton<CoreService>::GetInstance()->telRilManager_ = nullptr;
DelayedSingleton<CoreService>::GetInstance()->GetRadioState(slotId, callback);
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::FACTORY_RESET);
DelayedSingleton<CoreService>::GetInstance()->GetRadioState(slotId, nullptr);
uint32_t maxCode = static_cast<uint32_t>(CoreServiceInterfaceCode::GET_SIM_IO_DONE);
for (uint32_t code = 0; code <= maxCode; code++) {
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(CoreServiceStub::GetDescriptor());
data.WriteInt32(slotId);
data.WriteRemoteObject(callback->AsObject().GetRefPtr());
data.WriteRemoteObject(nullptr);
DelayedSingleton<CoreService>::GetInstance()->OnRemoteRequest(code, data, reply, option);
}
DelayedSingleton<CoreService>::GetInstance()->simManager_ = simManager;
@ -386,15 +382,7 @@ HWTEST_F(CoreServiceBranchTest, Telephony_CoreService_DumpHelper_001, Function |
std::string result;
coreServiceDumpHelper->ShowHelp(result);
coreServiceDumpHelper->ShowCoreServiceTimeInfo(result);
int32_t slotId = SLOT_ID;
bool hasSimCard = false;
simManager->simStateManager_[slotId]->simStateHandle_->iccState_.simStatus_ = ICC_CARD_ABSENT;
DelayedSingleton<CoreService>::GetInstance()->HasSimCard(slotId, hasSimCard);
EXPECT_FALSE(hasSimCard);
coreServiceDumpHelper->ShowCoreServiceInfo(result);
simManager->simStateManager_[slotId]->simStateHandle_->iccState_.simStatus_ = ICC_CONTENT_READY;
DelayedSingleton<CoreService>::GetInstance()->HasSimCard(slotId, hasSimCard);
EXPECT_TRUE(hasSimCard);
coreServiceDumpHelper->ShowCoreServiceInfo(result);
coreServiceDumpHelper->Dump(argsInStr, result);
EXPECT_FALSE(result.empty());

View File

@ -17,6 +17,7 @@
#include <gtest/gtest.h>
#include <string_ex.h>
#include "core_manager_inner.h"
#include "core_service.h"
#include "icc_dialling_numbers_handler.h"
#include "icc_dialling_numbers_manager.h"
@ -32,6 +33,8 @@
#include "sim_file_controller.h"
#include "sim_manager.h"
#include "sim_rdb_helper.h"
#include "sim_sms_manager.h"
#include "telephony_ext_wrapper.h"
#include "telephony_log_wrapper.h"
#include "usim_dialling_numbers_service.h"
#include "want.h"
@ -238,10 +241,6 @@ HWTEST_F(SimRilBranchTest, Telephony_SimStateTracker_001, Function | MediumTest
simStateTracker->ProcessEvent(event);
simFileManager = nullptr;
simStateTracker->simFileManager_ = simFileManager;
std::shared_ptr<OperatorConfigLoader> operatorConfigLoader_ = nullptr;
auto statusChangeListener_ =
new (std::nothrow) SimStateTracker::SystemAbilityStatusChangeListener(0, operatorConfigLoader_);
statusChangeListener_->OnAddSystemAbility(0, "test");
EXPECT_FALSE(simStateTracker->RegisterForIccLoaded());
EXPECT_FALSE(simStateTracker->UnRegisterForIccLoaded());
}
@ -320,9 +319,12 @@ HWTEST_F(SimRilBranchTest, Telephony_IccDiallingNumbersCache_002, Function | Med
diallingNumbersCache->SendBackResult(event, list, object);
diallingNumbersCache->SendUpdateResult(event, object);
data->result = static_cast<std::shared_ptr<void>>(list);
diallingNumbersCache->ProcessObtainPbrDetailsDone(event);
diallingNumbersCache->ProcessObtainAdnDetailsDone(event);
diallingNumbersCache->ProcessChangeDiallingNumbersDone(event);
auto owner = event->GetOwner();
int eventParam = 0;
AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(-1, data, eventParam);
diallingNumbersCache->ProcessObtainPbrDetailsDone(response);
diallingNumbersCache->ProcessObtainAdnDetailsDone(response);
diallingNumbersCache->ProcessChangeDiallingNumbersDone(response);
diallingNumbersCache->LoadReadyDiallingNumbers(ELEMENTARY_FILE_ADN);
diallingNumbersCache->ExtendedElementFile(ELEMENTARY_FILE_ADN);
std::u16string str1(u"Hello");
@ -354,6 +356,78 @@ HWTEST_F(SimRilBranchTest, Telephony_IccDiallingNumbersCache_003, Function | Med
EXPECT_TRUE(diallingNumbersCache->StringEqual(str1, str1));
}
/**
* @tc.number Telephony_IccDiallingNumbersCache_004
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_IccDiallingNumbersCache_004, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
auto diallingNumbersCache = std::make_shared<IccDiallingNumbersCache>(simFileManager);
auto iccDiallingNumbersManager = IccDiallingNumbersManager::CreateInstance(simFileManager, simStateManager);
diallingNumbersCache->simFileManager_ = nullptr;
diallingNumbersCache->Init();
auto caller = iccDiallingNumbersManager->BuildCallerInfo(-1);
AppExecFwk::InnerEvent::Pointer event = diallingNumbersCache->CreateUsimPointer(-1, ELEMENTARY_FILE_PBR, caller);
std::unique_ptr<UsimFetcher> fd = event->GetUniqueObject<UsimFetcher>();
std::unique_ptr<UsimResult> data = std::make_unique<UsimResult>(fd.get());
std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> list =
std::make_shared<std::vector<std::shared_ptr<DiallingNumbersInfo>>>();
std::shared_ptr<DiallingNumbersInfo> diallingNumber =
std::make_shared<DiallingNumbersInfo>(DiallingNumbersInfo::SIM_ADN, 0);
diallingNumber->name_ = Str8ToStr16("SimAdnZhang");
diallingNumber->number_ = Str8ToStr16("12345678901");
std::shared_ptr<DiallingNumbersInfo> diallingNumberEx = std::make_shared<DiallingNumbersInfo>();
list->push_back(diallingNumber);
list->push_back(diallingNumberEx);
data->result = static_cast<std::shared_ptr<void>>(list);
auto owner = event->GetOwner();
int eventParam = 0;
AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(-1, data, eventParam);
diallingNumbersCache->ProcessObtainPbrDetailsDone(response);
event = iccDiallingNumbersManager->BuildCallerInfo(-1);
diallingNumbersCache->UpdateDiallingNumberToIcc(ELEMENTARY_FILE_PBR, diallingNumber, 0, true, event);
diallingNumbersCache->UpdateDiallingNumberToIcc(ELEMENTARY_FILE_PBR, diallingNumber, -1, true, event);
int extensionEf = diallingNumbersCache->ExtendedElementFile(ELEMENTARY_FILE_PBR);
event = iccDiallingNumbersManager->BuildCallerInfo(-2);
diallingNumbersCache->ObtainAllDiallingNumberFiles(ELEMENTARY_FILE_PBR, extensionEf, event);
diallingNumbersCache->IsDiallingNumberEqual(diallingNumber, diallingNumber);
}
/**
* @tc.number Telephony_IccDiallingNumbersCache_005
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_IccDiallingNumbersCache_005, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
auto diallingNumbersCache = std::make_shared<IccDiallingNumbersCache>(simFileManager);
auto iccDiallingNumbersManager = IccDiallingNumbersManager::CreateInstance(simFileManager, simStateManager);
diallingNumbersCache->simFileManager_ = nullptr;
diallingNumbersCache->Init();
int extensionEf = diallingNumbersCache->ExtendedElementFile(ELEMENTARY_FILE_ADN);
AppExecFwk::InnerEvent::Pointer event = iccDiallingNumbersManager->BuildCallerInfo(-1);
diallingNumbersCache->ObtainAllDiallingNumberFiles(ELEMENTARY_FILE_ADN, extensionEf, event);
AppExecFwk::InnerEvent::Pointer caller = iccDiallingNumbersManager->BuildCallerInfo(-2);
extensionEf = diallingNumbersCache->ExtendedElementFile(ELEMENTARY_FILE_PBR);
diallingNumbersCache->ObtainAllDiallingNumberFiles(ELEMENTARY_FILE_PBR, extensionEf, caller);
std::vector<std::u16string> args1 = { u"test", u"test1" };
std::vector<std::u16string> args2 = { u"test"};
diallingNumbersCache->ArrayEqual(args1, args2);
}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_001
* @tc.name test error branch
@ -447,6 +521,30 @@ HWTEST_F(SimRilBranchTest, Telephony_IccDiallingNumbersManager_001, Function | M
EXPECT_GE(iccDiallingNumbersManager->QueryIccDiallingNumbers(-1, result), TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number Telephony_IccDiallingNumbersManager_003
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_IccDiallingNumbersManager_003, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
auto iccDiallingNumbersManager = IccDiallingNumbersManager::CreateInstance(simFileManager, simStateManager);
iccDiallingNumbersManager->ProcessSimStateChanged();
iccDiallingNumbersManager->Init();
iccDiallingNumbersManager->ProcessEvent(AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SIM_STATE_CHANGE, 1));
iccDiallingNumbersManager->ProcessSimStateChanged();
std::shared_ptr<DiallingNumbersInfo> diallingNumber =
std::make_shared<DiallingNumbersInfo>(DiallingNumbersInfo::SIM_ADN, 0);
EXPECT_FALSE(iccDiallingNumbersManager->IsValidParam(DiallingNumbersInfo::SIM_FDN, diallingNumber));
EXPECT_TRUE(iccDiallingNumbersManager->IsValidParam(DiallingNumbersInfo::SIM_ADN, diallingNumber));
}
/**
* @tc.number Telephony_UsimDiallingNumbersService_001
* @tc.name test error branch
@ -480,6 +578,133 @@ HWTEST_F(SimRilBranchTest, Telephony_UsimDiallingNumbersService_001, Function |
EXPECT_TRUE(usimDiallingNumbersService->fileController_ == nullptr);
}
/**
* @tc.number Telephony_UsimDiallingNumbersService_002
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_UsimDiallingNumbersService_002, Function | MediumTest | Level1)
{
auto usimDiallingNumbersService = std::make_shared<UsimDiallingNumbersService>();
usimDiallingNumbersService->InitFuncMap();
AppExecFwk::InnerEvent::Pointer event = usimDiallingNumbersService->BuildCallerInfo(MSG_USIM_PBR_LOAD_DONE);
event = nullptr;
usimDiallingNumbersService->ProcessPbrLoadDone(event);
usimDiallingNumbersService->ProcessDiallingNumberLoadDone(event);
usimDiallingNumbersService->NextStep(0);
}
/**
* @tc.number Telephony_UsimDiallingNumbersService_003
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_UsimDiallingNumbersService_003, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
auto diallingNumbersCache = std::make_shared<IccDiallingNumbersCache>(simFileManager);
auto iccDiallingNumbersManager = IccDiallingNumbersManager::CreateInstance(simFileManager, simStateManager);
diallingNumbersCache->simFileManager_ = nullptr;
diallingNumbersCache->Init();
auto usimDiallingNumbersService = std::make_shared<UsimDiallingNumbersService>();
usimDiallingNumbersService->InitFuncMap();
auto caller = iccDiallingNumbersManager->BuildCallerInfo(-1);
AppExecFwk::InnerEvent::Pointer pointer = diallingNumbersCache->CreateUsimPointer(-1, ELEMENTARY_FILE_PBR, caller);
usimDiallingNumbersService->ObtainUsimElementaryFiles(pointer);
AppExecFwk::InnerEvent::Pointer event = usimDiallingNumbersService->BuildCallerInfo(-1);
std::unique_ptr<FileToControllerMsg> cmdData = event->GetUniqueObject<FileToControllerMsg>();
std::shared_ptr<MultiRecordResult> object = std::make_shared<MultiRecordResult>(cmdData.get());
std::vector<std::string> strValue = {"FFFFFFFFFFFFFFFF"};
object->fileResults.assign(strValue.begin(), strValue.end());
object->resultLength = static_cast<int>(strValue.size());
int eventParam = 0;
AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(-1, object, eventParam);
usimDiallingNumbersService->ProcessPbrLoadDone(response);
}
/**
* @tc.number Telephony_UsimDiallingNumbersService_004
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_UsimDiallingNumbersService_004, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
auto diallingNumbersCache = std::make_shared<IccDiallingNumbersCache>(simFileManager);
auto iccDiallingNumbersManager = IccDiallingNumbersManager::CreateInstance(simFileManager, simStateManager);
diallingNumbersCache->simFileManager_ = nullptr;
diallingNumbersCache->Init();
auto usimDiallingNumbersService = std::make_shared<UsimDiallingNumbersService>();
usimDiallingNumbersService->InitFuncMap();
AppExecFwk::InnerEvent::Pointer event = usimDiallingNumbersService->CreateHandlerPointer(
MSG_USIM_USIM_ADN_LOAD_DONE, ELEMENTARY_FILE_PBR, 0, nullptr);
std::unique_ptr<DiallingNumbersHandleHolder> fd = event->GetUniqueObject<DiallingNumbersHandleHolder>();
std::unique_ptr<DiallingNumbersHandlerResult> data = std::make_unique<DiallingNumbersHandlerResult>(fd.get());
std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> diallingNumberList =
std::make_shared<std::vector<std::shared_ptr<DiallingNumbersInfo>>>();
data->result = diallingNumberList;
data->exception = nullptr;
int eventParam = 0;
AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(-1, data, eventParam);
}
/**
* @tc.number Telephony_UsimDiallingNumbersService_005
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_UsimDiallingNumbersService_005, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
auto diallingNumbersCache = std::make_shared<IccDiallingNumbersCache>(simFileManager);
auto iccDiallingNumbersManager = IccDiallingNumbersManager::CreateInstance(simFileManager, simStateManager);
diallingNumbersCache->simFileManager_ = nullptr;
diallingNumbersCache->Init();
auto usimDiallingNumbersService = std::make_shared<UsimDiallingNumbersService>();
usimDiallingNumbersService->InitFuncMap();
std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> diallingNumberList =
std::make_shared<std::vector<std::shared_ptr<DiallingNumbersInfo>>>();
std::shared_ptr<DiallingNumbersInfo> diallingNumber =
std::make_shared<DiallingNumbersInfo>(DiallingNumbersInfo::SIM_ADN, 0);
diallingNumber->name_ = Str8ToStr16("SimAdnZhang");
diallingNumber->number_ = Str8ToStr16("12345678901");
diallingNumberList->push_back(diallingNumber);
usimDiallingNumbersService->FillDiallingNumbersRecords(diallingNumberList);
std::string record = "record";
std::vector<std::string> records;
records.push_back(record);
usimDiallingNumbersService->GeneratePbrFile(records);
usimDiallingNumbersService->LoadDiallingNumberFiles(0);
}
/**
* @tc.number Telephony_SimStateManager_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_SimStateManager_001, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->SyncCmdResponse();
EXPECT_FALSE(simStateManager->HasSimCard());
}
/**
* @tc.number Telephony_SimStateManager_002
* @tc.name test error branch
@ -520,6 +745,28 @@ HWTEST_F(SimRilBranchTest, Telephony_SimStateManager_002, Function | MediumTest
EXPECT_NE(simStateManager->SendSimMatchedOperatorInfo(0, 0, "", ""), TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number Telephony_SimStateManager_005
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_SimStateManager_005, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(0);
LockInfo mLockInfo;
LockStatusResponse mLockStatusResponse;
EXPECT_GT(simStateManager->SetLockState(0, mLockInfo, mLockStatusResponse), TELEPHONY_ERR_SUCCESS);
LockType mLockType = LockType::PIN_LOCK;
LockState lockState;
EXPECT_EQ(simStateManager->GetLockState(0, mLockType, lockState), TELEPHONY_ERR_SUCCESS);
SimIoRequestInfo requestInfo;
SimAuthenticationResponse response;
EXPECT_EQ(simStateManager->GetSimIO(0, requestInfo, response), TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number Telephony_SimStateHandle_002
* @tc.name test error branch
@ -684,42 +931,6 @@ HWTEST_F(SimRilBranchTest, Telephony_IccFileController_001, Function | MediumTes
ASSERT_TRUE(iccFileController->BuildCallerInfo(0, 0, 0, holder) != nullptr);
}
/**
* @tc.number Telephony_SimManager_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(SimRilBranchTest, Telephony_SimManager_001, Function | MediumTest | Level1)
{
std::shared_ptr<ITelRilManager> telRilManager = nullptr;
auto simManager = std::make_shared<SimManager>(telRilManager);
simManager->InitSingleSimObject();
simManager->slotCount_ = 1;
int32_t slotId;
std::u16string testU = u"";
simManager->SetShowNumber(INVALID_SLOTID, testU);
simManager->GetShowNumber(INVALID_SLOTID, testU);
simManager->GetDefaultVoiceSimId(slotId);
simManager->GetDefaultSmsSlotId();
simManager->slotCount_ = 1;
int32_t dsdsMode = 0;
int32_t slotCount = 1;
std::string testS = "";
simManager->GetDsdsMode(dsdsMode);
simManager->stkManager_.resize(slotCount);
simManager->simFileManager_.resize(slotCount);
simManager->SendCallSetupRequestResult(INVALID_SLOTID, true);
simManager->GetSimGid2(INVALID_SLOTID);
simManager->GetOpName(INVALID_SLOTID, testU);
simManager->GetOpKey(INVALID_SLOTID, testU);
simManager->GetOpKeyExt(INVALID_SLOTID, testU);
simManager->GetSimTeleNumberIdentifier(INVALID_SLOTID);
simManager->ObtainSpnCondition(INVALID_SLOTID, false, testS);
simManager->slotCount_ = 0;
simManager->GetPrimarySlotId(slotId);
EXPECT_GT(simManager->GetDefaultSmsSlotId(), TELEPHONY_PERMISSION_ERROR);
}
AppExecFwk::InnerEvent::Pointer GetControllerToFileMsgEvent(int32_t code, bool withException)
{
auto objectUnique = std::make_unique<ControllerToFileMsg>(nullptr, nullptr);
@ -830,5 +1041,476 @@ HWTEST_F(SimRilBranchTest, Telephony_MccPool_001, Function | MediumTest | Level1
ASSERT_FALSE(MccPool::MccCompare(mccAccessC, mccAccessB));
ASSERT_FALSE(MccPool::MccCompare(mccAccessA, mccAccessD));
}
HWTEST_F(SimRilBranchTest, Telephony_IsChineseString001, Function | MediumTest | Level1)
{
auto simCharDecode = std::make_shared<SimCharDecode>();
EXPECT_TRUE(simCharDecode->IsChineseString("测试文本"));
EXPECT_FALSE(simCharDecode->IsChineseString("testString"));
}
HWTEST_F(SimRilBranchTest, Telephony_IsValidNumberString001, Function | MediumTest | Level1)
{
auto simNumberDecode = std::make_shared<SimNumberDecode>();
EXPECT_TRUE(simNumberDecode->IsValidNumberString("123###"));
EXPECT_FALSE(simNumberDecode->IsValidNumberString("abc@abc"));
EXPECT_EQ(simNumberDecode->chooseExtendedByType(0), nullptr);
}
HWTEST_F(SimRilBranchTest, Telephony_CharToBCD001, Function | MediumTest | Level1)
{
auto simNumberDecode = std::make_shared<SimNumberDecode>();
uint8_t result = 1;
EXPECT_TRUE(simNumberDecode->CharToBCD('0', result, 0));
EXPECT_EQ(result, 0);
result = 1;
EXPECT_FALSE(simNumberDecode->CharToBCD('a', result, 0));
EXPECT_EQ(result, 1);
EXPECT_FALSE(simNumberDecode->CharToBCD('a', result, SimNumberDecode::BCD_TYPE_ADN));
EXPECT_EQ(result, 1);
EXPECT_TRUE(simNumberDecode->CharToBCD('a', result, SimNumberDecode::BCD_TYPE_CALLER));
EXPECT_EQ(result, 0xc);
}
HWTEST_F(SimRilBranchTest, Telephony_BcdToChar, Function | MediumTest | Level1)
{
auto simNumberDecode = std::make_shared<SimNumberDecode>();
uint8_t bcdCode = 9;
char result = 'a';
EXPECT_TRUE(simNumberDecode->BcdToChar(bcdCode, result, 0));
EXPECT_EQ(result, '9');
bcdCode = 0xa;
result = 'a';
EXPECT_FALSE(simNumberDecode->BcdToChar(bcdCode, result, 0));
EXPECT_EQ(result, 'a');
EXPECT_TRUE(simNumberDecode->BcdToChar(bcdCode, result, SimNumberDecode::BCD_TYPE_ADN));
EXPECT_EQ(result, '*');
bcdCode = 0xff;
EXPECT_FALSE(simNumberDecode->BcdToChar(bcdCode, result, SimNumberDecode::BCD_TYPE_CALLER));
EXPECT_EQ(result, '*');
bcdCode = 0xb;
EXPECT_TRUE(simNumberDecode->BcdToChar(bcdCode, result, SimNumberDecode::BCD_TYPE_CALLER));
EXPECT_EQ(result, '#');
}
HWTEST_F(SimRilBranchTest, Telephony_TagService, Function | MediumTest | Level1)
{
TagService tagService("");
EXPECT_EQ(tagService.data_.size(), 0);
TagService tagService1("1234");
EXPECT_EQ(tagService1.data_.size(), 2);
TagService tagService2("1234");
EXPECT_EQ(tagService2.data_.size(), 2);
}
HWTEST_F(SimRilBranchTest, Telephony_OperatorConfigLoader_002, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
auto operatorConfigCache = std::make_shared<OperatorConfigCache>(simFileManager, 0);
auto operatorConfigLoader = std::make_shared<OperatorConfigLoader>(simFileManager, operatorConfigCache);
operatorConfigLoader->iccidFromSim_ = "";
EXPECT_EQ(operatorConfigLoader->InsertOpkeyToSimDb(""), TELEPHONY_ERR_ARGUMENT_NULL);
EXPECT_EQ(operatorConfigLoader->InsertOpkeyToSimDb("testOpKey"), TELEPHONY_ERR_ARGUMENT_NULL);
operatorConfigLoader->iccidFromSim_ = "12345678901234567890";
EXPECT_EQ(operatorConfigLoader->InsertOpkeyToSimDb(""), TELEPHONY_ERR_ARGUMENT_NULL);
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
operatorConfigLoader->simFileManager_.reset();
EXPECT_STREQ((operatorConfigLoader->GetOpKey(resultSet, 0)).c_str(), DEFAULT_OPERATOR_KEY);
}
HWTEST_F(SimRilBranchTest, Telephony_VoiceMailConstants001, Function | MediumTest | Level1)
{
ASSERT_EQ(TELEPHONY_EXT_WRAPPER.telephonyExtWrapperHandle_, nullptr);
VoiceMailConstants voiceMailConstants(0);
CoreManagerInner mInner;
mInner.simManager_ = nullptr;
OperatorConfig operatorConfig;
ASSERT_EQ(mInner.GetOperatorConfigs(0, operatorConfig), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_STREQ((voiceMailConstants.GetStringValueFromCust(0, "key")).c_str(), "");
voiceMailConstants.isVoiceMailFixed_ = true;
voiceMailConstants.ResetVoiceMailLoadedFlag();
ASSERT_EQ(voiceMailConstants.isVoiceMailFixed_, false);
EXPECT_EQ(voiceMailConstants.GetVoiceMailFixed("test"), true);
EXPECT_STREQ((voiceMailConstants.GetVoiceMailNumber("test")).c_str(), "");
EXPECT_STREQ((voiceMailConstants.GetVoiceMailTag("test")).c_str(), "");
EXPECT_STREQ((voiceMailConstants.LoadVoiceMailConfigFromCard("testName", "testCarrier")).c_str(), "");
}
HWTEST_F(SimRilBranchTest, Telephony_IccOperatorRule_003, Function | MediumTest | Level1)
{
auto iccOperatorRule = std::make_shared<IccOperatorRule>();
EXPECT_FALSE(iccOperatorRule->SetPackageNameByHexStr("G"));
EXPECT_FALSE(iccOperatorRule->SetPackageNameByHexStr("G1"));
std::string pkgHexStr = "E1E";
std::string::const_iterator pkgHexStrBeg = pkgHexStr.begin();
std::string::const_iterator pkgHexStrEnd = pkgHexStr.end();
IccOperatorRule result;
EXPECT_FALSE(iccOperatorRule->DecodeTLVTagCertPkg(pkgHexStrBeg, pkgHexStrEnd, result));
std::string limitHexStr = "E3E";
std::string::const_iterator limitHexStrBeg = limitHexStr.begin();
std::string::const_iterator limitHexStrEnd = limitHexStr.end();
EXPECT_FALSE(iccOperatorRule->DecodeTLVTagLimits(limitHexStrBeg, limitHexStrEnd, result));
std::string ruleHexStr = "E2E";
std::string::const_iterator ruleHexStrBeg = ruleHexStr.begin();
std::string::const_iterator ruleHexStrEnd = ruleHexStr.end();
int32_t len = 0;
EXPECT_FALSE(iccOperatorRule->DecodeTLVTagRule(ruleHexStrBeg, ruleHexStrEnd, result, len));
ruleHexStr = "E202E1E";
ruleHexStrBeg = ruleHexStr.begin();
ruleHexStrEnd = ruleHexStr.end();
EXPECT_FALSE(iccOperatorRule->DecodeTLVTagRule(ruleHexStrBeg, ruleHexStrEnd, result, len));
iccOperatorRule->SetCertificate("testCertificate");
iccOperatorRule->SetPackageName("testPackageName");
std::string_view certHash = "testCertificate";
std::string_view packageName = "testPackageName";
EXPECT_TRUE(iccOperatorRule->Matche(certHash, packageName));
}
HWTEST_F(SimRilBranchTest, Telephony_IccDiallingNumbersManager_002, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
IccDiallingNumbersManager iccDiallingNumbersManager(simFileManager, nullptr);
std::shared_ptr<DiallingNumbersInfo> diallingNumbers = std::make_shared<DiallingNumbersInfo>();
EXPECT_EQ(iccDiallingNumbersManager.UpdateIccDiallingNumbers(0, diallingNumbers), TELEPHONY_ERR_NO_SIM_CARD);
EXPECT_EQ(iccDiallingNumbersManager.DelIccDiallingNumbers(0, diallingNumbers), TELEPHONY_ERR_NO_SIM_CARD);
EXPECT_EQ(iccDiallingNumbersManager.AddIccDiallingNumbers(0, diallingNumbers), TELEPHONY_ERR_NO_SIM_CARD);
EXPECT_EQ(iccDiallingNumbersManager.GetFileIdForType(DiallingNumbersInfo::SIM_ADN), ELEMENTARY_FILE_ADN);
EXPECT_EQ(iccDiallingNumbersManager.GetFileIdForType(DiallingNumbersInfo::SIM_FDN), ELEMENTARY_FILE_FDN);
EXPECT_EQ(iccDiallingNumbersManager.GetFileIdForType(-1), 0);
EXPECT_TRUE(iccDiallingNumbersManager.IsValidType(DiallingNumbersInfo::SIM_ADN));
EXPECT_TRUE(iccDiallingNumbersManager.IsValidType(DiallingNumbersInfo::SIM_FDN));
EXPECT_FALSE(iccDiallingNumbersManager.IsValidType(-1));
EXPECT_TRUE(iccDiallingNumbersManager.IsValidParam(DiallingNumbersInfo::SIM_ADN, diallingNumbers));
EXPECT_FALSE(iccDiallingNumbersManager.IsValidParam(DiallingNumbersInfo::SIM_FDN, diallingNumbers));
}
HWTEST_F(SimRilBranchTest, Telephony_SimSmsManager, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto simStateManager = std::make_shared<SimStateManager>(telRilManager);
EventFwk::MatchingSkills matchingSkills;
matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
EventFwk::CommonEventSubscribeInfo subcribeInfo(matchingSkills);
auto simFileManager = std::make_shared<SimFileManager>(subcribeInfo, telRilManager, simStateManager);
SimSmsManager simSmsManager1(telRilManager, simFileManager, simStateManager);
simSmsManager1.stateSms_ = SimSmsManager::HandleRunningState::STATE_RUNNING;
simSmsManager1.Init(0);
SimSmsManager simSmsManager2(nullptr, simFileManager, simStateManager);
simSmsManager2.stateSms_ = SimSmsManager::HandleRunningState::STATE_NOT_START;
simSmsManager2.Init(1);
SimSmsManager simSmsManager3(telRilManager, nullptr, simStateManager);
simSmsManager3.stateSms_ = SimSmsManager::HandleRunningState::STATE_NOT_START;
simSmsManager3.Init(1);
EXPECT_EQ(simSmsManager3.smsController_, nullptr);
std::string testPdu = "testPdu";
std::string testSmsc = "testSmsc";
EXPECT_EQ(simSmsManager3.AddSmsToIcc(0, testPdu, testSmsc), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(simSmsManager3.UpdateSmsIcc(0, 0, testPdu, testSmsc), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ(simSmsManager3.DelSmsIcc(0), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_EQ((simSmsManager3.ObtainAllSmsOfIcc()).size(), 0);
}
HWTEST_F(SimRilBranchTest, Telephony_SimSmsController_002, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
std::shared_ptr<Telephony::SimSmsController> simSmsController = std::make_shared<SimSmsController>(simStateManager);
EXPECT_FALSE(simSmsController->loadDone_);
AppExecFwk::InnerEvent::Pointer event(nullptr, nullptr);
ASSERT_EQ(event, nullptr);
simSmsController->ProcessEvent(event);
simSmsController->ProcessLoadDone(event);
simSmsController->ProcessUpdateDone(event);
simSmsController->ProcessWriteDone(event);
simSmsController->ProcessDeleteDone(event);
EXPECT_FALSE(simSmsController->loadDone_);
simSmsController->stateManager_ = std::make_shared<SimStateManager>(telRilManager);
simSmsController->stateManager_->simStateHandle_ = std::make_shared<SimStateHandle>(simStateManager);
simSmsController->stateManager_->simStateHandle_->externalType_ = CardType::SINGLE_MODE_RUIM_CARD;
EXPECT_TRUE(simSmsController->IsCdmaCardType());
}
HWTEST_F(SimRilBranchTest, Telephony_IccFileController_002, Function | MediumTest | Level1)
{
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
int32_t fileSize[] = { 0, 0, 0 };
int32_t testLenNum = 3;
AppExecFwk::InnerEvent::Pointer respone(nullptr, nullptr);
iccFileController->SendEfLinearResult(respone, fileSize, testLenNum);
std::vector<std::string> strValue;
iccFileController->SendMultiRecordResult(respone, strValue);
unsigned char data[] = {0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 1, 1};
iccFileController->ParseFileSize(fileSize, testLenNum, data);
EXPECT_EQ(fileSize[0], 1);
EXPECT_EQ(fileSize[1], 2);
EXPECT_EQ(fileSize[2], 2);
fileSize[2] = 0;
data[SIZE_TWO_OF_FILE] = 1;
data[LENGTH_OF_RECORD] = 0;
iccFileController->ParseFileSize(fileSize, testLenNum, data);
EXPECT_EQ(fileSize[0], 0);
EXPECT_EQ(fileSize[1], 1);
EXPECT_EQ(fileSize[2], 0);
EXPECT_FALSE(iccFileController->IsValidRecordSizeData(data));
EXPECT_FALSE(iccFileController->IsValidBinarySizeData(data));
data[TYPE_OF_FILE] = ICC_ELEMENTARY_FILE;
EXPECT_FALSE(iccFileController->IsValidRecordSizeData(data));
EXPECT_FALSE(iccFileController->IsValidBinarySizeData(data));
data[STRUCTURE_OF_DATA] = 1;
EXPECT_TRUE(iccFileController->IsValidRecordSizeData(data));
data[STRUCTURE_OF_DATA] = ELEMENTARY_FILE_TYPE_TRANSPARENT;
EXPECT_TRUE(iccFileController->IsValidBinarySizeData(data));
EXPECT_STREQ((iccFileController->CheckRightPath("testPath", 0)).c_str(), "testPath");
auto objectUnique = std::make_unique<ControllerToFileMsg>(nullptr, nullptr);
iccFileController->SendEvent(nullptr, 1, true, nullptr, objectUnique);
iccFileController->SendEvent(nullptr, 1, false, nullptr, objectUnique);
}
HWTEST_F(SimRilBranchTest, Telephony_SimStateManager_003, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
auto simStateManagerTwo = std::make_shared<SimStateManager>(telRilManager);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManagerTwo);
simStateManager->simStateHandle_ = simStateHandle;
EXPECT_EQ(simStateManager->SetModemInit(false), TELEPHONY_ERR_SUCCESS);
EXPECT_FALSE(simStateManager->IfModemInitDone());
simStateManager->simStateHandle_ = nullptr;
EXPECT_EQ(simStateManager->SetModemInit(false), TELEPHONY_ERR_LOCAL_PTR_NULL);
EXPECT_FALSE(simStateManager->IfModemInitDone());
LockInfo lockInfo;
lockInfo.lockType = static_cast<LockType>(0);
LockStatusResponse lockStatusResponse;
lockStatusResponse.result = UNLOCK_OK;
EXPECT_EQ(simStateManager->SetLockState(0, lockInfo, lockStatusResponse), TELEPHONY_ERR_ARGUMENT_INVALID);
EXPECT_EQ(lockStatusResponse.result, UNLOCK_FAIL);
lockInfo.lockType = LockType::FDN_LOCK;
EXPECT_EQ(simStateManager->SetLockState(0, lockInfo, lockStatusResponse), TELEPHONY_ERR_ARGUMENT_INVALID);
LockState lockState;
LockType lockType = static_cast<LockType>(0);
EXPECT_EQ(simStateManager->GetLockState(0, lockType, lockState), TELEPHONY_ERR_ARGUMENT_INVALID);
EXPECT_EQ(lockState, LockState::LOCK_ERROR);
lockType = LockType::FDN_LOCK;
EXPECT_EQ(simStateManager->GetLockState(0, lockType, lockState), TELEPHONY_ERR_LOCAL_PTR_NULL);
SimIoRequestInfo simIoRequestInfo;
SimAuthenticationResponse response;
EXPECT_EQ(simStateManager->GetSimIO(0, simIoRequestInfo, response), SIM_AUTH_FAIL);
}
HWTEST_F(SimRilBranchTest, Telephony_StkController_003, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = nullptr;
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
auto stkController = std::make_shared<StkController>(telRilManager, simStateManager, INVALID_SLOTID);
EXPECT_FALSE(stkController->CheckIsBipCmd("01234567890000"));
ASSERT_EQ(TELEPHONY_EXT_WRAPPER.sendEvent_, nullptr);
EXPECT_TRUE(stkController->CheckIsBipCmd("01234567894000"));
EXPECT_TRUE(stkController->CheckIsBipCmd("01234567894300"));
EXPECT_TRUE(stkController->CheckIsBipCmd("01234567894200"));
EXPECT_TRUE(stkController->CheckIsBipCmd("01234567894400"));
EXPECT_TRUE(stkController->CheckIsBipCmd("01234567894100"));
AppExecFwk::InnerEvent::Pointer event(nullptr, nullptr);
stkController->OnSendTerminalResponseResult(event);
stkController->OnSendEnvelopeCmdResult(event);
stkController->OnSendCallSetupRequestResult(event);
}
HWTEST_F(SimRilBranchTest, Telephony_SimStateHandle_003, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->observerHandler_ = std::make_unique<ObserverHandler>();
LockReason reason = LockReason::SIM_NONE;
simStateHandle->SimStateEscape(ICC_CARD_ABSENT, 0, reason);
EXPECT_EQ(simStateHandle->externalState_, SimState::SIM_STATE_NOT_PRESENT);
simStateHandle->SimStateEscape(ICC_CONTENT_READY, 0, reason);
EXPECT_EQ(simStateHandle->externalState_, SimState::SIM_STATE_READY);
simStateHandle->SimStateEscape(ICC_CONTENT_PIN, 0, reason);
EXPECT_EQ(simStateHandle->externalState_, SimState::SIM_STATE_LOCKED);
EXPECT_EQ(reason, LockReason::SIM_PIN);
simStateHandle->SimStateEscape(ICC_CONTENT_PUK, 0, reason);
EXPECT_EQ(simStateHandle->externalState_, SimState::SIM_STATE_LOCKED);
EXPECT_EQ(reason, LockReason::SIM_PUK);
simStateHandle->SimStateEscape(-1, 0, reason);
}
HWTEST_F(SimRilBranchTest, Telephony_SimStateHandle_004, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->observerHandler_ = std::make_unique<ObserverHandler>();
LockReason reason = LockReason::SIM_NONE;
simStateHandle->SimLockStateEscape(ICC_CONTENT_PH_NET_PIN, 0, reason);
EXPECT_EQ(reason, LockReason::SIM_PN_PIN);
simStateHandle->SimLockStateEscape(ICC_CONTENT_PH_NET_PUK, 0, reason);
EXPECT_EQ(reason, LockReason::SIM_PN_PUK);
simStateHandle->SimLockStateEscape(ICC_CONTENT_PH_NET_SUB_PIN, 0, reason);
EXPECT_EQ(reason, LockReason::SIM_PU_PIN);
simStateHandle->SimLockStateEscape(ICC_CONTENT_PH_NET_SUB_PUK, 0, reason);
EXPECT_EQ(reason, LockReason::SIM_PU_PUK);
simStateHandle->SimLockStateEscape(ICC_CONTENT_PH_SP_PIN, 0, reason);
EXPECT_EQ(reason, LockReason::SIM_PP_PIN);
simStateHandle->SimLockStateEscape(ICC_CONTENT_PH_SP_PUK, 0, reason);
EXPECT_EQ(reason, LockReason::SIM_PP_PUK);
simStateHandle->SimLockStateEscape(ICC_CONTENT_UNKNOWN, 0, reason);
EXPECT_EQ(simStateHandle->externalState_, SimState::SIM_STATE_UNKNOWN);
}
HWTEST_F(SimRilBranchTest, Telephony_SimStateHandle_005, Function | MediumTest | Level1)
{
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->observerHandler_ = std::make_unique<ObserverHandler>();
simStateHandle->externalType_ = CardType::UNKNOWN_CARD;
simStateHandle->CardTypeEscape(-1, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::UNKNOWN_CARD);
simStateHandle->CardTypeEscape(ICC_SIM_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::SINGLE_MODE_SIM_CARD);
simStateHandle->CardTypeEscape(ICC_USIM_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::SINGLE_MODE_USIM_CARD);
simStateHandle->CardTypeEscape(ICC_RUIM_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::SINGLE_MODE_RUIM_CARD);
simStateHandle->CardTypeEscape(ICC_CG_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::DUAL_MODE_CG_CARD);
simStateHandle->CardTypeEscape(ICC_DUAL_MODE_ROAMING_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::CT_NATIONAL_ROAMING_CARD);
simStateHandle->CardTypeEscape(ICC_UNICOM_DUAL_MODE_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::CU_DUAL_MODE_CARD);
simStateHandle->CardTypeEscape(ICC_4G_LTE_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::DUAL_MODE_TELECOM_LTE_CARD);
simStateHandle->CardTypeEscape(ICC_UG_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::DUAL_MODE_UG_CARD);
simStateHandle->CardTypeEscape(ICC_IMS_TYPE, 0);
EXPECT_EQ(simStateHandle->externalType_, CardType::SINGLE_MODE_ISIM_CARD);
simStateHandle->UnRegisterCoreNotify(nullptr, RadioEvent::RADIO_SIM_STATE_CHANGE);
simStateHandle->UnRegisterCoreNotify(nullptr, RadioEvent::RADIO_SIM_STATE_READY);
simStateHandle->UnRegisterCoreNotify(nullptr, RadioEvent::RADIO_SIM_STATE_LOCKED);
simStateHandle->UnRegisterCoreNotify(nullptr, RadioEvent::RADIO_SIM_STATE_SIMLOCK);
simStateHandle->UnRegisterCoreNotify(nullptr, RadioEvent::RADIO_CARD_TYPE_CHANGE);
simStateHandle->UnRegisterCoreNotify(nullptr, -1);
}
HWTEST_F(SimRilBranchTest, Telephony_OperatorFileParser, Function | MediumTest | Level1)
{
OperatorFileParser parser;
EXPECT_FALSE(parser.WriteOperatorConfigJson("testName", nullptr));
EXPECT_STREQ((parser.GetOperatorConfigFilePath("")).c_str(), "");
parser.tempConfig_ = {{"valid_key", "{\"name\":\"valid_value\"}"}, {"invalid_key", ""}};
cJSON *root = cJSON_CreateObject();
parser.CreateJsonFromOperatorConfig(root);
EXPECT_NE(cJSON_GetObjectItem(root, "valid_key"), nullptr);
EXPECT_EQ(cJSON_GetObjectItem(root, "invalid_key"), nullptr);
cJSON_Delete(root);
root = nullptr;
OperatorConfig operatorConfig;
parser.ParseArray("testKey", nullptr, operatorConfig);
cJSON *value = cJSON_CreateArray();
ASSERT_NE(value, nullptr);
parser.ParseArray("testKey", value, operatorConfig);
cJSON_Delete(value);
value = nullptr;
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,105 @@
# Copyright (C) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
SOURCE_DIR = "../../../"
ohos_unittest("icc_dialling_numbers_handler_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "icc_dialling_numbers_handler_gtest"
module_out_path = part_name + "/" + test_module
sources = [ "icc_dialling_numbers_handler_gtest.cpp" ]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
group("unittest") {
testonly = true
deps = [ ":icc_dialling_numbers_handler_gtest" ]
}

View File

@ -0,0 +1,197 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include <gtest/gtest.h>
#include <string_ex.h>
#include "core_manager_inner.h"
#include "core_service.h"
#include "icc_dialling_numbers_handler.h"
#include "icc_dialling_numbers_manager.h"
#include "icc_file_controller.h"
#include "icc_operator_privilege_controller.h"
#include "mcc_pool.h"
#include "operator_config_cache.h"
#include "operator_config_loader.h"
#include "parcel.h"
#include "plmn_file.h"
#include "sim_account_manager.h"
#include "sim_data_type.h"
#include "sim_file_controller.h"
#include "sim_manager.h"
#include "sim_rdb_helper.h"
#include "sim_sms_manager.h"
#include "telephony_ext_wrapper.h"
#include "telephony_log_wrapper.h"
#include "usim_dialling_numbers_service.h"
#include "want.h"
#include "sim_constant.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
class DemoHandler : public AppExecFwk::EventHandler {
public:
explicit DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> &runner) : AppExecFwk::EventHandler(runner) {}
virtual ~DemoHandler() {}
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) {}
};
class IccDiallingNumbersHandlerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void IccDiallingNumbersHandlerTest::SetUpTestCase() {}
void IccDiallingNumbersHandlerTest::TearDownTestCase() {}
void IccDiallingNumbersHandlerTest::SetUp() {}
void IccDiallingNumbersHandlerTest::TearDown() {}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_001
* @tc.name test IccDiallingNumbersHandler
* @tc.desc Function test
*/
HWTEST_F(IccDiallingNumbersHandlerTest, Telephony_IccDiallingNumbersHandler_001, Function | MediumTest | Level1)
{
int fileId = 0;
int exId = 1;
int indexNum = 0;
std::string pin2Str = "";
AppExecFwk::InnerEvent::Pointer result = AppExecFwk::InnerEvent::Get(1, 1);
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("test");
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
auto diallingNumberHandler = std::make_shared<IccDiallingNumbersHandler>(iccFileController);
std::shared_ptr<DiallingNumberLoadRequest> loadRequest =
diallingNumberHandler->CreateLoadRequest(fileId, exId, indexNum, pin2Str, result);
ASSERT_NE(loadRequest, nullptr);
}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_002
* @tc.name test IccDiallingNumbersHandler
* @tc.desc Function test
*/
HWTEST_F(IccDiallingNumbersHandlerTest, Telephony_IccDiallingNumbersHandler_002, Function | MediumTest | Level1)
{
int ef = 1;
int exid = 1;
AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(1, 1);
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("test");
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
ASSERT_NE(iccFileController, nullptr);
auto diallingNumberHandler = std::make_shared<IccDiallingNumbersHandler>(iccFileController);
diallingNumberHandler->GetAllDiallingNumbers(ef, exid, response);
}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_003
* @tc.name test IccDiallingNumbersHandler
* @tc.desc Function test
*/
HWTEST_F(IccDiallingNumbersHandlerTest, Telephony_IccDiallingNumbersHandler_003, Function | MediumTest | Level1)
{
int id = 1;
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(1, 1);
ASSERT_NE(event, nullptr);
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("test");
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
auto diallingNumberHandler = std::make_shared<IccDiallingNumbersHandler>(iccFileController);
diallingNumberHandler->ProcessDiallingNumberAllLoadDone(event, id);
}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_004
* @tc.name test IccDiallingNumbersHandler
* @tc.desc Function test
*/
HWTEST_F(IccDiallingNumbersHandlerTest, Telephony_IccDiallingNumbersHandler_004, Function | MediumTest | Level1)
{
int serialId = 1;
int fileId = 0;
int exId = 1;
int indexNum = 0;
std::string pin2Str = "";
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("test");
AppExecFwk::InnerEvent::Pointer pointer = AppExecFwk::InnerEvent::Get(1, 1);
std::shared_ptr<DiallingNumberLoadRequest> loadRequest =
std::make_shared<DiallingNumberLoadRequest>(serialId, fileId, exId, indexNum, pin2Str, pointer);
ASSERT_NE(loadRequest, nullptr);
std::shared_ptr<MultiRecordResult> object = nullptr;
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
auto diallingNumberHandler = std::make_shared<IccDiallingNumbersHandler>(iccFileController);
diallingNumberHandler->ProcessDiallingNumber(loadRequest, object);
}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_005
* @tc.name test IccDiallingNumbersHandler
* @tc.desc Function test
*/
HWTEST_F(IccDiallingNumbersHandlerTest, Telephony_IccDiallingNumbersHandler_005, Function | MediumTest | Level1)
{
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("test");
AppExecFwk::InnerEvent::Pointer pointer = AppExecFwk::InnerEvent::Get(1, 1);
std::shared_ptr<DiallingNumberLoadRequest> loadRequest = nullptr;
std::unique_ptr<FileToControllerMsg> cmdData = pointer->GetUniqueObject<FileToControllerMsg>();
std::shared_ptr<MultiRecordResult> object = std::make_shared<MultiRecordResult>(cmdData.get());
ASSERT_NE(object, nullptr);
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
auto diallingNumberHandler = std::make_shared<IccDiallingNumbersHandler>(iccFileController);
diallingNumberHandler->ProcessDiallingNumber(loadRequest, object);
}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_006
* @tc.name test IccDiallingNumbersHandler
* @tc.desc Function test
*/
HWTEST_F(IccDiallingNumbersHandlerTest, Telephony_IccDiallingNumbersHandler_006, Function | MediumTest | Level1)
{
std::u16string name = u"Hello, world!";
int seqLength = 0;
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("test");
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
auto diallingNumberHandler = std::make_shared<IccDiallingNumbersHandler>(iccFileController);
std::shared_ptr<unsigned char> seqResult = diallingNumberHandler->CreateNameSequence(name, seqLength);
ASSERT_NE(seqResult, nullptr);
}
/**
* @tc.number Telephony_IccDiallingNumbersHandler_007
* @tc.name test IccDiallingNumbersHandler
* @tc.desc Function test
*/
HWTEST_F(IccDiallingNumbersHandlerTest, Telephony_IccDiallingNumbersHandler_007, Function | MediumTest | Level1)
{
std::string number = "12345678910";
int dataLength = 0;
std::shared_ptr<unsigned char> diallingNumber = std::make_shared<unsigned char>(42);;
ASSERT_NE(diallingNumber, nullptr);
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("test");
std::shared_ptr<IccFileController> iccFileController = std::make_shared<SimFileController>(1);
auto diallingNumberHandler = std::make_shared<IccDiallingNumbersHandler>(iccFileController);
diallingNumberHandler->FillNumberFiledForDiallingNumber(diallingNumber, number, dataLength);
}
}
}

View File

@ -0,0 +1,105 @@
# Copyright (C) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
SOURCE_DIR = "../../../"
ohos_unittest("sim_manager_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "sim_manager_gtest"
module_out_path = part_name + "/" + test_module
sources = [ "sim_manager_gtest.cpp" ]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
group("unittest") {
testonly = true
deps = [ ":sim_manager_gtest" ]
}

View File

@ -0,0 +1,131 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include <string>
#include <unistd.h>
#include "sim_manager.h"
#include "core_manager_inner.h"
#include "core_service.h"
#include "core_service_client.h"
#include "enum_convert.h"
#include "operator_config_cache.h"
#include "operator_file_parser.h"
#include "sim_state_type.h"
#include "str_convert.h"
#include "string_ex.h"
#include "tel_profile_util.h"
#include "telephony_ext_wrapper.h"
#include "gtest/gtest.h"
#include "tel_ril_manager.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
class SimManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void SimManagerTest::TearDownTestCase() {}
void SimManagerTest::SetUp() {}
void SimManagerTest::TearDown() {}
void SimManagerTest::SetUpTestCase() {}
/**
* @tc.number Telephony_Sim_SimManager_0100
* @tc.name SimManager
* @tc.desc Function test
*/
HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_001, Function | MediumTest | Level1)
{
int32_t slotId = 0;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
std::shared_ptr<Telephony::SimManager> simManager = std::make_shared<SimManager>(telRilManager);
int32_t ret = simManager->InitTelExtraModule(slotId);
EXPECT_EQ(ret, TELEPHONY_ERROR);
}
/**
* @tc.number Telephony_Sim_SimManager_0200
* @tc.name SimManager
* @tc.desc Function test
*/
HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_002, Function | MediumTest | Level1)
{
int32_t simId = 0;
std::shared_ptr<Telephony::SimManager> simManager = std::make_shared<SimManager>(nullptr);
int32_t ret = simManager->GetDefaultSmsSimId(simId);
EXPECT_EQ(ret, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number Telephony_Sim_SimManager_0300
* @tc.name SimManager
* @tc.desc Function test
*/
HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_003, Function | MediumTest | Level1)
{
int32_t simId = 0;
std::shared_ptr<Telephony::SimManager> simManager = std::make_shared<SimManager>(nullptr);
int32_t ret = simManager->GetDefaultCellularDataSimId(simId);
EXPECT_EQ(ret, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number Telephony_Sim_SimManager_0400
* @tc.name SimManager
* @tc.desc Function test
*/
HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_004, Function | MediumTest | Level1)
{
int32_t slotId = 0;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<Telephony::SimManager> simManager = std::make_shared<SimManager>(telRilManager);
int32_t ret = simManager->UpdateOperatorConfigs(slotId);
EXPECT_EQ(ret, TELEPHONY_ERR_PERMISSION_ERR);
}
/**
* @tc.number Telephony_Sim_SimManager_0500
* @tc.name SimManager
* @tc.desc Function test
*/
HWTEST_F(SimManagerTest, Telephony_Sim_SimManager_005, Function | MediumTest | Level1)
{
int32_t slotId = 0;
int32_t command = 0;
int32_t fileId = 0;
std::string data = "ABCDEFG";
std::string path = "";
SimAuthenticationResponse mResponse;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<Telephony::SimManager> simManager = std::make_shared<SimManager>(telRilManager);
int32_t ret = simManager->GetSimIO(slotId, command, fileId, data, path, mResponse);
EXPECT_EQ(ret, TELEPHONY_ERR_NO_SIM_CARD);
}
}
}

View File

@ -0,0 +1,105 @@
# Copyright (C) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
SOURCE_DIR = "../../../"
ohos_unittest("sim_state_handle_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "sim_state_handle_gtest"
module_out_path = part_name + "/" + test_module
sources = [ "sim_state_handle_gtest.cpp" ]
include_dirs = [
"$SOURCE_DIR/services/core/include",
"$SOURCE_DIR/utils/log/include",
"$SOURCE_DIR/utils/preferences/include",
"$SOURCE_DIR/services/sim/include",
"$SOURCE_DIR/services/network_search/include",
"$SOURCE_DIR/services/tel_ril/include",
"$SOURCE_DIR/services/telephony_ext_wrapper/include",
]
configs = [ "$SOURCE_DIR/utils:telephony_log_config" ]
deps = [
"$SOURCE_DIR:tel_core_service",
"$SOURCE_DIR/interfaces/innerkits:tel_core_service_api",
"$SOURCE_DIR/utils:libtel_common",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_manager",
"ability_runtime:data_ability_helper",
"ability_runtime:wantagent_innerkits",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"cJSON:cjson",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"config_policy:configpolicy_util",
"core_service:libtel_vcard",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_ext:net_tether_manager_if",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
if (defined(global_parts_info) &&
defined(global_parts_info.location_location) &&
global_parts_info.location_location) {
external_deps += [
"location:lbsservice_common",
"location:locator_sdk",
]
defines += [ "ABILITY_LOCATION_SUPPORT" ]
}
cflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
"-fvisibility=hidden",
]
ldflags = [
"-flto",
"-fsanitize=cfi",
"-fsanitize-cfi-cross-dso",
]
}
group("unittest") {
testonly = true
deps = [ ":sim_state_handle_gtest" ]
}

View File

@ -0,0 +1,244 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include <gtest/gtest.h>
#include <string_ex.h>
#include "core_manager_inner.h"
#include "core_service.h"
#include "icc_dialling_numbers_handler.h"
#include "icc_dialling_numbers_manager.h"
#include "icc_file_controller.h"
#include "icc_operator_privilege_controller.h"
#include "mcc_pool.h"
#include "operator_config_cache.h"
#include "operator_config_loader.h"
#include "parcel.h"
#include "plmn_file.h"
#include "sim_account_manager.h"
#include "sim_data_type.h"
#include "sim_file_controller.h"
#include "sim_manager.h"
#include "sim_rdb_helper.h"
#include "sim_sms_manager.h"
#include "telephony_ext_wrapper.h"
#include "telephony_log_wrapper.h"
#include "usim_dialling_numbers_service.h"
#include "want.h"
#include "sim_constant.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
class DemoHandler : public AppExecFwk::EventHandler {
public:
explicit DemoHandler(std::shared_ptr<AppExecFwk::EventRunner> &runner) : AppExecFwk::EventHandler(runner) {}
virtual ~DemoHandler() {}
void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) {}
};
class SimStateHandleTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void SimStateHandleTest::SetUpTestCase() {}
void SimStateHandleTest::TearDownTestCase() {}
void SimStateHandleTest::SetUp() {}
void SimStateHandleTest::TearDown() {}
/**
* @tc.number Telephony_SimStateHandle_001
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_001, Function | MediumTest | Level1)
{
int32_t slotId = 0;
LockInfo options;
options.lockType = LockType::PIN_LOCK;
options.lockState = LockState::LOCK_OFF;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<ITelRilManager> telRilManager1 = std::make_shared<TelRilManager>();
std::weak_ptr<Telephony::ITelRilManager> weakTelRilManager = telRilManager1;
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->SetRilManager(weakTelRilManager);
auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_ENABLE_PIN_DONE);
ASSERT_NE(event, nullptr);
simStateHandle->SetLockState(slotId, options);
}
/**
* @tc.number Telephony_SimStateHandle_002
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_002, Function | MediumTest | Level1)
{
int32_t slotId = 0;
LockInfo options;
options.lockType = LockType::FDN_LOCK;
options.lockState = LockState::LOCK_ON;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<ITelRilManager> telRilManager1 = nullptr;
std::weak_ptr<Telephony::ITelRilManager> weakTelRilManager = telRilManager1;
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->SetRilManager(weakTelRilManager);
auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_ENABLE_PIN_DONE);
ASSERT_NE(event, nullptr);
simStateHandle->SetLockState(slotId, options);
}
/**
* @tc.number Telephony_SimStateHandle_003
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_003, Function | MediumTest | Level1)
{
int32_t slotId = 0;
LockType lockType = LockType::PIN_LOCK;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<ITelRilManager> telRilManager1 = std::make_shared<TelRilManager>();
std::weak_ptr<Telephony::ITelRilManager> weakTelRilManager = telRilManager1;
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->SetRilManager(weakTelRilManager);
auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_CHECK_PIN_DONE);
ASSERT_NE(event, nullptr);
simStateHandle->GetLockState(slotId, lockType);
}
/**
* @tc.number Telephony_SimStateHandle_004
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_004, Function | MediumTest | Level1)
{
int32_t slotId = 0;
LockType lockType = LockType::FDN_LOCK;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<ITelRilManager> telRilManager1 = nullptr;
std::weak_ptr<Telephony::ITelRilManager> weakTelRilManager = telRilManager1;
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->SetRilManager(weakTelRilManager);
auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_CHECK_PIN_DONE);
ASSERT_NE(event, nullptr);
simStateHandle->GetLockState(slotId, lockType);
}
/**
* @tc.number Telephony_SimStateHandle_005
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_005, Function | MediumTest | Level1)
{
int32_t slotId = 0;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
int32_t ret = simStateHandle->IsSatelliteSupported();
EXPECT_EQ(ret, 1);
simStateHandle->UnregisterSatelliteCallback();
}
/**
* @tc.number Telephony_SimStateHandle_006
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_006, Function | MediumTest | Level1)
{
int32_t slotId = 0;
SimIoRequestInfo requestInfo;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<ITelRilManager> telRilManager1 = std::make_shared<TelRilManager>();
std::weak_ptr<Telephony::ITelRilManager> weakTelRilManager = telRilManager1;
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->SetRilManager(weakTelRilManager);
auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_GET_SIM_IO_DONE);
ASSERT_NE(event, nullptr);
int32_t ret = simStateHandle->GetSimIO(slotId, requestInfo);
EXPECT_EQ(ret, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number Telephony_SimStateHandle_007
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_007, Function | MediumTest | Level1)
{
int32_t slotId = 0;
SimIoRequestInfo requestInfo;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<ITelRilManager> telRilManager1 = nullptr;
std::weak_ptr<Telephony::ITelRilManager> weakTelRilManager = telRilManager1;
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->SetRilManager(weakTelRilManager);
auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_GET_SIM_IO_DONE);
ASSERT_NE(event, nullptr);
int32_t ret = simStateHandle->GetSimIO(slotId, requestInfo);
EXPECT_EQ(ret, SIM_AUTH_FAIL);
}
/**
* @tc.number Telephony_SimStateHandle_008
* @tc.name test SimStateHandle
* @tc.desc Function test
*/
HWTEST_F(SimStateHandleTest, Telephony_SimStateHandle_008, Function | MediumTest | Level1)
{
int32_t slotId = 0;
std::shared_ptr<TelRilManager> telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
std::shared_ptr<Telephony::SimStateManager> simStateManager = std::make_shared<SimStateManager>(telRilManager);
simStateManager->Init(slotId);
AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(1, 1);
ASSERT_NE(event, nullptr);
auto simStateHandle = std::make_shared<SimStateHandle>(simStateManager);
simStateHandle->GetSimIOResult(slotId, event);
}
}
}

View File

@ -24,7 +24,9 @@ ohos_unittest("tel_ril_gtest") {
sources = [
"$SOURCE_DIR/frameworks/native/src/i_network_search_callback_stub.cpp",
"tel_ril_call_test.cpp",
"tel_ril_common_test.cpp",
"tel_ril_data_test.cpp",
"tel_ril_handler_test.cpp",
"tel_ril_modem_test.cpp",
"tel_ril_network_test.cpp",
"tel_ril_sim_test.cpp",

View File

@ -0,0 +1,574 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include "gtest/gtest.h"
#include "tel_event_handler.h"
#include "tel_ril_callback.h"
#include "tel_ril_handler.h"
#include "tel_ril_manager.h"
#include "sim_data_type.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
class TelRilCommonTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void TelRilCommonTest::SetUpTestCase() {}
void TelRilCommonTest::TearDownTestCase() {}
void TelRilCommonTest::SetUp() {}
void TelRilCommonTest::TearDown() {}
/**
* @tc.number TelRilModem_BuildVoiceRadioTechnology_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilModem_BuildVoiceRadioTechnology_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilModem = std::make_shared<TelRilModem>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::VoiceRadioTechnology voiceRadioTechnology;
std::shared_ptr<VoiceRadioTechnology> mVoiceRadioTechnology = std::make_shared<VoiceRadioTechnology>();
telRilModem->BuildVoiceRadioTechnology(voiceRadioTechnology, mVoiceRadioTechnology);
}
/**
* @tc.number TelRilManager_ConnectRilInterface_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilManager_ConnectRilInterface_001, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
telRilManager->rilInterface_ = nullptr;
auto result = telRilManager->ConnectRilInterface();
telRilManager->OnInit();
telRilManager->ReduceRunningLock();
ASSERT_EQ(result, true);
}
/**
* @tc.number TelRilManager_InitTelExtraModule_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilManager_InitTelExtraModule_001, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
auto result = telRilManager->InitTelExtraModule(0);
ASSERT_EQ(result, TELEPHONY_ERROR);
telRilManager->telRilCall_.clear();
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
for (int i = 0; i < SIM_SLOT_3; i++) {
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(i, rilInterface, observerHandler, telRilManager->handler_);
telRilManager->telRilCall_.push_back(telRilCall);
}
telRilManager->InitTelExtraModule(SIM_SLOT_2);
ASSERT_EQ(result, TELEPHONY_SUCCESS);
}
/**
* @tc.number TelRilManager_GetObserverHandler_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilManager_GetObserverHandler_001, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
auto result = telRilManager->GetObserverHandler(-1);
ASSERT_EQ(result, nullptr);
telRilManager->observerHandler_.clear();
result = telRilManager->GetObserverHandler(SIM_SLOT_2);
ASSERT_EQ(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexCharToInt_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexCharToInt_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t ch = 'a';
uint8_t expected = 10;
uint8_t actual = telRilSms->ConvertHexCharToInt(ch);
EXPECT_EQ(expected, actual);
}
/**
* @tc.number TelRilSms_ConvertHexCharToInt_002
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexCharToInt_002, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t ch = 'A';
uint8_t expected = 10;
uint8_t actual = telRilSms->ConvertHexCharToInt(ch);
EXPECT_EQ(expected, actual);
}
/**
* @tc.number TelRilSms_ConvertHexCharToInt_003
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexCharToInt_003, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t ch = '5';
uint8_t expected = 5;
uint8_t actual = telRilSms->ConvertHexCharToInt(ch);
EXPECT_EQ(expected, actual);
}
/**
* @tc.number TelRilSms_ConvertHexCharToInt_004
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexCharToInt_004, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t ch = 'g';
uint8_t expected = INVALID_HEX_CHAR;
uint8_t actual = telRilSms->ConvertHexCharToInt(ch);
EXPECT_EQ(expected, actual);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "12345";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_EQ(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_002
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_002, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_EQ(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_003
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_003, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "123456";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_NE(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_004
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_004, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "12345g";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_EQ(result, nullptr);
}
/**
* @tc.number TelRilSms_ConvertHexStringToBytes_005
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_ConvertHexStringToBytes_005, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
uint8_t hexString[] = "123456";
uint8_t *result = telRilSms->ConvertHexStringToBytes(hexString, sizeof(hexString) - 1);
ASSERT_NE(result, nullptr);
}
/**
* @tc.number TelRilSms_GetSmscAddrResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_GetSmscAddrResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
HDI::Ril::V1_1::ServiceCenterAddress serviceCenterAddress;
int32_t result = telRilSms->GetSmscAddrResponse(responseInfo, serviceCenterAddress);
ASSERT_NE(result, 1);
}
/**
* @tc.number TelRilSms_GetCBConfigResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_GetCBConfigResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
HDI::Ril::V1_1::CBConfigInfo cellBroadcastInfo;
int32_t result = telRilSms->GetCBConfigResponse(responseInfo, cellBroadcastInfo);
ASSERT_NE(result, 1);
}
/**
* @tc.number TelRilSms_GetCdmaCBConfigResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSms_GetCdmaCBConfigResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSms = std::make_shared<TelRilSms>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
HDI::Ril::V1_1::CdmaCBConfigInfo cdmaCBConfigInfo;
int32_t result = telRilSms->GetCdmaCBConfigResponse(responseInfo, cdmaCBConfigInfo);
ASSERT_NE(result, 1);
}
/**
* @tc.number TelRilSim_ErrorIccIoResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSim_ErrorIccIoResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSim = std::make_shared<TelRilSim>(0, rilInterface, observerHandler, nullptr);
RadioResponseInfo responseInfo;
auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_DIAL);
auto telRilRequest = std::make_shared<TelRilRequest>(0, event);
int32_t result = telRilSim->ErrorIccIoResponse(telRilRequest, responseInfo);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
std::shared_ptr<IccControllerHolder> holder = nullptr;
std::unique_ptr<Telephony::IccFromRilMsg> object = std::make_unique<Telephony::IccFromRilMsg>(holder);
event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_DIAL, object);
telRilRequest = std::make_shared<TelRilRequest>(0, event);
result = telRilSim->ErrorIccIoResponse(telRilRequest, responseInfo);
ASSERT_NE(result, TELEPHONY_ERR_SUCCESS);
event = nullptr;
telRilRequest = std::make_shared<TelRilRequest>(0, event);
result = telRilSim->ErrorIccIoResponse(telRilRequest, responseInfo);
ASSERT_EQ(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number TelRilSim_ProcessIccIoInfo_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSim_ProcessIccIoInfo_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSim = std::make_shared<TelRilSim>(0, rilInterface, observerHandler, nullptr);
std::shared_ptr<IccIoResultInfo> iccIoResult = std::make_shared<IccIoResultInfo>();;
std::shared_ptr<IccControllerHolder> holder = nullptr;
std::unique_ptr<Telephony::IccFromRilMsg> object = std::make_unique<Telephony::IccFromRilMsg>(holder);
auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_DIAL, object);
auto telRilRequest = std::make_shared<TelRilRequest>(0, event);
int32_t result = telRilSim->ProcessIccIoInfo(telRilRequest, iccIoResult);
ASSERT_NE(result, TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number TelRilSim_ProcessIccIoInfo_002
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSim_ProcessIccIoInfo_002, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilSim = std::make_shared<TelRilSim>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::IccIoResultInfo iccIoResultInfo;
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
responseInfo.serial = 1;
responseInfo.error = HDI::Ril::V1_1::RilErrType::NONE;
auto event = AppExecFwk::InnerEvent::Get(1, 1);
telRilSim->CreateTelRilRequest(event);
auto result = telRilSim->ResponseIccIo(responseInfo, iccIoResultInfo);
ASSERT_NE(result, TELEPHONY_ERR_SUCCESS);
responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_GENERIC_FAILURE;
event = AppExecFwk::InnerEvent::Get(1, 1);
telRilSim->CreateTelRilRequest(event);
telRilSim->ResponseIccIo(responseInfo, iccIoResultInfo);
ASSERT_NE(result, 0);
}
/**
* @tc.number TelRilData_GetPdpContextListResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilData_GetPdpContextListResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilData = std::make_unique<TelRilData>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::SetupDataCallResultInfo setupDataCallResultInfo;
HDI::Ril::V1_1::DataCallResultList dataCallResultList;
dataCallResultList.dcList.push_back(setupDataCallResultInfo);
dataCallResultList.size = 1;
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
auto result = telRilData->GetPdpContextListResponse(responseInfo, dataCallResultList);
ASSERT_NE(result, TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number TelRilData_PdpContextListUpdated_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilData_PdpContextListUpdated_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilData = std::make_unique<TelRilData>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::SetupDataCallResultInfo setupDataCallResultInfo;
HDI::Ril::V1_1::DataCallResultList dataCallResultList;
dataCallResultList.dcList.push_back(setupDataCallResultInfo);
dataCallResultList.size = 1;
auto result = telRilData->PdpContextListUpdated(dataCallResultList);
ASSERT_EQ(result, TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number TelRilData_GetLinkBandwidthInfoResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilData_GetLinkBandwidthInfoResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilData = std::make_unique<TelRilData>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::DataLinkBandwidthInfo dataLinkBandwidthInfo;
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
auto result = telRilData->GetLinkBandwidthInfoResponse(responseInfo, dataLinkBandwidthInfo);
ASSERT_NE(result, TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number TelRilCallback_CommonErrorResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilCallback_CommonErrorResponse_001, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
auto telRilCallback = std::make_shared<TelRilCallback>(telRilManager);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
EXPECT_EQ(telRilCallback->CommonErrorResponse(responseInfo), TELEPHONY_ERR_SUCCESS);
}
/**
* @tc.number TelRilCall_GetCallListResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilCall_GetCallListResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_GENERIC_FAILURE;
HDI::Ril::V1_1::CallInfoList callInfoList;
auto result = telRilCall->GetCallListResponse(responseInfo, callInfoList);
EXPECT_EQ(result, TELEPHONY_ERR_ARGUMENT_INVALID);
}
/**
* @tc.number TelRilCall_GetCallWaitingResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilCall_GetCallWaitingResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_GENERIC_FAILURE;
HDI::Ril::V1_1::CallWaitResult callWaitResult;
auto result = telRilCall->GetCallWaitingResponse(responseInfo, callWaitResult);
EXPECT_EQ(result, TELEPHONY_ERR_ARGUMENT_INVALID);
}
/**
* @tc.number TelRilCall_GetCallTransferInfoResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilCall_GetCallTransferInfoResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_GENERIC_FAILURE;
HDI::Ril::V1_1::CallForwardQueryInfoList cFQueryList;
auto result = telRilCall->GetCallTransferInfoResponse(responseInfo, cFQueryList);
EXPECT_EQ(result, TELEPHONY_ERR_ARGUMENT_INVALID);
}
/**
* @tc.number TelRilCall_GetClipResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilCall_GetClipResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_GENERIC_FAILURE;
HDI::Ril::V1_1::GetClipResult getClipResult;
auto result = telRilCall->GetClipResponse(responseInfo, getClipResult);
EXPECT_EQ(result, TELEPHONY_ERR_ARGUMENT_INVALID);
}
/**
* @tc.number TelRilCall_GetCallRestrictionResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilCall_GetCallRestrictionResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
responseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_GENERIC_FAILURE;
HDI::Ril::V1_1::CallRestrictionResult callRestrictionResult;
auto result = telRilCall->GetCallRestrictionResponse(responseInfo, callRestrictionResult);
EXPECT_EQ(result, TELEPHONY_ERR_ARGUMENT_INVALID);
}
/**
* @tc.number TelRilSim_SendDtmfResponse_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSim_SendDtmfResponse_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
auto event = AppExecFwk::InnerEvent::Get(1, 1);
telRilCall->CreateTelRilRequest(event);
HDI::Ril::V1_1::RilRadioResponseInfo responseInfo;
responseInfo.serial = 1;
auto result = telRilCall->SendDtmfResponse(responseInfo);
ASSERT_NE(result, 1);
event = nullptr;
telRilCall->CreateTelRilRequest(event);
result = telRilCall->SendDtmfResponse(responseInfo);
ASSERT_NE(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number TelRilSim_CallUssdNotice_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSim_CallUssdNotice_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::UssdNoticeInfo ussdNoticeInfo;
auto result = telRilCall->CallUssdNotice(ussdNoticeInfo);
ASSERT_NE(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
/**
* @tc.number TelRilSim_ResponseSupplement_001
* @tc.name test error branch
* @tc.desc Function test
*/
HWTEST_F(TelRilCommonTest, TelRilSim_ResponseSupplement_001, Function | MediumTest | Level1)
{
auto rilInterface = HDI::Ril::V1_3::IRil::Get();
std::shared_ptr<ObserverHandler> observerHandler = std::make_shared<ObserverHandler>();
auto telRilCall = std::make_shared<TelRilCall>(0, rilInterface, observerHandler, nullptr);
HDI::Ril::V1_1::RilRadioResponseInfo rilRadioResponseInfo;
rilRadioResponseInfo.error = HDI::Ril::V1_1::RilErrType::RIL_ERR_GENERIC_FAILURE;
auto result = telRilCall->ResponseSupplement(TELEPHONY_LOG_FUNC_NAME, rilRadioResponseInfo);
ASSERT_NE(result, TELEPHONY_ERR_LOCAL_PTR_NULL);
}
} // namespace Telephony
} // namespace OHOS

View File

@ -0,0 +1,125 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include "gtest/gtest.h"
#include "tel_ril_handler.h"
#include "tel_ril_manager.h"
#include "tel_event_handler.h"
namespace OHOS {
namespace Telephony {
using namespace testing::ext;
class TelRilHandlerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void TelRilHandlerTest::SetUpTestCase() {}
void TelRilHandlerTest::TearDownTestCase() {}
void TelRilHandlerTest::SetUp() {}
void TelRilHandlerTest::TearDown() {}
/**
* @tc.number Telephony_tel_ril_manager_001
* @tc.name test function branch
* @tc.desc Function test
*/
HWTEST_F(TelRilHandlerTest, Telephony_tel_ril_handler_001, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
auto event = AppExecFwk::InnerEvent::Get(0);
event = nullptr;
telRilManager->handler_->ProcessEvent(event);
event = AppExecFwk::InnerEvent::Get(-1);
ASSERT_NE(telRilManager->handler_->reqRunningLockCount_, 0);
}
/**
* @tc.number Telephony_tel_ril_handler_002
* @tc.name test function branch
* @tc.desc Function test
*/
HWTEST_F(TelRilHandlerTest, Telephony_tel_ril_handler_002, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
#ifdef ABILITY_POWER_SUPPORT
telRilManager->handler_->ackRunningLock_ = nullptr;
telRilManager->handler_->reqRunningLock_ = nullptr;
#endif
int32_t lockType = 100;
telRilManager->handler_->ApplyRunningLock(lockType);
ASSERT_NE(telRilManager->handler_->ackLockSerialNum_, 0);
}
/**
* @tc.number Telephony_tel_ril_handler_003
* @tc.name test function branch
* @tc.desc Function test
*/
HWTEST_F(TelRilHandlerTest, Telephony_tel_ril_handler_003, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
int32_t lockType = TelRilHandler::NORMAL_RUNNING_LOCK;
telRilManager->handler_->ReduceRunningLock(lockType);
ASSERT_NE(telRilManager->handler_->reqRunningLockCount_, 0);
lockType = TelRilHandler::ACK_RUNNING_LOCK;
telRilManager->handler_->ReduceRunningLock(lockType);
ASSERT_NE(telRilManager->handler_->reqRunningLockCount_, 0);
#ifdef ABILITY_POWER_SUPPORT
telRilManager->handler_->reqRunningLock_ = nullptr;
#endif
lockType = TelRilHandler::NORMAL_RUNNING_LOCK;
telRilManager->handler_->ReduceRunningLock(lockType);
ASSERT_NE(telRilManager->handler_->reqRunningLockCount_, 0);
lockType = TelRilHandler::ACK_RUNNING_LOCK;
telRilManager->handler_->ReduceRunningLock(lockType);
ASSERT_NE(telRilManager->handler_->reqRunningLockCount_, 0);
}
/**
* @tc.number Telephony_tel_ril_handler_004
* @tc.name test function branch
* @tc.desc Function test
*/
HWTEST_F(TelRilHandlerTest, Telephony_tel_ril_handler_004, Function | MediumTest | Level1)
{
auto telRilManager = std::make_shared<TelRilManager>();
telRilManager->OnInit();
int32_t lockType = TelRilHandler::NORMAL_RUNNING_LOCK;
telRilManager->handler_->ReleaseRunningLock(lockType);
#ifdef ABILITY_POWER_SUPPORT
telRilManager->handler_->ackRunningLock_ = nullptr;
#endif
telRilManager->handler_->ReleaseRunningLock(lockType);
ASSERT_NE(telRilManager->handler_->reqRunningLockCount_, 0);
#ifdef ABILITY_POWER_SUPPORT
telRilManager->handler_->reqRunningLock_ = nullptr;
#endif
telRilManager->handler_->ReleaseRunningLock(lockType);
ASSERT_NE(telRilManager->handler_->reqRunningLockCount_, 0);
}
} // namespace Telephony
} // namespace OHOS

View File

@ -159,18 +159,35 @@ HWTEST_F(TelRilBranchTest, Telephony_tel_ril_Network_001, Function | MediumTest
HDI::Ril::V1_1::CellNearbyInfo info;
for (info.ratType = 0; info.ratType <= RAT_TYPE; info.ratType++) {
telRilNetwork->FillCellNearbyInfo(cellInfo, info);
EXPECT_EQ(cellInfo.ratType, info.ratType);
}
CellNearbyInfo cellInfo1;
HDI::Ril::V1_2::CellNearbyInfo_1_2 info1;
for (info.ratType = 0; info1.ratType <= RAT_TYPE; info1.ratType++) {
telRilNetwork->FillCellNearbyInfo(cellInfo1, info1);
EXPECT_EQ(cellInfo1.ratType, info1.ratType);
}
CurrentCellInfo currentCellInfo;
HDI::Ril::V1_1::CurrentCellInfo CurrentInfo;
for (info.ratType = 0; info.ratType <= RAT_TYPE; info.ratType++) {
for (info.ratType = 0; CurrentInfo.ratType <= RAT_TYPE; CurrentInfo.ratType++) {
telRilNetwork->FillCurrentCellInfo(currentCellInfo, CurrentInfo);
EXPECT_EQ(currentCellInfo.ratType, CurrentInfo.ratType);
}
CurrentCellInformation currentCellInformation;
HDI::Ril::V1_1::CurrentCellInfo_1_1 currentInformation;
for (info.ratType = 0; info.ratType <= RAT_TYPE; info.ratType++) {
for (info.ratType = 0; currentInformation.ratType <= RAT_TYPE; currentInformation.ratType++) {
telRilNetwork->FillCurrentCellInformation(currentCellInformation, currentInformation);
EXPECT_EQ(currentCellInformation.ratType, currentInformation.ratType);
}
CurrentCellInformation currentCellInformation1;
HDI::Ril::V1_2::CurrentCellInfo_1_2 currentInformation1;
for (info.ratType = 0; currentInformation1.ratType <= RAT_TYPE; currentInformation1.ratType++) {
telRilNetwork->FillCurrentCellInformation(currentCellInformation1, currentInformation1);
EXPECT_EQ(currentCellInformation1.ratType, currentInformation1.ratType);
}
}

View File

@ -0,0 +1,68 @@
# Copyright (C) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
SOURCE_DIR = "../../../"
ohos_unittest("utils_vcard_gtest") {
install_enable = true
subsystem_name = "telephony"
part_name = "core_service"
test_module = "utils_vcard_gtest"
module_out_path = part_name + "/" + test_module
sources = [ "contact_data_test.cpp" ]
include_dirs = [
"$SOURCE_DIR/interfaces/innerkits/include",
"$SOURCE_DIR/utils/vcard/include",
"$SOURCE_DIR/utils/vcard/include/contact_data",
]
deps = [
"$SOURCE_DIR/utils:libtel_vcard",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"data_share:datashare_common",
"data_share:datashare_consumer",
"drivers_interface_ril:libril_proxy_1.1",
"drivers_interface_ril:libril_proxy_1.2",
"drivers_interface_ril:libril_proxy_1.3",
"drivers_interface_ril:ril_idl_headers",
"eventhandler:libeventhandler",
"hdf_core:libhdi",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_single",
"power_manager:powermgr_client",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
defines = [
"TELEPHONY_LOG_TAG = \"CoreServiceGtest\"",
"LOG_DOMAIN = 0xD000F00",
]
# defines += [ "TEL_TEST_PIN_PUK" ]
}
group("unittest") {
testonly = true
deps = [ ":utils_vcard_gtest" ]
}

View File

@ -0,0 +1,789 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define private public
#define protected public
#include "vcard_email_data.h"
#include "vcard_event_data.h"
#include "vcard_im_data.h"
#include "vcard_manager.h"
#include "vcard_name_data.h"
#include "vcard_nickname_data.h"
#include "vcard_note_data.h"
#include "vcard_organization_data.h"
#include "vcard_phone_data.h"
#include "vcard_photo_data.h"
#include "vcard_postal_data.h"
#include "vcard_relation_data.h"
#include "vcard_contact.h"
#include "vcard_constant.h"
#include "vcard_decoder_v21.h"
#include "vcard_decoder_v30.h"
#include "vcard_decoder_v40.h"
#include "vcard_encoder.h"
#include "vcard_utils.h"
#include "telephony_errors.h"
#include <fcntl.h>
#include <iostream>
#include <gtest/gtest.h>
using namespace testing::ext;
namespace OHOS {
namespace Telephony {
#ifndef TEL_TEST_UNSUPPORT
class ContactDataTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
void SetNameData(const std::string &family, const std::string &given, const std::string &middle,
const std::string &prefix, const std::string &suffix);
void SetNameDataInfo(const std::string &phoneticFamily, const std::string &phoneticGiven,
const std::string &phoneticMiddle);
};
void ContactDataTest::SetUpTestCase() {}
void ContactDataTest::TearDownTestCase() {}
void ContactDataTest::SetUp() {}
void ContactDataTest::TearDown() {}
std::shared_ptr<VCardNameData> nameData_ = std::make_shared<VCardNameData>();
std::shared_ptr<VCardContact> contact_ = std::make_shared<VCardContact>();
void ContactDataTest::SetNameData(const std::string &family, const std::string &given, const std::string &middle,
const std::string &prefix, const std::string &suffix)
{
nameData_->SetFamily(family);
nameData_->SetGiven(given);
nameData_->SetMiddle(middle);
nameData_->SetPrefix(prefix);
nameData_->SetSuffix(suffix);
}
void ContactDataTest::SetNameDataInfo(const std::string &phoneticFamily, const std::string &phoneticGiven,
const std::string &phoneticMiddle)
{
nameData_->SetPhoneticFamily(phoneticFamily);
nameData_->SetPhoneticGiven(phoneticGiven);
nameData_->SetPhoneticMiddle(phoneticMiddle);
}
HWTEST_F(ContactDataTest, VCardEmailData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardEmailData emailData;
EXPECT_EQ(emailData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(emailData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardEventData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardEventData eventData;
EXPECT_EQ(eventData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(eventData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardImData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardImData imData;
EXPECT_EQ(imData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(imData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardNameData_BuildValuesBucket, Function | MediumTest | Level3)
{
DataShare::DataShareValuesBucket valuesBucket;
std::string family = "";
std::string given = "";
std::string middle = "";
std::string prefix = "";
std::string suffix = "";
std::string phoneticGiven = "";
std::string phoneticFamily = "";
std::string phoneticMiddle = "";
SetNameData(family, given, middle, prefix, suffix);
SetNameDataInfo(phoneticGiven, phoneticFamily, phoneticMiddle);
EXPECT_EQ(nameData_->BuildValuesBucket(valuesBucket), TELEPHONY_SUCCESS);
family = "family";
given = "given";
middle = "middle";
prefix = "prefix";
suffix = "suffix";
phoneticGiven = "phoneticGiven";
phoneticFamily = "phoneticFamily";
phoneticMiddle = "phoneticMiddle";
SetNameData(family, given, middle, prefix, suffix);
SetNameDataInfo(phoneticGiven, phoneticFamily, phoneticMiddle);
EXPECT_EQ(nameData_->BuildValuesBucket(valuesBucket), TELEPHONY_SUCCESS);
}
HWTEST_F(ContactDataTest, VCardNameData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardNameData nameData;
EXPECT_EQ(nameData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(nameData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardNicknameData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardNicknameData nickNameData;
EXPECT_EQ(nickNameData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(nickNameData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardNoteData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardNoteData noteData;
EXPECT_EQ(noteData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(noteData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardOrganizationData_BuildValuesBucket, Function | MediumTest | Level3)
{
VCardOrganizationData organizationData;
DataShare::DataShareValuesBucket valuesBucket;
std::string organization = "";
std::string departmentName = "";
std::string company = "";
std::string title = "";
std::string phoneticName = "";
int32_t type = 0;
organizationData.InitOrganizationData(organization, departmentName, company, phoneticName, title, type);
EXPECT_EQ(organizationData.BuildValuesBucket(valuesBucket), TELEPHONY_SUCCESS);
company = "company";
title = "title";
organizationData.InitOrganizationData(organization, departmentName, company, phoneticName, title, type);
EXPECT_EQ(organizationData.BuildValuesBucket(valuesBucket), TELEPHONY_SUCCESS);
}
HWTEST_F(ContactDataTest, VCardOrganizationData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardOrganizationData organizationData;
EXPECT_EQ(organizationData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(organizationData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardPhoneData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardPhoneData phoneData;
EXPECT_EQ(phoneData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(phoneData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardPhotoData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardPhotoData photoData;
EXPECT_EQ(photoData.BuildData(resultSet), TELEPHONY_SUCCESS);
EXPECT_EQ(photoData.BuildData(nullptr), TELEPHONY_ERROR);
}
HWTEST_F(ContactDataTest, VCardContact_AddRawData, Function | MediumTest | Level3)
{
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
int32_t errorCode = 0;
contact_->AddRawData(nullptr, errorCode);
rawData->SetName("Name");
rawData->SetRawValue("RawValue");
rawData->SetByte("");
rawData->SetValues({});
rawData->AppendGroup({});
contact_->AddRawData(rawData, errorCode);
EXPECT_EQ((rawData->GetValue()).size(), 0);
EXPECT_TRUE((rawData->GetByte()).empty());
rawData->SetValues({"Value1", "Value2"});
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_TRUE((rawData->GetByte()).empty());
rawData->SetByte("Byte");
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
rawData->SetValues({});
rawData->SetByte("Byte");
contact_->AddRawData(rawData, errorCode);
EXPECT_EQ((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
}
HWTEST_F(ContactDataTest, VCardContact_AddDatas001, Function | MediumTest | Level3)
{
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
int32_t errorCode = 0;
rawData->SetName("Name");
rawData->SetRawValue("RawValue");
rawData->SetByte("Byte");
rawData->SetValues({"Value1", "Value2"});
rawData->AppendGroup({"Group"});
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
rawData->SetName(VCARD_TYPE_VERSION);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_FN);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_NAME);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_N);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_SORT_STRING);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_PHONETIC_FIRST_NAME);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_PHONETIC_LAST_NAME);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_PHONETIC_MIDDLE_NAME);
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
}
HWTEST_F(ContactDataTest, VCardContact_AddDatas002, Function | MediumTest | Level3)
{
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
int32_t errorCode = 0;
rawData->SetName(VCARD_TYPE_NICKNAME);
rawData->SetRawValue("RawValue");
rawData->SetByte("Byte");
rawData->SetValues({"Value1", "Value2"});
rawData->AppendGroup({"Group"});
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
rawData->SetName(VCARD_TYPE_SOUND);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_ADR);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_EMAIL);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_ORG);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_TITLE);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_PHOTO);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_LOGO);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_TEL);
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
}
HWTEST_F(ContactDataTest, VCardContact_AddOtherDatas001, Function | MediumTest | Level3)
{
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
int32_t errorCode = 0;
rawData->SetName(VCARD_TYPE_X_SKYPE_PSTNNUMBER);
rawData->SetRawValue("RawValue");
rawData->SetByte("Byte");
rawData->SetValues({"Value1", "Value2"});
rawData->AppendGroup({"Group"});
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
rawData->SetName(VCARD_TYPE_NOTE);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_URL);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_BDAY);
contact_->AddRawData(rawData, errorCode);
std::vector<DataShare::DataShareValuesBucket> contactDataValues;
rawData->SetValues({"2000-1-1"});
contact_->AddRawData(rawData, errorCode);
int32_t result = contact_->BuildContactData(1, contactDataValues);
EXPECT_EQ(result, TELEPHONY_SUCCESS);
rawData->SetName(VCARD_TYPE_ANNIVERSARY);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_IMPP);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_SIP);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_OHOS_CUSTOM);
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
}
HWTEST_F(ContactDataTest, VCardContact_AddOtherDatas002, Function | MediumTest | Level3)
{
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
int32_t errorCode = 0;
rawData->SetName(VCARD_TYPE_X_AIM);
rawData->SetRawValue("RawValue");
rawData->SetByte("Byte");
rawData->SetValues({"Value1", "Value2"});
rawData->AppendGroup({"Group"});
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
rawData->SetName(VCARD_TYPE_X_MSN);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_YAHOO);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_ICQ);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_JABBER);
contact_->AddRawData(rawData, errorCode);
rawData->SetName(VCARD_TYPE_X_QQ);
contact_->AddRawData(rawData, errorCode);
EXPECT_NE((rawData->GetValue()).size(), 0);
EXPECT_FALSE((rawData->GetByte()).empty());
std::vector<DataShare::DataShareValuesBucket> contactDataValues;
int32_t result = contact_->BuildContactData(1, contactDataValues);
EXPECT_EQ(result, TELEPHONY_SUCCESS);
}
HWTEST_F(ContactDataTest, VCardContact_BuildContact, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
EXPECT_EQ(contact_->BuildContact(nullptr), TELEPHONY_ERROR);
EXPECT_EQ(contact_->BuildContact(resultSet), TELEPHONY_SUCCESS);
}
HWTEST_F(ContactDataTest, VCardPostalData_InitPostalData, Function | MediumTest | Level3)
{
VCardPostalData postalData;
std::vector<std::string> propValueList =
{"pobox", "postalAddress", "street", "city", "region", "postCode", "country"};
postalData.InitPostalData(propValueList, static_cast<int32_t>(PostalType::ADDR_HOME), "labelName_");
EXPECT_STREQ((postalData.GetPOBox()).c_str(), "pobox");
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
EXPECT_EQ(postalData.BuildData(nullptr), TELEPHONY_ERROR);
EXPECT_EQ(postalData.BuildData(resultSet), TELEPHONY_SUCCESS);
propValueList.push_back("default");
postalData.InitPostalData(propValueList, static_cast<int32_t>(PostalType::ADDR_HOME), "labelName_");
EXPECT_STREQ((postalData.GetPostCode()).c_str(), "postCode");
}
HWTEST_F(ContactDataTest, VCardRelationData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardRelationData relationData;
EXPECT_EQ(relationData.BuildData(nullptr), TELEPHONY_ERROR);
EXPECT_EQ(relationData.BuildData(resultSet), TELEPHONY_SUCCESS);
}
HWTEST_F(ContactDataTest, VCardSipData_InitSipData, Function | MediumTest | Level3)
{
VCardSipData sipData;
sipData.InitSipData("sip:john@example.com", static_cast<int32_t>(SipType::SIP_HOME), "Jhon");
EXPECT_STREQ((sipData.GetAddress()).c_str(), "john@example.com");
sipData.InitSipData("", static_cast<int32_t>(SipType::SIP_HOME), "Jhon");
EXPECT_STREQ((sipData.GetAddress()).c_str(), "");
sipData.InitSipData("pis:john@example.com", static_cast<int32_t>(SipType::SIP_HOME), "Jhon");
EXPECT_STREQ((sipData.GetAddress()).c_str(), "pis:john@example.com");
}
HWTEST_F(ContactDataTest, VCardWebsiteData_BuildData, Function | MediumTest | Level3)
{
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
VCardWebsiteData websiteData;
EXPECT_EQ(websiteData.BuildData(nullptr), TELEPHONY_ERROR);
EXPECT_EQ(websiteData.BuildData(resultSet), TELEPHONY_SUCCESS);
}
HWTEST_F(ContactDataTest, VCardDecoderV21_DecodeOne, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
std::shared_ptr<VCardManager::DecodeListener> listener = std::make_shared<VCardManager::DecodeListener>();
decoder.AddVCardDecodeListener(nullptr);
int32_t errorCode = -1;
decoder.Decode(errorCode);
EXPECT_EQ(TELEPHONY_ERR_VCARD_FILE_INVALID, errorCode);
EXPECT_FALSE(decoder.ParseItem(errorCode));
decoder.AddVCardDecodeListener(listener);
}
HWTEST_F(ContactDataTest, VCardDecoderV21_DealBase64OrB, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
int32_t errorCode = -1;
decoder.DealBase64OrB("RawValue", nullptr, errorCode);
EXPECT_EQ(errorCode, -1);
}
HWTEST_F(ContactDataTest, VCardDecoderV21_DealParams001, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
int32_t errorCode = 0;
decoder.DealParams("TYPE=ABC", nullptr, errorCode);
EXPECT_EQ(errorCode, 0);
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
decoder.DealParams("TYPE=ABC", rawData, errorCode);
decoder.DealParams("TYPE=DOM", rawData, errorCode);
decoder.DealParams("TYPE=X-DOM", rawData, errorCode);
decoder.DealParams("VALUE=ABC", nullptr, errorCode);
EXPECT_EQ(errorCode, 0);
decoder.DealParams("VALUE=ABC", rawData, errorCode);
decoder.DealParams("VALUE=URL", rawData, errorCode);
decoder.DealParams("VALUE=X-URL", rawData, errorCode);
decoder.DealParams("ENCODING=ABC", nullptr, errorCode);
EXPECT_EQ(errorCode, 0);
decoder.DealParams("ENCODING=ABC", rawData, errorCode);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
errorCode = 0;
decoder.DealParams("ENCODING=VCARD_PARAM_ENCODING_QP", rawData, errorCode);
decoder.DealParams("ENCODING=X-VCARD_PARAM_ENCODING_QP", rawData, errorCode);
}
HWTEST_F(ContactDataTest, VCardDecoderV21_DealParams002, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
int32_t errorCode = 0;
decoder.DealParams("CHARSET=ABC", nullptr, errorCode);
EXPECT_EQ(errorCode, 0);
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
decoder.DealParams("CHARSET=ABC", rawData, errorCode);
decoder.DealParams("LANGUAGE=ABC", nullptr, errorCode);
EXPECT_EQ(errorCode, 0);
decoder.DealParams("LANGUAGE=ABC", rawData, errorCode);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
errorCode = 0;
decoder.DealParams("LANGUAGE=####-CHINESE", rawData, errorCode);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
errorCode = 0;
decoder.DealParams("LANGUAGE=ENGLISH-####", rawData, errorCode);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
errorCode = 0;
decoder.DealParams("LANGUAGE=ENGLISH-CHINESE", rawData, errorCode);
EXPECT_EQ(errorCode, 0);
errorCode = 0;
decoder.DealParams("X-NAME=ENGLISH-CHINESE", rawData, errorCode);
EXPECT_EQ(errorCode, 0);
decoder.DealParams("NAME=ENGLISH-CHINESE", rawData, errorCode);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
}
HWTEST_F(ContactDataTest, VCardDecoderV21_DealEncodingQPOrNoEncodingFN, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
int32_t errorCode = 0;
decoder.DealEncodingQPOrNoEncodingFN("RawValue", nullptr, "", "", errorCode);
EXPECT_EQ(errorCode, 0);
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
decoder.DealEncodingQPOrNoEncodingFN("example=value=\r\n", rawData, "", "", errorCode);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
}
HWTEST_F(ContactDataTest, VCardDecoderV21_BuildListFromValue, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
EXPECT_STREQ((decoder.BuildListFromValue("test1test2test3"))[0].c_str(), "test1test2test3");
EXPECT_STREQ((decoder.BuildListFromValue("test1;test2;test3"))[0].c_str(), "test1");
EXPECT_STREQ((decoder.BuildListFromValue("test1\\;test2;test3"))[0].c_str(), "test1;test2");
EXPECT_STREQ((decoder.BuildListFromValue("test1\\atest2test3"))[0].c_str(), "test1\\atest2test3");
EXPECT_STREQ((decoder.BuildListFromValue("test1\\\\;test2\\;test3"))[0].c_str(), "test1\\");
}
HWTEST_F(ContactDataTest, VCardDecoderV21_DealAgent, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
int32_t errorCode = 0;
decoder.DealAgent(nullptr, errorCode);
EXPECT_EQ(errorCode, 0);
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
decoder.DealAgent(rawData, errorCode);
EXPECT_EQ(errorCode, 0);
rawData->SetRawValue("BEGIN : VCARD some other content");
decoder.DealAgent(rawData, errorCode);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
}
HWTEST_F(ContactDataTest, VCardDecoderV21_DealAdrOrgN, Function | MediumTest | Level3)
{
VCardDecoderV21 decoder;
int32_t errorCode = 0;
decoder.DealAdrOrgN("RawValue", nullptr, DEFAULT_INTERMEDIATE_CHARSET, DEFAULT_IMPORT_CHARSET, errorCode);
EXPECT_EQ(errorCode, 0);
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
decoder.DealEncodingParam(VCARD_PARAM_ENCODING_QP, rawData, errorCode);
EXPECT_NE(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
}
HWTEST_F(ContactDataTest, VCardDecoderV30_UnescapeText, Function | MediumTest | Level3)
{
VCardDecoderV30 decoder;
EXPECT_STREQ(decoder.UnescapeText("").c_str(), "");
EXPECT_STREQ(decoder.UnescapeText("teststring").c_str(), "teststring");
EXPECT_STREQ(decoder.UnescapeText("test\nstring").c_str(), "test\nstring");
EXPECT_STREQ(decoder.UnescapeText("test\\Nstring").c_str(), "test\nstring");
EXPECT_STREQ(decoder.UnescapeText("test\\Xstring").c_str(), "testXstring");
}
HWTEST_F(ContactDataTest, VCardDecoderV30_UnescapeChar, Function | MediumTest | Level3)
{
VCardDecoderV30 decoder;
EXPECT_STREQ(decoder.UnescapeChar('n').c_str(), "\n");
EXPECT_STREQ(decoder.UnescapeChar('N').c_str(), "\n");
EXPECT_STREQ(decoder.UnescapeChar('X').c_str(), "X");
}
HWTEST_F(ContactDataTest, VCardEncoder, Function | MediumTest | Level3)
{
VCardEncoder encoder;
int32_t errorCode = 0;
std::shared_ptr<DataShare::DataShareResultSet> resultSet = std::make_shared<DataShare::DataShareResultSet>();
EXPECT_STREQ((encoder.ContructVCard(nullptr, errorCode).c_str()), "");
EXPECT_STREQ((encoder.ContructVCard(resultSet, errorCode).c_str()), "");
EXPECT_EQ(errorCode, TELEPHONY_ERR_LOCAL_PTR_NULL);
errorCode = 0;
std::shared_ptr<VCardContact> contact = std::make_shared<VCardContact>();
encoder.ContructContact(contact, nullptr, errorCode);
EXPECT_EQ(errorCode, 0);
}
HWTEST_F(ContactDataTest, VCardFileUtils_Create, Function | MediumTest | Level3)
{
VCardDecoder decoder;
int32_t errorCode = 0;
EXPECT_EQ(decoder.Create("", errorCode), nullptr);
EXPECT_EQ(errorCode, TELEPHONY_ERR_VCARD_FILE_INVALID);
EXPECT_EQ(decoder.Create("TestFile.vcf", errorCode), nullptr);
}
HWTEST_F(ContactDataTest, VCardManager_ImportLock, Function | MediumTest | Level3)
{
VCardManager::GetInstance().listener_->OnRawDataCreated(nullptr);
std::shared_ptr<VCardRawData> rawData = std::make_shared<VCardRawData>();
VCardManager::GetInstance().listener_->OnRawDataCreated(rawData);
VCardManager::GetInstance().listener_->OnOneContactStarted();
VCardManager::GetInstance().listener_->OnRawDataCreated(rawData);
EXPECT_EQ(VCardManager::GetInstance().ImportLock("TestPath", nullptr, 1), TELEPHONY_ERR_LOCAL_PTR_NULL);
}
HWTEST_F(ContactDataTest, VCardRawData_AppendParameter, Function | MediumTest | Level3)
{
VCardRawData rawData;
rawData.AppendParameter("testParam", "testValue");
auto value = rawData.GetParameters("testParam");
EXPECT_EQ(value.size(), 1);
EXPECT_STREQ(value[0].c_str(), "testValue");
value = rawData.GetParameters("testErrParam");
EXPECT_EQ(value.size(), 0);
rawData.AppendParameter("testParam", "newTestValue");
value = rawData.GetParameters("testParam");
EXPECT_EQ(value.size(), 2);
EXPECT_STREQ(value[0].c_str(), "testValue");
EXPECT_STREQ(value[1].c_str(), "newTestValue");
}
HWTEST_F(ContactDataTest, VCardRdbHelper, Function | MediumTest | Level3)
{
VCardRdbHelper::GetInstance().SetDataHelper(nullptr);
EXPECT_EQ(VCardRdbHelper::GetInstance().QueryRawContactMaxId(), DB_FAILD);
std::vector<DataShare::DataShareValuesBucket> rawContactValues;
OHOS::DataShare::DataShareValuesBucket rawContactValue;
EXPECT_EQ(VCardRdbHelper::GetInstance().BatchInsertRawContact(rawContactValues), DB_FAILD);
EXPECT_EQ(VCardRdbHelper::GetInstance().InsertRawContact(rawContactValue), DB_FAILD);
std::vector<DataShare::DataShareValuesBucket> contactDataValues;
EXPECT_EQ(VCardRdbHelper::GetInstance().BatchInsertContactData(contactDataValues), DB_FAILD);
EXPECT_EQ(VCardRdbHelper::GetInstance().InsertContactData(rawContactValues), DB_FAILD);
std::vector<std::string> columns;
OHOS::DataShare::DataSharePredicates predicates;
EXPECT_EQ(VCardRdbHelper::GetInstance().QueryAccount(columns, predicates), nullptr);
EXPECT_EQ(VCardRdbHelper::GetInstance().QueryContact(columns, predicates), nullptr);
EXPECT_EQ(VCardRdbHelper::GetInstance().QueryRawContact(columns, predicates), nullptr);
EXPECT_EQ(VCardRdbHelper::GetInstance().QueryContactData(columns, predicates), nullptr);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_001, Function | MediumTest | Level3)
{
char nextCh = 'n';
std::string vcardType = VERSION_40;
std::string expected = "\n";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_002, Function | MediumTest | Level3)
{
char nextCh = 'N';
std::string vcardType = VERSION_40;
std::string expected = "\n";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_003, Function | MediumTest | Level3)
{
char nextCh = 'n';
std::string vcardType = VERSION_30;
std::string expected = "\n";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_004, Function | MediumTest | Level3)
{
char nextCh = 'N';
std::string vcardType = VERSION_30;
std::string expected = "\n";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_005, Function | MediumTest | Level3)
{
char nextCh = '\\';
std::string vcardType = "VERSION_21";
std::string expected = "\\";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_006, Function | MediumTest | Level3)
{
char nextCh = ';';
std::string vcardType = "VERSION_21";
std::string expected = ";";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_007, Function | MediumTest | Level3)
{
char nextCh = ':';
std::string vcardType = "VERSION_21";
std::string expected = ":";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_008, Function | MediumTest | Level3)
{
char nextCh = ',';
std::string vcardType = "VERSION_21";
std::string expected = ",";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_HandleCh_009, Function | MediumTest | Level3)
{
char nextCh = 'a';
std::string vcardType = "VERSION_21";
std::string expected = "";
std::string actual = VCardUtils::HandleCh(nextCh, vcardType);
ASSERT_EQ(expected, actual);
}
HWTEST_F(ContactDataTest, VCardUtils_ConstructListFromValue_001, Function | MediumTest | Level3)
{
std::string value = "";
std::string vcardType = "VCARD";
std::vector<std::string> expected = {""};
std::vector<std::string> result = VCardUtils::ConstructListFromValue(value, vcardType);
ASSERT_EQ(result, expected);
}
HWTEST_F(ContactDataTest, VCardUtils_ConstructListFromValue_002, Function | MediumTest | Level3)
{
std::string value = "Hello;World";
std::string vcardType = "VCARD";
std::vector<std::string> expected = {"Hello", "HelloWorld"};
std::vector<std::string> result = VCardUtils::ConstructListFromValue(value, vcardType);
ASSERT_EQ(result, expected);
}
HWTEST_F(ContactDataTest, VCardUtils_ConstructListFromValue_003, Function | MediumTest | Level3)
{
std::string value = "Hello\\;World";
std::string vcardType = "VCARD";
std::vector<std::string> expected = {"Hello;World"};
std::vector<std::string> result = VCardUtils::ConstructListFromValue(value, vcardType);
ASSERT_EQ(result, expected);
}
HWTEST_F(ContactDataTest, VCardUtils_ConstructListFromValue_004, Function | MediumTest | Level3)
{
std::string value = "Hello;World;";
std::string vcardType = "VCARD";
std::vector<std::string> expected = {"Hello", "HelloWorld", "HelloWorld"};
std::vector<std::string> result = VCardUtils::ConstructListFromValue(value, vcardType);
ASSERT_EQ(result, expected);
}
HWTEST_F(ContactDataTest, VCardUtils_ConstructListFromValue_005, Function | MediumTest | Level3)
{
std::string value = "Hello\\;World\\;";
std::string vcardType = "VCARD";
std::vector<std::string> expected = {"Hello;World;"};
std::vector<std::string> result = VCardUtils::ConstructListFromValue(value, vcardType);
ASSERT_EQ(result, expected);
}
#endif // TEL_TEST_UNSUPPORT
} // namespace Telephony
} // namespace OHOS

View File

@ -133,7 +133,7 @@ constexpr const char *VCARD_PARAM_LANGUAGE = "LANGUAGE";
constexpr const char *VCARD_PARAM_SORT_AS = "SORT-AS";
constexpr const char *VCARD_PARAM_EXTRA_TYPE_COMPANY = "COMPANY";
constexpr const char *VCARD_EXPORT_FILE_PATH = "/data/storage/el2/base/files/";
constexpr const char *VCARD_EXPORT_FILE_PATH = "/data/storage/el4/base/files/";
constexpr const char *VCARD_TIME_FORMAT = "%Y%m%d_%H%M%S";
constexpr const char *VCARD_FILE_EXTENSION = ".vcf";
@ -261,7 +261,7 @@ enum class EmailType {
/**
* Indicates a custom label.
*/
CUSTOM_LABEL = 0,
CUSTOM_LABEL = 10000,
/**
* Indicates a home email.
@ -361,7 +361,7 @@ enum class PhoneVcType {
/**
* Indicates a custom label.
*/
CUSTOM_LABEL = 0,
CUSTOM_LABEL = 10000,
/**
* Indicates a home number.
@ -473,7 +473,7 @@ enum class PostalType {
/**
* Indicates a custom label.
*/
CUSTOM_LABEL = 0,
CUSTOM_LABEL = 10000,
/**
* Indicates a home address.

View File

@ -564,7 +564,7 @@ void VCardConstructor::ConstructPostalLine(std::shared_ptr<VCardPostalData> post
(needAddQuotedPrintable ? EncodeQuotedPrintable(postalCode) : DealCharacters(postalCode));
std::string encodedCountry =
(needAddQuotedPrintable ? EncodeQuotedPrintable(country) : DealCharacters(country));
postalLine << encodedPoBox << ITEM_SEPARATOR << ITEM_SEPARATOR;
postalLine << encodedPoBox << ITEM_SEPARATOR;
postalLine << encodedStreet << ITEM_SEPARATOR;
postalLine << encodedCity << ITEM_SEPARATOR;
postalLine << encodedRegion << ITEM_SEPARATOR;
@ -586,7 +586,6 @@ void VCardConstructor::ConstructPostalLine(std::shared_ptr<VCardPostalData> post
postalLine << ITEM_SEPARATOR;
postalLine << ITEM_SEPARATOR;
postalLine << ITEM_SEPARATOR;
postalLine << ITEM_SEPARATOR;
}
int32_t VCardConstructor::ConstructOrganizations(std::shared_ptr<VCardContact> contact)
@ -632,7 +631,7 @@ int32_t VCardConstructor::ConstructWebsites(std::shared_ptr<VCardContact> contac
if (website.empty()) {
continue;
}
AddLineWithCharsetAndQP(VCARD_TYPE_URL, { website, websiteData->GetLabelId(), websiteData->GetLabelName() });
AddLineWithCharsetAndQP(VCARD_TYPE_URL, { website });
}
return TELEPHONY_SUCCESS;
}
@ -788,7 +787,7 @@ void VCardConstructor::AddEmailLine(
if (!postalTypeStr.empty()) {
paramTypes.push_back(postalTypeStr);
}
std::vector<std::string> valueList = { email, displayName };
std::vector<std::string> valueList = { email };
bool needAddCharset = IsNeedCharsetParam(valueList);
bool needAddQuotedPrintable = needQP_ && !VCardUtils::IsPrintableAscii(valueList);
AddLine(VCARD_TYPE_EMAIL, paramTypes, valueList, needAddCharset, needAddQuotedPrintable);

View File

@ -25,6 +25,7 @@ OHOS::Uri uriRawContact("datashare:///com.ohos.contactsdataability/contacts/raw_
OHOS::Uri uriContactData("datashare:///com.ohos.contactsdataability/contacts/contact_data");
OHOS::Uri uriAccount("datashare:///com.ohos.contactsdataability/contacts/account");
OHOS::Uri uriContact("datashare:///com.ohos.contactsdataability/contacts/contact");
OHOS::Uri uriRawContactMaxId("datashare:///com.ohos.contactsdataability/raw_contact/get_inc_id");
} // namespace
@ -40,18 +41,27 @@ VCardRdbHelper &VCardRdbHelper::GetInstance()
int32_t VCardRdbHelper::QueryRawContactMaxId()
{
if (dataShareHelper_ == nullptr) {
TELEPHONY_LOGE("dataShareHelper is nullptr");
return DB_FAILD;
}
Uri uriRawContactMaxIdQuery(uriRawContactMaxId.ToString() + "?isFromBatch=true");
std::vector<std::string> columns;
DataShare::DataSharePredicates predicates;
predicates.GreaterThanOrEqualTo(RawContact::ID, "1");
auto resultSet = QueryRawContact(columns, predicates);
std::shared_ptr<DataShare::DataShareResultSet> resultSet =
dataShareHelper_->Query(uriRawContactMaxIdQuery, predicates, columns);
if (resultSet == nullptr) {
TELEPHONY_LOGE("resultSet is nullptr");
return DB_FAILD;
}
int rowCount = 0;
resultSet->GetRowCount(rowCount);
TELEPHONY_LOGI("rowCount= %{public}d", rowCount);
return static_cast<int32_t>(rowCount);
int rawMaxId = 0;
if (resultSet->GoToFirstRow() == TELEPHONY_ERR_SUCCESS) {
int curValueIndex;
resultSet->GetColumnIndex("seq", curValueIndex);
resultSet->GetInt(curValueIndex, rawMaxId);
}
TELEPHONY_LOGI("batchInsert rawId: %{public}d", rawMaxId);
return rawMaxId;
}
int32_t VCardRdbHelper::BatchInsertRawContact(const std::vector<DataShare::DataShareValuesBucket> &rawContactValues)
@ -72,7 +82,7 @@ int32_t VCardRdbHelper::BatchInsertContactData(const std::vector<DataShare::Data
TELEPHONY_LOGE("dataShareHelper_ is nullptr");
return DB_FAILD;
}
Uri uriContactDataBatch(uriContactData.ToString() + "?isFromBatch=true");
Uri uriContactDataBatch(uriContactData.ToString() + "?isFromBatch=true&isSyncFromCloud=true");
int code = dataShareHelper_->BatchInsert(uriContactDataBatch, contactsDataValues);
TELEPHONY_LOGI("insert code %{public}d", code);
return code;