• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 OHOS_DM_NOTIFY_H
17 #define OHOS_DM_NOTIFY_H
18 
19 #include <chrono>
20 #include <condition_variable>
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <set>
25 
26 #include "device_manager_callback.h"
27 #include "dm_single_instance.h"
28 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
29 #include "ffrt.h"
30 #endif
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 class DeviceManagerNotify {
35     DM_DECLARE_SINGLE_INSTANCE(DeviceManagerNotify);
36 
37 public:
38     void RegisterDeathRecipientCallback(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback);
39     void UnRegisterDeathRecipientCallback(const std::string &pkgName);
40     void RegisterDeviceStateCallback(const std::string &pkgName, std::shared_ptr<DeviceStateCallback> callback);
41     void UnRegisterDeviceStateCallback(const std::string &pkgName);
42     void UnRegisterDeviceStatusCallback(const std::string &pkgName);
43     void RegisterDeviceStatusCallback(const std::string &pkgName, std::shared_ptr<DeviceStatusCallback> callback);
44     void RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId,
45                                    std::shared_ptr<DiscoveryCallback> callback);
46     void UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId);
47     void RegisterPublishCallback(const std::string &pkgName, int32_t publishId,
48         std::shared_ptr<PublishCallback> callback);
49     void UnRegisterPublishCallback(const std::string &pkgName, int32_t publishId);
50     void RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId,
51                                       std::shared_ptr<AuthenticateCallback> callback);
52     void UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId);
53     void UnRegisterPackageCallback(const std::string &pkgName);
54     void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr<DeviceManagerUiCallback> callback);
55     void UnRegisterDeviceManagerFaCallback(const std::string &pkgName);
56     void RegisterCredentialCallback(const std::string &pkgName, std::shared_ptr<CredentialCallback> callback);
57     void UnRegisterCredentialCallback(const std::string &pkgName);
58     void RegisterBindCallback(const std::string &pkgName, const PeerTargetId &targetId,
59         std::shared_ptr<BindTargetCallback> callback);
60     void RegisterUnbindCallback(const std::string &pkgName, const PeerTargetId &targetId,
61         std::shared_ptr<UnbindTargetCallback> callback);
62     void OnBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status,
63         std::string content);
64     void OnUnbindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, std::string content);
65     void RegisterPinHolderCallback(const std::string &pkgName, std::shared_ptr<PinHolderCallback> callback);
66     void RegDevTrustChangeCallback(const std::string &pkgName, std::shared_ptr<DevTrustChangeCallback> callback);
67     void RegisterDeviceScreenStatusCallback(const std::string &pkgName,
68         std::shared_ptr<DeviceScreenStatusCallback> callback);
69     void UnRegisterDeviceScreenStatusCallback(const std::string &pkgName);
70     void RegisterCredentialAuthStatusCallback(const std::string &pkgName,
71         std::shared_ptr<CredentialAuthStatusCallback> callback);
72     void UnRegisterCredentialAuthStatusCallback(const std::string &pkgName);
73     void RegisterSinkBindCallback(const std::string &pkgName, std::shared_ptr<BindTargetCallback> callback);
74     void UnRegisterSinkBindCallback(const std::string &pkgName);
75 
76     int32_t RegisterGetDeviceProfileInfoListCallback(const std::string &pkgName,
77         std::shared_ptr<GetDeviceProfileInfoListCallback> callback);
78     int32_t UnRegisterGetDeviceProfileInfoListCallback(const std::string &pkgName);
79     void OnGetDeviceProfileInfoListResult(const std::string &pkgName,
80         const std::vector<DmDeviceProfileInfo> &deviceProfileInfos, int32_t code);
81     int32_t RegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk,
82         std::shared_ptr<GetDeviceIconInfoCallback> callback);
83     int32_t UnRegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk);
84     void OnGetDeviceIconInfoResult(const std::string &pkgName, const DmDeviceIconInfo &deviceIconInfo, int32_t code);
85     int32_t RegisterSetLocalDeviceNameCallback(const std::string &pkgName,
86         std::shared_ptr<SetLocalDeviceNameCallback> callback);
87     int32_t UnRegisterSetLocalDeviceNameCallback(const std::string &pkgName);
88     void OnSetLocalDeviceNameResult(const std::string &pkgName, int32_t code);
89     int32_t RegisterSetRemoteDeviceNameCallback(const std::string &pkgName, const std::string &deviceId,
90         std::shared_ptr<SetRemoteDeviceNameCallback> callback);
91     int32_t UnRegisterSetRemoteDeviceNameCallback(const std::string &pkgName, const std::string &deviceId);
92     void OnSetRemoteDeviceNameResult(const std::string &pkgName, const std::string &deviceId, int32_t code);
93 
94 public:
95     static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
96     static void DeviceInfoOffline(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
97     static void DeviceInfoChanged(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
98     static void DeviceInfoReady(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk);
99     static void DeviceBasicInfoOnline(const DmDeviceBasicInfo &deviceBasicInfo,
100         std::shared_ptr<DeviceStatusCallback> tempCbk);
101     static void DeviceBasicInfoOffline(const DmDeviceBasicInfo &deviceBasicInfo,
102         std::shared_ptr<DeviceStatusCallback> tempCbk);
103     static void DeviceBasicInfoChanged(const DmDeviceBasicInfo &deviceBasicInfo,
104         std::shared_ptr<DeviceStatusCallback> tempCbk);
105     static void DeviceBasicInfoReady(const DmDeviceBasicInfo &deviceBasicInfo,
106         std::shared_ptr<DeviceStatusCallback> tempCbk);
107     static void DeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm,
108         std::shared_ptr<DevTrustChangeCallback> tempCbk);
109 public:
110     void OnRemoteDied();
111     void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
112     void OnDeviceOnline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
113     void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
114     void OnDeviceOffline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
115     void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
116     void OnDeviceChanged(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
117     void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
118     void OnDeviceReady(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo);
119     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo);
120     void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo);
121     void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason);
122     void OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId);
123     void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult);
124     void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token,
125                       int32_t status, int32_t reason);
126     void OnUiCall(std::string &pkgName, std::string &paramJson);
127     void OnCredentialResult(const std::string &pkgName, int32_t &action, const std::string &credentialResult);
128     void OnPinHolderCreate(const std::string &deviceId, const std::string &pkgName, DmPinType pinType,
129         const std::string &payload);
130     void OnPinHolderDestroy(const std::string &pkgName, DmPinType pinType, const std::string &payload);
131     void OnCreateResult(const std::string &pkgName, int32_t result);
132     void OnDestroyResult(const std::string &pkgName, int32_t result);
133     void OnPinHolderEvent(const std::string &pkgName, DmPinHolderEvent event, int32_t result,
134                           const std::string &content);
135     std::map<std::string, std::shared_ptr<DmInitCallback>> GetDmInitCallback();
136     void OnDeviceTrustChange(const std::string &pkgName, const std::string &udid, const std::string &uuid,
137         int32_t authForm);
138     void OnDeviceScreenStatus(const std::string &pkgName, const DmDeviceInfo &deviceInfo);
139     void OnCredentialAuthStatus(const std::string &pkgName, const std::string &deviceList,
140                                 uint16_t deviceTypeId, int32_t errcode);
141     void OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status,
142         std::string content);
143     std::shared_ptr<DiscoveryCallback> GetDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId);
144     void GetCallBack(std::map<DmCommonNotifyEvent, std::set<std::string>> &callbackMap);
145 
146 private:
147 #if !defined(__LITEOS_M__)
148     std::mutex lock_;
149 #endif
150     std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_;
151     std::map<std::string, std::shared_ptr<DeviceStatusCallback>> deviceStatusCallback_;
152     std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_;
153     std::map<std::string, std::map<int32_t, std::shared_ptr<PublishCallback>>> devicePublishCallbacks_;
154     std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_;
155     std::map<std::string, std::shared_ptr<DmInitCallback>> dmInitCallback_;
156     std::map<std::string, std::shared_ptr<DeviceManagerUiCallback>> dmUiCallback_;
157     std::map<std::string, std::shared_ptr<CredentialCallback>> credentialCallback_;
158     std::map<std::string, std::map<PeerTargetId, std::shared_ptr<BindTargetCallback>>> bindCallback_;
159     std::map<std::string, std::map<PeerTargetId, std::shared_ptr<UnbindTargetCallback>>> unbindCallback_;
160     std::map<std::string, std::shared_ptr<PinHolderCallback>> pinHolderCallback_;
161     std::map<std::string, std::shared_ptr<DevTrustChangeCallback>> devTrustChangeCallback_;
162     std::map<std::string, std::shared_ptr<DeviceScreenStatusCallback>> deviceScreenStatusCallback_;
163     std::map<std::string, std::shared_ptr<CredentialAuthStatusCallback>> credentialAuthStatusCallback_;
164     std::map<std::string, std::shared_ptr<BindTargetCallback>> sinkBindTargetCallback_;
165     std::mutex bindLock_;
166     std::map<std::string, std::shared_ptr<GetDeviceProfileInfoListCallback>> getDeviceProfileInfoCallback_;
167     std::map<std::string,
168         std::map<std::string, std::set<std::shared_ptr<GetDeviceIconInfoCallback>>>> getDeviceIconInfoCallback_;
169     std::map<std::string, std::shared_ptr<SetLocalDeviceNameCallback>> setLocalDeviceNameCallback_;
170     std::map<std::string,
171         std::map<std::string, std::shared_ptr<SetRemoteDeviceNameCallback>>> setRemoteDeviceNameCallback_;
172 };
173 } // namespace DistributedHardware
174 } // namespace OHOS
175 #endif // OHOS_DM_NOTIFY_H
176