1 /*
2 * Copyright (C) 2021 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 "ims_service.h"
17
18 #include "system_ability_definition.h"
19
20 #include "core_manager_inner.h"
21 #include "radio_event.h"
22
23 namespace OHOS {
24 namespace Telephony {
25 bool g_registerResult = SystemAbility::MakeAndRegisterAbility(DelayedSingleton<ImsService>::GetInstance().get());
26
ImsService()27 ImsService::ImsService() : SystemAbility(TELEPHONY_IMS_SYS_ABILITY_ID, true)
28 {
29 state_ = ServiceRunningState::STATE_STOPPED;
30 }
31
~ImsService()32 ImsService::~ImsService()
33 {
34 state_ = ServiceRunningState::STATE_STOPPED;
35 }
36
Init()37 bool ImsService::Init()
38 {
39 TELEPHONY_LOGI("ImsService Init");
40 eventLoop_ = AppExecFwk::EventRunner::Create("ImsService");
41 if (eventLoop_ == nullptr) {
42 TELEPHONY_LOGE("failed to create EventRunner");
43 return false;
44 }
45 CreateHandler();
46 AsynchronousRegister();
47 TELEPHONY_LOGI("init success");
48 return true;
49 }
50
OnStart()51 void ImsService::OnStart()
52 {
53 TELEPHONY_LOGI("ImsService OnStart");
54 if (state_ == ServiceRunningState::STATE_RUNNING) {
55 TELEPHONY_LOGE("ImsService has already started.");
56 return;
57 }
58 if (!Init()) {
59 TELEPHONY_LOGE("failed to init service.");
60 return;
61 }
62 state_ = ServiceRunningState::STATE_RUNNING;
63 if (eventLoop_ != nullptr) {
64 eventLoop_->Run();
65 }
66 bool ret = Publish(DelayedSingleton<ImsService>::GetInstance().get());
67 if (!ret) {
68 TELEPHONY_LOGE("ImsService::OnStart Publish failed!");
69 }
70 TELEPHONY_LOGI("ImsService start success.");
71 }
72
OnStop()73 void ImsService::OnStop()
74 {
75 TELEPHONY_LOGI("ImsService stop service");
76 if (eventLoop_ != nullptr) {
77 eventLoop_.reset();
78 }
79
80 state_ = ServiceRunningState::STATE_STOPPED;
81
82 HandlerResetUnRegister();
83 }
84
CreateHandler()85 void ImsService::CreateHandler()
86 {
87 int32_t slotId = DEFAULT_SIM_SLOT_ID;
88 auto handler = std::make_shared<ImsHandler>(eventLoop_);
89 handlerMap_.insert(std::make_pair(slotId, handler));
90 const int32_t slotDouble = 2;
91 if (SIM_SLOT_COUNT == slotDouble) {
92 int32_t slotId1 = SIM_SLOT_1;
93 auto handler1 = std::make_shared<ImsHandler>(eventLoop_);
94 handlerMap_.insert(std::make_pair(slotId1, handler1));
95 }
96 }
97
RegisterHandler()98 void ImsService::RegisterHandler()
99 {
100 TELEPHONY_LOGI("connect core service RegisterHandler start ");
101 for (uint32_t i = 0; i < CONNECT_MAX_TRY_COUNT; i++) {
102 std::this_thread::sleep_for(std::chrono::milliseconds(CONNECT_SERVICE_WAIT_TIME));
103 if (CoreManagerInner::GetInstance().IsInitFinished()) {
104 RegisterCoreServiceHandler();
105 break;
106 }
107 TELEPHONY_LOGW("connect core service RegisterHandler null or not init ");
108 }
109 TELEPHONY_LOGI("connect core service RegisterHandler end ");
110 }
111
HandlerResetUnRegister()112 void ImsService::HandlerResetUnRegister()
113 {
114 for (const auto &it : handlerMap_) {
115 auto handler = it.second;
116 if (handler != nullptr) {
117 handler.reset();
118 }
119 }
120 }
121
RegisterCoreServiceHandler()122 void ImsService::RegisterCoreServiceHandler()
123 {
124 for (const auto &it : handlerMap_) {
125 auto handler = it.second;
126 if (handler != nullptr) {
127 TELEPHONY_LOGI("RegisterCoreServiceHandler, RegisterCoreNotify handler");
128 }
129 }
130 }
131
AsynchronousRegister()132 void ImsService::AsynchronousRegister()
133 {
134 TELEPHONY_LOGI("ImsService::AsynchronousRegister entry");
135 int64_t delayTime = 1000;
136 int32_t slot = DEFAULT_SIM_SLOT_ID;
137 auto handler = handlerMap_[slot];
138 if (handler == nullptr) {
139 TELEPHONY_LOGE("AsynchronousRegister return, handler is nullptr");
140 return;
141 }
142 handler->SendEvent(handler->ASYNCHRONOUS_REGISTER_ID, delayTime, ImsHandler::Priority::HIGH);
143 }
144
GetHandler(int32_t slot)145 std::shared_ptr<ImsHandler> ImsService::GetHandler(int32_t slot)
146 {
147 return handlerMap_[slot];
148 }
149
Dial(const ImsCallInfo & callInfo,CLIRMode mode)150 int32_t ImsService::Dial(const ImsCallInfo &callInfo, CLIRMode mode)
151 {
152 TELEPHONY_LOGI("ImsService::Dial entry");
153 return request_.DialRequest(callInfo, mode);
154 }
155
HangUp(const ImsCallInfo & callInfo)156 int32_t ImsService::HangUp(const ImsCallInfo &callInfo)
157 {
158 TELEPHONY_LOGI("ImsService::HangUp entry");
159 return request_.HangUpRequest(callInfo.slotId, callInfo.index);
160 }
161
Reject(const ImsCallInfo & callInfo)162 int32_t ImsService::Reject(const ImsCallInfo &callInfo)
163 {
164 TELEPHONY_LOGI("ImsService::Reject entry");
165 return request_.RejectRequest(callInfo.slotId);
166 }
167
Answer(const ImsCallInfo & callInfo)168 int32_t ImsService::Answer(const ImsCallInfo &callInfo)
169 {
170 TELEPHONY_LOGI("ImsService::Answer entry");
171 return request_.AnswerRequest(callInfo.slotId, callInfo.videoState);
172 }
173
HoldCall(int32_t slotId)174 int32_t ImsService::HoldCall(int32_t slotId)
175 {
176 TELEPHONY_LOGI("ImsService::HoldCall entry");
177 return request_.HoldRequest(slotId);
178 }
179
UnHoldCall(int32_t slotId)180 int32_t ImsService::UnHoldCall(int32_t slotId)
181 {
182 TELEPHONY_LOGI("ImsService::UnHoldCall entry");
183 return request_.UnHoldCallRequest(slotId);
184 }
185
SwitchCall(int32_t slotId)186 int32_t ImsService::SwitchCall(int32_t slotId)
187 {
188 TELEPHONY_LOGI("ImsService::SwitchCall entry");
189 return request_.SwitchCallRequest(slotId);
190 }
191
CombineConference(int32_t slotId)192 int32_t ImsService::CombineConference(int32_t slotId)
193 {
194 TELEPHONY_LOGI("ImsService::CombineConference entry");
195 int32_t voiceCall = 0;
196 return request_.CombineConferenceRequest(slotId, voiceCall);
197 }
198
InviteToConference(int32_t slotId,const std::vector<std::string> & numberList)199 int32_t ImsService::InviteToConference(int32_t slotId, const std::vector<std::string> &numberList)
200 {
201 TELEPHONY_LOGI("ImsService::InviteToConference entry");
202 return request_.InviteToConferenceRequest(slotId, numberList);
203 }
204
KickOutFromConference(int32_t slotId,const std::vector<std::string> & numberList)205 int32_t ImsService::KickOutFromConference(int32_t slotId, const std::vector<std::string> &numberList)
206 {
207 TELEPHONY_LOGI("ImsService::KickOutFromConference entry");
208 return request_.KickOutFromConferenceRequest(slotId, numberList);
209 }
210
UpdateImsCallMode(const ImsCallInfo & callInfo,ImsCallMode mode)211 int32_t ImsService::UpdateImsCallMode(const ImsCallInfo &callInfo, ImsCallMode mode)
212 {
213 TELEPHONY_LOGI("ImsService::UpdateImsCallMode entry");
214 return request_.UpdateCallMediaModeRequest(callInfo.slotId, mode);
215 }
216
IsEmergencyPhoneNumber(int32_t slotId,const std::string & phoneNum)217 int32_t ImsService::IsEmergencyPhoneNumber(int32_t slotId, const std::string &phoneNum)
218 {
219 TELEPHONY_LOGI("ImsService::IsEmergencyPhoneNumber entry");
220 return request_.IsEmergencyPhoneNumberRequest(slotId, phoneNum);
221 }
222
StartDtmf(int32_t slotId,char cDtmfCode,int32_t index)223 int32_t ImsService::StartDtmf(int32_t slotId, char cDtmfCode, int32_t index)
224 {
225 TELEPHONY_LOGI("ImsService::StartDtmf entry");
226 return request_.StartDtmfRequest(slotId, cDtmfCode, index);
227 }
228
SendDtmf(int32_t slotId,char cDtmfCode,int32_t index)229 int32_t ImsService::SendDtmf(int32_t slotId, char cDtmfCode, int32_t index)
230 {
231 TELEPHONY_LOGI("ImsService::SendDtmf entry");
232 return request_.SendDtmfRequest(slotId, cDtmfCode, index);
233 }
234
StopDtmf(int32_t slotId,int32_t index)235 int32_t ImsService::StopDtmf(int32_t slotId, int32_t index)
236 {
237 TELEPHONY_LOGI("ImsService::StopDtmf entry");
238 return request_.StopDtmfRequest(slotId, index);
239 }
240
StartRtt(int32_t slotId,const std::string & msg)241 int32_t ImsService::StartRtt(int32_t slotId, const std::string &msg)
242 {
243 TELEPHONY_LOGI("ImsService::StartRtt entry");
244 return request_.StartRttRequest(slotId, msg);
245 }
246
StopRtt(int32_t slotId)247 int32_t ImsService::StopRtt(int32_t slotId)
248 {
249 TELEPHONY_LOGI("ImsService::StopRtt entry");
250 return request_.StopRttRequest(slotId);
251 }
252
SetDomainPreferenceMode(int32_t slotId,int32_t mode)253 int32_t ImsService::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
254 {
255 TELEPHONY_LOGI("ImsService::SetDomainPreferenceMode entry");
256 return request_.SetDomainPreferenceModeRequest(slotId, mode);
257 }
258
GetDomainPreferenceMode(int32_t slotId)259 int32_t ImsService::GetDomainPreferenceMode(int32_t slotId)
260 {
261 TELEPHONY_LOGI("ImsService::GetDomainPreferenceMode entry");
262 return request_.GetDomainPreferenceModeRequest(slotId);
263 }
264
SetLteImsSwitchStatus(int32_t slotId,bool active)265 int32_t ImsService::SetLteImsSwitchStatus(int32_t slotId, bool active)
266 {
267 TELEPHONY_LOGI("ImsService::SetLteImsSwitchStatus entry");
268 return request_.SetLteImsSwitchStatusRequest(slotId, active);
269 }
270
GetLteImsSwitchStatus(int32_t slotId)271 int32_t ImsService::GetLteImsSwitchStatus(int32_t slotId)
272 {
273 TELEPHONY_LOGI("ImsService::GetLteImsSwitchStatus entry");
274 return request_.GetLteImsSwitchStatusRequest(slotId);
275 }
276
SetImsConfig(ImsConfigItem item,const std::string & value)277 int32_t ImsService::SetImsConfig(ImsConfigItem item, const std::string &value)
278 {
279 TELEPHONY_LOGI("ImsService::SetImsConfig string entry");
280 return request_.SetImsConfigRequest(item, value);
281 }
282
SetImsConfig(ImsConfigItem item,int32_t value)283 int32_t ImsService::SetImsConfig(ImsConfigItem item, int32_t value)
284 {
285 TELEPHONY_LOGI("ImsService::SetImsConfig int entry");
286 return request_.SetImsConfigRequest(item, value);
287 }
288
GetImsConfig(ImsConfigItem item)289 int32_t ImsService::GetImsConfig(ImsConfigItem item)
290 {
291 TELEPHONY_LOGI("ImsService::GetImsConfig entry");
292 return request_.GetImsConfigRequest(item);
293 }
294
SetImsFeatureValue(FeatureType type,int32_t value)295 int32_t ImsService::SetImsFeatureValue(FeatureType type, int32_t value)
296 {
297 TELEPHONY_LOGI("ImsService::SetImsFeatureValue entry");
298 return request_.SetImsFeatureValueRequest(type, value);
299 }
300
GetImsFeatureValue(FeatureType type)301 int32_t ImsService::GetImsFeatureValue(FeatureType type)
302 {
303 TELEPHONY_LOGI("ImsService::GetImsFeatureValue entry");
304 return request_.GetImsFeatureValueRequest(type);
305 }
306
SetImsSwitchEnhanceMode(bool value)307 int32_t ImsService::SetImsSwitchEnhanceMode(bool value)
308 {
309 TELEPHONY_LOGI("ImsService::SetImsSwitchEnhanceMode entry");
310 return request_.SetImsSwitchEnhanceModeRequest(value);
311 }
312
GetImsSwitchEnhanceMode()313 int32_t ImsService::GetImsSwitchEnhanceMode()
314 {
315 TELEPHONY_LOGI("ImsService::GetImsSwitchEnhanceMode entry");
316 return request_.GetImsSwitchEnhanceModeRequest();
317 }
318
CtrlCamera(const std::u16string & cameraId,int32_t callingUid,int32_t callingPid)319 int32_t ImsService::CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid)
320 {
321 TELEPHONY_LOGI("ImsService::CtrlCamera entry");
322 return request_.CtrlCameraRequest(cameraId, callingUid, callingPid);
323 }
324
SetPreviewWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)325 int32_t ImsService::SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
326 {
327 TELEPHONY_LOGI("ImsService::SetPreviewWindow entry");
328 return request_.SetPreviewWindowRequest(x, y, z, width, height);
329 }
330
SetDisplayWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)331 int32_t ImsService::SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
332 {
333 TELEPHONY_LOGI("ImsService::SetDisplayWindow entry");
334 return request_.SetDisplayWindowRequest(x, y, z, width, height);
335 }
336
SetCameraZoom(float zoomRatio)337 int32_t ImsService::SetCameraZoom(float zoomRatio)
338 {
339 TELEPHONY_LOGI("ImsService::SetCameraZoom entry");
340 return request_.SetCameraZoomRequest(zoomRatio);
341 }
342
SetPauseImage(const std::u16string & path)343 int32_t ImsService::SetPauseImage(const std::u16string &path)
344 {
345 TELEPHONY_LOGI("ImsService::SetPauseImage entry");
346 return request_.SetPauseImageRequest(path);
347 }
348
SetDeviceDirection(int32_t rotation)349 int32_t ImsService::SetDeviceDirection(int32_t rotation)
350 {
351 TELEPHONY_LOGI("ImsService::SetDeviceDirection entry");
352 return request_.SetDeviceDirectionRequest(rotation);
353 }
354
RegisterCellularCallBack(const sptr<ImsCallback> & callback)355 int32_t ImsService::RegisterCellularCallBack(const sptr<ImsCallback> &callback)
356 {
357 TELEPHONY_LOGI("ImsService::RegisterCellularCallBack entry");
358 if (DelayedSingleton<ImsRegister>::GetInstance() == nullptr) {
359 TELEPHONY_LOGE("RegisterCellularCallBackInner return, error type: GetInstance() is nullptr.");
360 return TELEPHONY_ERR_LOCAL_PTR_NULL;
361 }
362 return DelayedSingleton<ImsRegister>::GetInstance()->RegisterCellularCallBack(callback);
363 }
364
IsCallBackExists()365 bool ImsService::IsCallBackExists()
366 {
367 TELEPHONY_LOGI("ImsService::IsCallBackExists entry");
368 return DelayedSingleton<ImsRegister>::GetInstance()->IsCallBackExists();
369 }
370
GetImsCallsDataRequest(int32_t slotId,int64_t lastCallsDataFlag)371 int32_t ImsService::GetImsCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag)
372 {
373 TELEPHONY_LOGI("ImsService::GetImsCallsDataRequest entry");
374 return request_.GetImsCallsDataRequest(slotId, lastCallsDataFlag);
375 }
376
SetMute(int32_t slotId,int32_t mute)377 int32_t ImsService::SetMute(int32_t slotId, int32_t mute)
378 {
379 TELEPHONY_LOGI("ImsService::SetMute entry");
380 TELEPHONY_LOGI("ImsService::SetMute entry slotId:%{public}d mute:%{public}d", slotId, mute);
381 return request_.SetMuteRequest(slotId, mute);
382 }
383
GetMute(int32_t slotId)384 int32_t ImsService::GetMute(int32_t slotId)
385 {
386 TELEPHONY_LOGI("ImsService::GetMute entry");
387 return request_.GetMuteRequest(slotId);
388 }
389
GetEmergencyCallList(int32_t slotId)390 int32_t ImsService::GetEmergencyCallList(int32_t slotId)
391 {
392 TELEPHONY_LOGI("ImsService::GetEmergencyCallList entry");
393 return request_.GetEmergencyCallListRequest(slotId);
394 }
395
GetCallFailReason(int32_t slotId)396 int32_t ImsService::GetCallFailReason(int32_t slotId)
397 {
398 TELEPHONY_LOGI("ImsService::GetCallFailReason entry");
399 return request_.GetCallFailReasonRequest(slotId);
400 }
401
InquireClip(int32_t slotId)402 int32_t ImsService::InquireClip(int32_t slotId)
403 {
404 TELEPHONY_LOGI("ImsService::InquireClip entry");
405 return request_.InquireClipRequest(slotId);
406 }
407
SetClir(int32_t slotId,int32_t action)408 int32_t ImsService::SetClir(int32_t slotId, int32_t action)
409 {
410 TELEPHONY_LOGI("ImsService::SetClir entry");
411 return request_.SetClirRequest(slotId, action);
412 }
413
InquireClir(int32_t slotId)414 int32_t ImsService::InquireClir(int32_t slotId)
415 {
416 TELEPHONY_LOGI("ImsService::InquireClir entry");
417 return request_.InquireClirRequest(slotId);
418 }
419
SetCallTransfer(int32_t slotId,int32_t reason,int32_t mode,const std::string & transferNum,int32_t classType)420 int32_t ImsService::SetCallTransfer(
421 int32_t slotId, int32_t reason, int32_t mode, const std::string &transferNum, int32_t classType)
422 {
423 TELEPHONY_LOGI("ImsService::SetCallTransfer entry");
424 return request_.SetCallTransferRequest(slotId, reason, mode, transferNum, classType);
425 }
426
GetCallTransfer(int32_t slotId,int32_t reason)427 int32_t ImsService::GetCallTransfer(int32_t slotId, int32_t reason)
428 {
429 TELEPHONY_LOGI("ImsService::GetCallTransfer entry");
430 return request_.GetCallTransferRequest(slotId, reason);
431 }
432
SetCallRestriction(int32_t slotId,const std::string & fac,int32_t mode,const std::string & pw)433 int32_t ImsService::SetCallRestriction(int32_t slotId, const std::string &fac, int32_t mode, const std::string &pw)
434 {
435 TELEPHONY_LOGI("ImsService::SetCallRestriction entry");
436 return request_.SetCallRestrictionRequest(slotId, fac, mode, pw);
437 }
438
GetCallRestriction(int32_t slotId,const std::string & fac)439 int32_t ImsService::GetCallRestriction(int32_t slotId, const std::string &fac)
440 {
441 TELEPHONY_LOGI("ImsService::GetCallRestriction entry");
442 return request_.GetCallRestrictionRequest(slotId, fac);
443 }
444
SetCallWaiting(int32_t slotId,bool activate)445 int32_t ImsService::SetCallWaiting(int32_t slotId, bool activate)
446 {
447 TELEPHONY_LOGI("ImsService::SetCallWaiting entry");
448 return request_.SetCallWaitingRequest(slotId, activate);
449 }
450
GetCallWaiting(int32_t slotId)451 int32_t ImsService::GetCallWaiting(int32_t slotId)
452 {
453 TELEPHONY_LOGI("ImsService::GetCallWaiting entry");
454 return request_.GetCallWaitingRequest(slotId);
455 }
456 } // namespace Telephony
457 } // namespace OHOS
458