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