From c8d4f51e4ac1d18cb8d3e155b923a2b3f3e7da4e Mon Sep 17 00:00:00 2001 From: qianlf Date: Wed, 30 Mar 2022 16:57:12 +0800 Subject: [PATCH] update wm log Signed-off-by: qianlf Change-Id: I36c0f7a103be4593ccc299bf4b83f61020f7c3fe --- interfaces/innerkits/wm/wm_common.h | 3 +- .../window_manager_napi/js_window_manager.cpp | 165 ++++----- .../window_runtime/window_napi/js_window.cpp | 331 +++++++++--------- .../window_napi/js_window_listener.cpp | 24 +- .../js_window_register_manager.cpp | 38 +- .../window_napi/js_window_utils.cpp | 81 ++--- .../window_stage_napi/js_window_stage.cpp | 109 +++--- 7 files changed, 367 insertions(+), 384 deletions(-) diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 1bceb4ef..392e345a 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -98,7 +98,8 @@ enum class WMError : int32_t { enum class WindowFlag : uint32_t { WINDOW_FLAG_NEED_AVOID = 1, WINDOW_FLAG_PARENT_LIMIT = 1 << 1, - WINDOW_FLAG_END = 1 << 2, + WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2, + WINDOW_FLAG_END = 1 << 3, }; enum class WindowSizeChangeReason : uint32_t { diff --git a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp index d6e0e3f9..8a3a68e4 100644 --- a/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_manager_napi/js_window_manager.cpp @@ -42,7 +42,7 @@ JsWindowManager::~JsWindowManager() void JsWindowManager::Finalizer(NativeEngine* engine, void* data, void* hint) { - WLOGFI("JsWindowManager::Finalizer is called"); + WLOGFI("[NAPI]Finalizer"); std::unique_ptr(static_cast(data)); } @@ -93,24 +93,24 @@ static bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability) napi_value global; auto env = reinterpret_cast(&engine); if (napi_get_global(env, &global) != napi_ok) { - WLOGFE("JsWindowManager::GetAPI7Ability get global failed"); + WLOGFE("[NAPI]Get global failed"); return false; } napi_value jsAbility; napi_status status = napi_get_named_property(env, global, "ability", &jsAbility); if (status != napi_ok || jsAbility == nullptr) { - WLOGFE("JsWindowManager::GetAPI7Ability get global failed"); + WLOGFE("[NAPI]Get ability property failed"); return false; } if (napi_get_value_external(env, jsAbility, reinterpret_cast(&ability)) != napi_ok) { - WLOGFE("JsWindowManager::GetAPI7Ability get global failed"); + WLOGFE("[NAPI]Get ability external failed"); return false; } if (ability == nullptr) { return false; } else { - WLOGI("JsWindowManager::GetAPI7Ability ability is success!"); + WLOGI("[NAPI]Get ability"); } return true; } @@ -120,7 +120,7 @@ static void GetNativeContext(NativeValue* nativeContext, void*& contextPtr, WMEr if (nativeContext != nullptr) { auto objContext = AbilityRuntime::ConvertNativeValueTo(nativeContext); if (objContext == nullptr) { - WLOGFE("ConvertNativeValueTo Context Object failed"); + WLOGFE("[NAPI]ConvertNativeValueTo Context Object failed"); errCode = WMError::WM_ERROR_INVALID_PARAM; return; } @@ -133,7 +133,7 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent { NativeNumber* type = ConvertNativeValueTo(nativeType); if (type == nullptr) { - WLOGFE("Failed to convert parameter to windowType"); + WLOGFE("[NAPI]Failed to convert parameter to windowType"); return false; } // adapt to the old version @@ -144,7 +144,7 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent static_cast(*type) <= static_cast(ApiWindowType::TYPE_END)) { winType = JS_TO_NATIVE_WINDOW_TYPE_MAP.at(static_cast(static_cast(*type))); } else { - WLOGFE("Do not surppot this type"); + WLOGFE("[NAPI]Type %{public}u is not supported", static_cast(*type)); return false; } } @@ -152,18 +152,18 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent bool isOldApi = GetAPI7Ability(engine, ability); if (isOldApi) { if (ability == nullptr || !WindowHelper::IsSubWindow(winType)) { - WLOGE("JsWindowManager FA mode GetAPI7Ability failed or type should be subWinodw!"); + WLOGE("[NAPI]FA mode GetAPI7Ability failed or type %{public}u is not subWinodw", winType); return false; } auto window = ability->GetWindow(); if (window == nullptr) { - WLOGE("JsWindowManager CheckJsWindowType in oldApi get mainWindow failed"); + WLOGE("[NAPI]Get mainWindow failed"); return false; } parentName = window->GetWindowName(); } else { if (!WindowHelper::IsSystemWindow(winType)) { - WLOGFE("Only SystemWindow support create in stage mode!"); + WLOGFE("[NAPI]Only SystemWindow support create in stage mode, type is %{public}u", winType); return false; } } @@ -173,13 +173,12 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent static void CreateSystemWindowTask(void* contextPtr, std::string windowName, WindowType winType, NativeEngine& engine, AsyncTask& task) { - WLOGFI("JsWindowManager::CreateSystemWindowTask is called"); + WLOGFI("[NAPI]CreateSystemWindowTask"); auto context = static_cast*>(contextPtr); if (contextPtr == nullptr || context == nullptr) { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), - "JsWindow::OnCreateWindow newAPI failed.")); - WLOGFE("JsWindowManager::OnCreateWindow in newApi use with empty context!"); + static_cast(WMError::WM_ERROR_NULLPTR), "Context is nullptr")); + WLOGFE("[NAPI]Context is nullptr"); return; } if (winType == WindowType::WINDOW_TYPE_FLOAT) { @@ -188,8 +187,7 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win if (!CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_INVALID_PERMISSION), - "JsWindow::OnCreateWindow newAPI failed.")); - WLOGFE("JsWindowManager::OnCreateWindow in newApi TYPE_FLOAT CheckCallingPermission failed!"); + "TYPE_FLOAT CheckCallingPermission failed")); return; } } @@ -197,30 +195,30 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win sptr windowOption = new(std::nothrow) WindowOption(); if (windowOption == nullptr) { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed.")); - WLOGFE("JsWindowManager::OnCreateWindow windowOption malloc failed"); + static_cast(WMError::WM_ERROR_NULLPTR), "New window option failed")); + WLOGFE("[NAPI]New window option failed"); return; } windowOption->SetWindowType(winType); sptr window = Window::Create(windowName, windowOption, context->lock()); if (window != nullptr) { task.Resolve(engine, CreateJsWindowObject(engine, window, false)); - WLOGFI("JsWindowManager::OnCreateWindow success"); } else { + WLOGFE("[NAPI]Create window failed"); task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed.")); + static_cast(WMError::WM_ERROR_NULLPTR), "Create window failed")); } } static void CreateSubWindowTask(std::string parentWinName, std::string windowName, WindowType winType, NativeEngine& engine, AsyncTask& task) { - WLOGFI("JsWindowManager::CreateSubWindowTask is called"); + WLOGFI("[NAPI]CreateSubWindowTask, parent name = %{public}s", parentWinName.c_str()); sptr windowOption = new(std::nothrow) WindowOption(); if (windowOption == nullptr) { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed.")); - WLOGFE("JsWindowManager::OnCreateWindow windowOption malloc failed"); + static_cast(WMError::WM_ERROR_NULLPTR), "New window option failed")); + WLOGFE("[NAPI]New window option failed"); return; } windowOption->SetWindowType(winType); @@ -229,16 +227,16 @@ static void CreateSubWindowTask(std::string parentWinName, std::string windowNam sptr window = Window::Create(windowName, windowOption); if (window != nullptr) { task.Resolve(engine, CreateJsWindowObject(engine, window, true)); - WLOGFI("JsWindowManager::OnCreateWindow success"); } else { + WLOGFE("[NAPI]Create window failed"); task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed.")); + static_cast(WMError::WM_ERROR_NULLPTR), "Create window failed")); } } NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::OnCreateWindow is called"); + WLOGFI("[NAPI]OnCreateWindow"); NativeValue* nativeString = nullptr; NativeValue* nativeContext = nullptr; NativeValue* nativeType = nullptr; @@ -260,7 +258,7 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac std::string windowName; WMError errCode = WMError::WM_OK; if (!ConvertFromJsValue(engine, nativeString, windowName)) { - WLOGFE("Failed to convert parameter to windowName"); + WLOGFE("[NAPI]Failed to convert parameter to windowName"); errCode = WMError::WM_ERROR_INVALID_PARAM; } std::string parentName; @@ -271,10 +269,12 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac } void* contextPtr = nullptr; GetNativeContext(nativeContext, contextPtr, errCode); + + WLOGFI("[NAPI]Window name = %{public}s, type = %{public}u, err = %{public}d", windowName.c_str(), winType, errCode); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (errCode != WMError::WM_OK) { - task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params")); return; } if (parentName.empty()) { @@ -284,43 +284,45 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac } }; NativeValue* result = nullptr; - AsyncTask::Schedule( - engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result)); + AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result)); return result; } NativeValue* JsWindowManager::OnFindWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::JsOnFindWindow is called"); + WLOGFI("[NAPI]OnFindWindow"); std::string windowName; WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2: maximum params num - WLOGFE("param not match!"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { if (!ConvertFromJsValue(engine, info.argv[0], windowName)) { - WLOGFE("Failed to convert parameter to windowName"); + WLOGFE("[NAPI]Failed to convert parameter to windowName"); errCode = WMError::WM_ERROR_INVALID_PARAM; } } + WLOGFI("[NAPI]Window name = %{public}s, err = %{public}d", windowName.c_str(), errCode); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (errCode != WMError::WM_OK) { - task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params")); return; } std::shared_ptr jsWindowObj = FindJsWindowObject(windowName); if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) { + WLOGFI("[NAPI]Find window: %{public}s, use exist js window", windowName.c_str()); task.Resolve(engine, jsWindowObj->Get()); - WLOGFI("JsWindowManager::OnFindWindow success"); } else { sptr window = Window::Find(windowName); if (window == nullptr) { + WLOGFE("[NAPI]Cannot find window: %{public}s", windowName.c_str()); task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnFindWindow failed.")); + static_cast(WMError::WM_ERROR_NULLPTR), "Cannot find window")); } else { AppExecFwk::Ability* ability = nullptr; task.Resolve(engine, CreateJsWindowObject(engine, window, GetAPI7Ability(engine, ability))); + WLOGFI("[NAPI]Find window: %{public}s, create js window", windowName.c_str()); } } }; @@ -335,33 +337,32 @@ NativeValue* JsWindowManager::OnFindWindow(NativeEngine& engine, NativeCallbackI NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::OnMinimizeAll is called"); + WLOGFI("[NAPI]OnMinimizeAll"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2: maximum params num - WLOGFE("param is too small!"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } int64_t displayId = static_cast(DISPLAY_ID_INVALID); if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], displayId)) { - WLOGFE("Failed to convert parameter to displayId"); + WLOGFE("[NAPI]Failed to convert parameter to displayId"); errCode = WMError::WM_ERROR_INVALID_PARAM; } if (displayId < 0 || SingletonContainer::Get().GetDisplayById(static_cast(displayId)) == nullptr) { - WLOGFE("displayId is invalid"); errCode = WMError::WM_ERROR_INVALID_PARAM; - } else { - WLOGFI("displayId %{public}" PRIu64"", static_cast(displayId)); } + + WLOGFI("[NAPI]Display id = %{public}" PRIu64", err = %{public}d", static_cast(displayId), errCode); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (errCode != WMError::WM_OK) { - task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params")); return; } SingletonContainer::Get().MinimizeAllAppWindows(static_cast(displayId)); task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindowManager::OnMinimizeAll success"); + WLOGFI("[NAPI]OnMinimizeAll success"); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); @@ -373,50 +374,52 @@ NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallback NativeValue* JsWindowManager::OnRegisterWindowMangerCallback(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback is called"); + WLOGFI("[NAPI]OnRegisterWindowMangerCallback"); if (info.argc != 2) { // 2: params num - WLOGFE("Params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); return engine.CreateUndefined(); } std::string cbType; if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { - WLOGFE("Failed to convert parameter to callbackType"); + WLOGFE("[NAPI]Failed to convert parameter to callbackType"); return engine.CreateUndefined(); } NativeValue* value = info.argv[1]; if (!value->IsCallable()) { - WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback info->argv[1] is not callable"); + WLOGFI("[NAPI]Callback(argv[1]) is not callable"); return engine.CreateUndefined(); } registerManager_->RegisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, engine, value); - WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback end!"); + WLOGFI("[NAPI]Register end, type = %{public}s, callback = %{public}p", cbType.c_str(), value); return engine.CreateUndefined(); } NativeValue* JsWindowManager::OnUnregisterWindowManagerCallback(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::OnUnregisterWindowCallback is called"); + WLOGFI("[NAPI]OnUnregisterWindowManagerCallback"); if (info.argc < 1 || info.argc > 2) { // 2: maximum params num - WLOGFE("Params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); return engine.CreateUndefined(); } std::string cbType; if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { - WLOGFE("Failed to convert parameter to callbackType"); + WLOGFE("[NAPI]Failed to convert parameter to callbackType"); return engine.CreateUndefined(); } + + NativeValue* value = nullptr; if (info.argc == 1) { - registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, nullptr); + registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, value); } else { - NativeValue* value = info.argv[1]; + value = info.argv[1]; if (!value->IsCallable()) { - WLOGFI("JsWindowManager::OnUnregisterWindowManagerCallback info->argv[1] is not callable"); + WLOGFI("[NAPI]Callback(argv[1]) is not callable"); return engine.CreateUndefined(); } registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, value); } - WLOGFI("JsWindowManager::OnUnregisterWindowCallback end!"); + WLOGFI("[NAPI]Unregister end, type = %{public}s, callback = %{public}p", cbType.c_str(), value); return engine.CreateUndefined(); } @@ -426,10 +429,10 @@ static void GetTopWindowTask(void* contextPtr, bool isOldApi, NativeEngine& engi sptr window = nullptr; if (isOldApi) { AppExecFwk::Ability* ability = nullptr; - if (!GetAPI7Ability(engine, ability)) { + if (!GetAPI7Ability(engine, ability) || ability->GetWindow() == nullptr) { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow failed.")); - WLOGE("JsWindowManager get top windowfailed with null ability"); + static_cast(WMError::WM_ERROR_NULLPTR), "FA mode can not get ability window")); + WLOGE("[NAPI]FA mode can not get ability window"); return; } window = Window::GetTopWindowWithId(ability->GetWindow()->GetWindowId()); @@ -437,17 +440,16 @@ static void GetTopWindowTask(void* contextPtr, bool isOldApi, NativeEngine& engi auto context = static_cast*>(contextPtr); if (contextPtr == nullptr || context == nullptr) { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), - "JsWindow::OnGetTopWindow newAPI failed.")); - WLOGFE("JsWindowManager::OnGetTopWindow in newApi use with empty context!"); + static_cast(WMError::WM_ERROR_NULLPTR), "Stage mode without context")); + WLOGFE("[NAPI]Stage mode without context"); return; } window = Window::GetTopWindowWithContext(context->lock()); } if (window == nullptr) { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnGetTopWindow failed.")); - WLOGFE("JsWindowManager::OnGetTopWindow failed"); + static_cast(WMError::WM_ERROR_NULLPTR), "Get top window failed")); + WLOGFE("[NAPI]Get top window failed"); return; } windowName = window->GetWindowName(); @@ -457,20 +459,20 @@ static void GetTopWindowTask(void* contextPtr, bool isOldApi, NativeEngine& engi } else { task.Resolve(engine, CreateJsWindowObject(engine, window, isOldApi)); } - WLOGFI("JsWindowManager::OnGetTopWindow success"); + WLOGFI("[NAPI]Get top window %{public}s success", windowName.c_str()); return; } NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::OnGetTopWindow is called"); + WLOGFI("[NAPI]OnGetTopWindow"); WMError errCode = WMError::WM_OK; NativeValue* nativeContext = nullptr; NativeValue* nativeCallback = nullptr; void* contextPtr = nullptr; bool isOldApi = false; if (info.argc > 2) { // 2: maximum params num - WLOGFE("param not match!"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?) @@ -486,10 +488,11 @@ NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbac GetNativeContext(nativeContext, contextPtr, errCode); } + WLOGFI("[NAPI]Context %{public}p, FA mode %{public}u, err %{public}u", contextPtr, isOldApi, errCode); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (errCode != WMError::WM_OK) { - task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params")); return; } return GetTopWindowTask(contextPtr, isOldApi, engine, task); @@ -502,10 +505,10 @@ NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbac NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowManager::OnSetWindowLayoutMode is called"); + WLOGFI("[NAPI]OnSetWindowLayoutMode"); WMError errCode = WMError::WM_OK; if (info.argc < 2 || info.argc > 3) { // 2: minimum params num; 3: maximum params num - WLOGFE("JsWindowManager::OnSetWindowLayoutMode params too small"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } WindowLayoutMode winLayoutMode = WindowLayoutMode::CASCADE; @@ -513,31 +516,33 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native if (errCode == WMError::WM_OK) { NativeNumber* nativeMode = ConvertNativeValueTo(info.argv[0]); if (nativeMode == nullptr) { - WLOGFE("Failed to convert parameter to windowLayoutMode"); + WLOGFE("[NAPI]Failed to convert parameter to windowLayoutMode"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { winLayoutMode = static_cast(static_cast(*nativeMode)); } if (!ConvertFromJsValue(engine, info.argv[1], displayId)) { - WLOGFE("Failed to convert parameter to displayId"); + WLOGFE("[NAPI]Failed to convert parameter to displayId"); errCode = WMError::WM_ERROR_INVALID_PARAM; } } + WLOGFI("[NAPI]Display id = %{public}" PRIu64", LayoutMode = %{public}u, err = %{public}d", + static_cast(displayId), winLayoutMode, errCode); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (errCode != WMError::WM_OK) { - task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params.")); + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "Invalidate params")); return; } WMError ret = SingletonContainer::Get().SetWindowLayoutMode(winLayoutMode, static_cast(displayId)); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindowManager::OnSetWindowLayoutMode success"); + WLOGFI("[NAPI]SetWindowLayoutMode success"); } else { - task.Reject(engine, CreateJsError(engine, static_cast(ret), "do failed")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "SetWindowLayoutMode failed")); } }; // 2: maximum params num; 2: index of callback @@ -551,16 +556,16 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) { - WLOGFI("JsWindowManagerInit is called"); + WLOGFI("[NAPI]JsWindowManagerInit"); if (engine == nullptr || exportObj == nullptr) { - WLOGFE("JsWindowManagerInit engine or exportObj is nullptr"); + WLOGFE("[NAPI]JsWindowManagerInit engine or exportObj is nullptr"); return nullptr; } NativeObject* object = ConvertNativeValueTo(exportObj); if (object == nullptr) { - WLOGFE("JsWindowManagerInit object is nullptr"); + WLOGFE("[NAPI]JsWindowManagerInit object is nullptr"); return nullptr; } @@ -581,4 +586,4 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj) return engine->CreateUndefined(); } } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp index af1297a2..631d529f 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.cpp @@ -32,21 +32,20 @@ JsWindow::JsWindow(const sptr& window, bool isOldApi) : windowToken_(window), registerManager_(std::make_unique()), isOldApi_(isOldApi) { NotifyNativeWinDestroyFunc func = [](std::string windowName) { - WLOGE("NotifyNativeWinDestroyFunc is called %{public}s", windowName.c_str()); std::lock_guard lock(g_mutex); if (windowName.empty() || g_jsWindowMap.count(windowName) == 0) { - WLOGE("windowName not exist %{public}s", windowName.c_str()); + WLOGE("[NAPI]Can not find window %{public}s ", windowName.c_str()); return; } g_jsWindowMap.erase(windowName); - WLOGFI("JsWindow::NotifyNativeWinDestroyFuncwindowName %{public}s is destroyed", windowName.c_str()); + WLOGE("[NAPI]Destroy window %{public}s in js window", windowName.c_str()); }; windowToken_->RegisterWindowDestroyedListener(func); } JsWindow::~JsWindow() { - WLOGFI("JsWindow::~JsWindow is called"); + WLOGFI("[NAPI]~JsWindow"); windowToken_ = nullptr; } @@ -60,239 +59,239 @@ std::string JsWindow::GetWindowName() void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint) { - WLOGFI("JsWindow::Finalizer is called"); + WLOGFI("[NAPI]Finalizer"); auto jsWin = std::unique_ptr(static_cast(data)); if (jsWin == nullptr) { - WLOGFE("JsWindow::Finalizer JsWindow is null"); + WLOGFE("[NAPI]jsWin is nullptr"); return; } std::string windowName = jsWin->GetWindowName(); - WLOGFI("JsWindow::Finalizer windowName : %{public}s", windowName.c_str()); + WLOGFI("[NAPI]Window %{public}s", windowName.c_str()); std::lock_guard lock(g_mutex); if (g_jsWindowMap.find(windowName) != g_jsWindowMap.end()) { - WLOGFI("JsWindow::windowName %{public}s is destroyed", windowName.c_str()); g_jsWindowMap.erase(windowName); + WLOGFI("[NAPI]Remove window %{public}s from g_jsWindowMap", windowName.c_str()); } } NativeValue* JsWindow::Show(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::Show is called"); + WLOGFI("[NAPI]Show"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnShow(*engine, *info) : nullptr; } NativeValue* JsWindow::Destroy(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::Destroy is called"); + WLOGFI("[NAPI]Destroy"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnDestroy(*engine, *info) : nullptr; } NativeValue* JsWindow::Hide(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::Hide is called"); + WLOGFI("[NAPI]Hide"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnHide(*engine, *info) : nullptr; } NativeValue* JsWindow::MoveTo(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::MoveTo is called"); + WLOGFI("[NAPI]MoveTo"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnMoveTo(*engine, *info) : nullptr; } NativeValue* JsWindow::Resize(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::Resize is called"); + WLOGFI("[NAPI]Resize"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnResize(*engine, *info) : nullptr; } NativeValue* JsWindow::SetWindowType(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetWindowType is called"); + WLOGFI("[NAPI]SetWindowType"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetWindowType(*engine, *info) : nullptr; } NativeValue* JsWindow::SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetWindowMode is called"); + WLOGFI("[NAPI]SetWindowMode"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetWindowMode(*engine, *info) : nullptr; } NativeValue* JsWindow::GetProperties(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::GetProperties is called"); + WLOGFI("[NAPI]GetProperties"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnGetProperties(*engine, *info) : nullptr; } NativeValue* JsWindow::RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::RegisterWindowCallback is called"); + WLOGFI("[NAPI]RegisterWindowCallback"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnRegisterWindowCallback(*engine, *info) : nullptr; } NativeValue* JsWindow::UnregisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::UnregisterWindowCallback is called"); + WLOGFI("[NAPI]UnregisterWindowCallback"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnUnregisterWindowCallback(*engine, *info) : nullptr; } NativeValue* JsWindow::LoadContent(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::LoadContent is called"); + WLOGFI("[NAPI]LoadContent"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnLoadContent(*engine, *info) : nullptr; } NativeValue* JsWindow::SetFullScreen(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetFullScreen is called"); + WLOGFI("[NAPI]SetFullScreen"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetFullScreen(*engine, *info) : nullptr; } NativeValue* JsWindow::SetLayoutFullScreen(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetLayoutFullScreen is called"); + WLOGFI("[NAPI]SetLayoutFullScreen"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetLayoutFullScreen(*engine, *info) : nullptr; } NativeValue* JsWindow::SetSystemBarEnable(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetSystemBarEnable is called"); + WLOGFI("[NAPI]SetSystemBarEnable"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetSystemBarEnable(*engine, *info) : nullptr; } NativeValue* JsWindow::SetSystemBarProperties(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetSystemBarProperties is called"); + WLOGFI("[NAPI]SetSystemBarProperties"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetSystemBarProperties(*engine, *info) : nullptr; } NativeValue* JsWindow::GetAvoidArea(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::GetAvoidArea is called"); + WLOGFI("[NAPI]GetAvoidArea"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnGetAvoidArea(*engine, *info) : nullptr; } NativeValue* JsWindow::IsShowing(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::IsShowing is called"); + WLOGFI("[NAPI]IsShowing"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnIsShowing(*engine, *info) : nullptr; } NativeValue* JsWindow::IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::IsSupportWideGamut is called"); + WLOGFI("[NAPI]IsSupportWideGamut"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnIsSupportWideGamut(*engine, *info) : nullptr; } NativeValue* JsWindow::SetBackgroundColor(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetBackgroundColor is called"); + WLOGFI("[NAPI]SetBackgroundColor"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetBackgroundColor(*engine, *info) : nullptr; } NativeValue* JsWindow::SetBrightness(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetBrightness is called"); + WLOGFI("[NAPI]SetBrightness"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetBrightness(*engine, *info) : nullptr; } NativeValue* JsWindow::SetDimBehind(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetDimBehind is called"); + WLOGFI("[NAPI]SetDimBehind"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetDimBehind(*engine, *info) : nullptr; } NativeValue* JsWindow::SetFocusable(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetFocusable is called"); + WLOGFI("[NAPI]SetFocusable"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetFocusable(*engine, *info) : nullptr; } NativeValue* JsWindow::SetKeepScreenOn(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetkeepScreenOn is called"); + WLOGFI("[NAPI]SetKeepScreenOn"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetKeepScreenOn(*engine, *info) : nullptr; } NativeValue* JsWindow::SetOutsideTouchable(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetOutsideTouchable is called"); + WLOGFI("[NAPI]SetOutsideTouchable"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetOutsideTouchable(*engine, *info) : nullptr; } NativeValue* JsWindow::SetPrivacyMode(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetPrivacyMode is called"); + WLOGFI("[NAPI]SetPrivacyMode"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetPrivacyMode(*engine, *info) : nullptr; } NativeValue* JsWindow::SetTouchable(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetTouchable is called"); + WLOGFI("[NAPI]SetTouchable"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetTouchable(*engine, *info) : nullptr; } NativeValue* JsWindow::SetColorSpace(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::SetColorSpace is called"); + WLOGFI("[NAPI]SetColorSpace"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetColorSpace(*engine, *info) : nullptr; } NativeValue* JsWindow::GetColorSpace(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindow::GetColorSpace is called"); + WLOGFI("[NAPI]GetColorSpace"); JsWindow* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnGetColorSpace(*engine, *info) : nullptr; } NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnShow is called"); WMError errCode = WMError::WM_OK; if (info.argc > 1) { - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->Show(); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnShow success"); } else { - task.Reject(engine, CreateJsError(engine, static_cast(ret), "ShowWindow failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window show failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] show end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -305,27 +304,28 @@ NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnDestroy is called"); WMError errCode = WMError::WM_OK; if (info.argc > 1) { - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->Destroy(); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] destroy end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); if (ret != WMError::WM_OK) { - task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnDestroy failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window destroy failed")); return; } + windowToken_ = nullptr; task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnDestroy success"); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -338,26 +338,26 @@ NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnHide is called"); WMError errCode = WMError::WM_OK; if (info.argc > 1) { - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->Hide(); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnHide success"); } else { - task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnHide failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window hide failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] hide end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -370,37 +370,38 @@ NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnMoveTo is called"); WMError errCode = WMError::WM_OK; if (info.argc < 2 || info.argc > 3) { // 2:minimum param num, 3: maximum param num - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } int32_t x = 0; if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], x)) { - WLOGFE("Failed to convert parameter to x"); + WLOGFE("[NAPI]Failed to convert parameter to x"); errCode = WMError::WM_ERROR_INVALID_PARAM; } int32_t y = 0; if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[1], y)) { - WLOGFE("Failed to convert parameter to y"); + WLOGFE("[NAPI]Failed to convert parameter to y"); errCode = WMError::WM_ERROR_INVALID_PARAM; } + AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->MoveTo(x, y); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnMoveTo success"); } else { - task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnMoveTo failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window move failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] move end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; // 2: params num; 2: index of callback NativeValue* lastParam = (info.argc <= 2) ? nullptr : @@ -413,36 +414,37 @@ NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnResize is called"); WMError errCode = WMError::WM_OK; if (info.argc < 2 || info.argc > 3) { // 2: minimum param num, 3: maximum param num - WLOGFE("JsWindow windowToken_ is nullptr or params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } uint32_t width = 0; if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], width)) { - WLOGFE("Failed to convert parameter to width"); + WLOGFE("[NAPI]Failed to convert parameter to width"); errCode = WMError::WM_ERROR_INVALID_PARAM; } uint32_t height = 0; if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[1], height)) { - WLOGFE("Failed to convert parameter to height"); + WLOGFE("[NAPI]Failed to convert parameter to height"); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->Resize(width, height); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); } else { - task.Reject(engine, CreateJsError(engine, static_cast(ret), "JsWindow::OnResize failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window resize failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] resize end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; // 2: params num; 2: index of callback NativeValue* lastParam = (info.argc <= 2) ? nullptr : @@ -455,17 +457,16 @@ NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetWindowType is called"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2 is max num of argc - WLOGFE("JsWindow windowToken_ is nullptr or params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } WindowType winType = WindowType::SYSTEM_WINDOW_BASE; if (errCode == WMError::WM_OK) { NativeNumber* nativeType = ConvertNativeValueTo(info.argv[0]); if (nativeType == nullptr) { - WLOGFE("Failed to convert parameter to windowType"); + WLOGFE("[NAPI]Failed to convert parameter to windowType"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else if (static_cast(*nativeType) >= static_cast(WindowType::SYSTEM_WINDOW_BASE)) { winType = static_cast(static_cast(*nativeType)); // adapt to the old version @@ -475,7 +476,7 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& winType = JS_TO_NATIVE_WINDOW_TYPE_MAP.at( static_cast(static_cast(*nativeType))); } else { - WLOGFE("Do not surppot this type"); + WLOGFE("[NAPI]Do not surppot this type: %{public}u", static_cast(*nativeType)); errCode = WMError::WM_ERROR_INVALID_PARAM; } } @@ -485,17 +486,17 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->SetWindowType(winType); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnSetWindowType success"); } else { - task.Reject(engine, CreateJsError(engine, - static_cast(ret), "JsWindow::OnSetWindowType failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window set type failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] set type end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -508,17 +509,16 @@ NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetWindowMode is called"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2 is max num of argc - WLOGFE("JsWindow windowToken_ is nullptr or params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } WindowMode winMode = WindowMode::WINDOW_MODE_FULLSCREEN; if (errCode == WMError::WM_OK) { NativeNumber* nativeMode = ConvertNativeValueTo(info.argv[0]); if (nativeMode == nullptr) { - WLOGFE("Failed to convert parameter to windowMode"); + WLOGFE("[NAPI]Failed to convert parameter to windowMode"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { if (static_cast(*nativeMode) >= static_cast(WindowMode::WINDOW_MODE_SPLIT_PRIMARY)) { @@ -528,7 +528,7 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& winMode = JS_TO_NATIVE_WINDOW_MODE_MAP.at( static_cast(static_cast(*nativeMode))); } else { - WLOGFE("Do not surppot this type"); + WLOGFE("[NAPI]Do not surppot this mode: %{public}u", static_cast(*nativeMode)); errCode = WMError::WM_ERROR_INVALID_PARAM; } } @@ -538,17 +538,18 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->SetWindowMode(winMode); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnSetWindowMode success"); } else { task.Reject(engine, - CreateJsError(engine, static_cast(ret), "JsWindow::OnSetWindowMode failed.")); + CreateJsError(engine, static_cast(ret), "Window set mode failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] set type end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc == 1) ? nullptr : @@ -561,28 +562,27 @@ NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnGetProperties is called"); WMError errCode = WMError::WM_OK; if (info.argc > 1) { - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } auto objValue = CreateJsWindowPropertiesObject(engine, windowToken_); - WLOGFI("JsWindow::OnGetProperties objValue %{public}p", objValue); if (objValue != nullptr) { task.Resolve(engine, objValue); - WLOGFI("JsWindow::OnGetProperties success"); } else { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetProperties failed.")); + static_cast(WMError::WM_ERROR_NULLPTR), "Window get properties failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] get properties end, objValue = %{public}p", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), objValue); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -594,68 +594,69 @@ NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& } NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info) - { - WLOGFI("JsWindow::OnRegisterWindowCallback is called"); if (windowToken_ == nullptr) { - WLOGFE("JsWindow windowToken_ is nullptr"); + WLOGFE("[NAPI]Window is nullptr"); return engine.CreateUndefined(); } if (info.argc != 2) { // 2: params num - WLOGFE("Params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); return engine.CreateUndefined(); } std::string cbType; if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { - WLOGFE("Failed to convert parameter to callbackType"); + WLOGFE("[NAPI]Failed to convert parameter to callbackType"); return engine.CreateUndefined(); } NativeValue* value = info.argv[1]; if (!value->IsCallable()) { - WLOGFI("JsWindow::OnRegisterWindowCallback info->argv[1] is not callable"); + WLOGFI("[NAPI]Callback(info->argv[1]) is not callable"); return engine.CreateUndefined(); } registerManager_->RegisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, engine, value); + WLOGFI("[NAPI]Register end, window [%{public}u, %{public}s], type = %{public}s, callback = %{public}p", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), cbType.c_str(), value); return engine.CreateUndefined(); } NativeValue* JsWindow::OnUnregisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnUnregisterWindowCallback is called"); if (windowToken_ == nullptr || info.argc < 1 || info.argc > 2) { // 2: maximum params nums - WLOGFE("JsWindow windowToken_ is nullptr or params not match"); + WLOGFE("[NAPI]Window is nullptr or argc is invalid: %{public}zu", info.argc); return engine.CreateUndefined(); } std::string cbType; if (!ConvertFromJsValue(engine, info.argv[0], cbType)) { - WLOGFE("Failed to convert parameter to callbackType"); + WLOGFE("[NAPI]Failed to convert parameter to callbackType"); return engine.CreateUndefined(); } + + NativeValue* value = nullptr; if (info.argc == 1) { - registerManager_->UnregisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, nullptr); + registerManager_->UnregisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, value); } else { - NativeValue* value = info.argv[1]; + value = info.argv[1]; if (!value->IsCallable()) { - WLOGFI("JsWindow::OnUnregisterWindowManagerCallback info->argv[1] is not callable"); + WLOGFI("[NAPI]Callback(info->argv[1]) is not callable"); return engine.CreateUndefined(); } registerManager_->UnregisterListener(windowToken_, cbType, CaseType::CASE_WINDOW, value); } - + WLOGFI("[NAPI]Unregister end, window [%{public}u, %{public}s], type = %{public}s, callback = %{public}p", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), cbType.c_str(), value); return engine.CreateUndefined(); } NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnLoadContent is called"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 3) { // 3 maximum param num - WLOGFE("JsWindow windowToken_ is nullptr or params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } std::string contextUrl; if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], contextUrl)) { - WLOGFE("Failed to convert parameter to context url"); + WLOGFE("[NAPI]Failed to convert parameter to context url"); errCode = WMError::WM_ERROR_INVALID_PARAM; } NativeValue* storage = nullptr; @@ -678,18 +679,18 @@ NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& i [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK || isOldApi_) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param or is old version API"); + WLOGFE("[NAPI]Window is nullptr or get invalid param or FA mode"); return; } NativeValue* nativeStorage = (contentStorage == nullptr) ? nullptr : contentStorage->Get(); Rosen::WMError ret = windowToken_->SetUIContent(contextUrl, &engine, nativeStorage, false); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnLoadContent success"); } else { - task.Reject(engine, - CreateJsError(engine, static_cast(ret), "JsWindow::OnLoadContent failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window load content failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] load content end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* result = nullptr; AsyncTask::Schedule( @@ -699,17 +700,16 @@ NativeValue* JsWindow::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& i NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetFullScreen is called"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2: maximum params num - WLOGFE("JsWindow param not match!"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } bool isFullScreen = false; if (errCode == WMError::WM_OK) { NativeBoolean* nativeVal = ConvertNativeValueTo(info.argv[0]); if (nativeVal == nullptr) { - WLOGFE("Failed to convert parameter to isFullScreen"); + WLOGFE("[NAPI]Failed to convert parameter to isFullScreen"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { isFullScreen = static_cast(*nativeVal); @@ -725,11 +725,11 @@ NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo& WMError ret = windowToken_->SetFullScreen(isFullScreen); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnSetFullScreen success"); } else { - task.Reject(engine, CreateJsError(engine, - static_cast(ret), "JsWindow::OnSetFullScreen failed.")); + task.Reject(engine, CreateJsError(engine, static_cast(ret), "Window SetFullScreen failed.")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] set full screen end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -742,17 +742,16 @@ NativeValue* JsWindow::OnSetFullScreen(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetLayoutFullScreen is called"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2: maximum params num - WLOGFE("JsWindow param not match!"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } bool isLayoutFullScreen = false; if (errCode == WMError::WM_OK) { NativeBoolean* nativeVal = ConvertNativeValueTo(info.argv[0]); if (nativeVal == nullptr) { - WLOGFE("Failed to convert parameter to isLayoutFullScreen"); + WLOGFE("[NAPI]Failed to convert parameter to isLayoutFullScreen"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { isLayoutFullScreen = static_cast(*nativeVal); @@ -767,11 +766,12 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac WMError ret = windowToken_->SetLayoutFullScreen(isLayoutFullScreen); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnSetLayoutFullScreen success"); } else { task.Reject(engine, CreateJsError(engine, - static_cast(ret), "JsWindow::OnSetLayoutFullScreen failed.")); + static_cast(ret), "Window OnSetLayoutFullScreen failed.")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] set layout full screen end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); @@ -783,10 +783,9 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetSystemBarEnable is called"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2 || windowToken_ == nullptr) { // 2: maximum params num - WLOGFE("JsWindow params not match or window token is nullptr!"); + WLOGFE("[NAPI]Window is nullptr or argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } std::map systemBarProperties; @@ -797,7 +796,7 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } WMError ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, @@ -806,11 +805,12 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnSetSystemBarEnable success"); } else { task.Reject(engine, CreateJsError(engine, - static_cast(ret), "JsWindow::OnSetSystemBarEnable failed.")); + static_cast(ret), "JsWindow::OnSetSystemBarEnable failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] set system bar enable end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -823,21 +823,20 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetSystemBarProperties is called"); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2: maximum params num - WLOGFE("JsWindow params not match!"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } std::map systemBarProperties; if (errCode == WMError::WM_OK) { NativeObject* nativeObj = ConvertNativeValueTo(info.argv[0]); if (nativeObj == nullptr) { - WLOGFE("Failed to convert object to SystemBarProperties"); + WLOGFE("[NAPI]Failed to convert object to SystemBarProperties"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { if (!SetSystemBarPropertiesFromJs(engine, nativeObj, systemBarProperties, windowToken_)) { - WLOGFE("Failed to GetSystemBarProperties From Js Object"); + WLOGFE("[NAPI]Failed to GetSystemBarProperties From Js Object"); errCode = WMError::WM_ERROR_INVALID_PARAM; } } @@ -846,7 +845,7 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); } WMError ret = windowToken_->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, systemBarProperties.at(WindowType::WINDOW_TYPE_STATUS_BAR)); @@ -854,11 +853,12 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall systemBarProperties.at(WindowType::WINDOW_TYPE_NAVIGATION_BAR)); if (ret == WMError::WM_OK) { task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindow::OnSetSystemBarProperties success"); } else { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnSetSystemBarProperties failed.")); + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnSetSystemBarProperties failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] set system bar properties end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -871,10 +871,9 @@ NativeValue* JsWindow::OnSetSystemBarProperties(NativeEngine& engine, NativeCall NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnGetAvoidArea is called info.argc: %{public}ld", (long)info.argc); WMError errCode = WMError::WM_OK; if (info.argc < 1 || info.argc > 2) { // 2: maximum params num - WLOGFE("JsWindow params not match!"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM; @@ -882,7 +881,7 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& // Parse info->argv[0] as AvoidAreaType NativeNumber* nativeMode = ConvertNativeValueTo(info.argv[0]); if (nativeMode == nullptr) { - WLOGFE("Failed to convert parameter to AvoidAreaType"); + WLOGFE("[NAPI]Failed to convert parameter to AvoidAreaType"); errCode = WMError::WM_ERROR_INVALID_PARAM; } else { avoidAreaType = static_cast(static_cast(*nativeMode)); @@ -892,29 +891,26 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } // getAvoidRect by avoidAreaType AvoidArea avoidArea; WMError ret = windowToken_->GetAvoidAreaByType(avoidAreaType, avoidArea); - if (ret == WMError::WM_OK) { - WLOGFI("JsWindow::OnGetAvoidArea GetAvoidAreaByType Success"); - } else { - WLOGFE("JsWindow::OnGetAvoidArea GetAvoidAreaByType Failed"); + if (ret != WMError::WM_OK) { avoidArea = { g_emptyRect, g_emptyRect, g_emptyRect, g_emptyRect }; // left, top, right, bottom } // native avoidArea -> js avoidArea NativeValue* avoidAreaObj = ChangeAvoidAreaToJsValue(engine, avoidArea); if (avoidAreaObj != nullptr) { - WLOGFI("JsWindow::OnGetAvoidArea ChangeAvoidAreaToJsValue Success"); task.Resolve(engine, avoidAreaObj); } else { task.Reject(engine, CreateJsError(engine, - static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetAvoidArea failed.")); + static_cast(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetAvoidArea failed")); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] get avoid area end, ret = %{public}d", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret); }; - WLOGFI("JsWindow::OnGetAvoidArea AsyncTask end"); NativeValue* lastParam = (info.argc <= 1) ? nullptr : (info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr); NativeValue* result = nullptr; @@ -925,21 +921,22 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnIsShowing is called"); WMError errCode = WMError::WM_OK; if (info.argc > 1) { - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } bool state = windowToken_->GetShowState(); task.Resolve(engine, CreateJsValue(engine, state)); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] get show state end, state = %{public}u", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), state); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -952,21 +949,22 @@ NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& inf NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnIsSupportWideGamut is called"); WMError errCode = WMError::WM_OK; if (info.argc > 1) { - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } bool flag = windowToken_->IsSupportWideGamut(); task.Resolve(engine, CreateJsValue(engine, flag)); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnIsSupportWideGamut end, ret = %{public}u", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), flag); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -979,7 +977,6 @@ NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallback NativeValue* JsWindow::OnSetBackgroundColor(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetBackgroundColor is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -995,7 +992,6 @@ NativeValue* JsWindow::OnSetBackgroundColor(NativeEngine& engine, NativeCallback NativeValue* JsWindow::OnSetBrightness(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetBrightness is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -1011,7 +1007,6 @@ NativeValue* JsWindow::OnSetBrightness(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetDimBehind(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetDimBehind is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -1027,7 +1022,6 @@ NativeValue* JsWindow::OnSetDimBehind(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetFocusable(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetFocusable is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -1043,7 +1037,6 @@ NativeValue* JsWindow::OnSetFocusable(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetKeepScreenOn is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -1059,7 +1052,6 @@ NativeValue* JsWindow::OnSetKeepScreenOn(NativeEngine& engine, NativeCallbackInf NativeValue* JsWindow::OnSetOutsideTouchable(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetOutsideTouchable is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -1075,7 +1067,6 @@ NativeValue* JsWindow::OnSetOutsideTouchable(NativeEngine& engine, NativeCallbac NativeValue* JsWindow::OnSetPrivacyMode(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetPrivacyMode is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -1091,7 +1082,6 @@ NativeValue* JsWindow::OnSetPrivacyMode(NativeEngine& engine, NativeCallbackInfo NativeValue* JsWindow::OnSetTouchable(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetTouchable is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); @@ -1107,25 +1097,21 @@ NativeValue* JsWindow::OnSetTouchable(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnSetColorSpace is called"); WMError errCode = WMError::WM_OK; ColorSpace colorSpace = ColorSpace::COLOR_SPACE_DEFAULT; if (info.argc < 1 || info.argc > 2) { // 2: maximum params num + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; - WLOGFE("JsWindow::OnSetColorSpace argc < 1"); } else { NativeNumber* nativeType = ConvertNativeValueTo(info.argv[0]); if (nativeType == nullptr) { errCode = WMError::WM_ERROR_INVALID_PARAM; - WLOGFE("JsWindow::OnSetColorSpace Failed to convert parameter to ColorSpace"); + WLOGFE("[NAPI]Failed to convert parameter to ColorSpace"); } else { colorSpace = static_cast(static_cast(*nativeType)); if (colorSpace > ColorSpace::COLOR_SPACE_WIDE_GAMUT) { - WLOGFE("JsWindow::OnSetColorSpace Failed, colorSpace %{public}u invalid!", - static_cast(colorSpace)); + WLOGFE("[NAPI]ColorSpace %{public}u invalid!", static_cast(colorSpace)); errCode = WMError::WM_ERROR_INVALID_PARAM; - } else { - WLOGFI("JsWindow::OnSetColorSpace %{public}u", static_cast(colorSpace)); } } } @@ -1133,13 +1119,14 @@ NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo& AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { - task.Reject(engine, CreateJsError(engine, static_cast(errCode), - "JsWindow::OnSetColorSpace failed.")); - WLOGFE("JsWindow windowToken_ is nullptr or args error"); + task.Reject(engine, CreateJsError(engine, static_cast(errCode), "OnSetColorSpace failed")); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } windowToken_->SetColorSpace(colorSpace); task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnSetColorSpace end, colorSpace = %{public}u", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), static_cast(colorSpace)); }; NativeValue* lastParam = (info.argc <= 1) ? nullptr : @@ -1152,21 +1139,22 @@ NativeValue* JsWindow::OnSetColorSpace(NativeEngine& engine, NativeCallbackInfo& NativeValue* JsWindow::OnGetColorSpace(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindow::OnGetColorSpace is called"); WMError errCode = WMError::WM_OK; if (info.argc > 1) { - WLOGFE("JsWindow params not match"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowToken_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindow windowToken_ is nullptr or invalid param"); + WLOGFE("[NAPI]window is nullptr or get invalid param"); return; } ColorSpace colorSpace = windowToken_->GetColorSpace(); task.Resolve(engine, CreateJsValue(engine, static_cast(colorSpace))); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnGetColorSpace end, colorSpace = %{public}u", + windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), static_cast(colorSpace)); }; NativeValue* lastParam = (info.argc == 0) ? nullptr : @@ -1179,9 +1167,10 @@ NativeValue* JsWindow::OnGetColorSpace(NativeEngine& engine, NativeCallbackInfo& std::shared_ptr FindJsWindowObject(std::string windowName) { - WLOGFI("JsWindow::FindJsWindowObject is called"); + WLOGFI("[NAPI]Try to find window %{public}s in g_jsWindowMap", windowName.c_str()); std::lock_guard lock(g_mutex); if (g_jsWindowMap.find(windowName) == g_jsWindowMap.end()) { + WLOGFI("[NAPI]Can not find window %{public}s in g_jsWindowMap", windowName.c_str()); return nullptr; } return g_jsWindowMap[windowName]; @@ -1189,18 +1178,18 @@ std::shared_ptr FindJsWindowObject(std::string windowName) NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window, bool isOldApi) { - WLOGFI("JsWindow::CreateJsWindow is called"); + WLOGFI("[NAPI]CreateJsWindowObject"); std::string windowName = window->GetWindowName(); // avoid repeatedly create js window when getWindow std::shared_ptr jsWindowObj = FindJsWindowObject(windowName); if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) { - WLOGFI("JsWindow::CreateJsWindow FindJsWindowObject %{public}s", windowName.c_str()); + WLOGFI("[NAPI]FindJsWindowObject %{public}s", windowName.c_str()); return jsWindowObj->Get(); } NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); - WLOGFI("JsWindow::CreateJsWindow isOldApi %{public}d", isOldApi); + WLOGFI("[NAPI]CreateJsWindow %{public}s, FA mode: %{public}u", windowName.c_str(), isOldApi); std::unique_ptr jsWindow = std::make_unique(window, isOldApi); object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr); @@ -1239,4 +1228,4 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr& window, bo return objValue; } } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp index a47addf8..c824c8ca 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_listener.cpp @@ -26,14 +26,14 @@ constexpr uint32_t AVOID_AREA_NUM = 4; void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc) { - WLOGFI("CallJsMethod methodName = %{public}s", methodName); + WLOGFI("[NAPI]CallJsMethod methodName = %{public}s", methodName); if (engine_ == nullptr || jsCallBack_ == nullptr) { - WLOGFE("engine_ nullptr or jsCallBack_ is nullptr"); + WLOGFE("[NAPI]engine_ nullptr or jsCallBack_ is nullptr"); return; } NativeValue* method = jsCallBack_->Get(); if (method == nullptr) { - WLOGFE("Failed to get method callback from object"); + WLOGFE("[NAPI]Failed to get method callback from object"); return; } engine_->CallFunction(engine_->CreateUndefined(), method, argv, argc); @@ -41,7 +41,7 @@ void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const* void JsWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason reason) { - WLOGFI("JsWindowListener::OnSizeChange is called"); + WLOGFI("[NAPI]OnSizeChange, wh[%{public}u, %{public}u], reason = %{public}u", rect.width_, rect.height_, reason); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( [this, rect] (NativeEngine &engine, AsyncTask &task, int32_t status) { @@ -65,19 +65,19 @@ void JsWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason reason) void JsWindowListener::OnModeChange(WindowMode mode) { - WLOGFI("JsWindowListener::OnModeChange is called"); + WLOGFI("[NAPI]OnModeChange %{public}u", mode); } void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) { - WLOGFI("JsWindowListener::OnSystemBarPropertyChange is called"); + WLOGFI("[NAPI]OnSystemBarPropertyChange"); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( [this, displayId, tints] (NativeEngine &engine, AsyncTask &task, int32_t status) { NativeValue* propertyValue = engine_->CreateObject(); NativeObject* object = ConvertNativeValueTo(propertyValue); if (object == nullptr) { - WLOGFE("Failed to convert prop to jsObject"); + WLOGFE("[NAPI]Failed to convert prop to jsObject"); return; } object->SetProperty("displayId", CreateJsValue(*engine_, static_cast(displayId))); @@ -94,19 +94,19 @@ void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const Syst void JsWindowListener::OnAvoidAreaChanged(const std::vector avoidAreas) { - WLOGFI("JsWindowListener::OnAvoidAreaChanged is called"); + WLOGFI("[NAPI]OnAvoidAreaChanged"); // js callback should run in js thread std::unique_ptr complete = std::make_unique ( [this, avoidAreas] (NativeEngine &engine, AsyncTask &task, int32_t status) { NativeValue* avoidAreaValue = engine_->CreateObject(); NativeObject* object = ConvertNativeValueTo(avoidAreaValue); if (object == nullptr) { - WLOGFE("JsWindowListener::OnAvoidAreaChanged Failed to convert rect to jsObject"); + WLOGFE("[NAPI]Failed to convert rect to jsObject"); return; } if (static_cast(avoidAreas.size()) != AVOID_AREA_NUM) { - WLOGFE("AvoidAreas size is not 4 (left, top, right, bottom). Current avoidAreas size is %{public}u", + WLOGFE("[NAPI]AvoidAreas size is not 4 (left, top, right, bottom), size is %{public}u", static_cast(avoidAreas.size())); return; } @@ -127,7 +127,7 @@ void JsWindowListener::OnAvoidAreaChanged(const std::vector avoidAreas) void JsWindowListener::LifeCycleCallBack(LifeCycleEventType eventType) { - WLOGFI("JsWindowListener::LifeCycleCallBack is called, type: %{public}d", eventType); + WLOGFI("[NAPI]LifeCycleCallBack, envent type: %{public}u", eventType); std::unique_ptr complete = std::make_unique( [=] (NativeEngine &engine, AsyncTask &task, int32_t status) { NativeValue* argv[] = {CreateJsValue(*engine_, static_cast(eventType))}; @@ -159,4 +159,4 @@ void JsWindowListener::AfterUnfocused() LifeCycleCallBack(LifeCycleEventType::INACTIVE); } } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp index 5b3d5575..c53c2286 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_register_manager.cpp @@ -48,7 +48,7 @@ bool JsWindowRegisterManager::ProcessWindowChangeRegister(sptr sptr window, bool isRegister) { if (window == nullptr) { - WLOGFE("window is nullptr"); + WLOGFE("[NAPI]Window is nullptr"); return false; } sptr thisListener(listener); @@ -64,7 +64,7 @@ bool JsWindowRegisterManager::ProcessAvoidAreaChangeRegister(sptr window, bool isRegister) { if (window == nullptr) { - WLOGFE("window is nullptr"); + WLOGFE("[NAPI]Window is nullptr"); return false; } sptr thisListener(listener); @@ -80,7 +80,7 @@ bool JsWindowRegisterManager::ProcessLifeCycleEventRegister(sptr window, bool isRegister) { if (window == nullptr) { - WLOGFE("window is nullptr"); + WLOGFE("[NAPI]Window is nullptr"); return false; } sptr thisListener(listener); @@ -107,13 +107,13 @@ bool JsWindowRegisterManager::ProcessSystemBarChangeRegister(sptrStrictEquals(iter->first->Get())) { - WLOGFE("JsWindowRegisterManager::IsCallbackRegistered %{public}s already registered!", type.c_str()); + WLOGFE("[NAPI]Method %{public}s has already been registered", type.c_str()); return true; } } @@ -128,23 +128,23 @@ void JsWindowRegisterManager::RegisterListener(sptr window, std::string return; } if (listenerProcess_[caseType].count(type) == 0) { - WLOGFE("JsWindowRegisterManager not support method: %{public}s!", type.c_str()); + WLOGFE("[NAPI]Type %{public}s is not supported", type.c_str()); return; } std::shared_ptr callbackRef; callbackRef.reset(engine.CreateReference(value, 1)); sptr windowManagerListener = new(std::nothrow) JsWindowListener(&engine, callbackRef); if (windowManagerListener == nullptr) { - WLOGFE("JsWindowRegisterManager::RegisterListener malloc failed"); + WLOGFE("[NAPI]New JsWindowListener failed"); return; } if (!((this->*listenerProcess_[caseType][type])(windowManagerListener, window, true))) { - WLOGFE("JsWindowRegisterManager::RegisterListener %{public}s failed!", type.c_str()); + WLOGFE("[NAPI]Register type %{public}s failed", type.c_str()); return; } jsCbMap_[type][callbackRef] = windowManagerListener; - WLOGFI("JsWindowRegisterManager::RegisterListener %{public}s success! callback map size: %{public}lu", - type.c_str(), (unsigned long)jsCbMap_[type].size()); + WLOGFI("[NAPI]Register type %{public}s success! callback map size: %{public}zu", + type.c_str(), jsCbMap_[type].size()); } void JsWindowRegisterManager::UnregisterListener(sptr window, std::string type, @@ -152,18 +152,17 @@ void JsWindowRegisterManager::UnregisterListener(sptr window, std::strin { std::lock_guard lock(mtx_); if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) { - WLOGFI("JsWindowRegisterManager::UnregisterListener methodName %{public}s not registerted!", - type.c_str()); + WLOGFE("[NAPI]Type %{public}s was not registerted", type.c_str()); return; } if (listenerProcess_[caseType].count(type) == 0) { - WLOGFE("JsWindowRegisterManager not support method: %{public}s!", type.c_str()); + WLOGFE("[NAPI]Type %{public}s is not supported", type.c_str()); return; } if (value == nullptr) { for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) { if (!((this->*listenerProcess_[caseType][type])(it->second, window, false))) { - WLOGFE("JsWindowRegisterManager::UnregisterListener %{public}s failed!", type.c_str()); + WLOGFE("[NAPI]Unregister type %{public}s failed, no value", type.c_str()); return; } jsCbMap_[type].erase(it++); @@ -176,24 +175,23 @@ void JsWindowRegisterManager::UnregisterListener(sptr window, std::strin } findFlag = true; if (!(this->*listenerProcess_[caseType][type])(it->second, window, false)) { - WLOGFE("JsWindowRegisterManager::UnregisterListener %{public}s failed!", type.c_str()); + WLOGFE("[NAPI]Unregister type %{public}s failed", type.c_str()); return; } jsCbMap_[type].erase(it); break; } if (!findFlag) { - WLOGFE("JsWindowRegisterManager::UnregisterListener %{public}s failed because not found callback!", - type.c_str()); + WLOGFE("[NAPI]Unregister type %{public}s failed because not found callback!", type.c_str()); return; } } - WLOGFI("JsWindowRegisterManager::UnregisterListener %{public}s success! callback map size: %{public}lu", - type.c_str(), (unsigned long)jsCbMap_[type].size()); + WLOGFI("[NAPI]Unregister type %{public}s success! callback map size: %{public}zu", + type.c_str(), jsCbMap_[type].size()); // erase type when there is no callback in one type if (jsCbMap_[type].empty()) { jsCbMap_.erase(type); } } } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp index e17647ca..cd315bf3 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window_utils.cpp @@ -30,18 +30,17 @@ namespace { NativeValue* WindowTypeInit(NativeEngine* engine) { - WLOGFI("WindowTypeInit"); + WLOGFI("[NAPI]WindowTypeInit"); if (engine == nullptr) { - WLOGFE("Invalid input parameters"); + WLOGFE("[NAPI]Engine is nullptr"); return nullptr; } NativeValue *objValue = engine->CreateObject(); NativeObject *object = ConvertNativeValueTo(objValue); - if (object == nullptr) { - WLOGFE("Failed to get object"); + WLOGFE("[NAPI]Failed to get object"); return nullptr; } @@ -68,18 +67,17 @@ NativeValue* WindowTypeInit(NativeEngine* engine) NativeValue* AvoidAreaTypeInit(NativeEngine* engine) { - WLOGFI("AvoidAreaTypeInit"); + WLOGFI("[NAPI]AvoidAreaTypeInit"); if (engine == nullptr) { - WLOGFE("Invalid input parameters"); + WLOGFE("[NAPI]Engine is nullptr"); return nullptr; } NativeValue *objValue = engine->CreateObject(); NativeObject *object = ConvertNativeValueTo(objValue); - if (object == nullptr) { - WLOGFE("Failed to get object"); + WLOGFE("[NAPI]Failed to get object"); return nullptr; } @@ -92,18 +90,17 @@ NativeValue* AvoidAreaTypeInit(NativeEngine* engine) NativeValue* WindowModeInit(NativeEngine* engine) { - WLOGFI("WindowModeInit"); + WLOGFI("[NAPI]WindowModeInit"); if (engine == nullptr) { - WLOGFE("Invalid input parameters"); + WLOGFE("[NAPI]Engine is nullptr"); return nullptr; } NativeValue *objValue = engine->CreateObject(); NativeObject *object = ConvertNativeValueTo(objValue); - if (object == nullptr) { - WLOGFE("Failed to get object"); + WLOGFE("[NAPI]Failed to get object"); return nullptr; } @@ -122,18 +119,17 @@ NativeValue* WindowModeInit(NativeEngine* engine) NativeValue* ColorSpaceInit(NativeEngine* engine) { - WLOGFI("ColorSpaceInit"); + WLOGFI("[NAPI]ColorSpaceInit"); if (engine == nullptr) { - WLOGFE("Invalid input parameters"); + WLOGFE("[NAPI]Engine is nullptr"); return nullptr; } NativeValue *objValue = engine->CreateObject(); NativeObject *object = ConvertNativeValueTo(objValue); - if (object == nullptr) { - WLOGFE("Failed to get object"); + WLOGFE("[NAPI]Failed to get object"); return nullptr; } @@ -146,18 +142,17 @@ NativeValue* ColorSpaceInit(NativeEngine* engine) NativeValue* WindowStageEventTypeInit(NativeEngine* engine) { - WLOGFI("WindowStageEventTypeInit"); + WLOGFI("[NAPI]WindowStageEventTypeInit"); if (engine == nullptr) { - WLOGFE("Invalid input parameters"); + WLOGFE("[NAPI]Engine is nullptr"); return nullptr; } NativeValue *objValue = engine->CreateObject(); NativeObject *object = ConvertNativeValueTo(objValue); - if (object == nullptr) { - WLOGFE("Failed to get object"); + WLOGFE("[NAPI]Failed to get object"); return nullptr; } @@ -177,7 +172,7 @@ NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect) NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); if (object == nullptr) { - WLOGFE("Failed to convert rect to jsObject"); + WLOGFE("[NAPI]Failed to convert rect to jsObject"); return nullptr; } object->SetProperty("left", CreateJsValue(engine, rect.posX_)); @@ -189,18 +184,18 @@ NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect) NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr& window) { - WLOGFI("JsWindowUtils::CreateJsWindowPropertiesObject is called"); + WLOGFI("[NAPI]CreateJsWindowPropertiesObject"); NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); if (object == nullptr) { - WLOGFE("Failed to convert windowProperties to jsObject"); + WLOGFE("[NAPI]Failed to convert windowProperties to jsObject"); return nullptr; } Rect rect = window->GetRect(); NativeValue* rectObj = GetRectAndConvertToJsValue(engine, rect); if (rectObj == nullptr) { - WLOGFE("GetRect failed!"); + WLOGFE("[NAPI]GetRect failed!"); } object->SetProperty("windowRect", rectObj); WindowType type = window->GetType(); @@ -232,39 +227,37 @@ static std::string GetHexColor(uint32_t color) static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, const SystemBarRegionTint& tint) { - WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject is called"); - NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); if (object == nullptr) { - WLOGFE("Failed to convert SystemBarProperty to jsObject"); + WLOGFE("[NAPI]Failed to convert SystemBarProperty to jsObject"); return nullptr; } object->SetProperty("type", CreateJsValue(engine, static_cast(tint.type_))); object->SetProperty("isEnable", CreateJsValue(engine, tint.prop_.enable_)); std::string bkgColor = GetHexColor(tint.prop_.backgroundColor_); - WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject backgroundColir: %{public}s", bkgColor.c_str()); object->SetProperty("backgroundColor", CreateJsValue(engine, bkgColor)); std::string contentColor = GetHexColor(tint.prop_.contentColor_); - WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject contentColor: %{public}s", contentColor.c_str()); object->SetProperty("contentColor", CreateJsValue(engine, contentColor)); Rect rect = tint.region_; object->SetProperty("region", GetRectAndConvertToJsValue(engine, rect)); - WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject rect: [%{public}d %{public}d %{public}d %{public}d]", + + WLOGFI("[NAPI]Type %{public}u [%{public}u %{public}s %{public}s] [%{public}d %{public}d %{public}u %{public}u]", + tint.type_, tint.prop_.enable_, bkgColor.c_str(), contentColor.c_str(), rect.posX_, rect.posY_, rect.width_, rect.height_); return objValue; } NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, const SystemBarRegionTints& tints) { - WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintArrayObject is called"); if (tints.empty()) { + WLOGFE("[NAPI]Empty tints"); return nullptr; } NativeValue* objValue = engine.CreateArray(tints.size()); NativeArray* array = ConvertNativeValueTo(objValue); if (array == nullptr) { - WLOGFE("Failed to convert SystemBarPropertys to jsArrayObject"); + WLOGFE("[NAPI]Failed to convert SystemBarPropertys to jsArrayObject"); return nullptr; } uint32_t index = 0; @@ -279,7 +272,7 @@ bool GetSystemBarStatus(std::map& systemBarProper { NativeArray* nativeArray = ConvertNativeValueTo(info.argv[0]); if (nativeArray == nullptr) { - WLOGFE("Failed to convert parameter to SystemBarArray"); + WLOGFE("[NAPI]Failed to convert parameter to SystemBarArray"); return false; } uint32_t size = nativeArray->GetLength(); @@ -292,7 +285,7 @@ bool GetSystemBarStatus(std::map& systemBarProper for (uint32_t i = 0; i < size; i++) { std::string name; if (!ConvertFromJsValue(engine, nativeArray->GetElement(i), name)) { - WLOGFE("Failed to convert parameter to SystemBarName"); + WLOGFE("[NAPI]Failed to convert parameter to SystemBarName"); return false; } if (name.compare("status") == 0) { @@ -311,12 +304,12 @@ static uint32_t GetColorFromJs(NativeEngine& engine, NativeObject* jsObject, if (jsColor->TypeOf() != NATIVE_UNDEFINED) { std::string colorStr; if (!ConvertFromJsValue(engine, jsColor, colorStr)) { - WLOGFE("Failed to convert parameter to color"); + WLOGFE("[NAPI]Failed to convert parameter to color"); return defaultColor; } std::regex pattern("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$"); if (!std::regex_match(colorStr, pattern)) { - WLOGFE("invalid color input"); + WLOGFE("[NAPI]Invalid color input"); return defaultColor; } WLOGFI("origin color: %{public}s", colorStr.c_str()); @@ -328,7 +321,8 @@ static uint32_t GetColorFromJs(NativeEngine& engine, NativeObject* jsObject, uint32_t hexColor; ss << std::hex << color; ss >> hexColor; - WLOGFI("color: %{public}s, Final Color is %{public}x", color.c_str(), hexColor); + WLOGFI("[NAPI]Origin %{public}s, process %{public}s, final %{public}x", + colorStr.c_str(), color.c_str(), hexColor); return hexColor; } return defaultColor; @@ -353,7 +347,7 @@ bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, } else if (jsStatusIcon->TypeOf() != NATIVE_UNDEFINED) { bool isStatusBarLightIcon; if (!ConvertFromJsValue(engine, jsStatusIcon, isStatusBarLightIcon)) { - WLOGFE("Failed to convert parameter to isStatusBarLightIcon"); + WLOGFE("[NAPI]Failed to convert parameter to isStatusBarLightIcon"); return false; } if (isStatusBarLightIcon) { @@ -370,7 +364,7 @@ bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject, } else if (jsNavigationIcon->TypeOf() != NATIVE_UNDEFINED) { bool isNavigationBarLightIcon; if (!ConvertFromJsValue(engine, jsNavigationIcon, isNavigationBarLightIcon)) { - WLOGFE("Failed to convert parameter to isNavigationBarLightIcon"); + WLOGFE("[NAPI]Failed to convert parameter to isNavigationBarLightIcon"); return false; } if (isNavigationBarLightIcon) { @@ -387,7 +381,7 @@ NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avo NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue); if (object == nullptr) { - WLOGFE("Failed to convert rect to jsObject"); + WLOGFE("[NAPI]Failed to convert rect to jsObject"); return engine.CreateUndefined(); } object->SetProperty("leftRect", GetRectAndConvertToJsValue(engine, avoidArea.leftRect)); @@ -399,15 +393,14 @@ NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avo bool CheckCallingPermission(std::string permission) { - WLOGFI("JsWindowUtils::CheckCallingPermission, permission:%{public}s", permission.c_str()); + WLOGFI("[NAPI]Permission: %{public}s", permission.c_str()); if (!permission.empty() && Security::AccessToken::AccessTokenKit::VerifyAccessToken(IPCSkeleton::GetCallingTokenID(), permission) != AppExecFwk::Constants::PERMISSION_GRANTED) { - WLOGFE("%{public}s permission not granted.", permission.c_str()); + WLOGFE("[NAPI]Permission %{public}s is not granted", permission.c_str()); return false; } - WLOGFI("JsWindowUtils::CheckCallingPermission end."); return true; } } // namespace Rosen -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp index 5d6325cb..02a3f808 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp @@ -39,116 +39,112 @@ JsWindowStage::~JsWindowStage() } void JsWindowStage::Finalizer(NativeEngine* engine, void* data, void* hint) { - WLOGFI("JsWindowStage::Finalizer is called"); + WLOGFI("[NAPI]Finalizer"); std::unique_ptr(static_cast(data)); } NativeValue* JsWindowStage::SetUIContent(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::SetUIContent is called"); + WLOGFI("[NAPI]SetUIContent"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetUIContent(*engine, *info) : nullptr; } NativeValue* JsWindowStage::GetMainWindow(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::GetMainWindow is called"); + WLOGFI("[NAPI]GetMainWindow"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnGetMainWindow(*engine, *info) : nullptr; } NativeValue* JsWindowStage::On(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::On is called"); + WLOGFI("[NAPI]On"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnEvent(*engine, *info) : nullptr; } NativeValue* JsWindowStage::Off(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::Off is called"); + WLOGFI("[NAPI]Off"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OffEvent(*engine, *info) : nullptr; } NativeValue* JsWindowStage::LoadContent(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::LoadContent is called"); + WLOGFI("[NAPI]LoadContent"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnLoadContent(*engine, *info) : nullptr; } NativeValue* JsWindowStage::GetWindowMode(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::GetWindowMode is called"); + WLOGFI("[NAPI]GetWindowMode"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnGetWindowMode(*engine, *info) : nullptr; } NativeValue* JsWindowStage::CreateSubWindow(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::CreateSubWindow is called"); + WLOGFI("[NAPI]CreateSubWindow"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnCreateSubWindow(*engine, *info) : nullptr; } NativeValue* JsWindowStage::GetSubWindow(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsWindowStage::GetSubWindow is called"); + WLOGFI("[NAPI]GetSubWindow"); JsWindowStage* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnGetSubWindow(*engine, *info) : nullptr; } NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OnSetUIContent is called"); if (info.argc < 2) { // 2: minimum param num - WLOGFE("JsWindowStage::OnSetUIContent Not enough params"); + WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc); return engine.CreateUndefined(); } if (windowScene_ == nullptr || windowScene_->GetMainWindow() == nullptr) { - WLOGFE("JsWindowStage::OnSetUIContent windowScene_ or MainWindow is nullptr"); + WLOGFE("[NAPI]WindowScene is null or window is null"); return engine.CreateUndefined(); } // Parse info->argv[0] as abilitycontext auto objContext = ConvertNativeValueTo(info.argv[0]); if (objContext == nullptr) { - WLOGFE("JsWindowStage::OnSetUIContent info->argv[0] InValid"); + WLOGFE("[NAPI]Context is nullptr"); return engine.CreateUndefined(); } // Parse info->argv[1] as url std::string contextUrl; if (!ConvertFromJsValue(engine, info.argv[1], contextUrl)) { - WLOGFE("JsWindowStage::OnSetUIContent failed to convert parameter to url"); + WLOGFE("[NAPI]Failed to convert parameter to url"); return engine.CreateUndefined(); } - WLOGFI("JsWindowStage::OnSetUIContent Get url"); - windowScene_->GetMainWindow()->SetUIContent(contextUrl, &engine, info.argv[CONTENT_STORAGE_ARG]); - return engine.CreateUndefined(); } NativeValue* JsWindowStage::OnGetMainWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OnGetMainWindow is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowScene_ == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); - WLOGFE("JsWindowStage windowScene_ is nullptr!"); + WLOGFE("[NAPI]WindowScene_ is nullptr!"); return; } auto window = windowScene_->GetMainWindow(); if (window != nullptr) { task.Resolve(engine, OHOS::Rosen::CreateJsWindowObject(engine, window, false)); - WLOGFI("JsWindowStage::OnGetMainWindow success"); + WLOGFI("[NAPI]Get main window [%{public}u, %{public}s]", + window->GetWindowId(), window->GetWindowName().c_str()); } else { task.Reject(engine, CreateJsError(engine, static_cast(Rosen::WMError::WM_ERROR_NULLPTR), - "JsWindowStage::OnGetMainWindow failed.")); + "Get main window failed.")); } }; NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr; @@ -160,76 +156,77 @@ NativeValue* JsWindowStage::OnGetMainWindow(NativeEngine& engine, NativeCallback NativeValue* JsWindowStage::OnEvent(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OnEvent is called"); if (windowScene_ == nullptr || info.argc < 2) { // 2: minimum param nums - WLOGFE("JsWindowStage::OnEvent windowScene_ is nullptr or params not match"); + WLOGFE("[NAPI]Window scene is null or argc is invalid: %{public}zu", info.argc); return engine.CreateUndefined(); } // Parse info->argv[0] as string std::string eventString; if (!ConvertFromJsValue(engine, info.argv[0], eventString)) { - WLOGFE("JsWindowStage::OnEvent info->argv[0] Failed to convert parameter to string"); + WLOGFE("[NAPI]Failed to convert parameter to string"); return engine.CreateUndefined(); } NativeValue* value = info.argv[1]; if (!value->IsCallable()) { - WLOGFE("JsWindowStage::OnEvent info->argv[1] is not callable"); + WLOGFE("[NAPI]Callback(info->argv[1]) is not callable"); return engine.CreateUndefined(); } auto window = windowScene_->GetMainWindow(); if (window == nullptr) { - WLOGFE("JsWindowStage::OnEvent GetMainWindow failed"); + WLOGFE("[NAPI]Get window failed"); return engine.CreateUndefined(); } g_listenerManager->RegisterListener(window, eventString, CaseType::CASE_STAGE, engine, value); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] register event %{public}s, callback %{public}p", + window->GetWindowId(), window->GetWindowName().c_str(), eventString.c_str(), value); + return engine.CreateUndefined(); } NativeValue* JsWindowStage::OffEvent(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OffEvent is called"); if (windowScene_ == nullptr) { - WLOGFE("JsWindowStage::OffEvent windowScene_ is nullptr"); + WLOGFE("[NAPI]Window scene is null"); return engine.CreateUndefined(); } // Parse info->argv[0] as string std::string eventString; if (!ConvertFromJsValue(engine, info.argv[0], eventString)) { - WLOGFE("JsWindowStage::OffEvent info->argv[0] Failed to convert parameter to string"); + WLOGFE("[NAPI]Failed to convert parameter to string"); return engine.CreateUndefined(); } if (eventString.compare("windowStageEvent") != 0) { - WLOGFE("JsWindowStage::OffEvent info->argv[0] is InValid"); + WLOGFE("[NAPI]Envent %{public}s is invalid", eventString.c_str()); return engine.CreateUndefined(); } NativeValue* value = info.argv[1]; auto window = windowScene_->GetMainWindow(); if (window == nullptr) { - WLOGFE("JsWindowStage::OnEvent GetMainWindow failed"); + WLOGFE("[NAPI]Get window failed"); return engine.CreateUndefined(); } if (value->TypeOf() == NATIVE_FUNCTION) { - WLOGFI("JsWindowStage::OffEvent info->argv[1] is callable type"); g_listenerManager->UnregisterListener(window, eventString, CaseType::CASE_STAGE, value); } else if (value->TypeOf() == NativeValueType::NATIVE_UNDEFINED) { - WLOGFI("JsWindowStage::OffEvent info->argv[1] is native undefined type"); g_listenerManager->UnregisterListener(window, eventString, CaseType::CASE_STAGE, nullptr); } else { - WLOGFE("JsWindowStage::OffEvent info->argv[1] is InValid param"); + WLOGFE("[NAPI]Callback(info->argv[1]) is invalid"); } + WLOGFI("[NAPI]Window [%{public}u, %{public}s] unregister event %{public}s, callback %{public}p", + window->GetWindowId(), window->GetWindowName().c_str(), eventString.c_str(), value); + return engine.CreateUndefined(); } NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OnLoadContent is called"); WMError errCode = WMError::WM_OK; std::string contextUrl; if (!ConvertFromJsValue(engine, info.argv[0], contextUrl)) { - WLOGFE("Failed to convert parameter to context url"); + WLOGFE("[NAPI]Failed to convert parameter to context url"); errCode = WMError::WM_ERROR_INVALID_PARAM; } NativeValue* storage = nullptr; @@ -250,12 +247,13 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowScene_ == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); - WLOGFE("JsWindowStage windowScene_ is nullptr!"); + WLOGFE("[NAPI]windowScene_ is nullptr"); return; } auto win = windowScene_->GetMainWindow(); if (win == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); + WLOGFE("[NAPI]Get window failed"); return; } NativeValue* nativeStorage = (contentStorage == nullptr) ? nullptr : contentStorage->Get(); @@ -265,7 +263,8 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn return; } task.Resolve(engine, engine.CreateUndefined()); - WLOGFI("JsWindowStage::OnLoadContent success"); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] load content %{public}s, storage %{public}p", + win->GetWindowId(), win->GetWindowName().c_str(), contextUrl.c_str(), nativeStorage); }; NativeValue* result = nullptr; AsyncTask::Schedule( @@ -275,28 +274,29 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn NativeValue* JsWindowStage::OnGetWindowMode(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OnGetWindowMode is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowScene_ == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); - WLOGFE("JsWindowStage windowScene_ is nullptr!"); + WLOGFE("[NAPI]windowScene_ is nullptr"); return; } auto window = windowScene_->GetMainWindow(); if (window == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(Rosen::WMError::WM_ERROR_NULLPTR), - "JsWindowStage::OnGetWindowMode failed.")); - WLOGFE("JsWindowStage window is nullptr"); + "Get window failed")); + WLOGFE("[NAPI]Get window failed"); return; } Rosen::WindowMode mode = window->GetMode(); if (NATIVE_TO_JS_WINDOW_MODE_MAP.count(mode) != 0) { task.Resolve(engine, CreateJsValue(engine, NATIVE_TO_JS_WINDOW_MODE_MAP.at(mode))); - WLOGFI("JsWindowStage OnGetWindowMode success"); + WLOGFI("[NAPI]Window [%{public}u, %{public}s] get mode %{public}u, api mode %{public}u", + window->GetWindowId(), window->GetWindowName().c_str(), + mode, NATIVE_TO_JS_WINDOW_MODE_MAP.at(mode)); } else { task.Resolve(engine, CreateJsValue(engine, mode)); - WLOGFI("JsWindowStage OnGetWindowMode success, but not in apimode"); + WLOGFE("[NAPI]Get mode %{public}u, but not in apimode", mode); } }; NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr; @@ -308,18 +308,17 @@ NativeValue* JsWindowStage::OnGetWindowMode(NativeEngine& engine, NativeCallback NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OnCreateSubWindow is called"); WMError errCode = WMError::WM_OK; std::string windowName; if (!ConvertFromJsValue(engine, info.argv[0], windowName)) { - WLOGFE("Failed to convert parameter to windowName"); + WLOGFE("[NAPI]Failed to convert parameter to windowName"); errCode = WMError::WM_ERROR_INVALID_PARAM; } AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowScene_ == nullptr || errCode != WMError::WM_OK) { task.Reject(engine, CreateJsError(engine, static_cast(errCode))); - WLOGFE("JsWindowStage windowScene_ is nullptr or invaliad params!"); + WLOGFE("[NAPI]Window scene is null or get invalid param"); return; } sptr windowOption = new Rosen::WindowOption(); @@ -328,12 +327,12 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba auto window = windowScene_->CreateWindow(windowName, windowOption); if (window == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(Rosen::WMError::WM_ERROR_NULLPTR), - "JsWindowStage::OnCreateSubWindow failed.")); - WLOGFE("JsWindowStage window is nullptr"); + "Get window failed")); + WLOGFE("[NAPI]Get window failed"); return; } task.Resolve(engine, CreateJsWindowObject(engine, window, false)); - WLOGFI("JsWindowStage OnCreateSubWindow success"); + WLOGFI("[NAPI]Create sub widdow %{public}s end", windowName.c_str()); }; NativeValue* callback = (info.argv[1]->TypeOf() == NATIVE_FUNCTION) ? info.argv[1] : nullptr; NativeValue* result = nullptr; @@ -345,11 +344,10 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba NativeValue* JsWindowStage::CreateJsSubWindowArrayObject(NativeEngine& engine, std::vector> subWinVec) { - WLOGFI("JsWindowUtils::CreateJsSubWindowArrayObject is called"); NativeValue* objValue = engine.CreateArray(subWinVec.size()); NativeArray* array = ConvertNativeValueTo(objValue); if (array == nullptr) { - WLOGFE("Failed to convert subWinVec to jsArrayObject"); + WLOGFE("[NAPI]Failed to convert subWinVec to jsArrayObject"); return nullptr; } uint32_t index = 0; @@ -361,17 +359,16 @@ NativeValue* JsWindowStage::CreateJsSubWindowArrayObject(NativeEngine& engine, NativeValue* JsWindowStage::OnGetSubWindow(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsWindowStage::OnGetSubWindow is called"); AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (windowScene_ == nullptr) { task.Reject(engine, CreateJsError(engine, static_cast(WMError::WM_ERROR_NULLPTR))); - WLOGFE("JsWindowStage windowScene_ is nullptr!"); + WLOGFE("[NAPI]Window scene is nullptr"); return; } std::vector> subWindowVec = windowScene_->GetSubWindow(); task.Resolve(engine, CreateJsSubWindowArrayObject(engine, subWindowVec)); - WLOGFI("JsWindowStage OnGetSubWindow success"); + WLOGFI("[NAPI]Get sub windows, size = %{public}zu", subWindowVec.size()); }; NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr; NativeValue* result = nullptr; @@ -383,7 +380,7 @@ NativeValue* JsWindowStage::OnGetSubWindow(NativeEngine& engine, NativeCallbackI NativeValue* CreateJsWindowStage(NativeEngine& engine, std::shared_ptr windowScene) { - WLOGFI("JsWindowStage::CreateJsWindowStage is called"); + WLOGFI("[NAPI]CreateJsWindowStage"); NativeValue* objValue = engine.CreateObject(); NativeObject* object = ConvertNativeValueTo(objValue);