1 /* 2 * Copyright (c) 2023-2024 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_IMPL_H 17 #define OHOS_DM_SERVICE_IMPL_H 18 19 #include <string> 20 #include <vector> 21 22 #include "dm_credential_manager.h" 23 #include "dm_device_info.h" 24 #include "dm_device_state_manager.h" 25 #include "mine_hichain_connector.h" 26 #include "idevice_manager_service_impl.h" 27 #include "dm_single_instance.h" 28 #include "softbus_connector.h" 29 30 namespace OHOS { 31 namespace DistributedHardware { 32 class DeviceManagerServiceImpl : public IDeviceManagerServiceImpl { 33 public: 34 DeviceManagerServiceImpl(); 35 virtual ~DeviceManagerServiceImpl(); 36 37 int32_t Initialize(const std::shared_ptr<IDeviceManagerServiceListener> &listener); 38 39 void Release(); 40 41 int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, 42 const std::string &extra); 43 44 int32_t StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId, 45 const std::string &filterOptions); 46 47 int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId); 48 49 int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo); 50 51 int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId); 52 53 int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, 54 const std::string &extra); 55 56 int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &networkId); 57 58 int32_t BindDevice(const std::string &pkgName, int32_t authType, const std::string &udidHash, 59 const std::string &bindParam); 60 61 int32_t UnBindDevice(const std::string &pkgName, const std::string &udidHash); 62 63 int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); 64 65 void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); 66 67 int OnSessionOpened(int sessionId, int result); 68 69 void OnSessionClosed(int sessionId); 70 71 void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen); 72 73 int OnPinHolderSessionOpened(int sessionId, int result); 74 75 int32_t MineRequestCredential(const std::string &pkgName, std::string &returnJsonStr); 76 77 int32_t CheckCredential(const std::string &pkgName, const std::string &reqJsonStr, 78 std::string &returnJsonStr); 79 80 int32_t ImportCredential(const std::string &pkgName, const std::string &reqJsonStr, 81 std::string &returnJsonStr); 82 83 int32_t DeleteCredential(const std::string &pkgName, const std::string &reqJsonStr, 84 std::string &returnJsonStr); 85 86 void OnPinHolderSessionClosed(int sessionId); 87 88 void OnPinHolderBytesReceived(int sessionId, const void *data, unsigned int dataLen); 89 90 int32_t RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr); 91 92 int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo); 93 94 int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo); 95 96 int32_t RegisterCredentialCallback(const std::string &pkgName); 97 98 int32_t UnRegisterCredentialCallback(const std::string &pkgName); 99 100 int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event); 101 102 int32_t GetGroupType(std::vector<DmDeviceInfo> &deviceList); 103 104 int32_t GetUdidHashByNetWorkId(const char *networkId, std::string &deviceId); 105 106 void LoadHardwareFwkService(); 107 108 int32_t RegisterUiStateCallback(const std::string &pkgName); 109 110 int32_t UnRegisterUiStateCallback(const std::string &pkgName); 111 112 int32_t ImportAuthCode(const std::string &pkgName, const std::string &authCode); 113 114 int32_t ExportAuthCode(std::string &authCode); 115 116 int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId, 117 const std::map<std::string, std::string> &bindParam); 118 119 int32_t RegisterPinHolderCallback(const std::string &pkgName); 120 int32_t CreatePinHolder(const std::string &pkgName, const PeerTargetId &targetId, 121 DmPinType pinType, const std::string &payload); 122 int32_t DestroyPinHolder(const std::string &pkgName, const PeerTargetId &targetId, 123 DmPinType pinType, const std::string &payload); 124 std::unordered_map<std::string, DmAuthForm> GetAppTrustDeviceIdList(std::string pkgname); 125 void OnUnbindSessionOpened(int32_t sessionId, PeerSocketInfo info); 126 void OnUnbindSessionCloseed(int32_t sessionId); 127 void OnUnbindBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen); 128 129 int32_t DpAclAdd(const std::string &udid); 130 int32_t IsSameAccount(const std::string &udid); 131 void AccountCommonEventCallback(int32_t userId, std::string commonEventType); 132 void ScreenCommonEventCallback(std::string commonEventType); 133 int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, 134 const DmAccessCallee &callee, const std::string &sinkUdid); 135 int32_t CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, 136 const DmAccessCallee &callee, const std::string &sinkUdid); 137 void HandleDeviceNotTrust(const std::string &udid); 138 void HandleIdentAccountLogout(const std::string &udid, int32_t userId, const std::string &accountId); 139 void HandleUserRemoved(int32_t preUserId); 140 std::map<std::string, int32_t> GetDeviceIdAndBindType(int32_t userId, const std::string &accountId); 141 int32_t StopAuthenticateDevice(const std::string &pkgName); 142 void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); 143 void HandleCredentialAuthStatus(const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode); 144 145 private: 146 std::string GetUdidHashByNetworkId(const std::string &networkId); 147 148 private: 149 std::shared_ptr<DmDeviceStateManager> deviceStateMgr_; 150 std::shared_ptr<SoftbusConnector> softbusConnector_; 151 std::shared_ptr<HiChainConnector> hiChainConnector_; 152 std::shared_ptr<MineHiChainConnector> mineHiChainConnector_; 153 std::shared_ptr<DmCredentialManager> credentialMgr_; 154 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector_; 155 }; 156 157 using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); 158 } // namespace DistributedHardware 159 } // namespace OHOS 160 #endif // OHOS_DM_SERVICE_IMPL_H 161