diff --git a/common/include/device_manager_ipc_interface_code.h b/common/include/device_manager_ipc_interface_code.h index ad592b650b57fe79943444d088d18d9d4df4e130..4d834a4ca2128dc3c42f7565d8c89a7a68a62cd9 100644 --- a/common/include/device_manager_ipc_interface_code.h +++ b/common/include/device_manager_ipc_interface_code.h @@ -97,6 +97,7 @@ enum DMIpcCmdInterfaceCode { GET_DEVICE_SCREEN_STATUS, SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, SYNC_CALLBACK, + SINK_BIND_TARGET_RESULT, IPC_MSG_BUTT }; } // namespace DistributedHardware diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index dc7f7b36095242357b53ead98237c479c80c3aa8..bb97916c1e78ab03f81f1f869ac6848fd2526a20 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -625,6 +625,9 @@ public: virtual int32_t RegisterCredentialAuthStatusCallback(const std::string &pkgName, std::shared_ptr callback) = 0; virtual int32_t UnRegisterCredentialAuthStatusCallback(const std::string &pkgName) = 0; + virtual int32_t RegisterSinkBindCallback(const std::string &pkgName, + std::shared_ptr callback) = 0; + virtual int32_t UnRegisterSinkBindCallback(const std::string &pkgName) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index d7d373df1b45ea7930906d5e0ee5958cac4b6710..23fe6ff26f2affd5d547e0e7db131c560aeea3eb 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -400,6 +400,9 @@ public: std::shared_ptr callback) override; virtual int32_t UnRegisterCredentialAuthStatusCallback(const std::string &pkgName) override; void SyncCallbacksToService(std::map> &callbackMap); + virtual int32_t RegisterSinkBindCallback(const std::string &pkgName, + std::shared_ptr callback) override; + virtual int32_t UnRegisterSinkBindCallback(const std::string &pkgName) override; private: DeviceManagerImpl() = default; diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index 0f183ecc30d7ebc450eb8d7a7194916a329fec9a..971ea968899dd967921e1c3fd92e8d1a2f92bc6d 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -73,6 +73,8 @@ public: void RegisterCredentialAuthStatusCallback(const std::string &pkgName, std::shared_ptr callback); void UnRegisterCredentialAuthStatusCallback(const std::string &pkgName); + void RegisterSinkBindCallback(const std::string &pkgName, std::shared_ptr callback); + void UnRegisterSinkBindCallback(const std::string &pkgName); public: static void DeviceInfoOnline(const DmDeviceInfo &deviceInfo, std::shared_ptr tempCbk); @@ -118,6 +120,8 @@ public: void OnCredentialAuthStatus(const std::string &pkgName, const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode); void GetCallBack(std::map> &callbackMap); + void OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, int32_t status, + std::string content); private: #if !defined(__LITEOS_M__) @@ -136,6 +140,7 @@ private: std::map> pinHolderCallback_; std::map> deviceScreenStatusCallback_; std::map> credentialAuthStatusCallback_; + std::map> sinkBindTargetCallback_; std::mutex bindLock_; }; } // namespace DistributedHardware diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 0b701dbd7b10155fa1fa25954c3a5dfa916fb37b..3b792c58667225761bd4c29fcbc97dd711b2033a 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2358,5 +2358,28 @@ void DeviceManagerImpl::SyncCallbacksToService(std::map callback) +{ + if (pkgName.empty()) { + LOGE("Error: Invalid para"); + return ERR_DM_INPUT_PARA_INVALID; + } + DeviceManagerNotify::GetInstance().RegisterSinkBindCallback(pkgName, callback); + LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); + return DM_OK; +} + +int32_t DeviceManagerImpl::UnRegisterSinkBindCallback(const std::string &pkgName) +{ + if (pkgName.empty()) { + LOGE("Error: Invalid para"); + return ERR_DM_INPUT_PARA_INVALID; + } + DeviceManagerNotify::GetInstance().UnRegisterSinkBindCallback(pkgName); + LOGI("Completed, pkgName: %{public}s", pkgName.c_str()); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index c1b939b369d3abd8d31d4e22bc2dcbfd43e3f251..8b64b7024a876493ed05d95eddcc5816c065ef55 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -1751,5 +1751,19 @@ ON_IPC_READ_RESPONSE(SYNC_CALLBACK, MessageParcel &reply, std::shared_ptrSetErrCode(reply.ReadInt32()); return DM_OK; } + +ON_IPC_CMD(SINK_BIND_TARGET_RESULT, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + PeerTargetId targetId; + DecodePeerTargetId(data, targetId); + int32_t result = data.ReadInt32(); + int32_t status = data.ReadInt32(); + std::string content = data.ReadString(); + + DeviceManagerNotify::GetInstance().OnSinkBindResult(pkgName, targetId, result, status, content); + reply.WriteInt32(DM_OK); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 00ab9b31d26f224eba962059e0164b93af05dd7c..5604636c876ec3545dd6f2e724ccd0264d0cc1d0 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -1175,5 +1175,50 @@ void DeviceManagerNotify::GetCallBack(std::map callback) +{ + if (pkgName.empty() || callback == nullptr) { + LOGE("Invalid parameter, pkgName is empty or callback is nullptr."); + return; + } + std::lock_guard autoLock(lock_); + sinkBindTargetCallback_[pkgName] = callback; +} + +void DeviceManagerNotify::UnRegisterSinkBindCallback(const std::string &pkgName) +{ + if (pkgName.empty()) { + LOGE("Invalid parameter, pkgName is empty."); + return; + } + std::lock_guard autoLock(lock_); + sinkBindTargetCallback_.erase(pkgName); +} + +void DeviceManagerNotify::OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, + int32_t result, int32_t status, std::string content) +{ + if (pkgName.empty()) { + LOGE("Invalid para, pkgName: %{public}s.", pkgName.c_str()); + return; + } + LOGI("DeviceManagerNotify::OnSinkBindResult in, pkgName:%{public}s, result:%{public}d", pkgName.c_str(), result); + std::shared_ptr tempCbk; + { + std::lock_guard autoLock(lock_); + if (sinkBindTargetCallback_.find(pkgName) == sinkBindTargetCallback_.end()) { + LOGE("error, sink bind callback not register."); + return; + } + tempCbk = sinkBindTargetCallback_[pkgName]; + } + if (tempCbk == nullptr) { + LOGE("error, registered sink bind callback is nullptr."); + return; + } + tempCbk->OnBindResult(targetId, result, status, content); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 400f6194a686dc4e18320d31c8ffede0b62cdc77..b547e56ca15dc26227b258ef969c115628ed6076 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -301,6 +301,7 @@ int32_t DmAuthManager::StopAuthenticateDevice(const std::string &pkgName) LOGI("Stop previous AuthenticateDevice."); authRequestContext_->reason = STOP_BIND; authResponseContext_->state = authRequestState_->GetStateType(); + authResponseContext_->reply = STOP_BIND; authRequestState_->TransitionTo(std::make_shared()); } return DM_OK; @@ -612,6 +613,7 @@ void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) if (status != DM_OK || authResponseContext_->requestId != requestId) { if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; + authResponseContext_->reply = ERR_DM_BIND_PIN_CODE_ERROR; authRequestContext_->reason = ERR_DM_BIND_PIN_CODE_ERROR; authRequestState_->TransitionTo(std::make_shared()); } else { @@ -643,6 +645,7 @@ void DmAuthManager::HandleMemberJoinImportAuthCode(const int64_t requestId, cons { if (status != DM_OK || authResponseContext_->requestId != requestId) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; + authResponseContext_->reply = ERR_DM_AUTH_CODE_INCORRECT; authRequestContext_->reason = ERR_DM_AUTH_CODE_INCORRECT; authRequestState_->TransitionTo(std::make_shared()); } else { @@ -658,6 +661,7 @@ void DmAuthManager::HandleAuthenticateTimeout(std::string name) authResponseContext_ = std::make_shared(); } authResponseContext_->state = authRequestState_->GetStateType(); + authResponseContext_->reply = ERR_DM_TIME_OUT; authRequestContext_->reason = ERR_DM_TIME_OUT; authRequestState_->TransitionTo(std::make_shared()); } @@ -697,6 +701,7 @@ int32_t DmAuthManager::EstablishAuthChannel(const std::string &deviceId) } authResponseContext_->state = AuthState::AUTH_REQUEST_NEGOTIATE; authRequestContext_->reason = sessionId; + authResponseContext_->reply = sessionId; if (authRequestState_ != nullptr) { authRequestState_->TransitionTo(std::make_shared()); } @@ -1104,6 +1109,7 @@ void DmAuthManager::StartRespAuthProcess() LOGE("do not accept"); authResponseContext_->state = AuthState::AUTH_REQUEST_REPLY; authRequestContext_->reason = ERR_DM_AUTH_PEER_REJECT; + authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT; authRequestState_->TransitionTo(std::make_shared()); } } @@ -1195,6 +1201,7 @@ int32_t DmAuthManager::JoinNetwork() authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authResponseContext_->isFinish = true; authRequestContext_->reason = DM_OK; + authResponseContext_->reply = DM_OK; authRequestState_->TransitionTo(std::make_shared()); return DM_OK; } @@ -1202,6 +1209,8 @@ int32_t DmAuthManager::JoinNetwork() void DmAuthManager::SinkAuthenticateFinish() { LOGI("DmAuthManager::SinkAuthenticateFinish, isFinishOfLocal: %{public}d", isFinishOfLocal_); + listener_->OnSinkBindResult(authResponseContext_->hostPkgName, peerTargetId_, authResponseContext_->reply, + authResponseContext_->state, GenerateBindResultContent()); if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH && authPtr_ != nullptr) { authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_SHOW); authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_CONFIRM_SHOW); @@ -1906,6 +1915,7 @@ void DmAuthManager::RequestCredentialDone() softbusConnector_->JoinLnn(authRequestContext_->ip); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; + authResponseContext_->reply = DM_OK; authRequestState_->TransitionTo(std::make_shared()); } @@ -2074,6 +2084,7 @@ void DmAuthManager::SrcAuthDeviceFinish() timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); } authRequestContext_->reason = DM_OK; + authResponseContext_->reply = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); return; @@ -2095,6 +2106,7 @@ void DmAuthManager::SrcAuthDeviceFinish() timer_->DeleteTimer(std::string(AUTHENTICATE_TIMEOUT_TASK)); } authRequestContext_->reason = DM_OK; + authResponseContext_->reply = DM_OK; authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestState_->TransitionTo(std::make_shared()); return; @@ -2152,6 +2164,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) if (authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authRequestContext_->reason = ERR_DM_AUTH_CODE_INCORRECT; + authResponseContext_->reply = ERR_DM_AUTH_CODE_INCORRECT; authRequestState_->TransitionTo(std::make_shared()); return; } @@ -2164,6 +2177,7 @@ void DmAuthManager::AuthDeviceError(int64_t requestId, int32_t errorCode) if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authRequestContext_->reason = ERR_DM_INPUT_PARA_INVALID; + authResponseContext_->reply = ERR_DM_INPUT_PARA_INVALID; authRequestState_->TransitionTo(std::make_shared()); } else { if (timer_ != nullptr) { @@ -2617,6 +2631,7 @@ int32_t DmAuthManager::CheckTrustState() softbusConnector_->JoinLnn(authResponseContext_->deviceId); authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; + authResponseContext_->reply = DM_OK; authRequestState_->TransitionTo(std::make_shared()); return ALREADY_BIND; } @@ -2639,6 +2654,7 @@ int32_t DmAuthManager::CheckTrustState() authResponseContext_->isAuthCodeReady == false)) { authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = ERR_DM_BIND_PEER_UNSUPPORTED; + authResponseContext_->reply = ERR_DM_BIND_PEER_UNSUPPORTED; authRequestState_->TransitionTo(std::make_shared()); return ERR_DM_BIND_PEER_UNSUPPORTED; } diff --git a/services/service/include/device_manager_service_listener.h b/services/service/include/device_manager_service_listener.h index 6bbcb8f4ce7c87de2012d9e211a0c2684d0d3354..a1caf69e4f5739536512e9064fac228fcb6ac6d6 100644 --- a/services/service/include/device_manager_service_listener.h +++ b/services/service/include/device_manager_service_listener.h @@ -76,6 +76,8 @@ public: void OnDeviceScreenStateChange(const std::string &pkgName, DmDeviceInfo &devInfo) override; void OnCredentialAuthStatus(const std::string &pkgName, const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode) override; + void OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, + int32_t status, std::string content) override; private: void ConvertDeviceInfoToDeviceBasicInfo(const std::string &pkgName, const DmDeviceInfo &info, DmDeviceBasicInfo &deviceBasicInfo); diff --git a/services/service/include/idevice_manager_service_listener.h b/services/service/include/idevice_manager_service_listener.h index 9f1a5d03204e49bd02e100044635beed96c5ff1e..c8977db252c592e3aca3ef79c3ba968518de2082 100644 --- a/services/service/include/idevice_manager_service_listener.h +++ b/services/service/include/idevice_manager_service_listener.h @@ -159,6 +159,8 @@ public: */ virtual void OnCredentialAuthStatus(const std::string &pkgName, const std::string &proofInfo, uint16_t deviceTypeId, int32_t errcode) = 0; + virtual void OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, + int32_t status, std::string content) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/device_manager_service_listener.cpp b/services/service/src/device_manager_service_listener.cpp index 3c2b68d97e0269f5dc3610146b4a2feaaf0f2bfc..4575d82eaa82abb2d842ca37d8ec3530b19fd811 100644 --- a/services/service/src/device_manager_service_listener.cpp +++ b/services/service/src/device_manager_service_listener.cpp @@ -584,5 +584,30 @@ std::vector DeviceManagerServiceListener::GetNotifyPkgName( } return pkgNamesTemp; } + +void DeviceManagerServiceListener::OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, + int32_t result, int32_t status, std::string content) +{ + std::shared_ptr pReq = std::make_shared(); + std::shared_ptr pRsp = std::make_shared(); + if (status < STATUS_DM_AUTH_FINISH && status > STATUS_DM_AUTH_DEFAULT) { + status = STATUS_DM_AUTH_DEFAULT; + } + PeerTargetId returnTargetId = targetId; +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::string deviceIdTemp = ""; + DmKVValue kvValue; + if (ConvertUdidHashToAnoyDeviceId(pkgName, targetId.deviceId, deviceIdTemp) == DM_OK && + KVAdapterManager::GetInstance().Get(deviceIdTemp, kvValue) == DM_OK) { + returnTargetId.deviceId = deviceIdTemp; + } +#endif + pReq->SetPkgName(pkgName); + pReq->SetPeerTargetId(returnTargetId); + pReq->SetResult(result); + pReq->SetStatus(status); + pReq->SetContent(content); + ipcServerListener_.SendRequest(SINK_BIND_TARGET_RESULT, pReq, pRsp); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 796773020481fb03c082774db7bd6d754ee4e15f..28eea7080c25b1a4146625850908b8960dec64a0 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -1102,6 +1102,51 @@ ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseReq, MessageParcel &data) +{ + if (pBaseReq == nullptr) { + return ERR_DM_FAILED; + } + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + PeerTargetId targetId = pReq->GetPeerTargetId(); + int32_t result = pReq->GetResult(); + int32_t status = pReq->GetStatus(); + std::string content = pReq->GetContent(); + + if (!data.WriteString(pkgName)) { + LOGE("write bind pkgName failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!EncodePeerTargetId(targetId, data)) { + LOGE("write bind peer target id failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteInt32(result)) { + LOGE("write bind result code failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteInt32(status)) { + LOGE("write bind result status failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + if (!data.WriteString(content)) { + LOGE("write bind result content failed"); + return ERR_DM_IPC_WRITE_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(SINK_BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return ERR_DM_FAILED; + } + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr pBaseReq, MessageParcel &data) { if (pBaseReq == nullptr) { diff --git a/test/unittest/UTTest_dm_pin_holder.h b/test/unittest/UTTest_dm_pin_holder.h index 71eae95a239c8437ebd96ca25105eeee6096d5a8..85daf85060cb71d5cb819ef5e5d446bf60291dd2 100644 --- a/test/unittest/UTTest_dm_pin_holder.h +++ b/test/unittest/UTTest_dm_pin_holder.h @@ -194,6 +194,16 @@ public: (void)deviceTypeId; (void)errcode; } + + void OnSinkBindResult(const std::string &pkgName, const PeerTargetId &targetId, int32_t result, + int32_t status, std::string content) override + { + (void)pkgName; + (void)targetId; + (void)result; + (void)status; + (void)content; + } }; } // namespace DistributedHardware } // namespace OHOS