1 /*
2  * Copyright (C) 2023 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 VOIP_CALL_CONNECTION_H
17 #define VOIP_CALL_CONNECTION_H
18 
19 #include <mutex>
20 
21 #include "call_status_callback.h"
22 #include "i_call_status_callback.h"
23 #include "i_voip_call_manager_callback.h"
24 #include "i_voip_call_manager_service.h"
25 #include "if_system_ability_manager.h"
26 #include "refbase.h"
27 #include "rwlock.h"
28 #include "singleton.h"
29 #include "system_ability_status_change_stub.h"
30 
31 namespace OHOS {
32 namespace Telephony {
33 class VoipCallConnection : public std::enable_shared_from_this<VoipCallConnection> {
34     DECLARE_DELAYED_SINGLETON(VoipCallConnection)
35 
36 public:
37     void Init(int32_t systemAbilityId);
38     void UnInit();
39     int32_t GetCallManagerProxy();
40     int32_t AnswerCall(const VoipCallEventInfo &events, int32_t videoState);
41     int32_t RejectCall(const VoipCallEventInfo &events);
42     int32_t HangUpCall(const VoipCallEventInfo &events);
43     void ClearVoipCall();
44     int32_t RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback);
45     int32_t UnRegisterCallManagerCallBack();
46     int32_t SendCallUiEvent(std::string voipCallId, const CallAudioEvent &callAudioEvent);
47 
48 private:
49     class SystemAbilityListener : public SystemAbilityStatusChangeStub {
50     public:
51         SystemAbilityListener() = default;
52         ~SystemAbilityListener() = default;
53         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
54         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
55     };
56 #ifndef TELEPHONY_VOIP_CALL_MANAGER_SYS_ABILITY_ID
57 #define TELEPHONY_VOIP_CALL_MANAGER_SYS_ABILITY_ID 65968
58 #endif
59     int32_t systemAbilityId_ = TELEPHONY_VOIP_CALL_MANAGER_SYS_ABILITY_ID;
60     sptr<ICallStatusCallback> voipCallCallbackPtr_;
61     sptr<IVoipCallManagerService> voipCallManagerInterfacePtr_ = nullptr;
62     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
63     bool connectCallManagerState_ = false;
64     Utils::RWLock rwClientLock_;
65     std::mutex mutex_;
66 };
67 } // namespace Telephony
68 } // namespace OHOS
69 
70 #endif
71