1d95e75fdSopenharmony_ci/*
2d95e75fdSopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3d95e75fdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d95e75fdSopenharmony_ci * you may not use this file except in compliance with the License.
5d95e75fdSopenharmony_ci * You may obtain a copy of the License at
6d95e75fdSopenharmony_ci *
7d95e75fdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d95e75fdSopenharmony_ci *
9d95e75fdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d95e75fdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d95e75fdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d95e75fdSopenharmony_ci * See the License for the specific language governing permissions and
13d95e75fdSopenharmony_ci * limitations under the License.
14d95e75fdSopenharmony_ci */
15d95e75fdSopenharmony_ci
16d95e75fdSopenharmony_ci#include "module_service_utils.h"
17d95e75fdSopenharmony_ci
18d95e75fdSopenharmony_ci#include "cellular_call_config.h"
19d95e75fdSopenharmony_ci#include "cellular_call_register.h"
20d95e75fdSopenharmony_ci#include "ims_call_client.h"
21d95e75fdSopenharmony_ci#include "ipc_skeleton.h"
22d95e75fdSopenharmony_ci#include "string_ex.h"
23d95e75fdSopenharmony_ci#include "telephony_log_wrapper.h"
24d95e75fdSopenharmony_ci#include "telephony_types.h"
25d95e75fdSopenharmony_ci
26d95e75fdSopenharmony_cinamespace OHOS {
27d95e75fdSopenharmony_cinamespace Telephony {
28d95e75fdSopenharmony_cibool ModuleServiceUtils::GetRadioState(int32_t slotId)
29d95e75fdSopenharmony_ci{
30d95e75fdSopenharmony_ci    int32_t ret = CoreManagerInner::GetInstance().GetRadioState(slotId);
31d95e75fdSopenharmony_ci    if (ret != ModemPowerState::CORE_SERVICE_POWER_ON) {
32d95e75fdSopenharmony_ci        TELEPHONY_LOGE("ModuleServiceUtils::GetRadioState radio off.");
33d95e75fdSopenharmony_ci        return false;
34d95e75fdSopenharmony_ci    }
35d95e75fdSopenharmony_ci    return true;
36d95e75fdSopenharmony_ci}
37d95e75fdSopenharmony_ci
38d95e75fdSopenharmony_ciint32_t ModuleServiceUtils::GetAirplaneMode(bool &airplaneMode)
39d95e75fdSopenharmony_ci{
40d95e75fdSopenharmony_ci    int32_t ret = CoreManagerInner::GetInstance().GetAirplaneMode(airplaneMode);
41d95e75fdSopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
42d95e75fdSopenharmony_ci        TELEPHONY_LOGE("ModuleServiceUtils::GetAirplaneMode fail.");
43d95e75fdSopenharmony_ci        return ret;
44d95e75fdSopenharmony_ci    }
45d95e75fdSopenharmony_ci    return TELEPHONY_SUCCESS;
46d95e75fdSopenharmony_ci}
47d95e75fdSopenharmony_ci
48d95e75fdSopenharmony_ciint32_t ModuleServiceUtils::UpdateRadioOn(int32_t slotId)
49d95e75fdSopenharmony_ci{
50d95e75fdSopenharmony_ci    CellularCallConfig config;
51d95e75fdSopenharmony_ci    config.SetReadyToCall(slotId, false);
52d95e75fdSopenharmony_ci    int32_t ret = CoreManagerInner::GetInstance().UpdateRadioOn(slotId);
53d95e75fdSopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
54d95e75fdSopenharmony_ci        TELEPHONY_LOGE("ModuleServiceUtils::UpdateRadioOn fail.");
55d95e75fdSopenharmony_ci        return ret;
56d95e75fdSopenharmony_ci    }
57d95e75fdSopenharmony_ci    return TELEPHONY_SUCCESS;
58d95e75fdSopenharmony_ci}
59d95e75fdSopenharmony_ci
60d95e75fdSopenharmony_ciPhoneType ModuleServiceUtils::GetNetworkStatus(int32_t slotId)
61d95e75fdSopenharmony_ci{
62d95e75fdSopenharmony_ci    return CoreManagerInner::GetInstance().GetPhoneType(slotId);
63d95e75fdSopenharmony_ci}
64d95e75fdSopenharmony_ci
65d95e75fdSopenharmony_cistd::string ModuleServiceUtils::GetIsoCountryCode(int32_t slotId)
66d95e75fdSopenharmony_ci{
67d95e75fdSopenharmony_ci    std::u16string countryCode;
68d95e75fdSopenharmony_ci    CoreManagerInner::GetInstance().GetISOCountryCodeForSim(slotId, countryCode);
69d95e75fdSopenharmony_ci    return Str16ToStr8(countryCode);
70d95e75fdSopenharmony_ci}
71d95e75fdSopenharmony_ci
72d95e75fdSopenharmony_cistd::string ModuleServiceUtils::GetNetworkCountryCode(int32_t slotId)
73d95e75fdSopenharmony_ci{
74d95e75fdSopenharmony_ci    std::u16string countryCode;
75d95e75fdSopenharmony_ci    CoreManagerInner::GetInstance().GetIsoCountryCodeForNetwork(slotId, countryCode);
76d95e75fdSopenharmony_ci    return Str16ToStr8(countryCode);
77d95e75fdSopenharmony_ci}
78d95e75fdSopenharmony_ci
79d95e75fdSopenharmony_cibool ModuleServiceUtils::GetSatelliteStatus()
80d95e75fdSopenharmony_ci{
81d95e75fdSopenharmony_ci    return CoreManagerInner::GetInstance().IsSatelliteEnabled();
82d95e75fdSopenharmony_ci}
83d95e75fdSopenharmony_ci
84d95e75fdSopenharmony_cibool ModuleServiceUtils::GetImsRegistrationState(int32_t slotId)
85d95e75fdSopenharmony_ci{
86d95e75fdSopenharmony_ci    ImsRegInfo info;
87d95e75fdSopenharmony_ci    CoreManagerInner::GetInstance().GetImsRegStatus(slotId, ImsServiceType::TYPE_VOICE, info);
88d95e75fdSopenharmony_ci    return info.imsRegState == ImsRegState::IMS_REGISTERED;
89d95e75fdSopenharmony_ci}
90d95e75fdSopenharmony_ci
91d95e75fdSopenharmony_cibool ModuleServiceUtils::GetImsUtSupportState(int32_t slotId)
92d95e75fdSopenharmony_ci{
93d95e75fdSopenharmony_ci    ImsRegInfo info;
94d95e75fdSopenharmony_ci    CoreManagerInner::GetInstance().GetImsRegStatus(slotId, ImsServiceType::TYPE_UT, info);
95d95e75fdSopenharmony_ci    return info.imsRegState == ImsRegState::IMS_REGISTERED;
96d95e75fdSopenharmony_ci}
97d95e75fdSopenharmony_ci
98d95e75fdSopenharmony_cistd::vector<int32_t> ModuleServiceUtils::GetSlotInfo()
99d95e75fdSopenharmony_ci{
100d95e75fdSopenharmony_ci    const int32_t slotSingle = 1;
101d95e75fdSopenharmony_ci    const int32_t slotDouble = 2;
102d95e75fdSopenharmony_ci    std::vector<int32_t> slotVector;
103d95e75fdSopenharmony_ci    if (SIM_SLOT_COUNT == slotSingle) {
104d95e75fdSopenharmony_ci        slotVector.push_back(DEFAULT_SIM_SLOT_ID);
105d95e75fdSopenharmony_ci    } else if (SIM_SLOT_COUNT == slotDouble) {
106d95e75fdSopenharmony_ci        slotVector.push_back(SIM_SLOT_0);
107d95e75fdSopenharmony_ci        slotVector.push_back(SIM_SLOT_1);
108d95e75fdSopenharmony_ci    }
109d95e75fdSopenharmony_ci    return slotVector;
110d95e75fdSopenharmony_ci}
111d95e75fdSopenharmony_ci
112d95e75fdSopenharmony_cibool ModuleServiceUtils::NeedCallImsService() const
113d95e75fdSopenharmony_ci{
114d95e75fdSopenharmony_ci    if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
115d95e75fdSopenharmony_ci        TELEPHONY_LOGE("ImsCallClient is nullptr.");
116d95e75fdSopenharmony_ci        return false;
117d95e75fdSopenharmony_ci    }
118d95e75fdSopenharmony_ci    auto remoteProxy = DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
119d95e75fdSopenharmony_ci    if (remoteProxy == nullptr) {
120d95e75fdSopenharmony_ci        TELEPHONY_LOGE("NeedCallImsService return, ims service SA not exists.");
121d95e75fdSopenharmony_ci        return false;
122d95e75fdSopenharmony_ci    }
123d95e75fdSopenharmony_ci    return true;
124d95e75fdSopenharmony_ci}
125d95e75fdSopenharmony_ci
126d95e75fdSopenharmony_cisptr<ImsCallInterface> ModuleServiceUtils::GetImsServiceRemoteObject() const
127d95e75fdSopenharmony_ci{
128d95e75fdSopenharmony_ci    if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
129d95e75fdSopenharmony_ci        TELEPHONY_LOGE("ImsCallClient is nullptr.");
130d95e75fdSopenharmony_ci        return nullptr;
131d95e75fdSopenharmony_ci    }
132d95e75fdSopenharmony_ci    return DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
133d95e75fdSopenharmony_ci}
134d95e75fdSopenharmony_ci
135d95e75fdSopenharmony_ciRegServiceState ModuleServiceUtils::GetCsRegState(int32_t slotId)
136d95e75fdSopenharmony_ci{
137d95e75fdSopenharmony_ci    return static_cast<RegServiceState>(CoreManagerInner::GetInstance().GetCsRegState(slotId));
138d95e75fdSopenharmony_ci}
139d95e75fdSopenharmony_ci
140d95e75fdSopenharmony_ciRegServiceState ModuleServiceUtils::GetPsRegState(int32_t slotId)
141d95e75fdSopenharmony_ci{
142d95e75fdSopenharmony_ci    return static_cast<RegServiceState>(CoreManagerInner::GetInstance().GetPsRegState(slotId));
143d95e75fdSopenharmony_ci}
144d95e75fdSopenharmony_ci} // namespace Telephony
145d95e75fdSopenharmony_ci} // namespace OHOS