• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 {
36     DECLARE_DELAYED_SINGLETON(DistributedCallManager)
37 public:
38     void Init();
39     void AddDCallDevice(const std::string& devId);
40     void RemoveDCallDevice(const std::string& devId);
41     void ClearDCallDevice();
42     void ClearConnectedDAudioDevice();
43     std::string GetConnectedDCallAddr();
44     AudioDeviceType GetConnectedDCallType();
45     void DisconnectDCallDevice();
46     bool IsDAudioDeviceConnected();
47     bool SwitchDCallDevice(const AudioDevice& device);
48     void SwitchDCallDeviceAsync(const AudioDevice& device);
49     void SetCallState(bool isActive);
50 
51     void OnDeviceOnline(const std::string &devId);
52     void OnDeviceOffline(const std::string &devId);
53     void OnDCallSystemAbilityAdded(const std::string &deviceId);
54     void OnDCallSystemAbilityRemoved(const std::string &deviceId);
55 
56 private:
57     class DistributedCallDeviceListener : public OHOS::DistributedHardware::IDCallDeviceCallback {
58     public:
59         DistributedCallDeviceListener() = default;
60         ~DistributedCallDeviceListener() = default;
61 
62         int32_t OnDeviceOnline(const std::string &devId) override;
63         int32_t OnDeviceOffline(const std::string &devId) override;
64     };
65 
66     bool CreateDAudioDevice(const std::string& devId, AudioDevice& device);
67     std::string GetDevIdFromAudioDevice(const AudioDevice& device);
68     void NotifyOnlineDCallDevices(std::vector<std::string> devices);
69     std::string GetConnectedDCallDeviceId();
70 
71     void GetConnectedAudioDevice(AudioDevice& device);
72     void SetConnectedAudioDevice(const AudioDevice& device);
73     void SwitchToDistributedCallDevice(std::unique_ptr<AudioDevice> device);
74 
75 private:
76     std::atomic<bool> isCallActived_ = false;
77     std::atomic<bool> isConnected_ = false;
78     std::mutex connectedDevMtx_;
79     std::mutex onlineDeviceMtx_;
80     std::string connectedDevId_;
81     AudioDevice connectedAudioDevice_;
82     std::map<std::string, AudioDevice> onlineDCallDevices_;
83     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
84     std::shared_ptr<DistributedCallProxy> dcallProxy_ = nullptr;
85     std::shared_ptr<DistributedCallDeviceListener> dcallDeviceListener_ = nullptr;
86 };
87 
88 class DCallSystemAbilityListener : public SystemAbilityStatusChangeStub {
89 public:
90     DCallSystemAbilityListener() = default;
91     ~DCallSystemAbilityListener() = default;
92     void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
93     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
94 };
95 } // namespace Telephony
96 } // namespace OHOS
97 #endif // TELEPHONY_DISTRIBUTED_CALL_MANAGER_H
98