• 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 #ifndef CELLULAR_CALL_SERVICE_H
17 #define CELLULAR_CALL_SERVICE_H
18 
19 #include <memory>
20 
21 #include "cellular_call_config.h"
22 #include "cellular_call_handler.h"
23 #include "cellular_call_stub.h"
24 #include "cellular_call_supplement.h"
25 #include "event_runner.h"
26 #include "iremote_broker.h"
27 #include "singleton.h"
28 #include "system_ability.h"
29 #include "system_ability_status_change_stub.h"
30 
31 namespace OHOS {
32 namespace Telephony {
33 enum class ServiceRunningState { STATE_STOPPED, STATE_RUNNING };
34 
35 class CellularCallService : public SystemAbility,
36                             public CellularCallStub,
37                             public std::enable_shared_from_this<CellularCallService> {
38     DECLARE_DELAYED_SINGLETON(CellularCallService)
39     DECLEAR_SYSTEM_ABILITY(CellularCallService)
40 
41 public:
42     /**
43      * service OnStart
44      */
45     void OnStart() override;
46 
47     /**
48      * service OnStop
49      */
50     void OnStop() override;
51 
52     /**
53      * service dump
54      *
55      * @param fd
56      * @param args
57      * @return
58      */
59     int32_t Dump(std::int32_t fd, const std::vector<std::u16string> &args) override;
60 
61     /**
62      * Get serviceRunningState_
63      * @return serviceRunningState_
64      */
65     int32_t GetServiceRunningState();
66 
67     /**
68      * RegisterHandler
69      */
70     void RegisterHandler();
71 
72     /**
73      * Get bindTime_
74      *
75      * @return int64_t
76      */
77     std::string GetBindTime();
78 
79     /**
80      * Get EndTime
81      *
82      * @return int64_t
83      */
84     std::string GetEndTime();
85 
86     /**
87      * Get SpendTime
88      *
89      * @return int64_t
90      */
91     std::string GetSpendTime();
92 
93     /**
94      * Dial
95      *
96      * @param CellularCallInfo, dial param.
97      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
98      */
99     int32_t Dial(const CellularCallInfo &callInfo) override;
100 
101     /**
102      * HangUp
103      *
104      * @param CellularCallInfo, HangUp param.
105      * @param CallSupplementType
106      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
107      */
108     int32_t HangUp(const CellularCallInfo &callInfo, CallSupplementType type) override;
109 
110     /**
111      * Reject
112      *
113      * @param CellularCallInfo, Reject param.
114      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
115      */
116     int32_t Reject(const CellularCallInfo &callInfo) override;
117 
118     /**
119      * Answer
120      *
121      * @param CellularCallInfo, Answer param.
122      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
123      */
124     int32_t Answer(const CellularCallInfo &callInfo) override;
125 
126     /**
127      * HoldCall
128      *
129      * @param CellularCallInfo, Hold param.
130      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
131      */
132     int32_t HoldCall(const CellularCallInfo &callInfo) override;
133 
134     /**
135      * UnHoldCall
136      *
137      * @param CellularCallInfo, UnHold param.
138      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
139      */
140     int32_t UnHoldCall(const CellularCallInfo &callInfo) override;
141 
142     /**
143      * SwitchCall
144      *
145      * @param CellularCallInfo, SwitchCall param.
146      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
147      */
148     int32_t SwitchCall(const CellularCallInfo &callInfo) override;
149 
150     /**
151      * IsEmergencyPhoneNumber
152      *
153      * @param slotId
154      * @param phone number
155      * @param enabled Is Urgent Call
156      * @return TELEPHONY_SUCCESS on success, others on failure.
157      */
158     int32_t IsEmergencyPhoneNumber(int32_t slotId, const std::string &phoneNum, bool &enabled) override;
159 
160     /**
161      * SetEmergencyCallList
162      *
163      * @param slotId
164      * @param eccVec
165      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
166      */
167     int32_t SetEmergencyCallList(int32_t slotId, std::vector<EmergencyCall> &eccVec) override;
168 
169     /**
170      * Merge into multiple calls
171      *
172      * @param CellularCallInfo
173      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
174      */
175     int32_t CombineConference(const CellularCallInfo &callInfo) override;
176 
177     /**
178      * SeparateConference
179      *
180      * @param CellularCallInfo
181      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
182      */
183     int32_t SeparateConference(const CellularCallInfo &callInfo) override;
184 
185     /**
186      * InviteToConference
187      *
188      * @param slotId
189      * @param numberList
190      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
191      */
192     int32_t InviteToConference(int32_t slotId, const std::vector<std::string> &numberList) override;
193 
194     /**
195      * KickOutFromConference
196      *
197      * @param slotId
198      * @param numberList
199      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
200      */
201     int32_t KickOutFromConference(int32_t slotId, const std::vector<std::string> &numberList) override;
202 
203     /**
204      * Hang Up All Connection
205      *
206      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
207      */
208     int32_t HangUpAllConnection() override;
209 
210     /**
211      * Hang Up All Connection
212      *
213      * @param slotId
214      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
215      */
216     int32_t HangUpAllConnection(int32_t slotId) override;
217 
218     /**
219      * IMS Update Call Media Mode
220      *
221      * @param CellularCallInfo
222      * @param ImsCallMode
223      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
224      */
225     int32_t UpdateImsCallMode(const CellularCallInfo &callInfo, ImsCallMode mode) override;
226 
227     /**
228      * Register CallManager CallBack
229      *
230      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
231      */
232     int32_t RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback) override;
233 
234     /**
235      * UnRegister CallManager CallBack
236      *
237      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
238      */
239     int32_t UnRegisterCallManagerCallBack() override;
240 
241     /**
242      * StartDtmf
243      *
244      * @param Dtmf Code
245      * @param CellularCallInfo
246      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
247      */
248     int32_t StartDtmf(char cDtmfCode, const CellularCallInfo &callInfo) override;
249 
250     /**
251      * StopDtmf
252      *
253      * @param CellularCallInfo
254      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
255      */
256     int32_t StopDtmf(const CellularCallInfo &callInfo) override;
257 
258     /**
259      * SendDtmf
260      *
261      * @param Dtmf Code
262      * @param CellularCallInfo
263      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
264      */
265     int32_t SendDtmf(char cDtmfCode, const CellularCallInfo &callInfo) override;
266 
267     /**
268      * Start Rtt
269      *
270      * @param slotId
271      * @param msg
272      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
273      */
274     int32_t StartRtt(int32_t slotId, const std::string &msg) override;
275 
276     /**
277      * Stop Rtt
278      *
279      * @param slotId
280      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
281      */
282     int32_t StopRtt(int32_t slotId) override;
283 
284     /**
285      * Set Call Transfer
286      *
287      * @param slotId
288      * @param CallTransferInfo
289      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
290      */
291     int32_t SetCallTransferInfo(int32_t slotId, const CallTransferInfo &cfInfo) override;
292 
293     /**
294      * Get Call Transfer
295      *
296      * @param slotId
297      * @param CallTransferType
298      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
299      */
300     int32_t GetCallTransferInfo(int32_t slotId, CallTransferType type) override;
301 
302     /**
303      * Set Call Waiting
304      *
305      * @param slotId
306      * @param activate
307      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
308      */
309     int32_t SetCallWaiting(int32_t slotId, bool activate) override;
310 
311     /**
312      * Inquire Call Waiting
313      *
314      * @param slotId
315      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
316      */
317     int32_t GetCallWaiting(int32_t slotId) override;
318 
319     /**
320      * Set Call Restriction
321      *
322      * @param slotId
323      * @param CallRestrictionInfo
324      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
325      */
326     int32_t SetCallRestriction(int32_t slotId, const CallRestrictionInfo &crInfo) override;
327 
328     /**
329      * Inquire Call Restriction
330      *
331      * @param slotId
332      * @param CallRestrictionType
333      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
334      */
335     int32_t GetCallRestriction(int32_t slotId, CallRestrictionType facType) override;
336 
337     /**
338      * Set Domain Preference Mode
339      *
340      * @param slotId
341      * @param mode
342      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
343      */
344     int32_t SetDomainPreferenceMode(int32_t slotId, int32_t mode) override;
345 
346     /**
347      * Get Domain Preference Mode
348      *
349      * @param slotId
350      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
351      */
352     int32_t GetDomainPreferenceMode(int32_t slotId) override;
353 
354     /**
355      * Set Ims Switch Status
356      *
357      * @param slotId
358      * @param active
359      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
360      */
361     int32_t SetImsSwitchStatus(int32_t slotId, bool active) override;
362 
363     /**
364      * Get Ims Switch Status
365      *
366      * @param slotId
367      * @param enabled
368      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
369      */
370     int32_t GetImsSwitchStatus(int32_t slotId, bool &enabled) override;
371 
372     /**
373      * Set Ims Config
374      *
375      * @param slotId
376      * @param ImsConfigItem
377      * @param value
378      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
379      */
380     int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, const std::string &value) override;
381 
382     /**
383      * Set Ims Config
384      *
385      * @param slotId
386      * @param ImsConfigItem
387      * @param value
388      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
389      */
390     int32_t SetImsConfig(int32_t slotId, ImsConfigItem item, int32_t value) override;
391 
392     /**
393      * Get Ims Config
394      *
395      * @param slotId
396      * @param ImsConfigItem
397      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
398      */
399     int32_t GetImsConfig(int32_t slotId, ImsConfigItem item) override;
400 
401     /**
402      * Set Ims Feature Value
403      *
404      * @param slotId
405      * @param FeatureType
406      * @param value
407      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
408      */
409     int32_t SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value) override;
410 
411     /**
412      * Get Ims Feature Value
413      *
414      * @param slotId
415      * @param FeatureType
416      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
417      */
418     int32_t GetImsFeatureValue(int32_t slotId, FeatureType type) override;
419 
420     /**
421      * CtrlCamera
422      *
423      * @param cameraId
424      * @param callingUid
425      * @param callingPid
426      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
427      */
428     int32_t CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid) override;
429 
430     /**
431      * SetPreviewWindow
432      *
433      * @param x
434      * @param y
435      * @param z
436      * @param width
437      * @param height
438      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
439      */
440     int32_t SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height) override;
441 
442     /**
443      * SetDisplayWindow
444      *
445      * @param x
446      * @param y
447      * @param z
448      * @param width
449      * @param height
450      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
451      */
452     int32_t SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height) override;
453 
454     /**
455      * SetCameraZoom
456      *
457      * @param zoomRatio
458      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
459      */
460     int32_t SetCameraZoom(float zoomRatio) override;
461 
462     /**
463      * SetPauseImage
464      *
465      * @param path
466      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
467      */
468     int32_t SetPauseImage(const std::u16string &path) override;
469 
470     /**
471      * SetDeviceDirection
472      *
473      * @param rotation
474      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
475      */
476     int32_t SetDeviceDirection(int32_t rotation) override;
477 
478     /**
479      * SetMute
480      *
481      * @param mute
482      * @param slotId
483      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
484      */
485     int32_t SetMute(int32_t slotId, int32_t mute) override;
486 
487     /**
488      * GetMute
489      *
490      * @param slotId
491      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
492      */
493     int32_t GetMute(int32_t slotId) override;
494 
495     /**
496      * Is need choose IMS for execute
497      *
498      * @param slotId
499      * @return bool
500      */
501     bool IsNeedIms(int32_t slotId) const;
502 
503     /**
504      * Get CSControl
505      *
506      * @param slotId
507      * @return shared_ptr CSControl
508      */
509     std::shared_ptr<CSControl> GetCsControl(int32_t slotId);
510 
511     /**
512      * Get IMControl
513      *
514      * @param slotId
515      * @return shared_ptr CSControl
516      */
517     std::shared_ptr<IMSControl> GetImsControl(int32_t slotId);
518 
519     /**
520      * Set SetCsControl
521      *
522      * @param slotId
523      * @param  shared_ptr CSControl
524      */
525     void SetCsControl(int32_t slotId, const std::shared_ptr<CSControl> &csControl);
526 
527     /**
528      * Set IMSControl
529      *
530      * @param slotId
531      * @param  shared_ptr IMSControl
532      */
533     void SetImsControl(int32_t slotId, const std::shared_ptr<IMSControl> &imsControl);
534 
535     /**
536      * Get Handler
537      *
538      * @param slotId
539      * @return CellularCallHandler
540      */
541     std::shared_ptr<CellularCallHandler> GetHandler(int32_t slotId);
542 
543     void SetSrvccState(int32_t srvccState);
544 
545     int32_t GetSrvccState();
546 
547 #ifdef CALL_MANAGER_AUTO_START_OPTIMIZE
548     /**
549      * Get call manager service
550      */
551     void StartCallManagerService();
552 #endif
553 
554 private:
555     /**
556      * Init service
557      *
558      * @return whether init success
559      */
560     bool Init();
561 
562     /**
563      * Register Handler
564      */
565     void RegisterCoreServiceHandler();
566 
567     /**
568      * Create Handler
569      */
570     void CreateHandler();
571 
572     /**
573      * Handler Reset UnRegister
574      */
575     void HandlerResetUnRegister();
576 
577     /**
578      * SendEventRegisterHandler
579      */
580     void SendEventRegisterHandler();
581 
582     /**
583      * Is Valid Slot Id
584      *
585      * @param slotId
586      * @return bool
587      */
588     bool IsValidSlotId(int32_t slotId) const;
589 
590     /**
591      * Check whether IMS should be used firstly for emergency call
592      *
593      * @param CellularCallInfo
594      * @return bool
595      */
596     bool UseImsForEmergency(const CellularCallInfo &callInfo);
597 
598     /**
599      * Handle CallManager exception
600      */
601     void HandleCallManagerException();
602 
603 private:
604     int64_t bindTime_ = 0L;
605     int64_t endTime_ = 0L;
606     int64_t spendTime_ = 0L;
607     ServiceRunningState state_;
608     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
609     std::map<int32_t, std::shared_ptr<CellularCallHandler>> handlerMap_;
610     int32_t srvccState_ = SrvccState::SRVCC_NONE;
611     std::map<int32_t, std::shared_ptr<CSControl>> csControlMap_;
612     std::map<int32_t, std::shared_ptr<IMSControl>> imsControlMap_;
613     sptr<NetworkSearchCallBackBase> networkSearchCallBack_;
614     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
615     sptr<ISystemAbilityStatusChange> callManagerListener_ = nullptr;
616 
617 private:
618     class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub {
619     public:
620         SystemAbilityStatusChangeListener() = default;
621         explicit SystemAbilityStatusChangeListener(std::shared_ptr<CellularCallHandler> &cellularCallHandler);
622         ~SystemAbilityStatusChangeListener() = default;
623         virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
624         virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
625 
626     private:
627         std::shared_ptr<CellularCallHandler> cellularCallHandler_ = nullptr;
628         int32_t count_ = 0;
629     };
630 };
631 } // namespace Telephony
632 } // namespace OHOS
633 
634 #endif // CELLULAR_CALL_SERVICE_H
635