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 <string> 21 #include <unordered_set> 22 #include <mutex> 23 24 #include "dm_device_info.h" 25 #include "dm_device_profile_info.h" 26 #include "idevice_manager_service_listener.h" 27 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 28 #include "kv_adapter_manager.h" 29 #endif 30 #if !defined(__LITEOS_M__) 31 #include "ipc_notify_dmfa_result_req.h" 32 #include "ipc_server_listener.h" 33 #endif 34 #include "ipc_notify_device_state_req.h" 35 36 namespace OHOS { 37 namespace DistributedHardware { 38 class DeviceManagerServiceListener : public IDeviceManagerServiceListener { 39 public: DeviceManagerServiceListener()40 DeviceManagerServiceListener() {}; ~DeviceManagerServiceListener()41 virtual ~DeviceManagerServiceListener() {}; 42 43 void OnDeviceStateChange(const std::string &pkgName, const DmDeviceState &state, const DmDeviceInfo &info) override; 44 45 void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &info) override; 46 47 void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, DmDeviceBasicInfo &info) override; 48 49 void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason) override; 50 51 void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId) override; 52 53 void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) override; 54 55 void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, int32_t status, 56 int32_t reason) override; 57 58 void OnUiCall(std::string &pkgName, std::string ¶mJson) override; 59 60 void OnCredentialResult(const std::string &pkgName, int32_t action, const std::string &resultInfo) override; 61 62 void OnBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, 63 int32_t status, std::string content) override; 64 65 void OnUnbindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, 66 std::string content) override; 67 68 void OnPinHolderCreate(const std::string &pkgName, const std::string &deviceId, DmPinType pinType, 69 const std::string &payload) override; 70 void OnPinHolderDestroy(const std::string &pkgName, DmPinType pinType, const std::string &payload) override; 71 void OnCreateResult(const std::string &pkgName, int32_t result) override; 72 void OnDestroyResult(const std::string &pkgName, int32_t result) override; 73 void OnPinHolderEvent(const std::string &pkgName, DmPinHolderEvent event, int32_t result, 74 const std::string &content) override; 75 76 void OnDeviceScreenStateChange(const std::string &pkgName, DmDeviceInfo &devInfo) override; 77 void OnCredentialAuthStatus(const std::string &pkgName, const std::string &proofInfo, uint16_t deviceTypeId, 78 int32_t errcode) override; 79 void OnGetDeviceProfileInfoListResult(const ProcessInfo &processInfo, 80 const std::vector<DmDeviceProfileInfo> &deviceProfileInfos, int32_t code) override; 81 private: 82 void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, 83 const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo); 84 void SetDeviceInfo(std::shared_ptr<IpcNotifyDeviceStateReq> pReq, const std::string &pkgName, 85 const DmDeviceState &state, const DmDeviceInfo &deviceInfo, const DmDeviceBasicInfo &deviceBasicInfo); 86 void ProcessDeviceStateChange(const DmDeviceState &state, const DmDeviceInfo &info, 87 const DmDeviceBasicInfo &deviceBasicInfo); 88 void ProcessAppStateChange(const std::string &pkgName, const DmDeviceState &state, 89 const DmDeviceInfo &info, const DmDeviceBasicInfo &deviceBasicInfo); 90 std::string ComposeOnlineKey(const std::string &pkgName, const std::string &devId); 91 void SetDeviceScreenInfo(std::shared_ptr<IpcNotifyDeviceStateReq> pReq, const std::string &pkgName, 92 const DmDeviceInfo &deviceInfo); 93 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 94 int32_t ConvertUdidHashToAnoyAndSave(const std::string &pkgName, DmDeviceInfo &deviceInfo); 95 int32_t ConvertUdidHashToAnoyDeviceId(const std::string &pkgName, const std::string &udidHash, 96 std::string &anoyDeviceId); 97 #endif 98 private: 99 #if !defined(__LITEOS_M__) 100 IpcServerListener ipcServerListener_; 101 static std::mutex alreadyOnlineSetLock_; 102 static std::unordered_set<std::string> alreadyOnlineSet_; 103 #endif 104 }; 105 } // namespace DistributedHardware 106 } // namespace OHOS 107 #endif // OHOS_DM_SERVICE_LISTENER_H