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 "ipc_skeleton.h"
19 #include "string_ex.h"
20
21 #include "cellular_call_config.h"
22 #include "cellular_call_register.h"
23 #include "ims_call_client.h"
24 #include "telephony_log_wrapper.h"
25 #include "telephony_types.h"
26
27 namespace OHOS {
28 namespace Telephony {
GetRadioState(int32_t slotId)29 bool ModuleServiceUtils::GetRadioState(int32_t slotId)
30 {
31 int32_t ret = CoreManagerInner::GetInstance().GetRadioState(slotId);
32 if (ret != ModemPowerState::CORE_SERVICE_POWER_ON) {
33 TELEPHONY_LOGE("ModuleServiceUtils::GetRadioState radio off.");
34 return false;
35 }
36 return true;
37 }
38
GetAirplaneMode(bool & airplaneMode)39 int32_t ModuleServiceUtils::GetAirplaneMode(bool &airplaneMode)
40 {
41 int32_t ret = CoreManagerInner::GetInstance().GetAirplaneMode(airplaneMode);
42 if (ret != TELEPHONY_SUCCESS) {
43 TELEPHONY_LOGE("ModuleServiceUtils::GetAirplaneMode fail.");
44 return ret;
45 }
46 return TELEPHONY_SUCCESS;
47 }
48
UpdateRadioOn(int32_t slotId)49 int32_t ModuleServiceUtils::UpdateRadioOn(int32_t slotId)
50 {
51 CellularCallConfig config;
52 config.SetReadyToCall(slotId, false);
53 int32_t ret = CoreManagerInner::GetInstance().UpdateRadioOn(slotId);
54 if (ret != TELEPHONY_SUCCESS) {
55 TELEPHONY_LOGE("ModuleServiceUtils::UpdateRadioOn fail.");
56 return ret;
57 }
58 return TELEPHONY_SUCCESS;
59 }
60
GetNetworkStatus(int32_t slotId)61 PhoneType ModuleServiceUtils::GetNetworkStatus(int32_t slotId)
62 {
63 return CoreManagerInner::GetInstance().GetPhoneType(slotId);
64 }
65
GetIsoCountryCode(int32_t slotId)66 std::string ModuleServiceUtils::GetIsoCountryCode(int32_t slotId)
67 {
68 std::u16string countryCode;
69 CoreManagerInner::GetInstance().GetISOCountryCodeForSim(slotId, countryCode);
70 return Str16ToStr8(countryCode);
71 }
72
GetNetworkCountryCode(int32_t slotId)73 std::string ModuleServiceUtils::GetNetworkCountryCode(int32_t slotId)
74 {
75 std::u16string countryCode;
76 CoreManagerInner::GetInstance().GetIsoCountryCodeForNetwork(slotId, countryCode);
77 return Str16ToStr8(countryCode);
78 }
79
GetImsRegistrationState(int32_t slotId)80 bool ModuleServiceUtils::GetImsRegistrationState(int32_t slotId)
81 {
82 ImsRegInfo info;
83 CoreManagerInner::GetInstance().GetImsRegStatus(slotId, ImsServiceType::TYPE_VOICE, info);
84 return info.imsRegState == ImsRegState::IMS_REGISTERED;
85 }
86
GetImsUtSupportState(int32_t slotId)87 bool ModuleServiceUtils::GetImsUtSupportState(int32_t slotId)
88 {
89 ImsRegInfo info;
90 CoreManagerInner::GetInstance().GetImsRegStatus(slotId, ImsServiceType::TYPE_UT, info);
91 return info.imsRegState == ImsRegState::IMS_REGISTERED;
92 }
93
GetSlotInfo()94 std::vector<int32_t> ModuleServiceUtils::GetSlotInfo()
95 {
96 const int32_t slotSingle = 1;
97 const int32_t slotDouble = 2;
98 std::vector<int32_t> slotVector;
99 if (SIM_SLOT_COUNT == slotSingle) {
100 slotVector.push_back(DEFAULT_SIM_SLOT_ID);
101 } else if (SIM_SLOT_COUNT == slotDouble) {
102 slotVector.push_back(SIM_SLOT_0);
103 slotVector.push_back(SIM_SLOT_1);
104 }
105 return slotVector;
106 }
107
NeedCallImsService() const108 bool ModuleServiceUtils::NeedCallImsService() const
109 {
110 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
111 TELEPHONY_LOGE("ImsCallClient is nullptr.");
112 return false;
113 }
114 auto remoteProxy = DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
115 if (remoteProxy == nullptr) {
116 TELEPHONY_LOGE("NeedCallImsService return, ims service SA not exists.");
117 return false;
118 }
119 return true;
120 }
121
GetImsServiceRemoteObject() const122 sptr<ImsCallInterface> ModuleServiceUtils::GetImsServiceRemoteObject() const
123 {
124 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
125 TELEPHONY_LOGE("ImsCallClient is nullptr.");
126 return nullptr;
127 }
128 return DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
129 }
130
GetCsRegState(int32_t slotId)131 RegServiceState ModuleServiceUtils::GetCsRegState(int32_t slotId)
132 {
133 return static_cast<RegServiceState>(CoreManagerInner::GetInstance().GetCsRegState(slotId));
134 }
135
GetPsRegState(int32_t slotId)136 RegServiceState ModuleServiceUtils::GetPsRegState(int32_t slotId)
137 {
138 return static_cast<RegServiceState>(CoreManagerInner::GetInstance().GetPsRegState(slotId));
139 }
140 } // namespace Telephony
141 } // namespace OHOS