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