From 890b3e6c8af6370861958ce0f4efdae6b6484bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 12 Feb 2025 15:06:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../src/deviceprofile_connector.cpp | 1 + .../src/main/ets/pages/ConfirmDialog.ets | 22 ++++----- .../include/ability/dm_dialog_manager.h | 9 ++-- .../include/authentication/dm_auth_manager.h | 2 +- .../ability/standard/dm_dialog_manager.cpp | 47 ++++++++++++------- .../src/authentication/dm_auth_manager.cpp | 11 ++--- 6 files changed, 53 insertions(+), 39 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index eeb470b29..8c2bd5d4d 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -346,6 +346,7 @@ std::vector DeviceProfileConnector::GetPkgNameFromAcl(std::string & std::vector profiles = GetAccessControlProfile(); LOGI("AccessControlProfile size is %d.", profiles.size()); std::vector pkgNameVec; + pkgNameVec.push_back("Samgr_Networking"); for (auto &item : profiles) { if (item.GetTrustDeviceId() != targetDeviceId || item.GetStatus() != ACTIVE) { continue; diff --git a/display/entry/src/main/ets/pages/ConfirmDialog.ets b/display/entry/src/main/ets/pages/ConfirmDialog.ets index fd9971ee9..0f4f3ac3b 100644 --- a/display/entry/src/main/ets/pages/ConfirmDialog.ets +++ b/display/entry/src/main/ets/pages/ConfirmDialog.ets @@ -129,14 +129,7 @@ struct ConfirmCustomDialog { } destruction() { - if (dmClass != null) { - try { - dmClass.release(); - dmClass = null; - } catch (error) { - console.log('dmClass release failed') - } - } + console.log(TAG + 'ConfirmCustomDialog destruction') let session = AppStorage.get('ConfirmSession'); if (session) { session.terminateSelf(); @@ -342,6 +335,15 @@ struct dialogPlusPage { } destruction() { + console.log(TAG + 'dialogPlusPage destruction') + let session = AppStorage.get('ConfirmSession'); + if (session) { + session.terminateSelf(); + } + } + + aboutToDisappear() { + console.log(TAG + 'aboutToDisappear aboutToDisappear') if (dmClass != null) { try { dmClass.release(); @@ -350,10 +352,6 @@ struct dialogPlusPage { console.log('dmClass release failed') } } - let session = AppStorage.get('ConfirmSession'); - if (session) { - session.terminateSelf(); - } } build() { diff --git a/services/implementation/include/ability/dm_dialog_manager.h b/services/implementation/include/ability/dm_dialog_manager.h index 7bca9996a..0d451b182 100644 --- a/services/implementation/include/ability/dm_dialog_manager.h +++ b/services/implementation/include/ability/dm_dialog_manager.h @@ -28,8 +28,7 @@ namespace OHOS { namespace DistributedHardware { class DmDialogManager { public: - DmDialogManager(); - ~DmDialogManager(); + static DmDialogManager &GetInstance(); void ConnectExtension(); void ShowConfirmDialog(const std::string param); void ShowPinDialog(const std::string param); @@ -74,6 +73,8 @@ public: return targetDeviceName_; } private: + DmDialogManager(); + ~DmDialogManager(); class DialogAbilityConnection : public OHOS::AAFwk::AbilityConnectionStub { public: void OnAbilityConnectDone( @@ -94,7 +95,9 @@ private: static int32_t deviceType_; static std::atomic isDialogDestroy_; static std::condition_variable dialogCondition_; - sptr dialogConnectionCallback_ {nullptr}; + static sptr dialogConnectionCallback_; + static DmDialogManager dialogMgr_; + static std::atomic isConnectSystemUI_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 0173bc269..51248b68e 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -164,7 +164,7 @@ typedef struct DmAuthResponseContext { std::string accountGroupIdHash; std::string publicKey; bool isOnline; - int32_t bindLevel; + int32_t bindLevel = INVALIED_TYPE; bool haveCredential; int32_t confirmOperation; std::string localAccountId; diff --git a/services/implementation/src/ability/standard/dm_dialog_manager.cpp b/services/implementation/src/ability/standard/dm_dialog_manager.cpp index 3157a0583..1e164071a 100644 --- a/services/implementation/src/ability/standard/dm_dialog_manager.cpp +++ b/services/implementation/src/ability/standard/dm_dialog_manager.cpp @@ -28,8 +28,6 @@ namespace OHOS { namespace DistributedHardware { static constexpr int32_t INVALID_USERID = -1; static constexpr int32_t MESSAGE_PARCEL_KEY_SIZE = 3; -static constexpr int32_t WAIT_DIALOG_CLOSE_TIME_S = 10; -const int32_t USLEEP_SHOW_PIN_TIME_US = 50000; // 50ms const std::string dmUiBundleName = "com.ohos.devicemanagerui"; const std::string comfirmAbilityName = "com.ohos.devicemanagerui.ConfirmUIExtAbility"; const std::string pinAbilityName = "com.ohos.devicemanagerui.PincodeUIExtAbility"; @@ -46,14 +44,27 @@ std::string DmDialogManager::appOperationStr_ = ""; std::string DmDialogManager::customDescriptionStr_ = ""; std::string DmDialogManager::targetDeviceName_ = ""; std::string DmDialogManager::pinCode_ = ""; -std::atomic DmDialogManager::isDialogDestroy_(true); -std::condition_variable DmDialogManager::dialogCondition_; +DmDialogManager DmDialogManager::dialogMgr_; int32_t DmDialogManager::deviceType_ = -1; +sptr DmDialogManager::dialogConnectionCallback_( + new (std::nothrow) DialogAbilityConnection()); + +std::atomic DmDialogManager::isConnectSystemUI_(false); +sptr g_remoteObject = nullptr; + +DmDialogManager::DmDialogManager() +{ + LOGI("DmDialogManager constructor"); +} -DmDialogManager::DmDialogManager() : dialogConnectionCallback_(new DialogAbilityConnection()) {} DmDialogManager::~DmDialogManager() { - dialogConnectionCallback_ = nullptr; + LOGI("DmDialogManager destructor"); +} + +DmDialogManager &DmDialogManager::GetInstance() +{ + return dialogMgr_; } void DmDialogManager::ShowConfirmDialog(const std::string param) @@ -105,6 +116,13 @@ void DmDialogManager::ShowInputDialog(const std::string param) void DmDialogManager::ConnectExtension() { + LOGI("DmDialogManager::ConnectExtension start."); + if (isConnectSystemUI_.load() && dialogConnectionCallback_ != nullptr && g_remoteObject != nullptr) { + AppExecFwk::ElementName element; + dialogConnectionCallback_->OnAbilityConnectDone(element, g_remoteObject, INVALID_USERID); + LOGI("DmDialogManager::ConnectExtension dialog has been show."); + return; + } AAFwk::Want want; std::string bundleName = "com.ohos.sceneboard"; std::string abilityName = "com.ohos.sceneboard.systemdialog"; @@ -137,15 +155,10 @@ void DmDialogManager::DialogAbilityConnection::OnAbilityConnectDone( LOGE("remoteObject is nullptr"); return; } - if (!isDialogDestroy_.load()) { - auto status = dialogCondition_.wait_for(lock, std::chrono::seconds(WAIT_DIALOG_CLOSE_TIME_S), - [] () { return isDialogDestroy_.load(); }); - if (!status) { - LOGE("wait dm dialog close failed."); - return; - } - usleep(USLEEP_SHOW_PIN_TIME_US); // 50ms + if (g_remoteObject == nullptr) { + g_remoteObject = remoteObject; } + MessageParcel data; MessageParcel reply; MessageOption option; @@ -172,7 +185,7 @@ void DmDialogManager::DialogAbilityConnection::OnAbilityConnectDone( LOGE("show dm dialog is failed: %{public}d", ret); return; } - isDialogDestroy_.store(false); + isConnectSystemUI_.store(true); LOGI("show dm dialog is success"); } @@ -181,8 +194,8 @@ void DmDialogManager::DialogAbilityConnection::OnAbilityDisconnectDone( { LOGI("OnAbilityDisconnectDone"); std::lock_guard lock(mutex_); - isDialogDestroy_.store(true); - dialogCondition_.notify_all(); + g_remoteObject = nullptr; + isConnectSystemUI_.store(false); } } } \ No newline at end of file diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 7319f82af..3c7461666 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -181,6 +181,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->bindLevel = jsonObject[TAG_BIND_LEVEL].get(); } } + LOGI("GetAuthParam, bindLevel %d, dmVersion: %s.", authRequestContext_->bindLevel, authRequestContext_->dmVersion); authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); } @@ -686,6 +687,7 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authResponseContext_->isIdenticalAccount = false; authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); + LOGI("DmAuthManager::StartNegotiate msg 80 %s.", message); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); timer_->StartTimer(std::string(NEGOTIATE_TIMEOUT_TASK), NEGOTIATE_TIMEOUT, [this] (std::string name) { @@ -1287,8 +1289,7 @@ void DmAuthManager::ShowConfigDialog() std::string localUdid = static_cast(localDeviceId); DeviceProfileConnector::GetInstance().SyncAclByBindType(authResponseContext_->hostPkgName, authResponseContext_->bindType, localUdid, remoteDeviceId_); - DmDialogManager dialogMgr; - dialogMgr.ShowConfirmDialog(params); + DmDialogManager::GetInstance().ShowConfirmDialog(params); struct RadarInfo info = { .funcName = "ShowConfigDialog", .stageRes = static_cast(StageRes::STAGE_IDLE), @@ -1320,8 +1321,7 @@ void DmAuthManager::ShowAuthInfoDialog() nlohmann::json jsonObj; jsonObj[PIN_CODE_KEY] = authResponseContext_->code; std::string authParam = jsonObj.dump(); - DmDialogManager dialogMgr; - dialogMgr.ShowPinDialog(std::to_string(authResponseContext_->code)); + DmDialogManager::GetInstance().ShowPinDialog(std::to_string(authResponseContext_->code)); } void DmAuthManager::ShowStartAuthDialog() @@ -1345,8 +1345,7 @@ void DmAuthManager::ShowStartAuthDialog() return; } LOGI("DmAuthManager::ShowStartAuthDialog start"); - DmDialogManager dialogMgr; - dialogMgr.ShowInputDialog(authResponseContext_->targetDeviceName); + DmDialogManager::GetInstance().ShowInputDialog(authResponseContext_->targetDeviceName); } int32_t DmAuthManager::ProcessPincode(int32_t pinCode) -- Gitee From 23b188f81b7a1bb0c11a44f4abb0550322da3b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 12 Feb 2025 15:17:03 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- .../implementation/src/authentication/dm_auth_manager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 3c7461666..29edef608 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -181,7 +181,8 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->bindLevel = jsonObject[TAG_BIND_LEVEL].get(); } } - LOGI("GetAuthParam, bindLevel %d, dmVersion: %s.", authRequestContext_->bindLevel, authRequestContext_->dmVersion); + LOGI("GetAuthParam, bindLevel %d, dmVersion: %s.", authRequestContext_->bindLevel, + authRequestContext_->dmVersion.c_str()); authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); } @@ -687,7 +688,7 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authResponseContext_->isIdenticalAccount = false; authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_NEGOTIATE); - LOGI("DmAuthManager::StartNegotiate msg 80 %s.", message); + LOGI("DmAuthManager::StartNegotiate msg 80 %s.", message.c_str()); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); timer_->StartTimer(std::string(NEGOTIATE_TIMEOUT_TASK), NEGOTIATE_TIMEOUT, [this] (std::string name) { -- Gitee From 6c07fd62f25c8fe26f9203cc880e5c854191e94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 12 Feb 2025 15:24:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- services/implementation/src/authentication/dm_auth_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 29edef608..9e095a6e0 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -738,6 +738,8 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) remoteDeviceId_ = authResponseContext_->localDeviceId; authResponseContext_->networkId = softbusConnector_->GetLocalDeviceNetworkId(); authResponseContext_->targetDeviceName = softbusConnector_->GetLocalDeviceName(); + LOGI("DmAuthManager::RespNegotiate dmVersion %s", authResponseContext_->dmVersion.c_str()); + LOGI("DmAuthManager::RespNegotiate bindLevel %d", authResponseContext_->bindLevel); if (authResponseContext_->dmVersion != "" && authResponseContext_->bindLevel != INVALIED_TYPE) { ProRespNegotiateExt(sessionId); } else { -- Gitee From 2cd305ed5084d87e63861dc11d15d3c36d1b55bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Wed, 12 Feb 2025 17:29:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- interfaces/kits/js4.0/src/native_devicemanager_js.cpp | 1 + services/implementation/src/authentication/dm_auth_manager.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index 09e0a47e0..01355a89b 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -1453,6 +1453,7 @@ void DeviceManagerNapi::BindDevOrTarget(DeviceManagerNapi *deviceManagerWrapper, std::string bindParam; bool isMetaType = false; JsToBindParam(env, object, bindParam, authAsyncCallbackInfo_.authType, isMetaType); + LOGI("bindParam %s", bindParam.c_str()); if (isMetaType) { std::shared_ptr bindTargetCallback = nullptr; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9e095a6e0..75e9b0b78 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -160,6 +160,7 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->isOnline = false; authRequestContext_->authed = !authRequestContext_->bindType.empty(); authRequestContext_->bindLevel = INVALIED_TYPE; + LOGI("Get auth param extra: %s.", extra.c_str()); nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); if (!jsonObject.is_discarded()) { if (IsString(jsonObject, TARGET_PKG_NAME_KEY)) { @@ -228,6 +229,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au { LOGI("DmAuthManager::AuthenticateDevice start auth type %d.", authType); int32_t ret = CheckAuthParamVaild(pkgName, authType, deviceId, extra); + LOGI("extra: %s.", extra.c_str()); if (ret != DM_OK) { LOGE("DmAuthManager::AuthenticateDevice failed, param is invaild."); return ret; -- Gitee