From afc5c35d41ab0225b2bee27b625f38f9adf9485d Mon Sep 17 00:00:00 2001 From: imp9527 Date: Thu, 11 Sep 2025 22:08:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E7=94=A8ts=E4=BE=A7transfer?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B9=9F=E9=80=9A=E7=9F=A5=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: imp9527 --- .../js_scene_session_manager.cpp | 86 +++++++++++++------ .../js_scene_session_manager.h | 4 +- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index 89767ca4c7..fff1b6557e 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -325,6 +325,8 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) JsSceneSessionManager::SetPiPSettingSwitchStatus); BindNativeFunction(env, exportObj, "applyFeatureConfig", moduleName, JsSceneSessionManager::ApplyFeatureConfig); + BindNativeFunction(env, exportObj, "notifySessionTransferToTargetScreenEvent", moduleName, + JsSceneSessionManager::NotifySessionTransferToTargetScreenEvent); return NapiGetUndefined(env); } @@ -4990,23 +4992,16 @@ void JsSceneSessionManager::RegisterTransferSessionToTargetScreenCallback() { SceneSessionManager::GetInstance().RegisterTransferSessionToTargetScreenCallback( [this](const TransferSessionInfo& info) { - auto sceneSession = SceneSessionManager::GetInstance().GetSceneSession(info.persistentId); - if (sceneSession == nullptr) { - TLOGE(WmsLogTag::WMS_MAIN, "sceneSession is nullptr"); - return; - } - this->OnTransferSessionToTargetScreen(info, sceneSession->GetSessionProperty()->GetDisplayId()); + this->OnTransferSessionToTargetScreen(info); }); } -void JsSceneSessionManager::OnTransferSessionToTargetScreen(const TransferSessionInfo& info, - const uint64_t fromScreenId) +void JsSceneSessionManager::OnTransferSessionToTargetScreen(const TransferSessionInfo& info) { TLOGI(WmsLogTag::WMS_LIFE, "in"); const char* const where = __func__; taskScheduler_->PostMainThreadTask( - [info, fromScreenId, where, - jsCallBack = GetJSCallback(SCENE_SESSION_TRANSFER_TO_TARGET_SCREEN_CB), env = env_] { + [info, where, jsCallBack = GetJSCallback(SCENE_SESSION_TRANSFER_TO_TARGET_SCREEN_CB), env = env_] { if (jsCallBack == nullptr) { TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s:jsCallBack is nullptr", where); return; @@ -5015,25 +5010,66 @@ void JsSceneSessionManager::OnTransferSessionToTargetScreen(const TransferSessio napi_value toScreenId = CreateJsValue(env, info.toScreenId); napi_value wantParams = OHOS::AppExecFwk::WrapWantParams(env, info.wantParams); napi_value argv[] = { persistentId, toScreenId, wantParams }; - napi_value callResult = nullptr; - napi_status ret = napi_call_function( - env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, &callResult); - if (ret != napi_ok) { - TLOGNE(WmsLogTag::WMS_LIFE, "%{public}s:napi call exception ret:%{public}d", where, ret); - return; - } + napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); SceneSessionManager::GetInstance().UpdateScreenLockState(info.persistentId); - - uint32_t resultCode = 0; - std::string resultMessage = ""; - if (!ConvertSessionResultFromJsValue(env, callResult, resultCode, resultMessage)) { - return; - } - SceneSessionManager::GetInstance().NotifySessionTransferToTargetScreenEvent( - info.persistentId, resultCode, fromScreenId, info.toScreenId); }, __func__); } +napi_value JsSceneSessionManager::NotifySessionTransferToTargetScreenEvent(napi_env env, napi_callback_info info) +{ + TLOGD(WmsLogTag::WMS_LIFE, "[NAPI]"); + JsSceneSessionManager* me = CheckParamsAndGetThis(env, info); + return (me != nullptr) ? me->OnNotifySessionTransferToTargetScreenEvent(env, info) : nullptr; +} + +napi_value JsSceneSessionManager::OnNotifySessionTransferToTargetScreenEvent(napi_env env, napi_callback_info info) +{ + size_t argc = ARGC_FOUR; + napi_value argv[ARGC_FOUR] = {nullptr}; + napi_get_cb_info(env, info, &argc, argc, nullptr, nullptr); + if (argc != ARGC_FOUR) { + TLOGE(WmsLogTag::WMS_LIFE, "Argc is invalid: %{public}zu", argc); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + int32_t persistentId; + if (!ConvertFromJsValue(env, argv[ARG_INDEX_ZERO], persistentId)) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert persistentId"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + uint32_t resultCode; + if (!ConvertFromJsValue(env, argv[ARG_INDEX_ONE], resultCode)) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert resultCode"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + int64_t fromScreenId; + if (!ConvertFromJsValue(env, argv[ARG_INDEX_TWO], fromScreenId) || fromScreenId < 0 ) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert fromScreenId"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + int64_t toScreenId; + if (!ConvertFromJsValue(env, argv[ARG_INDEX_THREE], toScreenId) || toScreenId < 0 ) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert toScreenId"); + napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), + "Input parameter is missing or invalid")); + return NapiGetUndefined(env); + } + TLOGI(WmsLogTag::WMS_LIFE, + "persistentId: %{public}d, resultCode: %{public}d, fromScreenId: %{public}ld, toScreenId: %{public}ld", + persistentId, resultCode, fromScreenId, toScreenId); + SceneSessionManager::GetInstance().NotifySessionTransferToTargetScreenEvent( + persistentId, resultCode, static_cast(fromScreenId), static_cast(toScreenId)); + return NapiGetUndefined(env); +} + + napi_value JsSceneSessionManager::OnSupportFollowParentWindowLayout(napi_env env, napi_callback_info info) { SceneSessionManager::GetInstance().ConfigSupportFollowParentWindowLayout(); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h index 1aca2a271c..57c0d9e4fd 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h @@ -378,7 +378,9 @@ private: void RegisterSceneSessionDestructCallback(); void OnSceneSessionDestruct(int32_t persistentId); void RegisterTransferSessionToTargetScreenCallback(); - void OnTransferSessionToTargetScreen(const TransferSessionInfo& info, const uint64_t fromScreenId); + void OnTransferSessionToTargetScreen(const TransferSessionInfo& info); + static napi_value NotifySessionTransferToTargetScreenEvent(napi_env env, napi_callback_info info); + napi_value OnNotifySessionTransferToTargetScreenEvent(napi_env env, napi_callback_info info); static napi_value UpdateRecentMainSessionInfos(napi_env env, napi_callback_info info); napi_env env_; -- Gitee From 5b9e4afa418585a0486b6264b25919f43cae76c7 Mon Sep 17 00:00:00 2001 From: imp9527 Date: Thu, 11 Sep 2025 22:35:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: imp9527 --- .../js_scene_session_manager.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index fff1b6557e..d66918a075 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -5026,7 +5026,7 @@ napi_value JsSceneSessionManager::OnNotifySessionTransferToTargetScreenEvent(nap { size_t argc = ARGC_FOUR; napi_value argv[ARGC_FOUR] = {nullptr}; - napi_get_cb_info(env, info, &argc, argc, nullptr, nullptr); + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARGC_FOUR) { TLOGE(WmsLogTag::WMS_LIFE, "Argc is invalid: %{public}zu", argc); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), @@ -5035,41 +5035,40 @@ napi_value JsSceneSessionManager::OnNotifySessionTransferToTargetScreenEvent(nap } int32_t persistentId; if (!ConvertFromJsValue(env, argv[ARG_INDEX_ZERO], persistentId)) { - TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert persistentId"); + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert parameter to persistentId"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); return NapiGetUndefined(env); } uint32_t resultCode; if (!ConvertFromJsValue(env, argv[ARG_INDEX_ONE], resultCode)) { - TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert resultCode"); + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert parameter to resultCode"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); return NapiGetUndefined(env); } int64_t fromScreenId; - if (!ConvertFromJsValue(env, argv[ARG_INDEX_TWO], fromScreenId) || fromScreenId < 0 ) { - TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert fromScreenId"); + if (!ConvertFromJsValue(env, argv[ARG_INDEX_TWO], fromScreenId) || fromScreenId < 0) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert parameter to fromScreenId"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); return NapiGetUndefined(env); } int64_t toScreenId; - if (!ConvertFromJsValue(env, argv[ARG_INDEX_THREE], toScreenId) || toScreenId < 0 ) { - TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert toScreenId"); + if (!ConvertFromJsValue(env, argv[ARG_INDEX_THREE], toScreenId) || toScreenId < 0) { + TLOGE(WmsLogTag::WMS_LIFE, "Failed to convert parameter to toScreenId"); napi_throw(env, CreateJsError(env, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); return NapiGetUndefined(env); } - TLOGI(WmsLogTag::WMS_LIFE, - "persistentId: %{public}d, resultCode: %{public}d, fromScreenId: %{public}ld, toScreenId: %{public}ld", + TLOGI(WmsLogTag::WMS_LIFE, "persistentId: %{public}d, resultCode: %{public}d, " + "fromScreenId: %{public}" PRId64 " , toScreenId: %{public}" PRId64, persistentId, resultCode, fromScreenId, toScreenId); SceneSessionManager::GetInstance().NotifySessionTransferToTargetScreenEvent( persistentId, resultCode, static_cast(fromScreenId), static_cast(toScreenId)); return NapiGetUndefined(env); } - napi_value JsSceneSessionManager::OnSupportFollowParentWindowLayout(napi_env env, napi_callback_info info) { SceneSessionManager::GetInstance().ConfigSupportFollowParentWindowLayout(); -- Gitee