• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-2025 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 TELEPHONY_DISTRIBUTED_CALL_MANAGER_H
17 #define TELEPHONY_DISTRIBUTED_CALL_MANAGER_H
18 
19 #include <string>
20 #include <memory>
21 #include <map>
22 #include <mutex>
23 #include <atomic>
24 
25 #include "singleton.h"
26 #include "idcall_device_callback.h"
27 #include "iservice_registry.h"
28 #include "system_ability_definition.h"
29 #include "system_ability_status_change_stub.h"
30 #include "call_manager_inner_type.h"
31 #include "distributed_call_proxy.h"
32 
33 namespace OHOS {
34 namespace Telephony {
35 class DistributedCallManager : public std::enable_shared_from_this<DistributedCallManager> {
36     DECLARE_DELAYED_SINGLETON(DistributedCallManager)
37 public:
38     void Init();
39     int32_t AddDCallDevice(const std::string& devId);
40     int32_t RemoveDCallDevice(const std::string& devId);
41     void ClearDCallDevices();
42     void ClearConnectedDCallDevice();
43     std::string GetConnectedDCallDeviceAddr();
44     AudioDeviceType GetConnectedDCallDeviceType();
45     void SwitchOffDCallDeviceSync();
46     bool IsDCallDeviceSwitchedOn();
47     bool SwitchOnDCallDeviceSync(const AudioDevice& device);
48     void SwitchOnDCallDeviceAsync(const AudioDevice& device);
49     void SetCallState(bool isActive);
50     void DealDisconnectCall();
51     bool IsDistributedCarDeviceOnline();
52 
53     int32_t OnDCallDeviceOnline(const std::string &devId);
54     int32_t OnDCallDeviceOffline(const std::string &devId);
55     void OnDCallSystemAbilityAdded(const std::string &deviceId);
56     void OnDCallSystemAbilityRemoved(const std::string &deviceId);
57 
58     void GetConnectedDCallDevice(AudioDevice& device);
59     bool IsSelectVirtualModem();
60     void ReportDistributedDeviceInfo(const AudioDevice& device);
61     void ReportDistributedDeviceInfoForSwitchOff();
62 
63     std::string GetConnectedDCallDeviceId();
64 private:
65     class DistributedCallDeviceListener : public OHOS::DistributedHardware::IDCallDeviceCallback {
66     public:
67         DistributedCallDeviceListener() = default;
68         ~DistributedCallDeviceListener() = default;
69 
70         int32_t OnDCallDeviceOnline(const std::string &devId) override;
71         int32_t OnDCallDeviceOffline(const std::string &devId) override;
72     };
73 
74     bool CreateDAudioDevice(const std::string& devId, AudioDevice& device);
75     std::string GetDevIdFromAudioDevice(const AudioDevice& device);
76     void NotifyOnlineDCallDevices(std::vector<std::string> devices);
77     bool isCeliaCall();
78     void SetConnectedDCallDevice(const AudioDevice& device);
79 
80 private:
81     std::atomic<bool> isCallActived_ = false;
82     std::atomic<bool> dCallDeviceSwitchedOn_ = false;
83     std::mutex connectedDevMtx_;
84     std::mutex onlineDeviceMtx_;
85     std::string connectedDevId_;
86     AudioDevice connectedAudioDevice_;
87     AudioDevice currentAudioDevice_;
88     std::map<std::string, AudioDevice> onlineDCallDevices_;
89     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
90     std::mutex dcallProxyMtx_;
91     std::shared_ptr<DistributedCallProxy> dcallProxy_ = nullptr;
92     std::shared_ptr<DistributedCallDeviceListener> dcallDeviceListener_ = nullptr;
93 };
94 
95 class DCallSystemAbilityListener : public SystemAbilityStatusChangeStub {
96 public:
97     DCallSystemAbilityListener() = default;
98     ~DCallSystemAbilityListener() = default;
99     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
100     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
101 };
102 
103 } // namespace Telephony
104 } // namespace OHOS
105 #endif // TELEPHONY_DISTRIBUTED_CALL_MANAGER_H
106