!2383 【demend】手势禁用

Merge pull request !2383 from 张凯/demend_gesture_disabeld
This commit is contained in:
openharmony_ci 2023-03-30 11:07:14 +00:00 committed by Gitee
commit e314b8171b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
34 changed files with 586 additions and 5 deletions

View File

@ -66,6 +66,11 @@ public:
virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) = 0;
};
class IGestureNavigationEnabledChangedListener : virtual public RefBase {
public:
virtual void OnGestureNavigationEnabledUpdate(bool enable) = 0;
};
class WindowVisibilityInfo : public Parcelable {
public:
WindowVisibilityInfo() = default;
@ -138,11 +143,16 @@ public:
WMError UnregisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener);
WMError RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener);
WMError UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener);
WMError RegisterGestureNavigationEnabledChangedListener(
const sptr<IGestureNavigationEnabledChangedListener>& listener);
WMError UnregisterGestureNavigationEnabledChangedListener(
const sptr<IGestureNavigationEnabledChangedListener>& listener);
WMError MinimizeAllAppWindows(DisplayId displayId);
WMError ToggleShownStateForAllAppWindows();
WMError SetWindowLayoutMode(WindowLayoutMode mode);
WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const;
WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const;
WMError SetGestureNavigaionEnabled(bool enable) const;
private:
WindowManager();
@ -160,6 +170,7 @@ private:
const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const;
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const;
void NotifyWaterMarkFlagChangedResult(bool showWaterMark) const;
void NotifyGestureNavigationEnabledResult(bool enable) const;
void OnRemoteDied() const;
};
} // namespace Rosen

View File

@ -114,6 +114,12 @@ NativeValue* JsWindowManager::SetWindowLayoutMode(NativeEngine* engine, NativeCa
return (me != nullptr) ? me->OnSetWindowLayoutMode(*engine, *info) : nullptr;
}
NativeValue* JsWindowManager::SetGestureNavigationEnabled(NativeEngine* engine, NativeCallbackInfo* info)
{
JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
return (me != nullptr) ? me->OnSetGestureNavigationEnabled(*engine, *info) : nullptr;
}
static void GetNativeContext(NativeEngine& engine, NativeValue* nativeContext, void*& contextPtr, WMError& errCode)
{
AppExecFwk::Ability* ability = nullptr;
@ -882,6 +888,46 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native
return result;
}
NativeValue* JsWindowManager::OnSetGestureNavigationEnabled(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFD("OnSetGestureNavigationEnabled");
if (info.argc < 1) { // 1: minimum params num
WLOGFE("Argc is invalid: %{public}zu", info.argc);
engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
return engine.CreateUndefined();
}
NativeBoolean* nativeBool = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
if (nativeBool == nullptr) {
WLOGFE("Failed to convert parameter to bool");
engine.Throw(CreateJsError(engine, static_cast<int32_t>(WmErrorCode::WM_ERROR_INVALID_PARAM)));
return engine.CreateUndefined();
}
bool gestureNavigationEnable = static_cast<bool>(*nativeBool);
WLOGI("Set gesture navigation enable as %{public}d", gestureNavigationEnable);
AsyncTask::CompleteCallback complete =
[gestureNavigationEnable](NativeEngine& engine, AsyncTask& task, int32_t status) {
WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<WindowManager>().SetGestureNavigaionEnabled(gestureNavigationEnable));
if (ret == WmErrorCode::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
WLOGD("SetGestureNavigationEnabled success");
} else {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(ret), "SetGestureNavigationEnabled failed"));
}
};
// 1: maximum params num; 1: index of callback
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
((info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ?
info.argv[1] : nullptr);
NativeValue* result = nullptr;
AsyncTask::Schedule("JsWindowManager::OnSetGestureNavigationEnabled",
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
{
WLOGFD("JsWindowManagerInit");
@ -923,6 +969,8 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
BindNativeFunction(*engine, *object, "toggleShownStateForAllAppWindows", moduleName,
JsWindowManager::ToggleShownStateForAllAppWindows);
BindNativeFunction(*engine, *object, "setWindowLayoutMode", moduleName, JsWindowManager::SetWindowLayoutMode);
BindNativeFunction(*engine, *object, "setGestureNavigationEnabled", moduleName,
JsWindowManager::SetGestureNavigationEnabled);
return engine->CreateUndefined();
}
} // namespace Rosen

View File

@ -41,6 +41,7 @@ public:
static NativeValue* GetTopWindow(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetLastWindow(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetWindowLayoutMode(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetGestureNavigationEnabled(NativeEngine* engine, NativeCallbackInfo* info);
private:
static NativeValue* OnCreate(NativeEngine& engine, NativeCallbackInfo& info);
static NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info);
@ -53,6 +54,7 @@ private:
static NativeValue* OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info);
static NativeValue* OnGetLastWindow(NativeEngine& engine, NativeCallbackInfo& info);
static NativeValue* OnSetWindowLayoutMode(NativeEngine& engine, NativeCallbackInfo& info);
static NativeValue* OnSetGestureNavigationEnabled(NativeEngine& engine, NativeCallbackInfo& info);
static bool ParseConfigOption(
NativeEngine& engine, NativeObject* jsObject, WindowOption& option, void*& contextPtr);
std::unique_ptr<JsWindowRegisterManager> registerManager_ = nullptr;

View File

@ -304,5 +304,25 @@ void JsWindowListener::OnDialogDeathRecipient() const
AsyncTask::Schedule("JsWindowListener::OnDialogDeathRecipient",
*engine_, std::make_unique<AsyncTask>(callback, std::move(execute), std::move(complete)));
}
void JsWindowListener::OnGestureNavigationEnabledUpdate(bool enable)
{
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
[self = weakRef_, enable, eng = engine_] (NativeEngine &engine, AsyncTask &task, int32_t status) {
auto thisListener = self.promote();
if (thisListener == nullptr || eng == nullptr) {
WLOGFE("[NAPI]this listener or engine is nullptr");
return;
}
NativeValue* argv[] = {CreateJsValue(*eng, enable)};
thisListener->CallJsMethod(GESTURE_NAVIGATION_ENABLED_CHANGE_CB.c_str(), argv, ArraySize(argv));
}
);
NativeReference* callback = nullptr;
std::unique_ptr<AsyncTask::ExecuteCallback> execute = nullptr;
AsyncTask::Schedule("JsWindowListener::OnGestureNavigationEnabledUpdate",
*engine_, std::make_unique<AsyncTask>(callback, std::move(execute), std::move(complete)));
}
} // namespace Rosen
} // namespace OHOS

View File

@ -42,6 +42,7 @@ const std::string TOUCH_OUTSIDE_CB = "touchOutside";
const std::string SCREENSHOT_EVENT_CB = "screenshot";
const std::string DIALOG_TARGET_TOUCH_CB = "dialogTargetTouch";
const std::string DIALOG_DEATH_RECIPIENT_CB = "dialogDeathRecipient";
const std::string GESTURE_NAVIGATION_ENABLED_CHANGE_CB = "gestureNavigationEnabledChange";
class JsWindowListener : public IWindowChangeListener,
public ISystemBarChangedListener,
@ -51,7 +52,8 @@ class JsWindowListener : public IWindowChangeListener,
public ITouchOutsideListener,
public IScreenshotListener,
public IDialogTargetTouchListener,
public IDialogDeathRecipientListener {
public IDialogDeathRecipientListener,
public IGestureNavigationEnabledChangedListener {
public:
JsWindowListener(NativeEngine* engine, std::shared_ptr<NativeReference> callback)
: engine_(engine), jsCallBack_(callback), weakRef_(wptr<JsWindowListener> (this)) {}
@ -70,6 +72,7 @@ public:
void OnScreenshot() override;
void OnDialogTargetTouch() const override;
void OnDialogDeathRecipient() const override;
void OnGestureNavigationEnabledUpdate(bool enable) override;
void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
private:
WindowState state_ {WindowState::STATE_INITIAL};

View File

@ -26,7 +26,8 @@ JsWindowRegisterManager::JsWindowRegisterManager()
{
// white register list for window manager
listenerProcess_[CaseType::CASE_WINDOW_MANAGER] = {
{SYSTEM_BAR_TINT_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemBarChangeRegister }
{SYSTEM_BAR_TINT_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemBarChangeRegister },
{GESTURE_NAVIGATION_ENABLED_CHANGE_CB, &JsWindowRegisterManager::ProcessGestureNavigationEnabledChangeRegister},
};
// white register list for window
listenerProcess_[CaseType::CASE_WINDOW] = {
@ -156,6 +157,21 @@ WmErrorCode JsWindowRegisterManager::ProcessSystemBarChangeRegister(sptr<JsWindo
return ret;
}
WmErrorCode JsWindowRegisterManager::ProcessGestureNavigationEnabledChangeRegister(sptr<JsWindowListener> listener,
sptr<Window> window, bool isRegister)
{
sptr<IGestureNavigationEnabledChangedListener> thisListener(listener);
WmErrorCode ret;
if (isRegister) {
ret = WM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<WindowManager>().RegisterGestureNavigationEnabledChangedListener(thisListener));
} else {
ret = WM_JS_TO_ERROR_CODE_MAP.at(
SingletonContainer::Get<WindowManager>().UnregisterGestureNavigationEnabledChangedListener(thisListener));
}
return ret;
}
WmErrorCode JsWindowRegisterManager::ProcessTouchOutsideRegister(sptr<JsWindowListener> listener,
sptr<Window> window, bool isRegister)
{

View File

@ -52,6 +52,8 @@ private:
WmErrorCode ProcessDialogTargetTouchRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
WmErrorCode ProcessDialogDeathRecipientRegister(sptr<JsWindowListener> listener, sptr<Window> window,
bool isRegister);
WmErrorCode ProcessGestureNavigationEnabledChangeRegister(sptr<JsWindowListener> listener,
sptr<Window> window, bool isRegister);
using Func_t = WmErrorCode(JsWindowRegisterManager::*)(sptr<JsWindowListener>, sptr<Window> window, bool);
std::map<std::string, std::map<std::shared_ptr<NativeReference>, sptr<JsWindowListener>>> jsCbMap_;
std::mutex mtx_;

View File

@ -28,6 +28,7 @@ group("systemtest") {
":wms_window_effect_test",
":wms_window_focus_test",
":wms_window_gamut_test",
":wms_window_gesture_navigation_enabled_test",
":wms_window_immersive_test",
":wms_window_input_method_test",
":wms_window_input_test",
@ -160,6 +161,14 @@ ohos_systemtest("wms_window_gamut_test") {
deps = [ ":wms_systemtest_common" ]
}
ohos_systemtest("wms_window_gesture_navigation_enabled_test") {
module_out_path = module_out_path
sources = [ "window_gesture_navigation_enabled_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
}
ohos_systemtest("wms_window_input_test") {
module_out_path = module_out_path

View File

@ -0,0 +1,108 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// gtest
#include <gtest/gtest.h>
#include "future.h"
#include "window_manager.h"
#include "wm_common.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
namespace {
constexpr int WAIT_FUTURE_RESULT = 20000; // 20s
constexpr int WAIT_SLEEP_TIME = 1; // 1s
}
class TestGestureNavigationEnabledChangedListener : public IGestureNavigationEnabledChangedListener {
public:
void OnGestureNavigationEnabledUpdate(bool enable) override;
RunnableFuture<bool> future_;
};
void TestGestureNavigationEnabledChangedListener::OnGestureNavigationEnabledUpdate(bool enable)
{
future_.SetValue(enable);
}
class GestureNavigationEnabledTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
static sptr<TestGestureNavigationEnabledChangedListener> lisenter_;
};
sptr<TestGestureNavigationEnabledChangedListener> GestureNavigationEnabledTest::lisenter_ = nullptr;
void GestureNavigationEnabledTest::SetUpTestCase()
{
lisenter_= new (std::nothrow)TestGestureNavigationEnabledChangedListener();
if (lisenter_ == nullptr) {
return;
}
}
void GestureNavigationEnabledTest::TearDownTestCase()
{
}
void GestureNavigationEnabledTest::SetUp()
{
}
void GestureNavigationEnabledTest::TearDown()
{
}
namespace {
/**
* @tc.name: SetGestureNavigationEnabled
* @tc.desc: Check gesture navigation enabled
* @tc.type: FUNC
*/
HWTEST_F(GestureNavigationEnabledTest, SetGestureNavigationEnabled, Function | MediumTest | Level1)
{
ASSERT_NE(lisenter_, nullptr);
auto& windowManager = WindowManager::GetInstance();
windowManager.SetGestureNavigaionEnabled(false);
sleep(WAIT_SLEEP_TIME);
windowManager.RegisterGestureNavigationEnabledChangedListener(lisenter_);
sleep(WAIT_SLEEP_TIME);
windowManager.SetGestureNavigaionEnabled(true);
auto result = lisenter_->future_.GetResult(WAIT_FUTURE_RESULT);
ASSERT_EQ(result, true);
lisenter_->future_.Reset(true);
windowManager.SetGestureNavigaionEnabled(false);
result = lisenter_->future_.GetResult(WAIT_FUTURE_RESULT);
ASSERT_EQ(result, false);
lisenter_->future_.Reset(false);
windowManager.UnregisterGestureNavigationEnabledChangedListener(lisenter_);
sleep(WAIT_SLEEP_TIME);
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -74,6 +74,7 @@ public:
virtual void OffWindowZoom();
virtual WmErrorCode RaiseToAppTop(uint32_t windowId);
virtual std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId);
virtual WMError SetGestureNavigaionEnabled(bool enable);
private:
static inline SingletonDelegator<WindowAdapter> delegator;
bool InitWMSProxy();

View File

@ -33,6 +33,7 @@ public:
void UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos) override;
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) override;
void NotifyWaterMarkFlagChangedResult(bool showWaterMark) override;
void NotifyGestureNavigationEnabledResult(bool enable) override;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -29,6 +29,7 @@ enum class WindowManagerAgentType : uint32_t {
WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG,
WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
};
class IWindowManagerAgent : public IRemoteBroker {
@ -42,6 +43,7 @@ public:
TRANS_ID_UPDATE_WINDOW_VISIBILITY,
TRANS_ID_UPDATE_CAMERA_FLOAT,
TRANS_ID_UPDATE_WATER_MARK_FLAG,
TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED,
};
virtual void UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) = 0;
@ -51,6 +53,7 @@ public:
virtual void UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos) = 0;
virtual void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) = 0;
virtual void NotifyWaterMarkFlagChangedResult(bool isShowing) = 0;
virtual void NotifyGestureNavigationEnabledResult(bool enable) = 0;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -34,6 +34,7 @@ public:
void UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos) override;
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) override;
void NotifyWaterMarkFlagChangedResult(bool showWaterMark) override;
void NotifyGestureNavigationEnabledResult(bool enable) override;
private:
static inline BrokerDelegator<WindowManagerAgentProxy> delegator_;

View File

@ -290,5 +290,12 @@ std::shared_ptr<Media::PixelMap> WindowAdapter::GetSnapshot(int32_t windowId)
return windowManagerServiceProxy_->GetSnapshot(windowId);
}
WMError WindowAdapter::SetGestureNavigaionEnabled(bool enable)
{
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
return windowManagerServiceProxy_->SetGestureNavigaionEnabled(enable);
}
} // namespace Rosen
} // namespace OHOS

View File

@ -122,6 +122,8 @@ public:
void NotifyWindowVisibilityInfoChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos);
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing);
void NotifyWaterMarkFlagChangedResult(bool showWaterMark);
void NotifyGestureNavigationEnabledResult(bool enable);
static inline SingletonDelegator<WindowManager> delegator_;
std::recursive_mutex mutex_;
@ -137,6 +139,8 @@ public:
sptr<WindowManagerAgent> cameraFloatWindowChangedListenerAgent_;
std::vector<sptr<IWaterMarkFlagChangedListener>> waterMarkFlagChangeListeners_;
sptr<WindowManagerAgent> waterMarkFlagChangeAgent_;
std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners_;
sptr<WindowManagerAgent> gestureNavigationEnabledAgent_;
};
void WindowManager::Impl::NotifyFocused(const sptr<FocusChangeInfo>& focusChangeInfo)
@ -253,6 +257,19 @@ void WindowManager::Impl::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
}
}
void WindowManager::Impl::NotifyGestureNavigationEnabledResult(bool enable)
{
WLOGFI("Notify gesture navigation enable result, enable = %{public}d", enable);
std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners;
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
gestureNavigationEnabledListeners = gestureNavigationEnabledListeners_;
}
for (auto& listener : gestureNavigationEnabledListeners) {
listener->OnGestureNavigationEnabledUpdate(enable);
}
}
WindowManager::WindowManager() : pImpl_(std::make_unique<Impl>()) {}
WMError WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
@ -608,6 +625,75 @@ WMError WindowManager::UnregisterWaterMarkFlagChangedListener(const sptr<IWaterM
return ret;
}
WMError WindowManager::RegisterGestureNavigationEnabledChangedListener(
const sptr<IGestureNavigationEnabledChangedListener>& listener)
{
if (listener == nullptr) {
WLOGFE("listener could not be null");
return WMError::WM_ERROR_NULLPTR;
}
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
WMError ret = WMError::WM_OK;
if (pImpl_->gestureNavigationEnabledAgent_ == nullptr) {
pImpl_->gestureNavigationEnabledAgent_ = new (std::nothrow)WindowManagerAgent();
if (pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
pImpl_->gestureNavigationEnabledAgent_);
} else {
WLOGFE("Create windowManagerAgent object failed !");
ret = WMError::WM_ERROR_NULLPTR;
}
}
if (ret != WMError::WM_OK) {
WLOGFE("RegisterWindowManagerAgent failed !");
pImpl_->gestureNavigationEnabledAgent_ = nullptr;
} else {
auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
pImpl_->gestureNavigationEnabledListeners_.end(), listener);
if (iter != pImpl_->gestureNavigationEnabledListeners_.end()) {
WLOGFW("Listener is already registered.");
return WMError::WM_OK;
}
pImpl_->gestureNavigationEnabledListeners_.push_back(listener);
}
WLOGFD("Try to registerGestureNavigationEnabledChangedListener and result is %{public}u",
static_cast<uint32_t>(ret));
return ret;
}
WMError WindowManager::UnregisterGestureNavigationEnabledChangedListener(
const sptr<IGestureNavigationEnabledChangedListener>& listener)
{
if (listener == nullptr) {
WLOGFE("listener could not be null");
return WMError::WM_ERROR_NULLPTR;
}
std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
pImpl_->gestureNavigationEnabledListeners_.end(), listener);
if (iter == pImpl_->gestureNavigationEnabledListeners_.end()) {
WLOGFE("could not find this listener");
return WMError::WM_ERROR_INVALID_PARAM;
}
pImpl_->gestureNavigationEnabledListeners_.erase(iter);
WMError ret = WMError::WM_OK;
if (pImpl_->gestureNavigationEnabledListeners_.empty() &&
pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
pImpl_->gestureNavigationEnabledAgent_);
if (ret == WMError::WM_OK) {
pImpl_->gestureNavigationEnabledAgent_ = nullptr;
}
}
WLOGFD("Try to unregisterGestureNavigationEnabledChangedListener and result is %{public}u",
static_cast<uint32_t>(ret));
return ret;
}
void WindowManager::UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) const
{
if (focusChangeInfo == nullptr) {
@ -662,6 +748,16 @@ WMError WindowManager::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibility
return ret;
}
WMError WindowManager::SetGestureNavigaionEnabled(bool enable) const
{
WMError ret = SingletonContainer::Get<WindowAdapter>().SetGestureNavigaionEnabled(enable);
if (ret != WMError::WM_OK) {
WLOGFE("set gesture navigaion enabled failed");
}
return ret;
}
void WindowManager::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const
{
pImpl_->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
@ -672,6 +768,12 @@ void WindowManager::NotifyWaterMarkFlagChangedResult(bool showWaterMark) const
pImpl_->NotifyWaterMarkFlagChangedResult(showWaterMark);
}
void WindowManager::NotifyGestureNavigationEnabledResult(bool enable) const
{
pImpl_->NotifyGestureNavigationEnabledResult(enable);
}
void WindowManager::OnRemoteDied() const
{
WLOGI("wms is died");

View File

@ -50,5 +50,10 @@ void WindowManagerAgent::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
{
SingletonContainer::Get<WindowManager>().NotifyWaterMarkFlagChangedResult(showWaterMark);
}
void WindowManagerAgent::NotifyGestureNavigationEnabledResult(bool enable)
{
SingletonContainer::Get<WindowManager>().NotifyGestureNavigationEnabledResult(enable);
}
} // namespace Rosen
} // namespace OHOS

View File

@ -187,6 +187,26 @@ void WindowManagerAgentProxy::NotifyWaterMarkFlagChangedResult(bool showWaterMar
WLOGFE("SendRequest failed");
}
}
void WindowManagerAgentProxy::NotifyGestureNavigationEnabledResult(bool enable)
{
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteBool(enable)) {
WLOGFE("Write is showing status failed");
return;
}
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED),
data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -99,6 +99,11 @@ int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
NotifyWaterMarkFlagChangedResult(showWaterMark);
break;
}
case WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED: {
bool enbale = data.ReadBool();
NotifyGestureNavigationEnabledResult(enbale);
break;
}
default:
break;
}

View File

@ -116,7 +116,6 @@ HWTEST_F(WindowManagerAgentProxyTest, UpdateCameraFloatWindowStatus01, Function
{
windowManagerAgentProxy_->UpdateCameraFloatWindowStatus(100, false);
}
}
}
}

View File

@ -195,6 +195,43 @@ HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest08, Function | SmallTest | L
EXPECT_EQ(res, 0);
}
/**
* @tc.name: OnRemoteRequest09
* @tc.desc: test TRANS_ID_UPDATE_SYSTEM_BAR_PROPS success
* @tc.type: FUNC
*/
HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest09, Function | SmallTest | Level2)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
data.WriteBool(true);
uint32_t code = static_cast<uint32_t>(
IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG);
int res = stub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(res, 0);
}
/**
* @tc.name: OnRemoteRequest10
* @tc.desc: test TRANS_ID_UPDATE_SYSTEM_BAR_PROPS success
* @tc.type: FUNC
*/
HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest10, Function | SmallTest | Level2)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
data.WriteBool(true);
uint32_t code = static_cast<uint32_t>(
IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED);
int res = stub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(res, 0);
}
}
}
}

View File

@ -66,6 +66,14 @@ public:
};
};
class TestGestureNavigationEnabledChangedListener : public IGestureNavigationEnabledChangedListener {
public:
void OnGestureNavigationEnabledUpdate(bool enable) override
{
WLOGI("TestGestureNavigationEnabledChangedListener");
};
};
class WindowManagerTest : public testing::Test {
public:
static void SetUpTestCase();
@ -481,6 +489,76 @@ HWTEST_F(WindowManagerTest, UnregisterWaterMarkFlagChangedListener01, Function |
ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterWaterMarkFlagChangedListener(listener1));
ASSERT_EQ(0, windowManager.pImpl_->waterMarkFlagChangeListeners_.size());
}
/**
* @tc.name: RegisterGestureNavigationEnabledChangedListener
* @tc.desc: check RegisterGestureNavigationEnabledChangedListener
* @tc.type: FUNC
*/
HWTEST_F(WindowManagerTest, RegisterGestureNavigationEnabledChangedListener, Function | SmallTest | Level2)
{
auto& windowManager = WindowManager::GetInstance();
windowManager.pImpl_->gestureNavigationEnabledAgent_ = nullptr;
windowManager.pImpl_->gestureNavigationEnabledListeners_.clear();
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowManager.RegisterGestureNavigationEnabledChangedListener(nullptr));
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<TestGestureNavigationEnabledChangedListener> listener = new TestGestureNavigationEnabledChangedListener();
EXPECT_CALL(m->Mock(), RegisterWindowManagerAgent(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_NULLPTR));
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowManager.RegisterGestureNavigationEnabledChangedListener(listener));
ASSERT_EQ(0, windowManager.pImpl_->gestureNavigationEnabledListeners_.size());
ASSERT_EQ(nullptr, windowManager.pImpl_->gestureNavigationEnabledAgent_);
EXPECT_CALL(m->Mock(), RegisterWindowManagerAgent(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, windowManager.RegisterGestureNavigationEnabledChangedListener(listener));
ASSERT_EQ(1, windowManager.pImpl_->gestureNavigationEnabledListeners_.size());
ASSERT_NE(nullptr, windowManager.pImpl_->gestureNavigationEnabledAgent_);
// to check that the same listner can not be registered twice
ASSERT_EQ(WMError::WM_OK, windowManager.RegisterGestureNavigationEnabledChangedListener(listener));
ASSERT_EQ(1, windowManager.pImpl_->gestureNavigationEnabledListeners_.size());
}
/**
* @tc.name: UnregisterGestureNavigationEnabledChangedListener
* @tc.desc: check UnregisterGestureNavigationEnabledChangedListener
* @tc.type: FUNC
*/
HWTEST_F(WindowManagerTest, UnregisterGestureNavigationEnabledChangedListener, Function | SmallTest | Level2)
{
auto& windowManager = WindowManager::GetInstance();
windowManager.pImpl_->gestureNavigationEnabledAgent_ = nullptr;
windowManager.pImpl_->gestureNavigationEnabledListeners_.clear();
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
// check nullpter
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, windowManager.UnregisterGestureNavigationEnabledChangedListener(nullptr));
sptr<TestGestureNavigationEnabledChangedListener> listener1 = new TestGestureNavigationEnabledChangedListener();
sptr<TestGestureNavigationEnabledChangedListener> listener2 = new TestGestureNavigationEnabledChangedListener();
ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterGestureNavigationEnabledChangedListener(listener1));
EXPECT_CALL(m->Mock(), RegisterWindowManagerAgent(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
windowManager.RegisterGestureNavigationEnabledChangedListener(listener1);
windowManager.RegisterGestureNavigationEnabledChangedListener(listener2);
ASSERT_EQ(2, windowManager.pImpl_->gestureNavigationEnabledListeners_.size());
EXPECT_CALL(m->Mock(), UnregisterWindowManagerAgent(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterGestureNavigationEnabledChangedListener(listener1));
ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterGestureNavigationEnabledChangedListener(listener2));
ASSERT_EQ(0, windowManager.pImpl_->gestureNavigationEnabledListeners_.size());
ASSERT_EQ(nullptr, windowManager.pImpl_->gestureNavigationEnabledAgent_);
// if agent == nullptr, it can not be crashed.
windowManager.pImpl_->gestureNavigationEnabledListeners_.push_back(listener1);
ASSERT_EQ(WMError::WM_OK, windowManager.UnregisterGestureNavigationEnabledChangedListener(listener1));
ASSERT_EQ(0, windowManager.pImpl_->gestureNavigationEnabledListeners_.size());
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -37,7 +37,7 @@ public:
void UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos);
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing);
void NotifyWaterMarkFlagChangedResult(bool showWaterMark);
void NotifyGestureNavigationEnabledResult(bool enable);
private:
WindowManagerAgentController() {}
virtual ~WindowManagerAgentController() = default;

View File

@ -109,6 +109,8 @@ public:
WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) override;
WmErrorCode RaiseToAppTop(uint32_t windowId) override;
std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId) override;
WMError SetGestureNavigaionEnabled(bool enable) override;
WMError RegisterWindowManagerAgent(WindowManagerAgentType type,
const sptr<IWindowManagerAgent>& windowManagerAgent) override;
WMError UnregisterWindowManagerAgent(WindowManagerAgentType type,

View File

@ -112,6 +112,7 @@ public:
WMError NotifyDesktopUnfrozen();
void UpdateDisplayOrientationWhenHideWindow(sptr<WindowNode>& node);
bool HasMainFullScreenWindowShown(DisplayId displayId);
WMError SetGestureNavigaionEnabled(bool enable);
private:
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
WMError DestroyWindowInner(sptr<WindowNode>& node);
@ -147,6 +148,7 @@ private:
std::map<ScreenId, std::vector<DisplayId>> displayIdMap_;
bool lastWaterMarkShowStates_ { false };
bool needCheckFocusWindow = false;
bool lastGestureNativeEnabled_ { true };
std::map<WindowManagerAgentType, std::vector<sptr<IWindowManagerAgent>>> windowManagerAgents_;

View File

@ -70,6 +70,7 @@ public:
TRANS_ID_OFF_WINDOW_ZOOM,
TRANS_ID_RAISE_WINDOW_Z_ORDER,
TRANS_ID_GET_SNAPSHOT,
TRANS_ID_GESTURE_NAVIGATION_ENABLED,
};
virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
const std::shared_ptr<RSSurfaceNode>& surfaceNode,
@ -110,6 +111,7 @@ public:
virtual void OffWindowZoom() = 0;
virtual WmErrorCode RaiseToAppTop(uint32_t windowId) = 0;
virtual std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId) = 0;
virtual WMError SetGestureNavigaionEnabled(bool enable) = 0;
};
}
}

View File

@ -67,6 +67,7 @@ public:
void OffWindowZoom() override;
WmErrorCode RaiseToAppTop(uint32_t windowId) override;
std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId) override;
WMError SetGestureNavigaionEnabled(bool enable) override;
private:
static inline BrokerDelegator<WindowManagerProxy> delegator_;
};

View File

@ -91,5 +91,14 @@ void WindowManagerAgentController::NotifyWaterMarkFlagChangedResult(bool showWat
agent->NotifyWaterMarkFlagChangedResult(showWaterMark);
}
}
void WindowManagerAgentController::NotifyGestureNavigationEnabledResult(bool enable)
{
WLOGFD("NotifyGestureNavigationEnabledResult with result:%{public}d", enable);
for (auto& agent : wmAgentContainer_.GetAgentsByType(
WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED)) {
agent->NotifyGestureNavigationEnabledResult(enable);
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -1286,6 +1286,13 @@ void WindowManagerService::HasPrivateWindow(DisplayId displayId, bool& hasPrivat
WLOGI("called %{public}u", hasPrivateWindow);
}
WMError WindowManagerService::SetGestureNavigaionEnabled(bool enable)
{
return PostSyncTask([this, enable]() {
return windowRoot_->SetGestureNavigaionEnabled(enable);
});
}
void WindowInfoQueriedListener::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
WLOGI("called");

View File

@ -763,6 +763,18 @@ void WindowRoot::UpdateDisplayOrientationWhenHideWindow(sptr<WindowNode>& node)
}
}
WMError WindowRoot::SetGestureNavigaionEnabled(bool enable)
{
if (lastGestureNativeEnabled_ == enable) {
WLOGFW("Do not set gesture navigation too much times as same value and the value is %{public}d", enable);
return WMError::WM_DO_NOTHING;
}
WindowManagerAgentController::GetInstance().NotifyGestureNavigationEnabledResult(enable);
lastGestureNativeEnabled_ = enable;
WLOGFD("Set gesture navigation enabled succeeded and notify result of %{public}d", enable);
return WMError::WM_OK;
}
WMError WindowRoot::UpdateWindowNode(uint32_t windowId, WindowUpdateReason reason)
{
auto node = GetWindowNode(windowId);

View File

@ -854,5 +854,28 @@ std::shared_ptr<Media::PixelMap> WindowManagerProxy::GetSnapshot(int32_t windowI
return map;
}
WMError WindowManagerProxy::SetGestureNavigaionEnabled(bool enable)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteBool(enable)) {
WLOGFE("Write anchor delatX failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED),
data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
} // namespace Rosen
} // namespace OHOS

View File

@ -288,6 +288,12 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M
reply.WriteParcelable(pixelMap.get());
break;
}
case WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED: {
bool enable = data.ReadBool();
WMError errCode = SetGestureNavigaionEnabled(enable);
reply.WriteInt32(static_cast<int32_t>(errCode));
break;
}
default:
WLOGFW("unknown transaction code %{public}d", code);
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);

View File

@ -134,6 +134,10 @@ std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId) override
{
return nullptr;
}
WMError SetGestureNavigaionEnabled(bool enable) override
{
return WMError::WM_OK;
}
};
}
}

View File

@ -496,7 +496,7 @@ HWTEST_F(WindowManagerStubTest, OnRemoteRequest20, Function | SmallTest | Level2
}
/**
* @tc.name: OnRemoteRequest20
* @tc.name: OnRemoteRequest21
* @tc.desc: test TRANS_ID_RAISE_WINDOW_Z_ORDER success
* @tc.type: FUNC
*/
@ -514,6 +514,24 @@ HWTEST_F(WindowManagerStubTest, OnRemoteRequest21, Function | SmallTest | Level2
int res = stub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(res, 0);
}
/**
* @tc.name: OnRemoteRequest22
* @tc.desc: test TRANS_ID_RAISE_WINDOW_Z_ORDER success
* @tc.type: FUNC
*/
HWTEST_F(WindowManagerStubTest, OnRemoteRequest22, Function | SmallTest | Level2)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
data.WriteBool(true);
uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED);
int res = stub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(res, 0);
}
}
}
}

View File

@ -500,6 +500,23 @@ HWTEST_F(WindowRootTest, CheckAndNotifyWaterMarkChangedResult, Function | SmallT
windowRoot_->CheckAndNotifyWaterMarkChangedResult();
ASSERT_EQ(windowRoot_->lastWaterMarkShowStates_, false);
}
/**
* @tc.name: SetGestureNavigaionEnabled
* @tc.desc: test WindowRoot SetGestureNavigaionEnabled
* @tc.type: FUNC
*/
HWTEST_F(WindowRootTest, SetGestureNavigaionEnabled, Function | SmallTest | Level2)
{
windowRoot_->lastGestureNativeEnabled_ = false;
auto ret = windowRoot_->SetGestureNavigaionEnabled(false);
ASSERT_EQ(ret, WMError::WM_DO_NOTHING);
ret = windowRoot_->SetGestureNavigaionEnabled(true);
ASSERT_EQ(ret, WMError::WM_OK);
windowRoot_->lastGestureNativeEnabled_ = false;
}
}
}
}