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_IMPL_H 17 #define OHOS_DM_SERVICE_IMPL_H 18 19 #include <string> 20 #include <vector> 21 22 #include "access_control_profile.h" 23 #include "dm_ability_manager.h" 24 #include "dm_auth_manager.h" 25 #include "dm_common_event_manager.h" 26 #include "dm_credential_manager.h" 27 #include "dm_device_info.h" 28 #include "dm_device_state_manager.h" 29 #include "dp_inited_callback.h" 30 #include "idevice_manager_service_impl.h" 31 #include "dm_single_instance.h" 32 #include "softbus_connector.h" 33 #include "mine_hichain_connector.h" 34 35 namespace OHOS { 36 namespace DistributedHardware { 37 class DeviceManagerServiceImpl : public IDeviceManagerServiceImpl { 38 public: 39 DeviceManagerServiceImpl(); 40 virtual ~DeviceManagerServiceImpl(); 41 42 int32_t Initialize(const std::shared_ptr<IDeviceManagerServiceListener> &listener); 43 44 void Release(); 45 46 int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); 47 48 int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); 49 50 int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, 51 int32_t bindLevel, const std::string &extra); 52 53 int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); 54 55 void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); 56 57 int OnSessionOpened(int sessionId, int result); 58 59 void OnSessionClosed(int sessionId); 60 61 void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen); 62 63 int OnPinHolderSessionOpened(int sessionId, int result); 64 65 void OnPinHolderSessionClosed(int sessionId); 66 67 void OnPinHolderBytesReceived(int sessionId, const void *data, unsigned int dataLen); 68 69 int32_t RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr); 70 71 int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo); 72 73 int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo); 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 int32_t RegisterCredentialCallback(const std::string &pkgName); 87 88 int32_t UnRegisterCredentialCallback(const std::string &pkgName); 89 90 int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event); 91 92 int32_t GetGroupType(std::vector<DmDeviceInfo> &deviceList); 93 94 int32_t GetUdidHashByNetWorkId(const char *networkId, std::string &deviceId); 95 96 void LoadHardwareFwkService(); 97 98 int32_t RegisterUiStateCallback(const std::string &pkgName); 99 100 int32_t UnRegisterUiStateCallback(const std::string &pkgName); 101 102 int32_t ImportAuthCode(const std::string &pkgName, const std::string &authCode); 103 104 int32_t ExportAuthCode(std::string &authCode); 105 106 int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId, 107 const std::map<std::string, std::string> &bindParam); 108 109 std::unordered_map<std::string, DmAuthForm> GetAppTrustDeviceIdList(std::string pkgname); 110 111 int32_t DpAclAdd(const std::string &udid); 112 int32_t IsSameAccount(const std::string &udid); 113 uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId); 114 void ScreenCommonEventCallback(std::string commonEventType); 115 int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, 116 const DmAccessCallee &callee, const std::string &sinkUdid); 117 int32_t CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, 118 const DmAccessCallee &callee, const std::string &sinkUdid); 119 void HandleDeviceNotTrust(const std::string &udid); 120 int32_t GetBindLevel(const std::string &pkgName, const std::string &localUdid, 121 const std::string &udid, uint64_t &tokenId); 122 void HandleIdentAccountLogout(const std::string &localUdid, int32_t localUserId, const std::string &peerUdid, 123 int32_t peerUserId); 124 void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo); 125 int32_t StopAuthenticateDevice(const std::string &pkgName); 126 void HandleCredentialAuthStatus(const std::string &deviceList, uint16_t deviceTypeId, int32_t errcode); 127 int32_t ProcessAppUnintall(const std::string &appId, int32_t accessTokenId); 128 void HandleSyncUserIdEvent(const std::vector<uint32_t> &foregroundUserIds, 129 const std::vector<uint32_t> &backgroundUserIds, const std::string &remoteUdid, bool isCheckUserStatus); 130 void HandleUserSwitched(const std::vector<std::string> &deviceVec, int32_t currentUserId, 131 int32_t beforeUserId); 132 std::multimap<std::string, int32_t> GetDeviceIdAndUserId(int32_t localUserId); 133 int32_t SaveOnlineDeviceInfo(const std::vector<DmDeviceInfo> &deviceList); 134 void HandleDeviceUnBind(int32_t bindType, const std::string &peerUdid, 135 const std::string &localUdid, int32_t localUserId, const std::string &localAccountId); 136 int32_t RegisterAuthenticationType(int32_t authenticationType); 137 void DeleteAlwaysAllowTimeOut(); 138 void CheckDeleteCredential(const std::string &remoteUdid); 139 int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId); 140 private: 141 int32_t PraseNotifyEventJson(const std::string &event, JsonObject &jsonObject); 142 std::string GetUdidHashByNetworkId(const std::string &networkId); 143 void HandleOffline(DmDeviceState devState, DmDeviceInfo &devInfo); 144 void HandleOnline(DmDeviceState devState, DmDeviceInfo &devInfo); 145 void PutIdenticalAccountToAcl(std::string requestDeviceId, std::string trustDeviceId); 146 std::map<std::string, int32_t> GetDeviceIdAndBindLevel(int32_t userId); 147 std::multimap<std::string, int32_t> GetDeviceIdAndUserId(int32_t userId, const std::string &accountId); 148 void HandleAccountLogoutEvent(int32_t remoteUserId, const std::string &remoteAccountHash, 149 const std::string &remoteUdid); 150 void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid); 151 void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); 152 void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, 153 int32_t tokenId, int32_t peerTokenId); 154 void HandleUserRemoved(int32_t preUserId); 155 void HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid); 156 DmAuthForm ConvertBindTypeToAuthForm(int32_t bindType); 157 158 private: 159 std::shared_ptr<DmAuthManager> authMgr_; 160 std::shared_ptr<DmDeviceStateManager> deviceStateMgr_; 161 std::shared_ptr<SoftbusConnector> softbusConnector_; 162 std::shared_ptr<DmAbilityManager> abilityMgr_; 163 std::shared_ptr<HiChainConnector> hiChainConnector_; 164 std::shared_ptr<MineHiChainConnector> mineHiChainConnector_; 165 std::shared_ptr<DmCredentialManager> credentialMgr_; 166 std::shared_ptr<DmCommonEventManager> commonEventManager_; 167 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector_; 168 std::shared_ptr<IDeviceManagerServiceListener> listener_; 169 std::atomic<bool> isCredentialType_ = false; 170 sptr<DpInitedCallback> dpInitedCallback_ = nullptr; 171 }; 172 173 using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void); 174 } // namespace DistributedHardware 175 } // namespace OHOS 176 #endif // OHOS_DM_SERVICE_IMPL_H 177