• 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_SERVICE_LISTENER_H
17 #define OHOS_DM_SERVICE_LISTENER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <string>
22 #include <unordered_map>
23 #include <unordered_set>
24 
25 #include "dm_device_info.h"
26 #include "dm_device_profile_info.h"
27 #include "idevice_manager_service_listener.h"
28 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
29 #include "kv_adapter_manager.h"
30 #endif
31 #if !defined(__LITEOS_M__)
32 #include "ipc_notify_dmfa_result_req.h"
33 #include "ipc_server_listener.h"
34 #endif
35 #include "ipc_notify_device_state_req.h"
36 
37 namespace OHOS {
38 namespace DistributedHardware {
39 class DM_EXPORT DeviceManagerServiceListener : public IDeviceManagerServiceListener {
40 public:
DeviceManagerServiceListener()41     DeviceManagerServiceListener() {};
~DeviceManagerServiceListener()42     virtual ~DeviceManagerServiceListener() {};
43 
44     void OnDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state,
45         const DmDeviceInfo &info) override;
46 
47     void OnDeviceFound(const ProcessInfo &processInfo, uint16_t subscribeId, const DmDeviceInfo &info) override;
48 
49     void OnDiscoveryFailed(const ProcessInfo &processInfo, uint16_t subscribeId, int32_t failedReason) override;
50 
51     void OnDiscoverySuccess(const ProcessInfo &processInfo, int32_t subscribeId) override;
52 
53     void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) override;
54 
55     void OnAuthResult(const ProcessInfo &processInfo, const std::string &deviceId, const std::string &token,
56         int32_t status, int32_t reason) override;
57 
58     void OnUiCall(const ProcessInfo &processInfo, std::string &paramJson) override;
59 
60     void OnCredentialResult(const ProcessInfo &processInfo, int32_t action, const std::string &resultInfo) override;
61 
62     DM_EXPORT void OnBindResult(const ProcessInfo &processInfo,
63         const PeerTargetId &targetId, int32_t result, int32_t status, std::string content) override;
64 
65     DM_EXPORT void OnUnbindResult(const ProcessInfo &processInfo,
66         const PeerTargetId &targetId, int32_t result, std::string content) override;
67 
68     void OnPinHolderCreate(const ProcessInfo &processInfo, const std::string &deviceId, DmPinType pinType,
69         const std::string &payload) override;
70     void OnPinHolderDestroy(const ProcessInfo &processInfo, DmPinType pinType, const std::string &payload) override;
71     void OnCreateResult(const ProcessInfo &processInfo, int32_t result) override;
72     void OnDestroyResult(const ProcessInfo &processInfo, int32_t result) override;
73     void OnPinHolderEvent(const ProcessInfo &processInfo, DmPinHolderEvent event, int32_t result,
74         const std::string &content) override;
75     void OnDeviceTrustChange(const std::string &udid, const std::string &uuid, DmAuthForm authForm) override;
76     void OnDeviceScreenStateChange(const ProcessInfo &processInfo, DmDeviceInfo &devInfo) override;
77     void OnCredentialAuthStatus(const ProcessInfo &processInfo, const std::string &deviceList, uint16_t deviceTypeId,
78                                 int32_t errcode) override;
79     void OnAppUnintall(const std::string &pkgName) override;
80     void OnSinkBindResult(const ProcessInfo &processInfo, const PeerTargetId &targetId, int32_t result,
81         int32_t status, std::string content) override;
82     void OnProcessRemove(const ProcessInfo &processInfo) override;
83     void OnDevStateCallbackAdd(const ProcessInfo &processInfo, const std::vector<DmDeviceInfo> &deviceList) override;
84     void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo,
85         const std::vector<DmDeviceProfileInfo> &deviceProfileInfos, int32_t code) override;
86     void OnGetDeviceIconInfoResult(const ProcessInfo &processInfo,
87         const DmDeviceIconInfo &dmDeviceIconInfo, int32_t code) override;
88     void OnSetLocalDeviceNameResult(const ProcessInfo &processInfo,
89         const std::string &deviceName, int32_t code) override;
90     void OnSetRemoteDeviceNameResult(const ProcessInfo &processInfo, const std::string &deviceId,
91         const std::string &deviceName, int32_t code) override;
92     void SetExistPkgName(const std::set<std::string> &pkgNameSet) override;
93 
94     std::string GetLocalDisplayDeviceName() override;
95     int32_t OpenAuthSessionWithPara(const std::string &deviceId, int32_t actionId, bool isEnable160m) override;
96 
97 private:
98     void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName,
99         const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo);
100     void SetDeviceInfo(std::shared_ptr<IpcNotifyDeviceStateReq> pReq, const ProcessInfo &processInfo,
101         const DmDeviceState &state, const DmDeviceInfo &deviceInfo, const DmDeviceBasicInfo &deviceBasicInfo);
102     int32_t FillUdidAndUuidToDeviceInfo(const std::string &pkgName, DmDeviceInfo &dmDeviceInfo);
103     void ProcessDeviceStateChange(const ProcessInfo &processInfo, const DmDeviceState &state, const DmDeviceInfo &info,
104         const DmDeviceBasicInfo &deviceBasicInfo);
105     void ProcessAppStateChange(const ProcessInfo &processInfo, const DmDeviceState &state,
106         const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo);
107     void SetDeviceScreenInfo(std::shared_ptr<IpcNotifyDeviceStateReq> pReq, const ProcessInfo &processInfo,
108         const DmDeviceInfo &deviceInfo);
109     void RemoveOnlinePkgName(const DmDeviceInfo &info);
110 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
111     DM_EXPORT int32_t ConvertUdidHashToAnoyAndSave(const std::string &pkgName,
112         DmDeviceInfo &deviceInfo);
113     int32_t ConvertUdidHashToAnoyDeviceId(const std::string &pkgName, const std::string &udidHash,
114         std::string &anoyDeviceId);
115 #endif
116     std::vector<ProcessInfo> GetWhiteListSAProcessInfo(DmCommonNotifyEvent dmCommonNotifyEvent);
117     std::vector<ProcessInfo> GetNotifyProcessInfoByUserId(int32_t userId, DmCommonNotifyEvent dmCommonNotifyEvent);
118     ProcessInfo DealBindProcessInfo(const ProcessInfo &processInfo);
119     void ProcessDeviceOnline(const std::vector<ProcessInfo> &procInfoVec, const ProcessInfo &processInfo,
120         const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo);
121     void ProcessDeviceOffline(const std::vector<ProcessInfo> &procInfoVec, const ProcessInfo &processInfo,
122         const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo);
123     void ProcessDeviceInfoChange(const std::vector<ProcessInfo> &procInfoVec, const ProcessInfo &processInfo,
124         const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo);
125     void ProcessAppOnline(const std::vector<ProcessInfo> &procInfoVec, const ProcessInfo &processInfo,
126         const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo);
127     void ProcessAppOffline(const std::vector<ProcessInfo> &procInfoVec, const ProcessInfo &processInfo,
128         const DmDeviceState &state, const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo);
129     void RemoveNotExistProcess();
130 private:
131 #if !defined(__LITEOS_M__)
132     IpcServerListener ipcServerListener_;
133     static std::mutex alreadyNotifyPkgNameLock_;
134     static std::map<std::string, DmDeviceInfo> alreadyOnlinePkgName_;
135     static std::unordered_set<std::string> highPriorityPkgNameSet_;
136     static std::mutex actUnrelatedPkgNameLock_;
137     static std::set<std::string> actUnrelatedPkgName_;
138 #endif
139 };
140 } // namespace DistributedHardware
141 } // namespace OHOS
142 #endif // OHOS_DM_SERVICE_LISTENER_H