添加设置截图功能相关接口

Signed-off-by: dubj <dubingjian@huawei.com>
Change-Id: I43d5662facbce5d75ef8d38e202f199476134be2
This commit is contained in:
dubj
2022-07-16 14:27:26 +08:00
committed by d00347686
parent 41fb587b57
commit ee21feb859
30 changed files with 497 additions and 3 deletions
+1
View File
@@ -58,6 +58,7 @@ public:
virtual sptr<DisplayInfo> GetDisplayInfoByScreenId(ScreenId screenId);
virtual std::vector<DisplayId> GetAllDisplayIds();
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId);
virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
virtual bool WakeUpBegin(PowerStateChangeReason reason);
virtual bool WakeUpEnd();
virtual bool SuspendBegin(PowerStateChangeReason reason);
+11
View File
@@ -40,6 +40,7 @@ public:
bool CheckSizeValid(const Media::Size& size, int32_t oriHeight, int32_t oriWidth) const;
sptr<Display> GetDefaultDisplay();
sptr<Display> GetDisplayById(DisplayId displayId);
DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
bool RegisterDisplayListener(sptr<IDisplayListener> listener);
bool UnregisterDisplayListener(sptr<IDisplayListener> listener);
bool SetDisplayState(DisplayState state, DisplayStateCallback callback);
@@ -381,6 +382,16 @@ std::vector<sptr<Display>> DisplayManager::GetAllDisplays()
return res;
}
DMError DisplayManager::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
return pImpl_->HasPrivateWindow(displayId, hasPrivateWindow);
}
DMError DisplayManager::Impl::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
return SingletonContainer::Get<DisplayManagerAdapter>().HasPrivateWindow(displayId, hasPrivateWindow);
}
bool DisplayManager::Impl::RegisterDisplayListener(sptr<IDisplayListener> listener)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
+7
View File
@@ -322,6 +322,13 @@ std::vector<DisplayId> DisplayManagerAdapter::GetAllDisplayIds()
return displayManagerServiceProxy_->GetAllDisplayIds();
}
DMError DisplayManagerAdapter::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
INIT_PROXY_CHECK_RETURN(DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED);
return displayManagerServiceProxy_->HasPrivateWindow(displayId, hasPrivateWindow);
}
sptr<DisplayInfo> DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId)
{
if (displayId == DISPLAY_ID_INVALID) {
+12
View File
@@ -20,6 +20,7 @@ group("systemtest") {
deps = [
":dm_display_change_test",
":dm_display_manager_test",
":dm_display_minimal_test",
":dm_display_power_test",
":dm_screen_manager_test",
@@ -70,6 +71,17 @@ ohos_systemtest("dm_screenshot_test") {
## SystemTest dm_screenshot_test }}}
## SystemTest dm_display_manager_test {{{
ohos_systemtest("dm_display_manager_test") {
module_out_path = module_out_path
sources = [ "display_manager_test.cpp" ]
deps = [ ":dm_systemtest_common" ]
}
## SystemTest dm_display_manager_test }}}
## SystemTest dm_screenshot_cmd_test {{{
ohos_systemtest("dm_screenshot_cmd_test") {
module_out_path = module_out_path
+232
View File
@@ -0,0 +1,232 @@
/*
* Copyright (c) 2022 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.
*/
#include <gtest/gtest.h>
#include "display_test_utils.h"
#include "screen.h"
#include "test_utils.h"
#include "wm_common.h"
#include "window.h"
#include "window_option.h"
#include "window_manager_hilog.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS::Rosen {
namespace {
const int WAIT_FOR_SYNC_US = 1000 * 500; // 500ms
}
class DisplayManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
sptr<Window> CreateWindow(std::string name, WindowMode mode, Rect rect);
};
void DisplayManagerTest::SetUpTestCase()
{
}
void DisplayManagerTest::TearDownTestCase()
{
}
void DisplayManagerTest::SetUp()
{
}
void DisplayManagerTest::TearDown()
{
}
sptr<Window> DisplayManagerTest::CreateWindow(std::string name, WindowMode mode, Rect rect)
{
sptr<WindowOption> option = new WindowOption();
option->SetDisplayId(DisplayManager::GetInstance().GetDefaultDisplayId());
option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
if (mode != WindowMode::WINDOW_MODE_FULLSCREEN) {
option->SetWindowRect(rect);
}
option->SetWindowMode(mode);
option->SetWindowName(name);
sptr<Window> window = Window::Create(option->GetWindowName(), option);
window->AddWindowFlag(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED);
return window;
}
namespace {
/**
* @tc.name: HasPrivateWindow
* @tc.desc: Check whether there is a private window in the current display
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerTest, HasPrivateWindow, Function | SmallTest | Level2)
{
sptr<Window> window = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0});
window->SetPrivacyMode(true);
window->Show();
usleep(WAIT_FOR_SYNC_US);
bool hasPrivateWindow = false;
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow);
ASSERT_TRUE(hasPrivateWindow);
window->SetPrivacyMode(false);
usleep(WAIT_FOR_SYNC_US);
DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow);
ASSERT_TRUE(!hasPrivateWindow);
window->Destroy();
}
/**
* @tc.name: HasPrivateWindowCovered
* @tc.desc: The private window is covered
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered, Function | SmallTest | Level2)
{
sptr<Window> window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0});
window1->Show();
// 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height
sptr<Window> window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480});
window2->SetPrivacyMode(true);
window2->Show();
// 10:rect.posX_, 110:rect.posY_, 400:rect.width, 500:rect.height
sptr<Window> window3 = CreateWindow("covered", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 400, 500});
window3->Show();
usleep(WAIT_FOR_SYNC_US);
bool hasPrivateWindow = false;
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow);
ASSERT_TRUE(!hasPrivateWindow);
window1->Destroy();
window2->Destroy();
window3->Destroy();
}
/**
* @tc.name: HasPrivateWindowCovered01
* @tc.desc: The private window is partially covered
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered01, Function | SmallTest | Level2)
{
sptr<Window> window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0});
window1->Show();
// 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height
sptr<Window> window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480});
window2->SetPrivacyMode(true);
window2->Show();
// 10:rect.posX_, 110:rect.posY_, 360:rect.width, 480:rect.height
sptr<Window> window3 = CreateWindow("covered", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 360, 480});
window3->Show();
usleep(WAIT_FOR_SYNC_US);
bool hasPrivateWindow = false;
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow);
ASSERT_TRUE(hasPrivateWindow);
window1->Destroy();
window2->Destroy();
window3->Destroy();
}
/**
* @tc.name: HasPrivateWindowCovered02
* @tc.desc: The private window is covered
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered02, Function | SmallTest | Level2)
{
sptr<Window> window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0});
window1->Show();
// 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height
sptr<Window> window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480});
window2->SetPrivacyMode(true);
window2->Show();
// 10:rect.posX_, 110:rect.posY_, 380:rect.width, 480:rect.height
sptr<Window> window3 = CreateWindow("covered1", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 380, 480});
window3->Show();
// 10:rect.posX_, 300:rect.posY_, 380:rect.width, 480:rect.height
sptr<Window> window4 = CreateWindow("covered2", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 300, 380, 480});
window4->Show();
usleep(WAIT_FOR_SYNC_US);
bool hasPrivateWindow = false;
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow);
ASSERT_TRUE(!hasPrivateWindow);
window1->Destroy();
window2->Destroy();
window3->Destroy();
window4->Destroy();
}
/**
* @tc.name: HasPrivateWindowCovered03
* @tc.desc: The private window is partially covered
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered03, Function | SmallTest | Level2)
{
sptr<Window> window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0});
window1->Show();
// 20:rect.posX_, 120:rect.pos_Y, rect.width_:360, rect.height_:700
sptr<Window> window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 700});
window2->SetPrivacyMode(true);
window2->Show();
// 10:rect.posX_, 110:rect.pos_Y, rect.width_:380, rect.height_:480
sptr<Window> window3 = CreateWindow("covered1", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 380, 480});
window3->Show();
// 10:rect.posX_, 600:rect.pos_Y, rect.width_:380, rect.height_:480
sptr<Window> window4 = CreateWindow("covered2", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 600, 380, 480});
window4->Show();
usleep(WAIT_FOR_SYNC_US);
bool hasPrivateWindow = false;
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow);
ASSERT_TRUE(hasPrivateWindow);
window1->Destroy();
window2->Destroy();
window3->Destroy();
window4->Destroy();
}
/**
* @tc.name: HasPrivateWindowSkipSnapShot
* @tc.desc: set snap shot skip
* @tc.type: FUNC
*/
HWTEST_F(DisplayManagerTest, HasPrivateWindowSkipSnapShot, Function | SmallTest | Level2)
{
sptr<Window> window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0});
window1->Show();
// 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height
sptr<Window> window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480});
window2->SetSnapshotSkip(true);
window2->Show();
usleep(WAIT_FOR_SYNC_US);
bool hasPrivateWindow = false;
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow);
ASSERT_TRUE(!hasPrivateWindow);
window1->Destroy();
window2->Destroy();
}
}
} // namespace OHOS::Rosen
@@ -73,11 +73,13 @@ public:
TRANS_ID_SCREEN_SET_COLOR_TRANSFORM,
TRANS_ID_IS_SCREEN_ROTATION_LOCKED,
TRANS_ID_SET_SCREEN_ROTATION_LOCKED,
TRANS_ID_HAS_PRIVATE_WINDOW,
};
virtual sptr<DisplayInfo> GetDefaultDisplayInfo() = 0;
virtual sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) = 0;
virtual sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) = 0;
virtual DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow) = 0;
virtual ScreenId CreateVirtualScreen(VirtualScreenOption option,
const sptr<IRemoteObject>& displayManagerAgent) = 0;
+1
View File
@@ -34,6 +34,7 @@ public:
sptr<DisplayInfo> GetDefaultDisplayInfo() override;
sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
sptr<DisplayInfo> GetDisplayInfoByScreen(ScreenId screenId) override;
DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow) override;
ScreenId CreateVirtualScreen(VirtualScreenOption option,
const sptr<IRemoteObject>& displayManagerAgent) override;
+4 -1
View File
@@ -34,6 +34,7 @@
#include "display_manager_stub.h"
#include "display_power_controller.h"
#include "singleton_delegator.h"
#include "window_info_queried_listener.h"
namespace OHOS::Rosen {
class DisplayManagerService : public SystemAbility, public DisplayManagerStub {
@@ -60,7 +61,7 @@ public:
void SetGravitySensorSubscriptionEnabled();
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) override;
ScreenId GetRSScreenId(DisplayId displayId) const;
DMError HasPrivateWindow(DisplayId id, bool& hasPrivateWindow) override;
// colorspace, gamut
DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) override;
DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut) override;
@@ -100,6 +101,7 @@ public:
static float GetCustomVirtualPixelRatio();
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation);
void RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener);
private:
DisplayManagerService();
~DisplayManagerService() = default;
@@ -117,6 +119,7 @@ private:
sptr<AbstractScreenController> abstractScreenController_;
sptr<DisplayPowerController> displayPowerController_;
sptr<IDisplayChangeListener> displayChangeListener_;
sptr<IWindowInfoQueriedListener> windowInfoQueriedListener_;
sptr<DisplayDumper> displayDumper_;
static float customVirtualPixelRatio_;
AtomicMap<ScreenId, uint32_t> accessTokenIdMaps_;
@@ -24,6 +24,7 @@
#include "abstract_display.h"
#include "display_change_listener.h"
#include "wm_single_instance.h"
#include "window_info_queried_listener.h"
#include "singleton_delegator.h"
namespace OHOS::Rosen {
@@ -47,6 +48,7 @@ public:
bool SetRotationFromWindow(DisplayId displayId, Rotation targetRotation);
void SetGravitySensorSubscriptionEnabled();
void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation);
void RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener);
};
} // namespace OHOS::Rosen
+22
View File
@@ -721,6 +721,28 @@ std::vector<DisplayId> DisplayManagerProxy::GetAllDisplayIds()
return allDisplayIds;
}
DMError DisplayManagerProxy::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
return DMError::DM_ERROR_IPC_FAILED;
}
if (!data.WriteUint64(displayId)) {
return DMError::DM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW),
data, reply, option) != ERR_NONE) {
return DMError::DM_ERROR_IPC_FAILED;
}
DMError ret = static_cast<DMError>(reply.ReadInt32());
hasPrivateWindow = reply.ReadBool();
return ret;
}
void DisplayManagerProxy::NotifyDisplayEvent(DisplayEvent event)
{
MessageParcel data;
+14
View File
@@ -123,6 +123,20 @@ void DisplayManagerService::RegisterDisplayChangeListener(sptr<IDisplayChangeLis
WLOGFI("IDisplayChangeListener registered");
}
void DisplayManagerService::RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener)
{
windowInfoQueriedListener_ = listener;
}
DMError DisplayManagerService::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
if (windowInfoQueriedListener_ != nullptr) {
windowInfoQueriedListener_->HasPrivateWindow(displayId, hasPrivateWindow);
return DMError::DM_OK;
}
return DMError::DM_ERROR_NULLPTR;
}
void DisplayManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)
{
@@ -56,6 +56,11 @@ std::vector<DisplayId> DisplayManagerServiceInner::GetAllDisplayIds() const
return DisplayManagerService::GetInstance().GetAllDisplayIds();
}
void DisplayManagerServiceInner::RegisterWindowInfoQueriedListener(const sptr<IWindowInfoQueriedListener>& listener)
{
DisplayManagerService::GetInstance().RegisterWindowInfoQueriedListener(listener);
}
std::vector<sptr<DisplayInfo>> DisplayManagerServiceInner::GetAllDisplays() const
{
std::vector<sptr<DisplayInfo>> res;
+8
View File
@@ -323,6 +323,14 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
SetScreenRotationLocked(isLocked);
break;
}
case DisplayManagerMessage::TRANS_ID_HAS_PRIVATE_WINDOW: {
DisplayId id = static_cast<DisplayId>(data.ReadUint64());
bool hasPrivateWindow = false;
DMError ret = HasPrivateWindow(id, hasPrivateWindow);
reply.WriteInt32(static_cast<int32_t>(ret));
reply.WriteBool(hasPrivateWindow);
break;
}
default:
WLOGFW("unknown transaction code");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
@@ -41,6 +41,7 @@ public:
sptr<Display> GetDisplayById(DisplayId displayId);
sptr<Display> GetDisplayByScreen(ScreenId screenId);
std::vector<DisplayId> GetAllDisplayIds();
DMError HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
bool RegisterDisplayListener(sptr<IDisplayListener> listener);
bool UnregisterDisplayListener(sptr<IDisplayListener> listener);
+1
View File
@@ -327,6 +327,7 @@ public:
virtual void SetPrivacyMode(bool isPrivacyMode) = 0;
virtual bool IsPrivacyMode() const = 0;
virtual WMError BindDialogTarget(sptr<IRemoteObject> targetToken) = 0;
virtual void SetSnapshotSkip(bool isSkip) = 0;
virtual WMError RequestFocus() const = 0;
virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) = 0;
@@ -78,6 +78,12 @@ static NativeValue* UnregisterDisplayManagerCallback(NativeEngine* engine, Nativ
return (me != nullptr) ? me->OnUnregisterDisplayManagerCallback(*engine, *info) : nullptr;
}
static NativeValue* HasPrivateWindow(NativeEngine* engine, NativeCallbackInfo* info)
{
JsDisplayManager* me = CheckParamsAndGetThis<JsDisplayManager>(engine, info);
return (me != nullptr) ? me->OnHasPrivateWindow(*engine, *info) : nullptr;
}
private:
std::map<std::string, std::map<std::unique_ptr<NativeReference>, sptr<JsDisplayListener>>> jsCbMap_;
std::mutex mtx_;
@@ -308,6 +314,29 @@ NativeValue* OnUnregisterDisplayManagerCallback(NativeEngine& engine, NativeCall
return engine.CreateUndefined();
}
NativeValue* OnHasPrivateWindow(NativeEngine& engine, NativeCallbackInfo& info)
{
bool hasPrivateWindow = false;
if (info.argc != 1) {
return engine.CreateUndefined();
}
int64_t displayId = static_cast<int64_t>(DISPLAY_ID_INVALID);
if (!ConvertFromJsValue(engine, info.argv[0], displayId)) {
WLOGFE("[NAPI]Failed to convert parameter to displayId");
return engine.CreateUndefined();
}
if (displayId < 0) {
return engine.CreateUndefined();
}
DMError errCode = SingletonContainer::Get<DisplayManager>().HasPrivateWindow(displayId, hasPrivateWindow);
WLOGFI("[NAPI]Display id = %{public}" PRIu64", hasPrivateWindow = %{public}u err = %{public}d",
static_cast<uint64_t>(displayId), hasPrivateWindow, errCode);
if (errCode != DMError::DM_OK) {
return engine.CreateUndefined();
}
return engine.CreateBoolean(hasPrivateWindow);
}
NativeValue* CreateJsDisplayArrayObject(NativeEngine& engine, std::vector<sptr<Display>>& displays)
{
WLOGFI("JsDisplayManager::CreateJsDisplayArrayObject is called");
@@ -381,6 +410,7 @@ NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj)
BindNativeFunction(*engine, *object, "getDefaultDisplay", JsDisplayManager::GetDefaultDisplay);
BindNativeFunction(*engine, *object, "getDefaultDisplaySync", JsDisplayManager::GetDefaultDisplaySync);
BindNativeFunction(*engine, *object, "getAllDisplay", JsDisplayManager::GetAllDisplay);
BindNativeFunction(*engine, *object, "hasPrivateWindow", JsDisplayManager::HasPrivateWindow);
BindNativeFunction(*engine, *object, "on", JsDisplayManager::RegisterDisplayManagerCallback);
BindNativeFunction(*engine, *object, "off", JsDisplayManager::UnregisterDisplayManagerCallback);
return engine->CreateUndefined();
@@ -310,6 +310,13 @@ NativeValue* JsWindow::SetPreferredOrientation(NativeEngine* engine, NativeCallb
return (me != nullptr) ? me->OnSetPreferredOrientation(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetSnapshotSkip(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("NAPI");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetSnapshotSkip(*engine, *info) : nullptr;
}
NativeValue* JsWindow::DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("[NAPI]DisableWindowDecor");
@@ -1896,6 +1903,51 @@ NativeValue* JsWindow::OnSnapshot(NativeEngine& engine, NativeCallbackInfo& info
return result;
}
NativeValue* JsWindow::OnSetSnapshotSkip(NativeEngine& engine, NativeCallbackInfo& info)
{
WMError errCode = WMError::WM_OK;
if (info.argc < 1 || info.argc > 2) { // 2 is maximum params num
WLOGFE("[NAPI] inbalid param");
errCode = WMError::WM_ERROR_INVALID_PARAM;
}
bool isSkip = false;
if (errCode == WMError::WM_OK) {
NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
if (nativeVal == nullptr) {
errCode = WMError::WM_ERROR_INVALID_PARAM;
} else {
isSkip = static_cast<bool>(*nativeVal);
}
}
wptr<Window> weakToken(windowToken_);
AsyncTask::CompleteCallback complete =
[weakToken, isSkip, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (errCode != WMError::WM_OK) {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
return;
}
auto weakWindow = weakToken.promote();
if (weakWindow == nullptr) {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Invalidate params"));
return;
}
weakWindow->SetSnapshotSkip(isSkip);
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("NAPI [%{public}u, %{public}s] set snapshotSkip end",
weakWindow->GetWindowId(), weakWindow->GetWindowName().c_str());
};
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
NativeValue* result = nullptr;
AsyncTask::Schedule("JsWindow::OnSetSnapshotSkip",
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info)
{
if (info.argc != 1 || windowToken_ == nullptr) {
@@ -2212,6 +2264,7 @@ void BindFunctions(NativeEngine& engine, NativeObject* object)
BindNativeFunction(engine, *object, "setTouchable", JsWindow::SetTouchable);
BindNativeFunction(engine, *object, "setTransparent", JsWindow::SetTransparent);
BindNativeFunction(engine, *object, "setCallingWindow", JsWindow::SetCallingWindow);
BindNativeFunction(engine, *object, "setSnapshotSkip", JsWindow::SetSnapshotSkip);
BindNativeFunction(engine, *object, "disableWindowDecor", JsWindow::DisableWindowDecor);
BindNativeFunction(engine, *object, "dump", JsWindow::Dump);
BindNativeFunction(engine, *object, "setForbidSplitMove", JsWindow::SetForbidSplitMove);
@@ -65,6 +65,7 @@ public:
static NativeValue* SetCallingWindow(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetPreferredOrientation(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetSnapshotSkip(NativeEngine* engine, NativeCallbackInfo* info);
// colorspace, gamut
static NativeValue* IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetColorSpace(NativeEngine* engine, NativeCallbackInfo* info);
@@ -124,6 +125,7 @@ private:
NativeValue* OnDump(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetForbidSplitMove(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSnapshot(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetSnapshotSkip(NativeEngine& engine, NativeCallbackInfo& info);
// animation Config
NativeValue* OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info);
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef OHOS_ROSEN_WINDOW_INFO_QUERIED_LISTENER_H
#define OHOS_ROSEN_WINDOW_INFO_QUERIED_LISTENER_H
#include <refbase.h>
#include "dm_common.h"
namespace OHOS::Rosen {
class IWindowInfoQueriedListener : public RefBase {
public:
virtual void HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
};
} // OHOS::Rosen
#endif // OHOS_ROSEN_WINDOW_INFO_QUERIED_LISTENER_H
+1
View File
@@ -77,6 +77,7 @@ enum class PropertyChangeAction : uint32_t {
ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12,
ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13,
ACTION_UPDATE_ANIMATION_FLAG = 1 << 14,
ACTION_UPDATE_PRIVACY_MODE = 1 << 15,
};
struct ModeChangeHotZonesConfig {
+6
View File
@@ -681,6 +681,9 @@ bool WindowProperty::Write(Parcel& parcel, PropertyChangeAction action)
case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG:
ret = ret && parcel.WriteUint32(animationFlag_);
break;
case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE:
ret = ret && parcel.WriteBool(isPrivacyMode_);
break;
default:
break;
}
@@ -741,6 +744,9 @@ void WindowProperty::Read(Parcel& parcel, PropertyChangeAction action)
SetAnimationFlag(parcel.ReadUint32());
break;
}
case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE:
SetPrivacyMode(parcel.ReadBool());
break;
default:
break;
}
+1
View File
@@ -164,6 +164,7 @@ public:
virtual bool IsPrivacyMode() const override;
virtual void DisableAppWindowDecor() override;
virtual WMError BindDialogTarget(sptr<IRemoteObject> targetToken) override;
virtual void SetSnapshotSkip(bool isSkip) override;
virtual bool IsDecorEnable() const override;
virtual WMError Maximize() override;
+6
View File
@@ -1392,6 +1392,7 @@ void WindowImpl::SetPrivacyMode(bool isPrivacyMode)
{
property_->SetPrivacyMode(isPrivacyMode);
surfaceNode_->SetSecurityLayer(isPrivacyMode);
UpdateProperty(PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
}
bool WindowImpl::IsPrivacyMode() const
@@ -1399,6 +1400,11 @@ bool WindowImpl::IsPrivacyMode() const
return property_->GetPrivacyMode();
}
void WindowImpl::SetSnapshotSkip(bool isSkip)
{
surfaceNode_->SetSecurityLayer(isSkip);
}
void WindowImpl::DisableAppWindowDecor()
{
if (!WindowHelper::IsMainWindow(property_->GetWindowType())) {
+6 -1
View File
@@ -49,6 +49,11 @@ public:
virtual void OnScreenshot(DisplayId displayId) override;
};
class WindowInfoQueriedListener : public IWindowInfoQueriedListener {
public:
virtual void HasPrivateWindow(DisplayId id, bool& hasPrivateWindow) override;
};
class WindowManagerServiceHandler : public AAFwk::WindowManagerServiceHandlerStub {
public:
virtual void NotifyWindowTransition(
@@ -113,8 +118,8 @@ public:
WMError UpdateRsTree(uint32_t windowId, bool isAdd) override;
void OnScreenshot(DisplayId displayId);
void OnAccountSwitched(int accountId);
void OnAccountSwitched(int accountId) const;
WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken) override;
void HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow);
protected:
WindowManagerService();
virtual ~WindowManagerService() = default;
+1 -1
View File
@@ -110,8 +110,8 @@ public:
WindowLayoutMode GetCurrentLayoutMode() const;
void RemoveSingleUserWindowNodes(int accountId);
WMError IsTileRectSatisfiedWithSizeLimits(sptr<WindowNode>& node);
bool HasPrivateWindow();
static AnimationConfig& GetAnimationConfigRef();
private:
void TraverseWindowNode(sptr<WindowNode>& root, std::vector<sptr<WindowNode>>& windowNodes) const;
sptr<WindowNode> FindRoot(WindowType type) const;
+1
View File
@@ -99,6 +99,7 @@ public:
void RemoveSingleUserWindowNodes(int accountId);
sptr<WindowNode> FindDialogCallerNode(WindowType type, sptr<IRemoteObject> token);
bool CheckMultiDialogWindows(WindowType type, sptr<IRemoteObject> token);
bool HasPrivateWindow(DisplayId displayId);
private:
void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
+4
View File
@@ -928,6 +928,10 @@ WMError WindowController::UpdateProperty(sptr<WindowProperty>& property, Propert
ret = UpdateTransform(windowId);
break;
}
case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE: {
node->GetWindowProperty()->SetPrivacyMode(property->GetPrivacyMode());
break;
}
default:
break;
}
+16
View File
@@ -85,6 +85,8 @@ void WindowManagerService::OnStart()
WindowInnerManager::GetInstance().Start(system::GetParameter("persist.window.holder.enable", "0") == "1");
sptr<IDisplayChangeListener> listener = new DisplayChangeListener();
DisplayManagerServiceInner::GetInstance().RegisterDisplayChangeListener(listener);
sptr<IWindowInfoQueriedListener> windowInfoQueriedListener = new WindowInfoQueriedListener();
DisplayManagerServiceInner::GetInstance().RegisterWindowInfoQueriedListener(windowInfoQueriedListener);
RegisterSnapshotHandler();
RegisterWindowManagerServiceHandler();
RegisterWindowVisibilityChangeCallback();
@@ -851,5 +853,19 @@ WMError WindowManagerService::BindDialogTarget(uint32_t& windowId, sptr<IRemoteO
return windowController_->BindDialogTarget(windowId, targetToken);
});
}
void WindowManagerService::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
PostVoidSyncTask([this, displayId, &hasPrivateWindow]() mutable {
hasPrivateWindow = windowRoot_->HasPrivateWindow(displayId);
});
WLOGFI("called %{public}u", hasPrivateWindow);
}
void WindowInfoQueriedListener::HasPrivateWindow(DisplayId displayId, bool& hasPrivateWindow)
{
WLOGFI("called");
WindowManagerService::GetInstance().HasPrivateWindow(displayId, hasPrivateWindow);
}
} // namespace Rosen
} // namespace OHOS
+13
View File
@@ -1345,6 +1345,19 @@ void WindowNodeContainer::MinimizeAllAppWindows(DisplayId displayId)
return;
}
bool WindowNodeContainer::HasPrivateWindow()
{
std::vector<sptr<WindowNode>> windowNodes;
TraverseContainer(windowNodes);
for (const auto& node : windowNodes) {
if (node->isVisible_ && node->GetWindowProperty()->GetPrivacyMode()) {
WLOGFI("window name %{public}s", node->GetWindowName().c_str());
return true;
}
}
return false;
}
void WindowNodeContainer::MinimizeOldestAppWindow()
{
for (auto& appNode : appWindowNode_->children_) {
+6
View File
@@ -1301,6 +1301,12 @@ Rect WindowRoot::GetDisplayGroupRect(DisplayId displayId) const
return container->GetDisplayGroupRect();
}
bool WindowRoot::HasPrivateWindow(DisplayId displayId)
{
auto container = GetWindowNodeContainer(displayId);
return container != nullptr ? container->HasPrivateWindow() : false;
}
void WindowRoot::SetMaxAppWindowNumber(int windowNum)
{
maxAppWindowNumber_ = windowNum;