• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetSlotInfo()91 std::vector<int32_t> ModuleServiceUtils::GetSlotInfo()
92 {
93     const int32_t slotSingle = 1;
94     const int32_t slotDouble = 2;
95     std::vector<int32_t> slotVector;
96     if (SIM_SLOT_COUNT == slotSingle) {
97         slotVector.push_back(DEFAULT_SIM_SLOT_ID);
98     } else if (SIM_SLOT_COUNT == slotDouble) {
99         slotVector.push_back(SIM_SLOT_0);
100         slotVector.push_back(SIM_SLOT_1);
101     }
102     return slotVector;
103 }
104 
NeedCallImsService() const105 bool ModuleServiceUtils::NeedCallImsService() const
106 {
107     if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
108         TELEPHONY_LOGE("ImsCallClient is nullptr.");
109         return false;
110     }
111     auto remoteProxy = DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
112     if (remoteProxy == nullptr) {
113         TELEPHONY_LOGE("NeedCallImsService return, ims service SA not exists.");
114         return false;
115     }
116     return true;
117 }
118 
GetImsServiceRemoteObject() const119 sptr<ImsCallInterface> ModuleServiceUtils::GetImsServiceRemoteObject() const
120 {
121     if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
122         TELEPHONY_LOGE("ImsCallClient is nullptr.");
123         return nullptr;
124     }
125     return DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallProxy();
126 }
127 
GetCsRegState(int32_t slotId)128 RegServiceState ModuleServiceUtils::GetCsRegState(int32_t slotId)
129 {
130     return static_cast<RegServiceState>(CoreManagerInner::GetInstance().GetCsRegState(slotId));
131 }
132 
GetPsRegState(int32_t slotId)133 RegServiceState ModuleServiceUtils::GetPsRegState(int32_t slotId)
134 {
135     return static_cast<RegServiceState>(CoreManagerInner::GetInstance().GetPsRegState(slotId));
136 }
137 } // namespace Telephony
138 } // namespace OHOS