mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-21 04:25:28 -04:00
@@ -88,6 +88,7 @@ enum class WMError : int32_t {
|
||||
WM_ERROR_INVALID_WINDOW = 160,
|
||||
WM_ERROR_INVALID_OPERATION = 170,
|
||||
WM_ERROR_INVALID_TYPE = 180,
|
||||
WM_ERROR_INVALID_PERMISSION = 190,
|
||||
WM_ERROR_UNKNOWN,
|
||||
};
|
||||
|
||||
|
||||
@@ -55,7 +55,10 @@ ohos_shared_library("window_native_kit") {
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:runtime",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
@@ -68,7 +71,6 @@ ohos_shared_library("window_napi") {
|
||||
"window_manager_napi/js_window_manager.cpp",
|
||||
"window_manager_napi/window_manager_module.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":window_manager_napi_config" ]
|
||||
deps = [
|
||||
":window_native_kit",
|
||||
@@ -82,6 +84,7 @@ ohos_shared_library("window_napi") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "js_window_manager.h"
|
||||
#include <ability.h>
|
||||
#include <cinttypes>
|
||||
#include "ability_context.h"
|
||||
#include "dm_common.h"
|
||||
#include "js_window.h"
|
||||
#include "js_window_utils.h"
|
||||
@@ -173,6 +174,19 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win
|
||||
WLOGFE("JsWindowManager::OnCreateWindow in newApi use with empty context!");
|
||||
return;
|
||||
}
|
||||
// FixMe: adapt to service and xts
|
||||
if (winType == WindowType::WINDOW_TYPE_FLOAT) {
|
||||
auto abilityContext = Context::ConvertTo<AbilityRuntime::AbilityContext>(context->lock());
|
||||
if (abilityContext != nullptr) {
|
||||
if (!CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_INVALID_PERMISSION),
|
||||
"JsWindow::OnCreateWindow newAPI failed."));
|
||||
WLOGFE("JsWindowManager::OnCreateWindow in newApi TYPE_FLOAT CheckCallingPermission failed!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
sptr<WindowOption> windowOption = new WindowOption();
|
||||
windowOption->SetWindowType(winType);
|
||||
sptr<Window> window = Window::Create(windowName, windowOption, context->lock());
|
||||
@@ -396,8 +410,10 @@ void JsWindowManager::UnregisterWmListenerWithType(std::string type, NativeValue
|
||||
type.c_str());
|
||||
return;
|
||||
}
|
||||
bool findFlag = false;
|
||||
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
|
||||
if (value->StrictEquals(it->first->Get())) {
|
||||
findFlag = true;
|
||||
it->second->RemoveCallback(value);
|
||||
if (type.compare(SYSTEM_BAR_TINT_CHANGE_CB) == 0) {
|
||||
sptr<ISystemBarChangedListener> thisListener(it->second);
|
||||
@@ -410,6 +426,10 @@ void JsWindowManager::UnregisterWmListenerWithType(std::string type, NativeValue
|
||||
it++;
|
||||
}
|
||||
}
|
||||
if (!findFlag) {
|
||||
WLOGFE("JsWindowManager::UnregisterWmListenerWithType can't find callback!");
|
||||
return;
|
||||
}
|
||||
// one type with multi jscallback, erase type when there is no callback in one type
|
||||
if (jsCbMap_[type].empty()) {
|
||||
jsCbMap_.erase(type);
|
||||
@@ -436,6 +456,7 @@ NativeValue* JsWindowManager::OnRegisterWindowMangerCallback(NativeEngine& engin
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
RegisterWmListenerWithType(engine, cbType, value);
|
||||
WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback end!");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
@@ -462,6 +483,7 @@ NativeValue* JsWindowManager::OnUnregisterWindowManagerCallback(NativeEngine& en
|
||||
}
|
||||
UnregisterWmListenerWithType(cbType, value);
|
||||
}
|
||||
WLOGFI("JsWindowManager::OnUnregisterWindowCallback end!");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ void JsWindowListener::RemoveCallback(NativeValue* jsListenerObject)
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
WLOGFI("JsWindowListener::AddCallbackAndRegister success jsCallBack_ size: %{public}d!",
|
||||
WLOGFI("JsWindowListener::RemoveCallback success jsCallBack_ size: %{public}d!",
|
||||
static_cast<uint32_t>(jsCallBack_.size()));
|
||||
return;
|
||||
}
|
||||
@@ -118,7 +118,6 @@ void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const Syst
|
||||
WLOGFE("JsWindowListener::OnSystemBarPropertyChange systemBarTintChange not register!");
|
||||
return;
|
||||
}
|
||||
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[this, displayId, tints] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
#include <iomanip>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include "accesstoken_kit.h"
|
||||
#include "bundle_constants.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "window_manager_hilog.h"
|
||||
namespace OHOS {
|
||||
@@ -249,5 +252,18 @@ NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avo
|
||||
object->SetProperty("bottomRect", GetRectAndConvertToJsValue(engine, avoidArea.bottomRect));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
bool CheckCallingPermission(std::string permission)
|
||||
{
|
||||
WLOGFI("JsWindowUtils::CheckCallingPermission, 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());
|
||||
return false;
|
||||
}
|
||||
WLOGFI("JsWindowUtils::CheckCallingPermission end.");
|
||||
return true;
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -43,8 +43,10 @@ enum class ApiWindowType : uint32_t {
|
||||
TYPE_KEYGUARD,
|
||||
TYPE_VOLUME_OVERLAY,
|
||||
TYPE_NAVIGATION_BAR,
|
||||
TYPE_END = TYPE_NAVIGATION_BAR,
|
||||
TYPE_FLOAT,
|
||||
TYPE_END = TYPE_FLOAT,
|
||||
};
|
||||
|
||||
const std::map<WindowType, ApiWindowType> NATIVE_JS_TO_WINDOW_TYPE_MAP {
|
||||
{ WindowType::APP_SUB_WINDOW_BASE, ApiWindowType::TYPE_APP },
|
||||
{ WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ApiWindowType::TYPE_SYSTEM_ALERT },
|
||||
@@ -55,6 +57,7 @@ const std::map<WindowType, ApiWindowType> NATIVE_JS_TO_WINDOW_TYPE_MAP {
|
||||
{ WindowType::WINDOW_TYPE_VOLUME_OVERLAY, ApiWindowType::TYPE_VOLUME_OVERLAY },
|
||||
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, ApiWindowType::TYPE_NAVIGATION_BAR },
|
||||
{ WindowType::WINDOW_TYPE_APP_SUB_WINDOW, ApiWindowType::TYPE_APP_SUB_WINDOW },
|
||||
{ WindowType::WINDOW_TYPE_FLOAT, ApiWindowType::TYPE_FLOAT },
|
||||
};
|
||||
const std::map<ApiWindowType, WindowType> JS_TO_NATIVE_WINDOW_TYPE_MAP {
|
||||
{ ApiWindowType::TYPE_APP, WindowType::APP_SUB_WINDOW_BASE },
|
||||
@@ -66,6 +69,7 @@ const std::map<ApiWindowType, WindowType> JS_TO_NATIVE_WINDOW_TYPE_MAP {
|
||||
{ ApiWindowType::TYPE_VOLUME_OVERLAY, WindowType::WINDOW_TYPE_VOLUME_OVERLAY },
|
||||
{ ApiWindowType::TYPE_NAVIGATION_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR },
|
||||
{ ApiWindowType::TYPE_APP_SUB_WINDOW, WindowType::WINDOW_TYPE_APP_SUB_WINDOW },
|
||||
{ ApiWindowType::TYPE_FLOAT, WindowType::WINDOW_TYPE_FLOAT }
|
||||
};
|
||||
enum class ApiWindowMode : uint32_t {
|
||||
UNDEFINED = 1,
|
||||
@@ -91,6 +95,7 @@ const std::map<WindowMode, ApiWindowMode> NATIVE_TO_JS_WINDOW_MODE_MAP {
|
||||
NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine,
|
||||
const SystemBarRegionTints& tints);
|
||||
NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea);
|
||||
bool CheckCallingPermission(std::string permission);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user