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 <string> 25 #include <vector> 26 27 #include "device_manager_callback.h" 28 #include "dm_device_info.h" 29 #include "dm_device_profile_info.h" 30 #include "dm_subscribe_info.h" 31 #include "dm_single_instance.h" 32 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) 33 #include "ffrt.h" 34 #endif 35 36 namespace OHOS { 37 namespace DistributedHardware { 38 class DeviceManagerNotify { 39 DM_DECLARE_SINGLE_INSTANCE(DeviceManagerNotify); 40 41 public: 42 void RegisterDeathRecipientCallback(const std::string &pkgName, std::shared_ptr<DmInitCallback> dmInitCallback); 43 void UnRegisterDeathRecipientCallback(const std::string &pkgName); 44 void RegisterDeviceStateCallback(const std::string &pkgName, std::shared_ptr<DeviceStateCallback> callback); 45 void UnRegisterDeviceStateCallback(const std::string &pkgName); 46 void UnRegisterDeviceStatusCallback(const std::string &pkgName); 47 void RegisterDeviceStatusCallback(const std::string &pkgName, std::shared_ptr<DeviceStatusCallback> callback); 48 void RegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId, 49 std::shared_ptr<DiscoveryCallback> callback); 50 void UnRegisterDiscoveryCallback(const std::string &pkgName, uint16_t subscribeId); 51 void RegisterPublishCallback(const std::string &pkgName, int32_t publishId, 52 std::shared_ptr<PublishCallback> callback); 53 void UnRegisterPublishCallback(const std::string &pkgName, int32_t publishId); 54 void RegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId, 55 std::shared_ptr<AuthenticateCallback> callback); 56 void UnRegisterAuthenticateCallback(const std::string &pkgName, const std::string &deviceId); 57 void UnRegisterPackageCallback(const std::string &pkgName); 58 void RegisterDeviceManagerFaCallback(const std::string &pkgName, std::shared_ptr<DeviceManagerUiCallback> callback); 59 void UnRegisterDeviceManagerFaCallback(const std::string &pkgName); 60 void RegisterCredentialCallback(const std::string &pkgName, std::shared_ptr<CredentialCallback> callback); 61 void UnRegisterCredentialCallback(const std::string &pkgName); 62 void RegisterBindCallback(const std::string &pkgName, const PeerTargetId &targetId, 63 std::shared_ptr<BindTargetCallback> callback); 64 void RegisterUnbindCallback(const std::string &pkgName, const PeerTargetId &targetId, 65 std::shared_ptr<UnbindTargetCallback> callback); 66 void OnBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status, 67 std::string content); 68 void OnUnbindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, std::string content); 69 void RegisterPinHolderCallback(const std::string &pkgName, std::shared_ptr<PinHolderCallback> callback); 70 void RegisterDeviceScreenStatusCallback(const std::string &pkgName, 71 std::shared_ptr<DeviceScreenStatusCallback> callback); 72 void UnRegisterDeviceScreenStatusCallback(const std::string &pkgName); 73 void RegisterCredentialAuthStatusCallback(const std::string &pkgName, 74 std::shared_ptr<CredentialAuthStatusCallback> callback); 75 void UnRegisterCredentialAuthStatusCallback(const std::string &pkgName); 76 77 int32_t RegisterGetDeviceProfileInfoListCallback(const std::string &pkgName, 78 std::shared_ptr<GetDeviceProfileInfoListCallback> callback); 79 int32_t UnRegisterGetDeviceProfileInfoListCallback(const std::string &pkgName); 80 void OnGetDeviceProfileInfoListResult(const std::string &pkgName, 81 const std::vector<DmDeviceProfileInfo> &deviceProfileInfos, int32_t code); 82 83 public: 84 static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk); 85 static void DeviceInfoOffline(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk); 86 static void DeviceInfoChanged(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk); 87 static void DeviceInfoReady(const DmDeviceInfo &deviceInfo, std::shared_ptr<DeviceStateCallback> tempCbk); 88 static void DeviceBasicInfoOnline(const DmDeviceBasicInfo &deviceBasicInfo, 89 std::shared_ptr<DeviceStatusCallback> tempCbk); 90 static void DeviceBasicInfoOffline(const DmDeviceBasicInfo &deviceBasicInfo, 91 std::shared_ptr<DeviceStatusCallback> tempCbk); 92 static void DeviceBasicInfoChanged(const DmDeviceBasicInfo &deviceBasicInfo, 93 std::shared_ptr<DeviceStatusCallback> tempCbk); 94 static void DeviceBasicInfoReady(const DmDeviceBasicInfo &deviceBasicInfo, 95 std::shared_ptr<DeviceStatusCallback> tempCbk); 96 public: 97 void OnRemoteDied(); 98 void OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 99 void OnDeviceOnline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 100 void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 101 void OnDeviceOffline(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 102 void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 103 void OnDeviceChanged(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 104 void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 105 void OnDeviceReady(const std::string &pkgName, const DmDeviceBasicInfo &deviceBasicInfo); 106 void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &deviceInfo); 107 void OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceBasicInfo &deviceBasicInfo); 108 void OnDiscoveryFailed(const std::string &pkgName, uint16_t subscribeId, int32_t failedReason); 109 void OnDiscoverySuccess(const std::string &pkgName, uint16_t subscribeId); 110 void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult); 111 void OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, 112 int32_t status, int32_t reason); 113 void OnUiCall(std::string &pkgName, std::string ¶mJson); 114 void OnCredentialResult(const std::string &pkgName, int32_t &action, const std::string &credentialResult); 115 void OnPinHolderCreate(const std::string &deviceId, const std::string &pkgName, DmPinType pinType, 116 const std::string &payload); 117 void OnPinHolderDestroy(const std::string &pkgName, DmPinType pinType, const std::string &payload); 118 void OnCreateResult(const std::string &pkgName, int32_t result); 119 void OnDestroyResult(const std::string &pkgName, int32_t result); 120 void OnPinHolderEvent(const std::string &pkgName, DmPinHolderEvent event, int32_t result, 121 const std::string &content); 122 std::map<std::string, std::shared_ptr<DmInitCallback>> GetDmInitCallback(); 123 void OnDeviceScreenStatus(const std::string &pkgName, const DmDeviceInfo &deviceInfo); 124 void OnCredentialAuthStatus(const std::string &pkgName, const std::string &proofInfo, 125 uint16_t deviceTypeId, int32_t errcode); 126 127 private: 128 #if !defined(__LITEOS_M__) 129 std::mutex lock_; 130 #endif 131 std::map<std::string, std::shared_ptr<DeviceStateCallback>> deviceStateCallback_; 132 std::map<std::string, std::shared_ptr<DeviceStatusCallback>> deviceStatusCallback_; 133 std::map<std::string, std::map<uint16_t, std::shared_ptr<DiscoveryCallback>>> deviceDiscoveryCallbacks_; 134 std::map<std::string, std::map<int32_t, std::shared_ptr<PublishCallback>>> devicePublishCallbacks_; 135 std::map<std::string, std::map<std::string, std::shared_ptr<AuthenticateCallback>>> authenticateCallback_; 136 std::map<std::string, std::shared_ptr<DmInitCallback>> dmInitCallback_; 137 std::map<std::string, std::shared_ptr<DeviceManagerUiCallback>> dmUiCallback_; 138 std::map<std::string, std::shared_ptr<CredentialCallback>> credentialCallback_; 139 std::map<std::string, std::map<PeerTargetId, std::shared_ptr<BindTargetCallback>>> bindCallback_; 140 std::map<std::string, std::map<PeerTargetId, std::shared_ptr<UnbindTargetCallback>>> unbindCallback_; 141 std::map<std::string, std::shared_ptr<PinHolderCallback>> pinHolderCallback_; 142 std::map<std::string, std::shared_ptr<DeviceScreenStatusCallback>> deviceScreenStatusCallback_; 143 std::map<std::string, std::shared_ptr<CredentialAuthStatusCallback>> credentialAuthStatusCallback_; 144 std::mutex bindLock_; 145 std::map<std::string, std::shared_ptr<GetDeviceProfileInfoListCallback>> getDeviceProfileInfoCallback_; 146 }; 147 } // namespace DistributedHardware 148 } // namespace OHOS 149 #endif // OHOS_DM_NOTIFY_H 150