Add function dump for window

Signed-off-by: maojiangping <maojiangping@huawei.com>
Change-Id: I188d60ab6cd6792e93cc97f416bfd2b44a9948ba
Signed-off-by: maojiangping <maojiangping@huawei.com>
This commit is contained in:
maojiangping
2022-04-25 21:50:11 +08:00
parent a3413e3f9d
commit fac8f167df
5 changed files with 62 additions and 1 deletions
@@ -910,6 +910,15 @@ declare namespace window {
* @since 9
*/
disableWindowDecor(): void;
/**
* Dump window client information.
* Called in the dump callback of ability is the typical usage scenario.
* @since 9
* @param params Indicates the params from command.
* @return The dump info array.
*/
dump(params: Array<string>): Array<string>;
}
enum WindowStageEventType {
@@ -15,6 +15,7 @@
#include "js_window.h"
#include <new>
#include "js_window_utils.h"
#include "window.h"
#include "window_manager_hilog.h"
#include "window_option.h"
@@ -291,6 +292,13 @@ NativeValue* JsWindow::GetColorSpace(NativeEngine* engine, NativeCallbackInfo* i
return (me != nullptr) ? me->OnGetColorSpace(*engine, *info) : nullptr;
}
NativeValue* JsWindow::Dump(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("[NAPI]Dump");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnDump(*engine, *info) : nullptr;
}
NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info)
{
WMError errCode = WMError::WM_OK;
@@ -1438,6 +1446,30 @@ NativeValue* JsWindow::OnGetColorSpace(NativeEngine& engine, NativeCallbackInfo&
return result;
}
NativeValue* JsWindow::OnDump(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("[NAPI]dump window start");
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
return nullptr;
}
if (windowToken_ == nullptr) {
WLOGFE("[NAPI]window is nullptr or get invalid param");
return nullptr;
}
std::vector<std::string> params;
if (!ConvertNativeValueToVector(engine, info.argv[0], params)) {
WLOGFE("[NAPI]ConvertNativeValueToVector fail");
return nullptr;
}
std::vector<std::string> dumpInfo;
windowToken_->DumpInfo(params, dumpInfo);
NativeValue* dumpInfoValue = CreateNativeArray(engine, dumpInfo);
WLOGFI("[NAPI]Window [%{public}u, %{public}s] dump end",
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
return dumpInfoValue;
}
std::shared_ptr<NativeReference> FindJsWindowObject(std::string windowName)
{
WLOGFI("[NAPI]Try to find window %{public}s in g_jsWindowMap", windowName.c_str());
@@ -1497,6 +1529,7 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
BindNativeFunction(engine, *object, "setTransparent", JsWindow::SetTransparent);
BindNativeFunction(engine, *object, "setCallingWindow", JsWindow::SetCallingWindow);
BindNativeFunction(engine, *object, "disableWindowDecor", JsWindow::DisableWindowDecor);
BindNativeFunction(engine, *object, "dump", JsWindow::Dump);
std::shared_ptr<NativeReference> jsWindowRef;
jsWindowRef.reset(engine.CreateReference(objValue, 1));
@@ -65,6 +65,7 @@ public:
static NativeValue* IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetColorSpace(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetColorSpace(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* Dump(NativeEngine* engine, NativeCallbackInfo* info);
private:
std::string GetWindowName();
@@ -101,6 +102,7 @@ private:
NativeValue* OnSetTransparent(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetCallingWindow(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnDisableWindowDecor(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnDump(NativeEngine& engine, NativeCallbackInfo& info);
sptr<Window> windowToken_ = nullptr;
std::unique_ptr<JsWindowRegisterManager> registerManager_ = nullptr;
@@ -19,8 +19,8 @@
#include "accesstoken_kit.h"
#include "bundle_constants.h"
#include "ipc_skeleton.h"
#include "js_runtime_utils.h"
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
using namespace AbilityRuntime;
@@ -16,6 +16,7 @@
#ifndef OHOS_JS_WINDOW_UTILS_H
#define OHOS_JS_WINDOW_UTILS_H
#include <map>
#include "js_runtime_utils.h"
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "window.h"
@@ -110,6 +111,22 @@ const std::map<ApiWindowMode, WindowMode> JS_TO_NATIVE_WINDOW_MODE_MAP {
NativeValue* ColorSpaceInit(NativeEngine* engine);
NativeValue* WindowStageEventTypeInit(NativeEngine* engine);
bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability);
template<class T>
inline bool ConvertNativeValueToVector(NativeEngine& engine, NativeValue* nativeValue, std::vector<T>& out)
{
NativeArray* nativeArray = AbilityRuntime::ConvertNativeValueTo<NativeArray>(nativeValue);
if (nativeArray == nullptr) {
return false;
}
T value;
for (uint32_t i = 0; i < nativeArray->GetLength(); i++) {
if (!AbilityRuntime::ConvertFromJsValue(engine, nativeArray->GetElement(i), value)) {
return false;
}
out.emplace_back(value);
}
return true;
}
}
}
#endif