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 extra, std::string requestDeviceId); 126 void ScreenCommonEventCallback(std::string commonEventType); 127 bool CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, 128 const DmAccessCallee &callee, const std::string &sinkUdid); 129 bool 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 DMAclQuadInfo &info, const std::string &accountId); 142 void HandleUserRemoved(std::vector<std::string> peerUdids, int32_t preUserId); 143 void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); 144 void HandleUserSwitched(const std::vector<std::string> &deviceVec, int32_t currentUserId, 145 int32_t beforeUserId); 146 int32_t StopAuthenticateDevice(const std::string &pkgName); 147 void HandleCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode); 148 int32_t SyncLocalAclListProcess(const DevUserInfo &localDevUserInfo, 149 const DevUserInfo &remoteDevUserInfo, std::string remoteAclList); 150 int32_t GetAclListHash(const DevUserInfo &localDevUserInfo, 151 const DevUserInfo &remoteDevUserInfo, std::string &aclList); 152 int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); 153 int32_t ProcessAppUninstall(int32_t userId, int32_t accessTokenId); 154 void ProcessUnBindApp(int32_t userId, int32_t accessTokenId, const std::string &extra, const std::string &udid); 155 void HandleSyncUserIdEvent(const std::vector<uint32_t> &foregroundUserIds, 156 const std::vector<uint32_t> &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus); 157 void HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid); 158 std::map<std::string, int32_t> GetDeviceIdAndBindLevel(int32_t userId); 159 std::multimap<std::string, int32_t> GetDeviceIdAndUserId(int32_t localUserId); 160 int32_t SaveOnlineDeviceInfo(const std::vector<DmDeviceInfo> &deviceList); 161 void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, const std::string &localUdid, 162 int32_t localUserId, const std::string &localAccountId); 163 int32_t RegisterAuthenticationType(int32_t authenticationType); 164 void DeleteAlwaysAllowTimeOut(); 165 void CheckDeleteCredential(const std::string &remoteUdid, int32_t remoteUserId); 166 void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, 167 std::string &remoteUdid, bool &isSendBroadCast); 168 void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, const std::string &localUdid); 169 int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); 170 void HandleServiceUnBindEvent(int32_t userId, const std::string &remoteUdid, 171 int32_t remoteTokenId); 172 void HandleCommonEventBroadCast(const std::vector<uint32_t> &foregroundUserIds, 173 const std::vector<uint32_t> &backgroundUserIds, const std::string &remoteUdid); 174 std::vector<std::string> GetDeviceIdByUserIdAndTokenId(int32_t userId, int32_t tokenId); 175 bool CheckSrcAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, 176 const DmAccessCallee &callee, const std::string &sinkUdid); 177 bool CheckSinkAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, 178 const DmAccessCallee &callee, const std::string &sinkUdid); 179 bool CheckSrcIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, 180 const DmAccessCallee &callee, const std::string &sinkUdid); 181 bool CheckSinkIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, 182 const DmAccessCallee &callee, const std::string &sinkUdid); 183 void DeleteHoDevice(const std::string &peerUdid, const std::vector<int32_t> &foreGroundUserIds, 184 const std::vector<int32_t> &backGroundUserIds); 185 private: 186 std::string GetUdidHashByNetworkId(const std::string &networkId); 187 188 private: 189 std::shared_ptr<DmDeviceStateManager> deviceStateMgr_; 190 std::shared_ptr<SoftbusConnector> softbusConnector_; 191 std::shared_ptr<HiChainConnector> hiChainConnector_; 192 std::shared_ptr<MineHiChainConnector> mineHiChainConnector_; 193 std::shared_ptr<DmCredentialManager> credentialMgr_; 194 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector_; 195 }; 196 197 using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); 198 } // namespace DistributedHardware 199 } // namespace OHOS 200 #endif // OHOS_DM_SERVICE_IMPL_H 201