增加亮灭屏单元测试用例

Signed-off-by: chenqinxin <chenqinxin1@huawei.com>
Change-Id: Id9b4cd1b0e9a0792d84884affd68af7e3af0d75b
This commit is contained in:
chenqinxin 2022-01-19 12:41:02 +08:00
parent 65d918c308
commit d834bd91d9
17 changed files with 537 additions and 95 deletions

View File

@ -41,9 +41,9 @@ public:
virtual DMError DestroyVirtualScreen(ScreenId screenId);
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId);
virtual void RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
virtual bool RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type);
virtual void UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
virtual bool UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type);
virtual bool WakeUpBegin(PowerStateChangeReason reason);
virtual bool WakeUpEnd();

View File

@ -26,6 +26,7 @@
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"};
constexpr uint32_t MAX_SCREEN_BRIGHTNESS_VALUE = 100;
}
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager)
@ -173,42 +174,50 @@ std::vector<const sptr<Display>> DisplayManager::GetAllDisplays()
return res;
}
void DisplayManager::RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener)
bool DisplayManager::RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener)
{
if (listener == nullptr) {
WLOGFE("listener is nullptr");
return;
return false;
}
std::lock_guard<std::mutex> lock(mutex_);
powerEventListeners_.push_back(listener);
bool ret = true;
if (powerEventListenerAgent_ == nullptr) {
powerEventListenerAgent_ = new DisplayManagerAgent();
SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(powerEventListenerAgent_,
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(powerEventListenerAgent_,
DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
if (!ret) {
WLOGFW("RegisterDisplayManagerAgent failed ! remove listener!");
powerEventListeners_.pop_back();
}
}
WLOGFI("RegisterDisplayPowerEventListener end");
return ret;
}
void DisplayManager::UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener)
bool DisplayManager::UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener)
{
if (listener == nullptr) {
WLOGFE("listener is nullptr");
return;
return false;
}
std::lock_guard<std::mutex> lock(mutex_);
auto iter = std::find(powerEventListeners_.begin(), powerEventListeners_.end(), listener);
if (iter == powerEventListeners_.end()) {
WLOGFE("could not find this listener");
return;
return false;
}
powerEventListeners_.erase(iter);
bool ret = true;
if (powerEventListeners_.empty() && powerEventListenerAgent_ != nullptr) {
SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(powerEventListenerAgent_,
ret = SingletonContainer::Get<DisplayManagerAdapter>().UnregisterDisplayManagerAgent(powerEventListenerAgent_,
DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER);
powerEventListenerAgent_ = nullptr;
}
WLOGFI("UnregisterDisplayPowerEventListener end");
return ret;
}
void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)
@ -302,18 +311,19 @@ bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback ca
{
WLOGFI("state:%{public}u", state);
std::lock_guard<std::mutex> lock(mutex_);
if (displayStateCallback_ != nullptr) {
WLOGFI("previous callback not called, can't reset");
if (displayStateCallback_ != nullptr || callback == nullptr) {
WLOGFI("previous callback not called or callback invalid");
return false;
}
displayStateCallback_ = callback;
bool ret = true;
if (displayStateAgent_ == nullptr) {
displayStateAgent_ = new DisplayManagerAgent();
SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(displayStateAgent_,
ret = SingletonContainer::Get<DisplayManagerAdapter>().RegisterDisplayManagerAgent(displayStateAgent_,
DisplayManagerAgentType::DISPLAY_STATE_LISTENER);
}
bool ret = SingletonContainer::Get<DisplayManagerAdapter>().SetDisplayState(state);
ret &= SingletonContainer::Get<DisplayManagerAdapter>().SetDisplayState(state);
if (!ret) {
ClearDisplayStateCallback();
}
@ -328,6 +338,11 @@ DisplayState DisplayManager::GetDisplayState(uint64_t displayId)
bool DisplayManager::SetScreenBrightness(uint64_t screenId, uint32_t level)
{
WLOGFI("screenId:%{public}" PRIu64", level:%{public}u,", screenId, level);
if (level > MAX_SCREEN_BRIGHTNESS_VALUE) {
level = MAX_SCREEN_BRIGHTNESS_VALUE;
WLOGFW("level:%{public}u, exceed max value!", level);
return false;
}
RSInterfaces::GetInstance().SetScreenBacklight(screenId, level);
return true;
}

View File

@ -96,22 +96,22 @@ DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId)
return displayManagerServiceProxy_->DestroyVirtualScreen(screenId);
}
void DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitDMSProxyLocked()) {
return;
return false;
}
return displayManagerServiceProxy_->RegisterDisplayManagerAgent(displayManagerAgent, type);
}
void DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitDMSProxyLocked()) {
return;
return false;
}
return displayManagerServiceProxy_->UnregisterDisplayManagerAgent(displayManagerAgent, type);
}

View File

@ -24,7 +24,8 @@ namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayPowerTest"};
constexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 5;
constexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 40;
constexpr uint32_t SLEEP_TIME_IN_US = 50000;
}
class DisplayPowerEventListener : public IDisplayPowerEventListener {
@ -52,6 +53,7 @@ public:
static inline DisplayId defaultId_;
static inline uint32_t brightnessLevel_ = 80;
static inline uint32_t invalidBrightnessLevel_ = 180;
static inline uint32_t times_ = 0;
static inline bool isDisplayStateCallbackCalled_ = false;
static sptr<DisplayPowerEventListener> listener_;
@ -101,7 +103,7 @@ void DisplayPowerTest::CheckDisplayStateCallback(bool valueExpected)
if (isDisplayStateCallbackCalled_ == valueExpected) {
return;
}
sleep(1);
usleep(SLEEP_TIME_IN_US);
++times_;
} while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK);
}
@ -112,18 +114,41 @@ void DisplayPowerTest::CheckDisplayPowerEventCallback(bool valueExpected)
if (listener_->isCallbackCalled_ == valueExpected) {
return;
}
sleep(1);
usleep(SLEEP_TIME_IN_US);
++times_;
} while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK);
}
namespace {
/**
* @tc.name: SetDisplayStateValid
* @tc.name: register_display_power_event_listener_001
* @tc.desc: call RegisterDisplayPowerEventListener with a valid listener and check return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, register_display_power_event_listener_001, Function | SmallTest | Level2)
{
sptr<IDisplayPowerEventListener> listener = new DisplayPowerEventListener();
bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener);
ASSERT_EQ(true, ret);
}
/**
* @tc.name: register_display_power_event_listener_002
* @tc.desc: call RegisterDisplayPowerEventListener with an invalid listener and check return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, register_display_power_event_listener_002, Function | SmallTest | Level2)
{
bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(nullptr);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: set_display_state_001
* @tc.desc: Call SetDisplayState and check if it the state set is the same as calling GetDisplayState
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetDisplayStateValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_display_state_001, Function | MediumTest | Level2)
{
DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_);
DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF);
@ -135,11 +160,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateValid01, Function | MediumTest | Level
}
/**
* @tc.name: SetDisplayStateValid
* @tc.name: set_display_state_002
* @tc.desc: Call SetDisplayState to set a value already set and check the return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetDisplayStateValid02, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_display_state_002, Function | MediumTest | Level2)
{
DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_);
bool ret = DisplayManager::GetInstance().SetDisplayState(initialState, callback_);
@ -151,11 +176,26 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateValid02, Function | MediumTest | Level
}
/**
* @tc.name: SetDisplayStateCallbackValid
* @tc.name: set_display_state_003
* @tc.desc: Call SetDisplayState with an invalid value and check the return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, set_display_state_003, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::UNKNOWN, callback_);
ASSERT_EQ(false, ret);
CheckDisplayStateCallback(false);
ASSERT_EQ(false, isDisplayStateCallbackCalled_);
CheckDisplayPowerEventCallback(false);
ASSERT_EQ(false, listener_->isCallbackCalled_);
}
/**
* @tc.name: set_display_state_callback_001
* @tc.desc: Call SetDisplayState and check if callback state is correct
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_display_state_callback_001, Function | MediumTest | Level2)
{
DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_);
DisplayState stateToSet = (initialState == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF);
@ -166,11 +206,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid01, Function | MediumTest
}
/**
* @tc.name: SetDisplayStateCallbackValid
* @tc.name: set_display_state_callback_002
* @tc.desc: Call SetDisplayState to set a value already set and check the DisplayStateCallback
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid02, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_display_state_callback_002, Function | MediumTest | Level2)
{
DisplayState initialState = DisplayManager::GetInstance().GetDisplayState(defaultId_);
DisplayManager::GetInstance().SetDisplayState(initialState, callback_);
@ -179,11 +219,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStateCallbackValid02, Function | MediumTest
}
/**
* @tc.name: WakeUpBeginCallbackValid
* @tc.name: wake_up_begin_callback_001
* @tc.desc: Call WakeUpBegin and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, WakeUpBeginCallbackValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, wake_up_begin_callback_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(true, ret);
@ -194,11 +234,11 @@ HWTEST_F(DisplayPowerTest, WakeUpBeginCallbackValid01, Function | MediumTest | L
}
/**
* @tc.name: WakeUpEndCallbackValid
* @tc.desc: Call WakeUpBegin and check the OnDisplayPowerEvent callback is called
* @tc.name: wake_up_end_callback_001
* @tc.desc: Call WakeUpEnd and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, WakeUpEndCallbackValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, wake_up_end_callback_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().WakeUpEnd();
ASSERT_EQ(true, ret);
@ -209,11 +249,11 @@ HWTEST_F(DisplayPowerTest, WakeUpEndCallbackValid01, Function | MediumTest | Lev
}
/**
* @tc.name: SuspendBeginCallbackValid
* @tc.name: suspend_begin_callback_001
* @tc.desc: Call SuspendBegin and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SuspendBeginCallbackValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, suspend_begin_callback_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(true, ret);
@ -224,11 +264,11 @@ HWTEST_F(DisplayPowerTest, SuspendBeginCallbackValid01, Function | MediumTest |
}
/**
* @tc.name: SuspendEndCallbackValid
* @tc.name: suspend_end_callback_001
* @tc.desc: Call SuspendEnd and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SuspendEndCallbackValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, suspend_end_callback_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SuspendEnd();
ASSERT_EQ(true, ret);
@ -239,11 +279,11 @@ HWTEST_F(DisplayPowerTest, SuspendEndCallbackValid01, Function | MediumTest | Le
}
/**
* @tc.name: SetScreenPowerForAllCallbackValid
* @tc.name: set_screen_power_for_all_001
* @tc.desc: Call SetScreenPowerForAll OFF and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_screen_power_for_all_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_OFF,
PowerStateChangeReason::POWER_BUTTON);
@ -255,11 +295,11 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid01, Function | Mediu
}
/**
* @tc.name: SetScreenPowerForAllCallbackValid
* @tc.name: set_screen_power_for_all_002
* @tc.desc: Call SetScreenPowerForAll ON and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid02, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_screen_power_for_all_002, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_ON,
PowerStateChangeReason::POWER_BUTTON);
@ -271,11 +311,25 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllCallbackValid02, Function | Mediu
}
/**
* @tc.name: SetDisplayStatePowerCallbackValid
* @tc.desc: Call SetScreenPowerForAll OFF and check the OnDisplayPowerEvent callback is called
* @tc.name: set_screen_power_for_all_003
* @tc.desc: Call SetScreenPowerForAll with an invalid value and check the return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_screen_power_for_all_003, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::INVALID_STATE,
PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(false, ret);
CheckDisplayPowerEventCallback(true);
ASSERT_EQ(false, listener_->isCallbackCalled_);
}
/**
* @tc.name: set_display_state_power_event_callback_001
* @tc.desc: Call SetDisplayState OFF and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, set_display_state_power_event_callback_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::OFF, callback_);
ASSERT_EQ(true, ret);
@ -286,11 +340,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid01, Function | Mediu
}
/**
* @tc.name: SetDisplayStatePowerCallbackValid
* @tc.desc: Call SetScreenPowerForAll ON and check the OnDisplayPowerEvent callback is called
* @tc.name: set_display_state_power_event_callback_002
* @tc.desc: Call SetDisplayState ON and check the OnDisplayPowerEvent callback is called
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid02, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_display_state_power_event_callback_002, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetDisplayState(DisplayState::ON, callback_);
ASSERT_EQ(true, ret);
@ -301,11 +355,11 @@ HWTEST_F(DisplayPowerTest, SetDisplayStatePowerCallbackValid02, Function | Mediu
}
/**
* @tc.name: SetScreenPowerForAllValid
* @tc.name: get_display_power_001
* @tc.desc: Call SetScreenPowerForAll OFF and check the GetScreenPower return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, get_display_power_001, Function | MediumTest | Level2)
{
DisplayPowerState stateToSet = DisplayPowerState::POWER_OFF;
bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(stateToSet, PowerStateChangeReason::POWER_BUTTON);
@ -315,11 +369,11 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid01, Function | MediumTest |
}
/**
* @tc.name: SetScreenPowerForAllValid
* @tc.name: get_display_power_002
* @tc.desc: Call SetScreenPowerForAll ON and check the GetScreenPower return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid02, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, get_display_power_002, Function | MediumTest | Level2)
{
DisplayPowerState stateToSet = DisplayPowerState::POWER_ON;
bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(stateToSet, PowerStateChangeReason::POWER_BUTTON);
@ -329,17 +383,31 @@ HWTEST_F(DisplayPowerTest, SetScreenPowerForAllValid02, Function | MediumTest |
}
/**
* @tc.name: SetScreenBrightnessValid
* @tc.desc: Call SetScreenBrightness and check the GetScreenBrightness return value
* @tc.name: set_screen_brightness_001
* @tc.desc: Call SetScreenBrightness with a valid value and check the GetScreenBrightness return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, SetScreenBrightnessValid01, Function | MediumTest | Level2)
HWTEST_F(DisplayPowerTest, set_screen_brightness_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, brightnessLevel_);
ASSERT_EQ(true, ret);
uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
ASSERT_EQ(level, brightnessLevel_);
}
/**
* @tc.name: set_screen_brightness_002
* @tc.desc: Call SetScreenBrightness with an invalid value and check the GetScreenBrightness return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerTest, set_screen_brightness_002, Function | MediumTest | Level2)
{
uint32_t initialLevel = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, invalidBrightnessLevel_);
ASSERT_EQ(false, ret);
uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
ASSERT_EQ(level, initialLevel);
}
} // namespace
} // namespace Rosen
} // namespace OHOS

View File

@ -19,11 +19,23 @@ group("unittest") {
testonly = true
deps = [
":dm_display_power_unit_test",
":dm_screenshot_test",
":dm_snapshot_utils_test",
]
}
## UnitTest dm_display_power_unit_test {{{
ohos_unittest("dm_display_power_unit_test") {
module_out_path = module_out_path
sources = [ "display_power_unit_test.cpp" ]
deps = [ ":dm_unittest_common" ]
}
## UnitTest dm_snapshot_utils_test }}}
## UnitTest dm_snapshot_utils_test {{{
ohos_unittest("dm_snapshot_utils_test") {
module_out_path = module_out_path

View File

@ -0,0 +1,334 @@
/*
* 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_manager.h"
#include "mock_display_manager_adapter.h"
#include "singleton_mocker.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
class DisplayPowerEventListener : public IDisplayPowerEventListener {
public:
virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) {}
};
class DisplayPowerUnitTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
static inline sptr<DisplayPowerEventListener> listener_ = new DisplayPowerEventListener();
static inline DisplayId defaultId_ = 0;
static inline uint32_t brightnessLevel_ = 80;
static inline uint32_t invalidBrightnessLevel_ = 180;
static inline DisplayPowerState initialPowerState_;
static inline DisplayState initialState_;
};
void DisplayPowerUnitTest::SetUpTestCase()
{
}
void DisplayPowerUnitTest::TearDownTestCase()
{
}
void DisplayPowerUnitTest::SetUp()
{
initialPowerState_ = DisplayManager::GetInstance().GetScreenPower(defaultId_);
initialState_ = DisplayManager::GetInstance().GetDisplayState(defaultId_);
}
void DisplayPowerUnitTest::TearDown()
{
DisplayManager::GetInstance().SetScreenPowerForAll(initialPowerState_, PowerStateChangeReason::POWER_BUTTON);
DisplayStateCallback callback;
DisplayManager::GetInstance().SetDisplayState(initialState_, callback);
}
namespace {
/**
* @tc.name: register_display_power_event_listener_001
* @tc.desc: call Register/UnregisterDisplayPowerEventListener with a valid listener and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, register_display_power_event_listener_001, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(1).WillOnce(Return(true));
bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener_);
ASSERT_EQ(true, ret);
EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(1).WillOnce(Return(true));
ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener_);
ASSERT_EQ(true, ret);
}
/**
* @tc.name: register_display_power_event_listener_002
* @tc.desc: call Register/UnregisterDisplayPowerEventListener with nullptr and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, register_display_power_event_listener_002, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(0);
bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(nullptr);
ASSERT_EQ(false, ret);
EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(0);
ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(nullptr);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: register_display_power_event_listener_003
* @tc.desc: call Register/UnregisterDisplayPowerEventListener with ipc failed and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, register_display_power_event_listener_003, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(1).WillOnce(Return(false));
bool ret = DisplayManager::GetInstance().RegisterDisplayPowerEventListener(listener_);
ASSERT_EQ(false, ret);
EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(0);
ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener_);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: unregister_display_power_event_listener_001
* @tc.desc: call UnregisterDisplayPowerEventListener with a listener never registered and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, unregister_display_power_event_listener_001, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(0);
bool ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(listener_);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: unregister_display_power_event_listener_002
* @tc.desc: call UnregisterDisplayPowerEventListener with nullptr and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, unregister_display_power_event_listener_002, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), UnregisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER))
.Times(0);
bool ret = DisplayManager::GetInstance().UnregisterDisplayPowerEventListener(nullptr);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: wake_up_begin_001
* @tc.desc: call WakeUpBegin and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, wake_up_begin_001, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), WakeUpBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(true));;
bool ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(true, ret);
EXPECT_CALL(m.Mock(), WakeUpBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(false));;
ret = DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: wake_up_end_001
* @tc.desc: call WakeUpEnd and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, wake_up_end_001, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), WakeUpEnd()).Times(1).WillOnce(Return(true));
bool ret = DisplayManager::GetInstance().WakeUpEnd();
ASSERT_EQ(true, ret);
EXPECT_CALL(m.Mock(), WakeUpEnd()).Times(1).WillOnce(Return(false));
ret = DisplayManager::GetInstance().WakeUpEnd();
ASSERT_EQ(false, ret);
}
/**
* @tc.name: suspend_begin_001
* @tc.desc: call SuspendBegin and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, suspend_begin_001, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), SuspendBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(true));;
bool ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(true, ret);
EXPECT_CALL(m.Mock(), SuspendBegin(PowerStateChangeReason::POWER_BUTTON)).Times(1).WillOnce(Return(false));;
ret = DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(false, ret);
}
/**
* @tc.name: suspend_end_001
* @tc.desc: call SuspendEnd and check return value
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(DisplayPowerUnitTest, suspend_end_001, Function | SmallTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), SuspendEnd()).Times(1).WillOnce(Return(true));
bool ret = DisplayManager::GetInstance().SuspendEnd();
ASSERT_EQ(true, ret);
EXPECT_CALL(m.Mock(), SuspendEnd()).Times(1).WillOnce(Return(false));
ret = DisplayManager::GetInstance().SuspendEnd();
ASSERT_EQ(false, ret);
}
/**
* @tc.name: set_screen_brightness_001
* @tc.desc: Call SetScreenBrightness with a valid value and check the GetScreenBrightness return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerUnitTest, set_screen_brightness_001, Function | MediumTest | Level2)
{
bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, brightnessLevel_);
ASSERT_EQ(true, ret);
uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
ASSERT_EQ(level, brightnessLevel_);
}
/**
* @tc.name: set_screen_brightness_002
* @tc.desc: Call SetScreenBrightness with an invalid value and check the GetScreenBrightness return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerUnitTest, set_screen_brightness_002, Function | MediumTest | Level2)
{
uint32_t initialLevel = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, invalidBrightnessLevel_);
ASSERT_EQ(false, ret);
uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
ASSERT_EQ(level, initialLevel);
}
/**
* @tc.name: set_screen_power_for_all_001
* @tc.desc: Call SetScreenPowerForAll with valid value and check the GetScreenPower return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerUnitTest, set_screen_power_for_all_001, Function | MediumTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(defaultId_));
EXPECT_CALL(m.Mock(), SetScreenPowerForAll(_, PowerStateChangeReason::POWER_BUTTON))
.Times(1).WillOnce(Return(true));
bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::POWER_OFF,
PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(true, ret);
DisplayPowerState state = DisplayManager::GetInstance().GetScreenPower(defaultId_);
ASSERT_EQ(state, DisplayPowerState::POWER_OFF);
}
/**
* @tc.name: set_screen_power_for_all_002
* @tc.desc: Call SetScreenPowerForAll with invalid value and check the GetScreenPower return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerUnitTest, set_screen_power_for_all_002, Function | MediumTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), GetDefaultDisplayId()).Times(1).WillOnce(Return(defaultId_));
EXPECT_CALL(m.Mock(), SetScreenPowerForAll(_, PowerStateChangeReason::POWER_BUTTON)).Times(0);
bool ret = DisplayManager::GetInstance().SetScreenPowerForAll(DisplayPowerState::INVALID_STATE,
PowerStateChangeReason::POWER_BUTTON);
ASSERT_EQ(false, ret);
DisplayPowerState state = DisplayManager::GetInstance().GetScreenPower(defaultId_);
ASSERT_EQ(state, initialPowerState_);
}
/**
* @tc.name: set_display_state_001
* @tc.desc: Call SetDisplayState with valid value and check the GetDisplayState return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerUnitTest, set_display_state_001, Function | MediumTest | Level2)
{
DisplayState stateToSet = (initialState_ == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF);
Mocker m;
EXPECT_CALL(m.Mock(), RegisterDisplayManagerAgent(_, DisplayManagerAgentType::DISPLAY_STATE_LISTENER))
.Times(1).WillOnce(Return(true));
EXPECT_CALL(m.Mock(), SetDisplayState(stateToSet)).Times(1).WillOnce(Return(true));
DisplayStateCallback callback = [](DisplayState state) {};
bool ret = DisplayManager::GetInstance().SetDisplayState(stateToSet, callback);
ASSERT_EQ(true, ret);
EXPECT_CALL(m.Mock(), GetDisplayState(defaultId_)).Times(1).WillOnce(Return(stateToSet));
DisplayState state = DisplayManager::GetInstance().GetDisplayState(defaultId_);
ASSERT_EQ(state, stateToSet);
}
/**
* @tc.name: set_display_state_002
* @tc.desc: Call SetDisplayState with invalid callback and check the GetDisplayState return value
* @tc.type: FUNC
*/
HWTEST_F(DisplayPowerUnitTest, set_display_state_002, Function | MediumTest | Level2)
{
Mocker m;
EXPECT_CALL(m.Mock(), SetDisplayState(_)).Times(0);
DisplayState stateToSet = (initialState_ == DisplayState::OFF ? DisplayState::ON : DisplayState::OFF);
bool ret = DisplayManager::GetInstance().SetDisplayState(stateToSet, nullptr);
ASSERT_EQ(false, ret);
}
}
}
}

View File

@ -29,6 +29,17 @@ public:
MOCK_METHOD1(DestroyVirtualScreen, DMError(ScreenId screenId));
MOCK_METHOD1(GetDisplaySnapshot, std::shared_ptr<Media::PixelMap>(DisplayId displayId));
MOCK_METHOD0(Clear, void());
MOCK_METHOD2(RegisterDisplayManagerAgent, bool(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type));
MOCK_METHOD2(UnregisterDisplayManagerAgent, bool(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type));
MOCK_METHOD1(WakeUpBegin, bool(PowerStateChangeReason reason));
MOCK_METHOD0(WakeUpEnd, bool());
MOCK_METHOD1(SuspendBegin, bool(PowerStateChangeReason reason));
MOCK_METHOD0(SuspendEnd, bool());
MOCK_METHOD2(SetScreenPowerForAll, bool(DisplayPowerState state, PowerStateChangeReason reason));
MOCK_METHOD1(SetDisplayState, bool(DisplayState state));
MOCK_METHOD1(GetDisplayState, DisplayState(uint64_t displayId));
};
}
} // namespace OHOS

View File

@ -26,9 +26,9 @@ namespace Rosen {
class DisplayManagerAgentController {
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAgentController)
public:
void RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type);
void UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type);
bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status);

View File

@ -56,9 +56,9 @@ public:
virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0;
virtual std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) = 0;
virtual void RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
virtual bool RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type) = 0;
virtual void UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
virtual bool UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type) = 0;
virtual bool WakeUpBegin(PowerStateChangeReason reason) = 0;
virtual bool WakeUpEnd() = 0;

View File

@ -38,9 +38,9 @@ public:
DMError DestroyVirtualScreen(ScreenId screenId) override;
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
void RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type) override;
void UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type) override;
bool WakeUpBegin(PowerStateChangeReason reason) override;
bool WakeUpEnd() override;

View File

@ -46,9 +46,9 @@ public:
DisplayInfo GetDisplayInfoById(DisplayId displayId) override;
std::shared_ptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
void RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type) override;
void UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type) override;
bool WakeUpBegin(PowerStateChangeReason reason) override;
bool WakeUpEnd() override;

View File

@ -23,18 +23,18 @@ namespace {
}
WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController)
void DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
std::lock_guard<std::mutex> lock(mutex_);
dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type);
return dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type);
}
void DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
std::lock_guard<std::mutex> lock(mutex_);
dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type);
return dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type);
}
bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status)

View File

@ -171,7 +171,7 @@ std::shared_ptr<Media::PixelMap> DisplayManagerProxy::GetDispalySnapshot(Display
return pixelMap;
}
void DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
MessageParcel data;
@ -179,25 +179,27 @@ void DisplayManagerProxy::RegisterDisplayManagerAgent(const sptr<IDisplayManager
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
return false;
}
if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
WLOGFE("Write IDisplayManagerAgent failed");
return;
return false;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write DisplayManagerAgent type failed");
return;
return false;
}
if (Remote()->SendRequest(TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
return false;
}
return reply.ReadBool();
}
void DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
MessageParcel data;
@ -205,22 +207,24 @@ void DisplayManagerProxy::UnregisterDisplayManagerAgent(const sptr<IDisplayManag
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
return false;
}
if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
WLOGFE("Write IWindowManagerAgent failed");
return;
return false;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write DisplayManagerAgent type failed");
return;
return false;
}
if (Remote()->SendRequest(TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
return false;
}
return reply.ReadBool();
}
bool DisplayManagerProxy::WakeUpBegin(PowerStateChangeReason reason)

View File

@ -136,24 +136,24 @@ void DisplayManagerService::OnStop()
WLOGFI("ready to stop display service.");
}
void DisplayManagerService::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerService::RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
WLOGFE("displayManagerAgent invalid");
return;
return false;
}
DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type);
return DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type);
}
void DisplayManagerService::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
bool DisplayManagerService::UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent>& displayManagerAgent,
DisplayManagerAgentType type)
{
if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) {
WLOGFE("displayManagerAgent invalid");
return;
return false;
}
DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type);
return DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type);
}
bool DisplayManagerService::WakeUpBegin(PowerStateChangeReason reason)

View File

@ -87,13 +87,13 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
case TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT: {
auto agent = iface_cast<IDisplayManagerAgent>(data.ReadRemoteObject());
auto type = static_cast<DisplayManagerAgentType>(data.ReadUint32());
RegisterDisplayManagerAgent(agent, type);
reply.WriteBool(RegisterDisplayManagerAgent(agent, type));
break;
}
case TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT: {
auto agent = iface_cast<IDisplayManagerAgent>(data.ReadRemoteObject());
auto type = static_cast<DisplayManagerAgentType>(data.ReadUint32());
UnregisterDisplayManagerAgent(agent, type);
reply.WriteBool(UnregisterDisplayManagerAgent(agent, type));
break;
}
case TRANS_ID_WAKE_UP_BEGIN: {

View File

@ -47,8 +47,8 @@ public:
std::shared_ptr<Media::PixelMap> GetScreenshot(DisplayId displayId, const Media::Rect &rect,
const Media::Size &size, int rotation);
void RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener);
void UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener);
bool RegisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener);
bool UnregisterDisplayPowerEventListener(sptr<IDisplayPowerEventListener> listener);
bool WakeUpBegin(PowerStateChangeReason reason);
bool WakeUpEnd();
bool SuspendBegin(PowerStateChangeReason reason);

View File

@ -30,8 +30,8 @@ public:
ClientAgentContainer(std::mutex& mutex);
virtual ~ClientAgentContainer() = default;
void RegisterAgentLocked(const sptr<T1>& agent, T2 type);
void UnregisterAgentLocked(const sptr<T1>& agent, T2 type);
bool RegisterAgentLocked(const sptr<T1>& agent, T2 type);
bool UnregisterAgentLocked(const sptr<T1>& agent, T2 type);
std::vector<sptr<T1>> GetAgentsByType(T2 type);
private:
@ -60,29 +60,27 @@ ClientAgentContainer<T1, T2>::ClientAgentContainer(std::mutex& mutex)
std::bind(&ClientAgentContainer<T1, T2>::RemoveAgent, this, std::placeholders::_1))) {}
template<typename T1, typename T2>
void ClientAgentContainer<T1, T2>::RegisterAgentLocked(const sptr<T1>& agent, T2 type)
bool ClientAgentContainer<T1, T2>::RegisterAgentLocked(const sptr<T1>& agent, T2 type)
{
agentMap_[type].push_back(agent);
WLOG_I("ClientAgentContainer agent registered type:%{public}u", type);
if (deathRecipient_ == nullptr) {
WLOG_I("death Recipient is nullptr");
return;
}
if (!agent->AsObject()->AddDeathRecipient(deathRecipient_)) {
if (deathRecipient_ == nullptr || !agent->AsObject()->AddDeathRecipient(deathRecipient_)) {
WLOG_I("ClientAgentContainer failed to add death recipient");
}
return true;
}
template<typename T1, typename T2>
void ClientAgentContainer<T1, T2>::UnregisterAgentLocked(const sptr<T1>& agent, T2 type)
bool ClientAgentContainer<T1, T2>::UnregisterAgentLocked(const sptr<T1>& agent, T2 type)
{
if (agent == nullptr || agentMap_.count(type) == 0) {
WLOG_E("ClientAgentContainer agent or type is invalid");
return;
return false;
}
auto& agents = agentMap_.at(type);
UnregisterAgentLocked(agents, agent->AsObject());
bool ret = UnregisterAgentLocked(agents, agent->AsObject());
agent->AsObject()->RemoveDeathRecipient(deathRecipient_);
return ret;
}
template<typename T1, typename T2>