1 /* 2 * Copyright (c) 2023-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_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 UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); 54 55 int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); 56 57 int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, 58 int32_t bindLevel, const std::string &extra); 59 60 int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); 61 62 void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); 63 64 int OnSessionOpened(int sessionId, int result); 65 66 void OnSessionClosed(int sessionId); 67 68 void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen); 69 70 int OnPinHolderSessionOpened(int sessionId, int result); 71 72 int32_t MineRequestCredential(const std::string &pkgName, std::string &returnJsonStr); 73 74 int32_t CheckCredential(const std::string &pkgName, const std::string &reqJsonStr, 75 std::string &returnJsonStr); 76 77 int32_t ImportCredential(const std::string &pkgName, const std::string &reqJsonStr, 78 std::string &returnJsonStr); 79 80 int32_t DeleteCredential(const std::string &pkgName, const std::string &reqJsonStr, 81 std::string &returnJsonStr); 82 83 void OnPinHolderSessionClosed(int sessionId); 84 85 void OnPinHolderBytesReceived(int sessionId, const void *data, unsigned int dataLen); 86 87 int32_t RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr); 88 89 int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo); 90 91 int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo); 92 93 int32_t RegisterCredentialCallback(const std::string &pkgName); 94 95 int32_t UnRegisterCredentialCallback(const std::string &pkgName); 96 97 int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event); 98 99 int32_t GetGroupType(std::vector<DmDeviceInfo> &deviceList); 100 101 int32_t GetUdidHashByNetWorkId(const char *networkId, std::string &deviceId); 102 103 void LoadHardwareFwkService(); 104 105 int32_t RegisterUiStateCallback(const std::string &pkgName); 106 107 int32_t UnRegisterUiStateCallback(const std::string &pkgName); 108 109 int32_t ImportAuthCode(const std::string &pkgName, const std::string &authCode); 110 111 int32_t ExportAuthCode(std::string &authCode); 112 113 int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId, 114 const std::map<std::string, std::string> &bindParam); 115 116 int32_t RegisterPinHolderCallback(const std::string &pkgName); 117 int32_t CreatePinHolder(const std::string &pkgName, const PeerTargetId &targetId, 118 DmPinType pinType, const std::string &payload); 119 int32_t DestroyPinHolder(const std::string &pkgName, const PeerTargetId &targetId, 120 DmPinType pinType, const std::string &payload); 121 std::unordered_map<std::string, DmAuthForm> GetAppTrustDeviceIdList(std::string pkgname); 122 123 int32_t DpAclAdd(const std::string &udid); 124 int32_t IsSameAccount(const std::string &udid); 125 uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId); 126 void ScreenCommonEventCallback(std::string commonEventType); 127 int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, 128 const DmAccessCallee &callee, const std::string &sinkUdid); 129 int32_t CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, 130 const DmAccessCallee &callee, const std::string &sinkUdid); 131 void HandleDeviceNotTrust(const std::string &udid); 132 int32_t GetBindLevel(const std::string &pkgName, const std::string &localUdid, 133 const std::string &udid, uint64_t &tokenId); 134 std::multimap<std::string, int32_t> GetDeviceIdAndUserId(int32_t userId, const std::string &accountId); 135 void HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, 136 const std::string &remoteUdid); 137 void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid); 138 void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); 139 void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, 140 int32_t tokenId, int32_t peerTokenId); 141 void HandleIdentAccountLogout(const std::string &localUdid, int32_t localUserId, const std::string &peerUdid, 142 int32_t peerUserId); 143 void HandleUserRemoved(int32_t preUserId); 144 void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); 145 void HandleUserSwitched(const std::vector<std::string> &deviceVec, int32_t currentUserId, 146 int32_t beforeUserId); 147 int32_t StopAuthenticateDevice(const std::string &pkgName); 148 void HandleCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode); 149 int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); 150 void HandleSyncUserIdEvent(const std::vector<uint32_t> &foregroundUserIds, 151 const std::vector<uint32_t> &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus); 152 void HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid); 153 std::map<std::string, int32_t> GetDeviceIdAndBindLevel(int32_t userId); 154 std::multimap<std::string, int32_t> GetDeviceIdAndUserId(int32_t localUserId); 155 int32_t SaveOnlineDeviceInfo(const std::vector<DmDeviceInfo> &deviceList); 156 void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, 157 int32_t localUserId, const std::string &localAccountId); 158 int32_t RegisterAuthenticationType(int32_t authenticationType); 159 void DeleteAlwaysAllowTimeOut(); 160 void CheckDeleteCredential(const std::string &remoteUdid); 161 int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); 162 private: 163 std::string GetUdidHashByNetworkId(const std::string &networkId); 164 165 private: 166 std::shared_ptr<DmDeviceStateManager> deviceStateMgr_; 167 std::shared_ptr<SoftbusConnector> softbusConnector_; 168 std::shared_ptr<HiChainConnector> hiChainConnector_; 169 std::shared_ptr<MineHiChainConnector> mineHiChainConnector_; 170 std::shared_ptr<DmCredentialManager> credentialMgr_; 171 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector_; 172 }; 173 174 using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); 175 } // namespace DistributedHardware 176 } // namespace OHOS 177 #endif // OHOS_DM_SERVICE_IMPL_H 178