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_register.h"
22 #include "ims_call_client.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
GetNetworkStatus(int32_t slotId)38 PhoneType ModuleServiceUtils::GetNetworkStatus(int32_t slotId)
39 {
40 return CoreManagerInner::GetInstance().GetPhoneType(slotId);
41 }
42
GetIsoCountryCode(int32_t slotId)43 std::string ModuleServiceUtils::GetIsoCountryCode(int32_t slotId)
44 {
45 std::u16string countryCode;
46 CoreManagerInner::GetInstance().GetISOCountryCodeForSim(slotId, countryCode);
47 return Str16ToStr8(countryCode);
48 }
49
GetNetworkCountryCode(int32_t slotId)50 std::string ModuleServiceUtils::GetNetworkCountryCode(int32_t slotId)
51 {
52 std::u16string countryCode;
53 CoreManagerInner::GetInstance().GetIsoCountryCodeForNetwork(slotId, countryCode);
54 return Str16ToStr8(countryCode);
55 }
56
GetImsRegistrationState(int32_t slotId)57 bool ModuleServiceUtils::GetImsRegistrationState(int32_t slotId)
58 {
59 ImsRegInfo info;
60 CoreManagerInner::GetInstance().GetImsRegStatus(slotId, ImsServiceType::TYPE_VOICE, info);
61 return info.imsRegState == ImsRegState::IMS_REGISTERED;
62 }
63
GetSlotInfo()64 std::vector<int32_t> ModuleServiceUtils::GetSlotInfo()
65 {
66 const int32_t slotSingle = 1;
67 const int32_t slotDouble = 2;
68 std::vector<int32_t> slotVector;
69 if (SIM_SLOT_COUNT == slotSingle) {
70 slotVector.push_back(DEFAULT_SIM_SLOT_ID);
71 } else if (SIM_SLOT_COUNT == slotDouble) {
72 slotVector.push_back(SIM_SLOT_0);
73 slotVector.push_back(SIM_SLOT_1);
74 }
75 return slotVector;
76 }
77
NeedCallImsService() const78 bool ModuleServiceUtils::NeedCallImsService() const
79 {
80 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
81 TELEPHONY_LOGE("ImsCallClient is nullptr.");
82 return false;
83 }
84 auto remoteProxy = DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
85 if (remoteProxy == nullptr) {
86 TELEPHONY_LOGE("NeedCallImsService return, ims service SA not exists.");
87 return false;
88 }
89 return true;
90 }
91
GetImsServiceRemoteObject() const92 sptr<ImsCallInterface> ModuleServiceUtils::GetImsServiceRemoteObject() const
93 {
94 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
95 TELEPHONY_LOGE("ImsCallClient is nullptr.");
96 return nullptr;
97 }
98 return DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
99 }
100 } // namespace Telephony
101 } // namespace OHOS