diff --git a/frameworks/native/display_power_mgr_client.cpp b/frameworks/native/display_power_mgr_client.cpp index 4b2f261a8104e2e05ae85b6e0cf293b0bd859c1e..470d4eac5a94039013b368089c439f51bfb62151 100644 --- a/frameworks/native/display_power_mgr_client.cpp +++ b/frameworks/native/display_power_mgr_client.cpp @@ -95,7 +95,7 @@ std::vector DisplayPowerMgrClient::GetDisplayIds() { auto proxy = GetProxy(); if (proxy == nullptr) { - return std::vector(); + return {}; } return proxy->GetDisplayIds(); } @@ -104,18 +104,45 @@ int32_t DisplayPowerMgrClient::GetMainDisplayId() { auto proxy = GetProxy(); if (proxy == nullptr) { - return -1; + return INVALID_DISPLAY_ID; } - return proxy->GetMainDisplayId(); + return static_cast(proxy->GetMainDisplayId()); } -bool DisplayPowerMgrClient::SetBrightness(uint32_t value, uint32_t id) +bool DisplayPowerMgrClient::SetBrightness(uint32_t value, uint32_t displayId) { auto proxy = GetProxy(); if (proxy == nullptr) { return false; } - return proxy->SetBrightness(id, value); + return proxy->SetBrightness(value, displayId); +} + +bool DisplayPowerMgrClient::OverrideBrightness(uint32_t value, uint32_t displayId) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return false; + } + return proxy->OverrideBrightness(value, displayId); +} + +bool DisplayPowerMgrClient::RestoreBrightness(uint32_t displayId) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return false; + } + return proxy->RestoreBrightness(displayId); +} + +uint32_t DisplayPowerMgrClient::GetBrightness(uint32_t displayId) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return BRIGHTNESS_OFF; + } + return proxy->GetBrightness(displayId); } bool DisplayPowerMgrClient::AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id) diff --git a/interfaces/innerkits/native/include/display_power_mgr_client.h b/interfaces/innerkits/native/include/display_power_mgr_client.h index e16fa0441b42aab3e53e5e04ef426b31c69d0f7b..068e5ad84e44932d59614fefaa87ecdc988c7f26 100644 --- a/interfaces/innerkits/native/include/display_power_mgr_client.h +++ b/interfaces/innerkits/native/include/display_power_mgr_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -37,7 +37,10 @@ public: DisplayState GetDisplayState(uint32_t id = 0); std::vector GetDisplayIds(); int32_t GetMainDisplayId(); - bool SetBrightness(uint32_t value, uint32_t id = 0); + bool SetBrightness(uint32_t value, uint32_t displayId = 0); + bool OverrideBrightness(uint32_t value, uint32_t displayId = 0); + bool RestoreBrightness(uint32_t displayId = 0); + uint32_t GetBrightness(uint32_t displayId = 0); bool AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id = 0); bool SetStateConfig(DisplayState state, uint32_t value, uint32_t id = 0); bool AutoAdjustBrightness(bool enable); @@ -59,6 +62,8 @@ private: sptr GetProxy(); void OnRemoteDied(const wptr& remote); + static constexpr int32_t INVALID_DISPLAY_ID {-1}; + static constexpr uint32_t BRIGHTNESS_OFF {0}; std::mutex mutex_; sptr proxy_ {nullptr}; diff --git a/interfaces/innerkits/native/include/idisplay_power_mgr.h b/interfaces/innerkits/native/include/idisplay_power_mgr.h index f093dec6dbb610ab17afe6b98dcaf89e9cf93e14..fa6e87181b185dc86550284996026d98ed4c71da 100644 --- a/interfaces/innerkits/native/include/idisplay_power_mgr.h +++ b/interfaces/innerkits/native/include/idisplay_power_mgr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -32,6 +32,9 @@ public: GET_DISPLAY_IDS, GET_MAIN_DISPLAY_ID, SET_BRIGHTNESS, + OVERRIDE_BRIGHTNESS, + RESTORE_BRIGHTNESS, + GET_BRIGHTNESS, ADJUST_BRIGHTNESS, AUTO_ADJUST_BRIGHTNESS, SET_STATE_CONFIG, @@ -42,7 +45,10 @@ public: virtual DisplayState GetDisplayState(uint32_t id) = 0; virtual std::vector GetDisplayIds() = 0; virtual uint32_t GetMainDisplayId() = 0; - virtual bool SetBrightness(uint32_t id, int32_t value) = 0; + virtual bool SetBrightness(uint32_t value, uint32_t displayId) = 0; + virtual bool OverrideBrightness(uint32_t value, uint32_t displayId) = 0; + virtual bool RestoreBrightness(uint32_t displayId) = 0; + virtual uint32_t GetBrightness(uint32_t displayId) = 0; virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) = 0; virtual bool AutoAdjustBrightness(bool enable) = 0; virtual bool SetStateConfig(uint32_t id, DisplayState state, int32_t value) = 0; diff --git a/service/native/include/display_power_mgr_service.h b/service/native/include/display_power_mgr_service.h index 87d09ab0847e16a11d42f782f57f3f9e57b5a695..6559752714f34a7a92e79706ea7dafae2b1c835a 100644 --- a/service/native/include/display_power_mgr_service.h +++ b/service/native/include/display_power_mgr_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -35,7 +35,10 @@ public: virtual DisplayState GetDisplayState(uint32_t id) override; virtual std::vector GetDisplayIds() override; virtual uint32_t GetMainDisplayId() override; - virtual bool SetBrightness(uint32_t id, int32_t value) override; + virtual bool SetBrightness(uint32_t value, uint32_t displayId) override; + virtual bool OverrideBrightness(uint32_t value, uint32_t displayId) override; + virtual bool RestoreBrightness(uint32_t displayId) override; + virtual uint32_t GetBrightness(uint32_t displayId) override; virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) override; virtual bool AutoAdjustBrightness(bool enable) override; virtual bool SetStateConfig(uint32_t id, DisplayState state, int32_t value) override; @@ -59,8 +62,9 @@ private: static constexpr float LUX_CHANGE_STABLE_MIN = 100.0; static const int32_t NIT_MIN = 2; static const int32_t NIT_MAX = 450; - static const int32_t BRIGHTNESS_MIN = 1; - static const int32_t BRIGHTNESS_MAX = 255; + static const uint32_t BRIGHTNESS_OFF = 0; + static const uint32_t BRIGHTNESS_MIN = 1; + static const uint32_t BRIGHTNESS_MAX = 255; static void AmbientLightCallback(SensorEvent *event); friend DelayedSpSingleton; @@ -68,6 +72,7 @@ private: DisplayPowerMgrService(); void InitSensors(); bool IsChangedLux(float scalar); + static uint32_t GetSafeBrightness(uint32_t value); bool CalculateBrightness(float scalar, int32_t& brightness); int32_t GetBrightnessFromLightScalar(float scalar); void ActivateAmbientSensor(); diff --git a/service/native/include/gradual_animator.h b/service/native/include/gradual_animator.h index 8f1d54c1f20849e8efc0af0e1bbb023a6c2636d8..9300cb1944ce0e64d6bcf0b9ef9ed40ffafc036b 100644 --- a/service/native/include/gradual_animator.h +++ b/service/native/include/gradual_animator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -26,24 +26,24 @@ namespace DisplayPowerMgr { class AnimateCallback { public: virtual void OnStart() = 0; - virtual void OnChanged(int32_t currentValue) = 0; + virtual void OnChanged(uint32_t currentValue) = 0; virtual void OnEnd() = 0; }; class GradualAnimator : public std::enable_shared_from_this { public: - GradualAnimator(const std::string& name, std::shared_ptr callback); + GradualAnimator(const std::string& name, const std::shared_ptr& callback); ~GradualAnimator() = default; - void StartAnimation(int32_t from, int32_t to, uint32_t duration); + void StartAnimation(uint32_t from, uint32_t to, uint32_t duration); void StopAnimation(); - bool IsAnimating(); + bool IsAnimating() const; private: static const uint32_t DEFAULT_UPDATE_TIME = 200; static const uint32_t EVENT_STEP = 1; class AnimatorHandler : public AppExecFwk::EventHandler { public: AnimatorHandler(const std::shared_ptr& runner, - std::shared_ptr owner); + const std::shared_ptr& owner); ~AnimatorHandler() = default; void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; private: @@ -55,13 +55,13 @@ private: std::shared_ptr eventRunner_; std::shared_ptr handler_; bool animating_ = false; - int32_t from_; - int32_t to_; + uint32_t fromBrightness_; + uint32_t toBrightness_; uint32_t duration_; uint32_t updateTime_; - uint32_t steps_; + uint32_t totalSteps_; int32_t stride_; - int32_t current_; + uint32_t currentBrightness_; uint32_t currentStep_; }; } // namespace DisplayPowerMgr diff --git a/service/native/include/screen_action.h b/service/native/include/screen_action.h index 6439ef9e29945aea2ceee8c905057f3490f7198a..dfa93bf0d8ed6e4649f571d27d806b033b9396ba 100644 --- a/service/native/include/screen_action.h +++ b/service/native/include/screen_action.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -30,34 +30,17 @@ class ScreenAction { public: ScreenAction(); ~ScreenAction() = default; - uint64_t GetDefaultDisplayId(); - std::vector GetDisplayIds(); - DisplayState GetPowerState(uint64_t devId); - bool SetDisplayState(uint64_t devId, DisplayState state, - std::function callback); - bool SetDisplayPower(uint64_t devId, DisplayState state, uint32_t reason); - uint32_t GetBrightness(uint64_t devId); - bool SetBrightness(uint64_t devId, uint32_t value); + uint32_t GetDefaultDisplayId(); + std::vector GetDisplayIds(); + DisplayState GetPowerState(uint32_t displayId); + bool SetDisplayState(uint32_t displayId, DisplayState state, const std::function &callback); + bool SetDisplayPower(uint32_t displayId, DisplayState state, uint32_t reason); + uint32_t GetBrightness(uint32_t displayId); + bool SetBrightness(uint32_t displayId, uint32_t value); private: - struct DeviceFuncCloser { - void operator()(DeviceFuncs* f) - { - (void)DeviceUninitialize(f); - } - }; - using DeviceFuncPtr = std::unique_ptr; - - static inline int32_t GetValidBrightness(int32_t value) - { - return (value < MIN_BRIGHTNESS) ? MIN_BRIGHTNESS : ((value > MAX_BRIGHTNESS) ? MAX_BRIGHTNESS : value); - } - - static constexpr int32_t MAX_BRIGHTNESS = 255; - static constexpr int32_t MIN_BRIGHTNESS = 6; - - std::vector devIds_; - DeviceFuncPtr hdiFuncs_; + static constexpr uint32_t DEFAULT_DISPLAY_ID = 0; + std::vector displayIds_; }; } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/native/include/screen_controller.h b/service/native/include/screen_controller.h index 3ae5591f2ef440a89370e25fa81cefa5db1e550e..c05c18d7c8cb7d1c0de7e43ef60bfae9841c1a27 100644 --- a/service/native/include/screen_controller.h +++ b/service/native/include/screen_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -29,7 +29,7 @@ class ScreenController : public AnimateCallback, public std::enable_shared_from_this { public: - ScreenController(uint64_t devId, std::shared_ptr action); + ScreenController(uint32_t displayId, std::shared_ptr action); virtual ~ScreenController() = default; DisplayState GetState() @@ -38,23 +38,30 @@ public: }; bool UpdateState(DisplayState state, uint32_t reason); bool UpdateStateConfig(DisplayState state, uint32_t value); - bool UpdateBrightness(uint32_t value, uint32_t duration = 0); - bool IsScreenOn(); + bool SetBrightness(uint32_t value, uint32_t gradualDuration = 0); + bool OverrideBrightness(uint32_t value, uint32_t gradualDuration = SCREEN_BRIGHTNESS_UPDATE_DURATION); + bool RestoreBrightness(uint32_t gradualDuration = SCREEN_BRIGHTNESS_UPDATE_DURATION); uint32_t GetBrightness(); + bool IsScreenOn(); + bool IsBrightnessOverride() const; + uint32_t GetBeforeOverrideBrightness() const; virtual void OnStart() override; - virtual void OnChanged(int32_t currentValue) override; + virtual void OnChanged(uint32_t currentValue) override; virtual void OnEnd() override; private: static const uint32_t SCREEN_BRIGHTNESS_UPDATE_DURATION = 200; void OnStateChanged(DisplayState state); void BeforeUpdateState(DisplayState state); void AfterUpdateState(DisplayState state); + bool UpdateBrightness(uint32_t value, uint32_t gradualDuration); std::mutex mutex_; - const uint64_t devId_; + const uint32_t displayId_; DisplayState state_; std::map stateValues_; uint32_t brightness_ {0}; + bool isBrightnessOverride_ {false}; + uint32_t beforeOverrideBrightness_ {0}; uint32_t beforeOffBrightness_ {0}; uint32_t stateChangeReason_ {0}; std::shared_ptr action_; diff --git a/service/native/src/display_power_mgr_service.cpp b/service/native/src/display_power_mgr_service.cpp index 167d6f526a3c7cc6478857af283760081fbb0b76..66c8dbcc01c213c2b3baac856a87c29e017ebd7e 100644 --- a/service/native/src/display_power_mgr_service.cpp +++ b/service/native/src/display_power_mgr_service.cpp @@ -27,11 +27,11 @@ DisplayPowerMgrService::DisplayPowerMgrService() { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService Create"); action_ = std::make_shared(); - std::vector devIds = action_->GetDisplayIds(); - uint32_t count = devIds.size(); + std::vector displayIds = action_->GetDisplayIds(); + uint32_t count = displayIds.size(); for (uint32_t i = 0; i < count; i++) { - DISPLAY_HILOGI(MODULE_SERVICE, "find display: %{public}d", static_cast(devIds[i])); - controllerMap_.emplace(devIds[i], std::make_shared(devIds[i], action_)); + DISPLAY_HILOGI(MODULE_SERVICE, "find display, id=%{public}u", displayIds[i]); + controllerMap_.emplace(displayIds[i], std::make_shared(displayIds[i], action_)); } callback_ = nullptr; cbDeathRecipient_ = nullptr; @@ -74,27 +74,59 @@ std::vector DisplayPowerMgrService::GetDisplayIds() { DISPLAY_HILOGI(MODULE_SERVICE, "GetDisplayIds"); std::vector ids; - for (auto iter = controllerMap_.begin(); iter != controllerMap_.end(); iter++) { - ids.push_back(iter->first); + for (auto& iter: controllerMap_) { + ids.push_back(iter.first); } return ids; } uint32_t DisplayPowerMgrService::GetMainDisplayId() { - uint64_t id = action_->GetDefaultDisplayId(); - DISPLAY_HILOGI(MODULE_SERVICE, "GetMainDisplayId %{public}d", static_cast(id)); - return static_cast(id); + uint32_t id = action_->GetDefaultDisplayId(); + DISPLAY_HILOGI(MODULE_SERVICE, "GetMainDisplayId %{public}d", id); + return id; } -bool DisplayPowerMgrService::SetBrightness(uint32_t id, int32_t value) +bool DisplayPowerMgrService::SetBrightness(uint32_t value, uint32_t displayId) { - DISPLAY_HILOGI(MODULE_SERVICE, "SetBrightness %{public}d, %{public}d", id, value); - auto iterater = controllerMap_.find(id); - if (iterater == controllerMap_.end()) { + auto brightness = GetSafeBrightness(value); + DISPLAY_HILOGI(MODULE_SERVICE, "SetBrightness displayId=%{public}u, value=%{public}u", displayId, brightness); + auto iter = controllerMap_.find(displayId); + if (iter == controllerMap_.end()) { + return false; + } + return iter->second->SetBrightness(brightness); +} + +bool DisplayPowerMgrService::OverrideBrightness(uint32_t value, uint32_t displayId) +{ + auto brightness = GetSafeBrightness(value); + DISPLAY_HILOGI(MODULE_SERVICE, "OverrideBrightness displayId=%{public}u, value=%{public}u", displayId, brightness); + auto iter = controllerMap_.find(displayId); + if (iter == controllerMap_.end()) { + return false; + } + return iter->second->OverrideBrightness(brightness); +} + +bool DisplayPowerMgrService::RestoreBrightness(uint32_t displayId) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "RestoreBrightness displayId=%{public}u", displayId); + auto iter = controllerMap_.find(displayId); + if (iter == controllerMap_.end()) { return false; } - return iterater->second->UpdateBrightness(value); + return iter->second->RestoreBrightness(); +} + +uint32_t DisplayPowerMgrService::GetBrightness(uint32_t displayId) +{ + DISPLAY_HILOGD(MODULE_SERVICE, "GetBrightness displayId=%{public}u", displayId); + auto iter = controllerMap_.find(displayId); + if (iter == controllerMap_.end()) { + return BRIGHTNESS_OFF; + } + return iter->second->GetBrightness(); } bool DisplayPowerMgrService::AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) @@ -105,7 +137,7 @@ bool DisplayPowerMgrService::AdjustBrightness(uint32_t id, int32_t value, uint32 if (iterater == controllerMap_.end()) { return false; } - return iterater->second->UpdateBrightness(value, duration); + return iterater->second->SetBrightness(value, duration); } bool DisplayPowerMgrService::AutoAdjustBrightness(bool enable) @@ -215,13 +247,20 @@ void DisplayPowerMgrService::NotifyStateChangeCallback(uint32_t displayId, Displ int32_t DisplayPowerMgrService::Dump(int32_t fd, const std::vector& args) { std::string result("DISPLAY POWER MANAGER DUMP:\n"); - for (auto iter = controllerMap_.begin(); iter != controllerMap_.end(); iter++) { + for (auto& iter: controllerMap_) { result.append("Display Id="); - result.append(std::to_string(iter->first)); + result.append(std::to_string(iter.first)); result.append(" State="); - result.append(std::to_string(static_cast(iter->second->GetState()))); - result.append(" Brightness="); - result.append(std::to_string(iter->second->GetBrightness())); + result.append(std::to_string(static_cast(iter.second->GetState()))); + if (!iter.second->IsBrightnessOverride()) { + result.append(" Brightness="); + result.append(std::to_string(iter.second->GetBrightness())); + } else { + result.append(" Brightness="); + result.append(std::to_string(iter.second->GetBeforeOverrideBrightness())); + result.append(" OverrideBrightness="); + result.append(std::to_string(iter.second->GetBrightness())); + } result.append("\n"); } @@ -345,6 +384,20 @@ bool DisplayPowerMgrService::IsChangedLux(float scalar) return false; } +uint32_t DisplayPowerMgrService::GetSafeBrightness(uint32_t value) +{ + auto brightnessValue = value; + if (brightnessValue > BRIGHTNESS_MAX) { + DISPLAY_HILOGW(MODULE_SERVICE, "brightness value is greater than max, value=%{public}u", value); + brightnessValue = BRIGHTNESS_MAX; + } + if (brightnessValue < BRIGHTNESS_MIN) { + DISPLAY_HILOGW(MODULE_SERVICE, "brightness value is less than min, value=%{public}u", value); + brightnessValue = BRIGHTNESS_MIN; + } + return brightnessValue; +} + bool DisplayPowerMgrService::CalculateBrightness(float scalar, int32_t& brightness) { const float lastLux = lastLux_; @@ -377,8 +430,8 @@ int32_t DisplayPowerMgrService::GetBrightnessFromLightScalar(float scalar) } DISPLAY_HILOGI(MODULE_SERVICE, "nit: %{public}d", nit); - int32_t brightness = BRIGHTNESS_MIN - + ((BRIGHTNESS_MAX - BRIGHTNESS_MIN) * (nit - NIT_MIN) / (NIT_MAX - NIT_MIN)); + int32_t brightness = static_cast(BRIGHTNESS_MIN + + ((BRIGHTNESS_MAX - BRIGHTNESS_MIN) * (nit - NIT_MIN) / (NIT_MAX - NIT_MIN))); DISPLAY_HILOGI(MODULE_SERVICE, "brightness: %{public}d", brightness); return brightness; diff --git a/service/native/src/gradual_animator.cpp b/service/native/src/gradual_animator.cpp index c4bf120f712ad0db4ea568d938bbc7f4556d50c2..6cb3c024b6c3607252deb110e444a5a71abb6d3a 100644 --- a/service/native/src/gradual_animator.cpp +++ b/service/native/src/gradual_animator.cpp @@ -21,44 +21,42 @@ namespace OHOS { namespace DisplayPowerMgr { GradualAnimator::GradualAnimator(const std::string& name, - std::shared_ptr callback) + const std::shared_ptr& callback) { - DISPLAY_HILOGD(MODULE_SERVICE, "GradualAnimator construct start"); name_ = name; callback_ = callback; - from_ = 0; - to_ = 0; - current_ = 0; + fromBrightness_ = 0; + toBrightness_ = 0; + currentBrightness_ = 0; duration_ = 0; - steps_ = 0; + totalSteps_ = 0; stride_ = 0; updateTime_ = DEFAULT_UPDATE_TIME; handler_ = nullptr; - DISPLAY_HILOGD(MODULE_SERVICE, "GradualAnimator construct end"); } -void GradualAnimator::StartAnimation(int32_t from, int32_t to, uint32_t duration) +void GradualAnimator::StartAnimation(uint32_t from, uint32_t to, uint32_t duration) { if (animating_) { - DISPLAY_HILOGD(MODULE_SERVICE, "StartAnimation is running..."); + DISPLAY_HILOGD(MODULE_SERVICE, "animation is running, no need to start again"); return; } - DISPLAY_HILOGD(MODULE_SERVICE, - "StartAnimation from=%{public}d, to=%{public}d, duration=%{public}d", + DISPLAY_HILOGD(MODULE_SERVICE, "animation from=%{public}u, to=%{public}u, duration=%{public}u", from, to, duration); if (callback_.lock() == nullptr) { - DISPLAY_HILOGW(MODULE_SERVICE, "Callback is NULL"); + DISPLAY_HILOGW(MODULE_SERVICE, "callback_ is nullptr"); return; } - from_ = from; - to_ = to; - current_ = from_; + fromBrightness_ = from; + toBrightness_ = to; + currentBrightness_ = fromBrightness_; duration_ = duration; - steps_ = duration_ / updateTime_; - if (steps_ < 1) { - steps_ = 1; + totalSteps_ = duration_ / updateTime_; + if (totalSteps_ < 1) { + totalSteps_ = 1; } - stride_ = (to_ - from_) / static_cast(steps_); + stride_ = (static_cast(toBrightness_) - static_cast(fromBrightness_)) / + static_cast(totalSteps_); currentStep_ = 0; if (handler_ == nullptr) { eventRunner_ = AppExecFwk::EventRunner::Create(name_); @@ -72,24 +70,23 @@ void GradualAnimator::StartAnimation(int32_t from, int32_t to, uint32_t duration } animating_ = true; handler_->SendEvent(EVENT_STEP, 0, updateTime_); - DISPLAY_HILOGD(MODULE_SERVICE, "StartAnimation end"); + DISPLAY_HILOGD(MODULE_SERVICE, "animation started"); } void GradualAnimator::StopAnimation() { - DISPLAY_HILOGD(MODULE_SERVICE, "GradualAnimator StopAnimation start"); animating_ = false; handler_->RemoveEvent(EVENT_STEP); if (callback_.lock() == nullptr) { - DISPLAY_HILOGW(MODULE_SERVICE, "Callback is NULL"); + DISPLAY_HILOGW(MODULE_SERVICE, "Callback is nullptr"); return; } std::shared_ptr callback = callback_.lock(); callback->OnEnd(); - DISPLAY_HILOGD(MODULE_SERVICE, "GradualAnimator StopAnimation end"); + DISPLAY_HILOGD(MODULE_SERVICE, "animation stopped"); } -bool GradualAnimator::IsAnimating() +bool GradualAnimator::IsAnimating() const { return animating_; } @@ -97,11 +94,11 @@ bool GradualAnimator::IsAnimating() void GradualAnimator::NextStep() { if (!animating_) { - DISPLAY_HILOGW(MODULE_SERVICE, "NextStep, not animating"); + DISPLAY_HILOGW(MODULE_SERVICE, "is not animating, return"); return; } if (callback_.lock() == nullptr) { - DISPLAY_HILOGW(MODULE_SERVICE, "Callback is NULL"); + DISPLAY_HILOGW(MODULE_SERVICE, "Callback is nullptr"); return; } std::shared_ptr callback = callback_.lock(); @@ -109,23 +106,23 @@ void GradualAnimator::NextStep() if (currentStep_ == 1) { callback->OnStart(); } - if (currentStep_ < steps_) { - current_ = current_ + stride_; - callback->OnChanged(current_); + if (currentStep_ < totalSteps_) { + currentBrightness_ = currentBrightness_ + stride_; + callback->OnChanged(currentBrightness_); handler_->SendEvent(EVENT_STEP, 0, updateTime_); } else { - current_ = to_; - callback->OnChanged(current_); + currentBrightness_ = toBrightness_; + callback->OnChanged(currentBrightness_); callback->OnEnd(); animating_ = false; } - DISPLAY_HILOGD(MODULE_SERVICE, "NextStep: Step=%{public}d, current=%{public}d, stride=%{public}d", - currentStep_, current_, stride_); + DISPLAY_HILOGD(MODULE_SERVICE, "animating next step, step=%{public}u, brightness=%{public}u, stride=%{public}d", + currentStep_, currentBrightness_, stride_); } GradualAnimator::AnimatorHandler::AnimatorHandler( const std::shared_ptr& runner, - std::shared_ptr owner) + const std::shared_ptr& owner) : AppExecFwk::EventHandler(runner), owner_(owner) { DISPLAY_HILOGD(MODULE_SERVICE, "AnimatorHandler is created"); @@ -133,11 +130,10 @@ GradualAnimator::AnimatorHandler::AnimatorHandler( void GradualAnimator::AnimatorHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) { - DISPLAY_HILOGD(MODULE_SERVICE, "AnimatorHandler::%{public}s ,eventid = %d", __func__, - event->GetInnerEventId()); + DISPLAY_HILOGD(MODULE_SERVICE, "process animator event ,eventId = %{public}d", event->GetInnerEventId()); std::shared_ptr animator = owner_.lock(); if (animator == nullptr) { - DISPLAY_HILOGD(MODULE_SERVICE, "AnimatorHandler no object"); + DISPLAY_HILOGD(MODULE_SERVICE, "animator is nullptr"); return; } switch (event->GetInnerEventId()) { diff --git a/service/native/src/screen_action.cpp b/service/native/src/screen_action.cpp index 681feccd55944de56374321d8d0bb7f7bbc9d8bf..0c52fea40bebebf0916afe9924d1343bcf5f994a 100644 --- a/service/native/src/screen_action.cpp +++ b/service/native/src/screen_action.cpp @@ -15,12 +15,9 @@ #include "screen_action.h" -#include "display_common.h" #include "display_manager.h" -#include "display_type.h" #include "hilog_wrapper.h" #include "screen_manager.h" -#include "window_manager_service_client.h" #include "display_power_info.h" namespace OHOS { @@ -30,29 +27,30 @@ ScreenAction::ScreenAction() DISPLAY_HILOGI(MODULE_SERVICE, "Succeed to init"); } -uint64_t ScreenAction::GetDefaultDisplayId() +uint32_t ScreenAction::GetDefaultDisplayId() { - DISPLAY_HILOGI(MODULE_SERVICE, "GetDefaultDisplayId"); - return Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); + uint64_t defaultId = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); + return static_cast(defaultId); } -std::vector ScreenAction::GetDisplayIds() +std::vector ScreenAction::GetDisplayIds() { - DISPLAY_HILOGI(MODULE_SERVICE, "GetDisplayIds"); - devIds_ = Rosen::DisplayManager::GetInstance().GetAllDisplayIds(); - if (devIds_.empty()) { - devIds_.push_back(0); + std::vector allIds = Rosen::DisplayManager::GetInstance().GetAllDisplayIds(); + if (allIds.empty()) { + displayIds_.push_back(DEFAULT_DISPLAY_ID); + return displayIds_; } - return devIds_; + for (const auto& id: allIds) { + displayIds_.push_back(static_cast(id)); + } + return displayIds_; } -DisplayState ScreenAction::GetPowerState(uint64_t devId) +DisplayState ScreenAction::GetPowerState(uint32_t displayId) { - DISPLAY_HILOGI(MODULE_SERVICE, "GetPowerState: %{public}d", static_cast(devId)); - + DISPLAY_HILOGI(MODULE_SERVICE, "GetPowerState of displayId=%{public}u", displayId); DisplayState ret = DisplayState::DISPLAY_UNKNOWN; - Rosen::ScreenPowerState state = Rosen::ScreenManager::GetInstance() - .GetScreenPower(devId); + Rosen::ScreenPowerState state = Rosen::ScreenManager::GetInstance().GetScreenPower(displayId); DISPLAY_HILOGI(MODULE_SERVICE, "GetPowerState: %{public}d", static_cast(state)); switch (state) { case Rosen::ScreenPowerState::POWER_ON: @@ -74,11 +72,11 @@ DisplayState ScreenAction::GetPowerState(uint64_t devId) return ret; } -bool ScreenAction::SetDisplayState(uint64_t devId, DisplayState state, - std::function callback) +bool ScreenAction::SetDisplayState(uint32_t displayId, DisplayState state, + const std::function& callback) { - DISPLAY_HILOGI(MODULE_SERVICE, "SetDisplayState: devId=%{public}d, state=%{public}d", - static_cast(devId), static_cast(state)); + DISPLAY_HILOGI(MODULE_SERVICE, "SetDisplayState: displayId=%{public}u, state=%{public}u", + displayId, static_cast(state)); Rosen::DisplayState rds = Rosen::DisplayState::UNKNOWN; switch (state) { @@ -112,10 +110,10 @@ bool ScreenAction::SetDisplayState(uint64_t devId, DisplayState state, return ret; } -bool ScreenAction::SetDisplayPower(uint64_t devId, DisplayState state, uint32_t reason) +bool ScreenAction::SetDisplayPower(uint32_t displayId, DisplayState state, uint32_t reason) { - DISPLAY_HILOGI(MODULE_SERVICE, "SetDisplayPower: devId=%{public}d, state=%{public}d, state=%{public}d", - static_cast(devId), static_cast(state), reason); + DISPLAY_HILOGI(MODULE_SERVICE, "SetDisplayPower: displayId=%{public}u, state=%{public}u, state=%{public}u", + displayId, static_cast(state), reason); Rosen::ScreenPowerState status = Rosen::ScreenPowerState::INVALID_STATE; switch (state) { case DisplayState::DISPLAY_ON: @@ -139,19 +137,17 @@ bool ScreenAction::SetDisplayPower(uint64_t devId, DisplayState state, uint32_t return true; } -uint32_t ScreenAction::GetBrightness(uint64_t devId) +uint32_t ScreenAction::GetBrightness(uint32_t displayId) { - DISPLAY_HILOGI(MODULE_SERVICE, "GetBrightness: %{public}d", static_cast(devId)); - return Rosen::DisplayManager::GetInstance() - .GetScreenBrightness(static_cast(devId)); + auto brightness = Rosen::DisplayManager::GetInstance().GetScreenBrightness(displayId); + DISPLAY_HILOGD(MODULE_SERVICE, "displayId=%{public}u, brightness=%{public}u", displayId, brightness); + return brightness; } -bool ScreenAction::SetBrightness(uint64_t devId, uint32_t value) +bool ScreenAction::SetBrightness(uint32_t displayId, uint32_t value) { - DISPLAY_HILOGI(MODULE_SERVICE, "SetBrightness: %{public}d, %{public}d", - static_cast(devId), value); - return Rosen::DisplayManager::GetInstance() - .SetScreenBrightness(static_cast(devId), value); + DISPLAY_HILOGI(MODULE_SERVICE, "displayId=%{public}u, brightness=%{public}u", displayId, value); + return Rosen::DisplayManager::GetInstance().SetScreenBrightness(displayId, value); } } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/native/src/screen_controller.cpp b/service/native/src/screen_controller.cpp index 28610a1ab7ec015b78a910b9997cccce45b5d891..a776dcc5c79e11d90a515e32017d0b6f4cac051b 100644 --- a/service/native/src/screen_controller.cpp +++ b/service/native/src/screen_controller.cpp @@ -15,7 +15,6 @@ #include "screen_controller.h" -#include "display_common.h" #include "display_power_mgr_service.h" #include "hilog_wrapper.h" @@ -26,10 +25,10 @@ const int DISPLAY_DIM_BRIGHTNESS = 50; const int DISPLAY_OFF_BRIGHTNESS = 0; const int DISPLAY_SUSPEND_BRIGHTNESS = 50; -ScreenController::ScreenController(uint64_t devId, std::shared_ptr action) - : devId_(devId), state_(DisplayState::DISPLAY_UNKNOWN), action_(action) +ScreenController::ScreenController(uint32_t displayId, std::shared_ptr action) + : displayId_(displayId), state_(DisplayState::DISPLAY_UNKNOWN), action_(std::move(action)) { - DISPLAY_HILOGI(MODULE_SERVICE, "ScreenController created: %{public}d", static_cast(devId_)); + DISPLAY_HILOGI(MODULE_SERVICE, "ScreenController created for displayId=%{public}u", displayId_); stateValues_.emplace(DisplayState::DISPLAY_ON, DISPLAY_FULL_BRIGHTNESS); stateValues_.emplace(DisplayState::DISPLAY_DIM, DISPLAY_DIM_BRIGHTNESS); stateValues_.emplace(DisplayState::DISPLAY_OFF, DISPLAY_OFF_BRIGHTNESS); @@ -40,8 +39,9 @@ ScreenController::ScreenController(uint64_t devId, std::shared_ptr bool ScreenController::UpdateState(DisplayState state, uint32_t reason) { std::lock_guard lock(mutex_); - DISPLAY_HILOGI(MODULE_SERVICE, "ScreenController UpdateState: %{public}d, %{public}d", - static_cast(devId_), static_cast(state)); + DISPLAY_HILOGI(MODULE_SERVICE, + "ScreenController UpdateState, displayId=%{public}u, state=%{public}u, state_=%{public}u", + displayId_, static_cast(state), static_cast(state_)); if (state == state_) { return true; } @@ -52,7 +52,7 @@ bool ScreenController::UpdateState(DisplayState state, uint32_t reason) BeforeUpdateState(state); std::function callback = std::bind(&ScreenController::OnStateChanged, this, std::placeholders::_1); - bool ret = action_->SetDisplayState(devId_, state, callback); + bool ret = action_->SetDisplayState(displayId_, state, callback); if (!ret) { DISPLAY_HILOGW(MODULE_SERVICE, "SetDisplayState failed state=%{public}d", state); return ret; @@ -62,7 +62,7 @@ bool ScreenController::UpdateState(DisplayState state, uint32_t reason) } case DisplayState::DISPLAY_DIM: // fall through case DisplayState::DISPLAY_SUSPEND: { - bool ret = action_->SetDisplayPower(devId_, state, stateChangeReason_); + bool ret = action_->SetDisplayPower(displayId_, state, stateChangeReason_); if (!ret) { DISPLAY_HILOGW(MODULE_SERVICE, "SetDisplayPower failed state=%{public}d", state); return ret; @@ -83,7 +83,7 @@ bool ScreenController::UpdateState(DisplayState state, uint32_t reason) void ScreenController::BeforeUpdateState(DisplayState state) { if (state == DisplayState::DISPLAY_OFF) { - beforeOffBrightness_ = action_->GetBrightness(devId_); + beforeOffBrightness_ = action_->GetBrightness(displayId_); beforeOffBrightness_ = (beforeOffBrightness_ <= DISPLAY_OFF_BRIGHTNESS || beforeOffBrightness_ > DISPLAY_FULL_BRIGHTNESS) ? DISPLAY_FULL_BRIGHTNESS : beforeOffBrightness_; @@ -95,49 +95,90 @@ void ScreenController::BeforeUpdateState(DisplayState state) void ScreenController::AfterUpdateState(DisplayState state) { if (state == DisplayState::DISPLAY_ON) { - bool ret = action_->SetBrightness(devId_, beforeOffBrightness_); + bool ret = action_->SetBrightness(displayId_, beforeOffBrightness_); DISPLAY_HILOGI(MODULE_SERVICE, "Is SetBrightness %{public}d, \ - Update brightness to %{public}d", ret, beforeOffBrightness_); + Update brightness to %{public}u", ret, beforeOffBrightness_); } } -bool ScreenController::UpdateBrightness(uint32_t value, uint32_t duraion) +bool ScreenController::UpdateBrightness(uint32_t value, uint32_t gradualDuration) { std::lock_guard lock(mutex_); - DISPLAY_HILOGI(MODULE_SERVICE, "ScreenController UpdateBrightness: %{public}d, %{public}d, %{public}d", - static_cast(devId_), value, duraion); + DISPLAY_HILOGI(MODULE_SERVICE, "Update brightness, displayId=%{public}u, value=%{public}u, duration=%{public}u", + displayId_, value, gradualDuration); if (animator_ == nullptr) { - std::string name = "ScreenController_" + std::to_string(devId_); + std::string name = "ScreenController_" + std::to_string(displayId_); std::shared_ptr callback = shared_from_this(); animator_ = std::make_shared(name, callback); } if (animator_->IsAnimating()) { animator_->StopAnimation(); } - if (duraion > 0) { - DISPLAY_HILOGI(MODULE_SERVICE, "UpdateState gradually"); - animator_->StartAnimation(brightness_, value, duraion); + if (gradualDuration > 0) { + DISPLAY_HILOGI(MODULE_SERVICE, "Update brightness gradually"); + animator_->StartAnimation(brightness_, value, gradualDuration); return true; } - bool ret = action_->SetBrightness(devId_, value); + bool ret = action_->SetBrightness(displayId_, value); if (ret) { brightness_ = value; - DISPLAY_HILOGI(MODULE_SERVICE, "Update brightness to %{public}d", value); + DISPLAY_HILOGI(MODULE_SERVICE, "Updated brightness, value=%{public}u", value); } else { - DISPLAY_HILOGI(MODULE_SERVICE, "Update brightness falied! %{public}d", value); + DISPLAY_HILOGI(MODULE_SERVICE, "Updated brightness failed, value=%{public}u", value); } return ret; } +bool ScreenController::SetBrightness(uint32_t value, uint32_t gradualDuration) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "Set brightness, value=%{public}u", value); + if (isBrightnessOverride_) { + DISPLAY_HILOGI(MODULE_SERVICE, "brightness is override, ignore the change"); + return false; + } + return UpdateBrightness(value, gradualDuration); +} + +bool ScreenController::OverrideBrightness(uint32_t value, uint32_t gradualDuration) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "Override brightness, value=%{public}u", value); + if (!isBrightnessOverride_) { + isBrightnessOverride_ = true; + beforeOverrideBrightness_ = brightness_; + DISPLAY_HILOGI(MODULE_SERVICE, "Confirm override brightness, brightness_=%{public}u", brightness_); + } + return UpdateBrightness(value, gradualDuration); +} + +bool ScreenController::RestoreBrightness(uint32_t gradualDuration) +{ + if (!isBrightnessOverride_) { + DISPLAY_HILOGD(MODULE_SERVICE, "Brightness is not override, no need to restore"); + return false; + } + isBrightnessOverride_ = false; + DISPLAY_HILOGI(MODULE_SERVICE, "Restore brightness to value=%{public}u", beforeOverrideBrightness_); + return UpdateBrightness(beforeOverrideBrightness_, gradualDuration); +} + +uint32_t ScreenController::GetBrightness() +{ + std::lock_guard lock(mutex_); + if (brightness_ == DISPLAY_OFF_BRIGHTNESS) { + brightness_ = action_->GetBrightness(displayId_); + } + return brightness_; +} + bool ScreenController::UpdateStateConfig(DisplayState state, uint32_t value) { std::lock_guard lock(mutex_); DISPLAY_HILOGI(MODULE_SERVICE, - "ScreenController UpdateStateConfig: Id=%{public}d, State=%{public}d, Value=%{public}d", - static_cast(devId_), static_cast(state), value); + "ScreenController UpdateStateConfig, displayId=%{public}u, state=%{public}u, value=%{public}u", + displayId_, static_cast(state), value); auto iterator = stateValues_.find(state); if (iterator == stateValues_.end()) { - DISPLAY_HILOGI(MODULE_SERVICE, "UpdateStateConfig No such state"); + DISPLAY_HILOGI(MODULE_SERVICE, "UpdateStateConfig no such state"); return false; } iterator->second = value; @@ -150,13 +191,14 @@ bool ScreenController::IsScreenOn() return (state_ == DisplayState::DISPLAY_ON || state_ == DisplayState::DISPLAY_DIM); } -uint32_t ScreenController::GetBrightness() +bool ScreenController::IsBrightnessOverride() const { - std::lock_guard lock(mutex_); - if (brightness_ == 0) { - brightness_ = action_->GetBrightness(devId_); - } - return brightness_; + return isBrightnessOverride_; +} + +uint32_t ScreenController::GetBeforeOverrideBrightness() const +{ + return beforeOverrideBrightness_; } void ScreenController::OnStart() @@ -164,14 +206,14 @@ void ScreenController::OnStart() DISPLAY_HILOGD(MODULE_SERVICE, "ScreenAnimatorCallback onStart"); } -void ScreenController::OnChanged(int32_t currentValue) +void ScreenController::OnChanged(uint32_t currentValue) { brightness_ = static_cast(currentValue); - bool ret = action_->SetBrightness(devId_, brightness_); + bool ret = action_->SetBrightness(displayId_, brightness_); if (ret) { - DISPLAY_HILOGD(MODULE_SERVICE, "Update brightness to %{public}d", brightness_); + DISPLAY_HILOGD(MODULE_SERVICE, "Update brightness, brightness_=%{public}u", brightness_); } else { - DISPLAY_HILOGD(MODULE_SERVICE, "Update brightness falied! %{public}d", brightness_); + DISPLAY_HILOGD(MODULE_SERVICE, "Update brightness failed, brightness_=%{public}d", brightness_); } } @@ -182,16 +224,16 @@ void ScreenController::OnEnd() void ScreenController::OnStateChanged(DisplayState state) { - DISPLAY_HILOGD(MODULE_SERVICE, "OnStateChanged %{public}d", state); + DISPLAY_HILOGD(MODULE_SERVICE, "OnStateChanged %{public}u", static_cast(state)); auto pms = DelayedSpSingleton::GetInstance(); if (pms == nullptr) { DISPLAY_HILOGI(MODULE_SERVICE, "OnRemoteDied no service"); return; } - bool ret = action_->SetDisplayPower(devId_, state, stateChangeReason_); + bool ret = action_->SetDisplayPower(displayId_, state, stateChangeReason_); if (ret) { - pms->NotifyStateChangeCallback(devId_, state); + pms->NotifyStateChangeCallback(displayId_, state); } } } // namespace DisplayPowerMgr diff --git a/service/zidl/include/display_power_mgr_proxy.h b/service/zidl/include/display_power_mgr_proxy.h index 8d8e5bfb631809aefd915928c06a93c5af7c9565..24139c5f1205eeabf4ea58ff0dc515ad0c1191f7 100644 --- a/service/zidl/include/display_power_mgr_proxy.h +++ b/service/zidl/include/display_power_mgr_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -33,7 +33,10 @@ public: virtual std::vector GetDisplayIds() override; virtual uint32_t GetMainDisplayId() override; - virtual bool SetBrightness(uint32_t id, int32_t value) override; + virtual bool SetBrightness(uint32_t value, uint32_t displayId) override; + virtual bool OverrideBrightness(uint32_t value, uint32_t displayId) override; + virtual bool RestoreBrightness(uint32_t displayId) override; + virtual uint32_t GetBrightness(uint32_t displayId) override; virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) override; virtual bool AutoAdjustBrightness(bool enable) override; virtual bool SetStateConfig(uint32_t id, DisplayState state, int32_t value) override; diff --git a/service/zidl/include/display_power_mgr_stub.h b/service/zidl/include/display_power_mgr_stub.h index 726833930cb225425ec7724bde66f6807d8b61dd..6f342dfba32a75a112859e13efe56bcb25fb328f 100644 --- a/service/zidl/include/display_power_mgr_stub.h +++ b/service/zidl/include/display_power_mgr_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -32,6 +32,9 @@ private: int32_t GetDisplayIdsStub(MessageParcel& data, MessageParcel& reply); int32_t GetMainDisplayIdStub(MessageParcel& data, MessageParcel& reply); int32_t SetBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t OverrideBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t RestoreBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t GetBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t AutoAdjustBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t SetStateConfigStub(MessageParcel& data, MessageParcel& reply); diff --git a/service/zidl/src/display_power_mgr_proxy.cpp b/service/zidl/src/display_power_mgr_proxy.cpp index 5783118525e6c4b0360b2df50307e30e9192c0b1..54e21e2c1113f83bebb0510c9c740db803128e32 100644 --- a/service/zidl/src/display_power_mgr_proxy.cpp +++ b/service/zidl/src/display_power_mgr_proxy.cpp @@ -158,7 +158,7 @@ uint32_t DisplayPowerMgrProxy::GetMainDisplayId() return result; } -bool DisplayPowerMgrProxy::SetBrightness(uint32_t id, int32_t value) +bool DisplayPowerMgrProxy::SetBrightness(uint32_t value, uint32_t displayId) { sptr remote = Remote(); RETURN_IF_WITH_RET(remote == nullptr, false); @@ -173,13 +173,47 @@ bool DisplayPowerMgrProxy::SetBrightness(uint32_t id, int32_t value) return result; } - WRITE_PARCEL_WITH_RET(data, Uint32, id, false); - WRITE_PARCEL_WITH_RET(data, Int32, value, false); + WRITE_PARCEL_WITH_RET(data, Uint32, value, false); + WRITE_PARCEL_WITH_RET(data, Uint32, displayId, false); - int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::SET_BRIGHTNESS), + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::SET_BRIGHTNESS), data, reply, option); if (ret != ERR_OK) { - DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s SendRequest is failed: %d", __func__, ret); + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s SendRequest is failed: %{public}d", __func__, + ret); + return result; + } + + if (!reply.ReadBool(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return result; + } + + return result; +} + +bool DisplayPowerMgrProxy::OverrideBrightness(uint32_t value, uint32_t displayId) +{ + sptr remote = Remote(); + RETURN_IF_WITH_RET(remote == nullptr, false); + + bool result = false; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(DisplayPowerMgrProxy::GetDescriptor())) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s write descriptor failed!", __func__); + return result; + } + + WRITE_PARCEL_WITH_RET(data, Uint32, value, false); + WRITE_PARCEL_WITH_RET(data, Uint32, displayId, false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::OVERRIDE_BRIGHTNESS), data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s SendRequest is failed: %{public}d", __func__, + ret); return result; } @@ -225,6 +259,72 @@ bool DisplayPowerMgrProxy::AdjustBrightness(uint32_t id, int32_t value, uint32_t return result; } +bool DisplayPowerMgrProxy::RestoreBrightness(uint32_t displayId) +{ + sptr remote = Remote(); + uint32_t result = 0; + + RETURN_IF_WITH_RET(remote == nullptr, result); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(DisplayPowerMgrProxy::GetDescriptor())) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return result; + } + + WRITE_PARCEL_WITH_RET(data, Uint32, displayId, false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::RESTORE_BRIGHTNESS), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return result; + } + + return result; +} + +uint32_t DisplayPowerMgrProxy::GetBrightness(uint32_t displayId) +{ + sptr remote = Remote(); + uint32_t result = 0; + + RETURN_IF_WITH_RET(remote == nullptr, result); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(DisplayPowerMgrProxy::GetDescriptor())) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return result; + } + + WRITE_PARCEL_WITH_RET(data, Uint32, displayId, false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::GET_BRIGHTNESS), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return result; + } + + return result; +} + bool DisplayPowerMgrProxy::AutoAdjustBrightness(bool enable) { sptr remote = Remote(); diff --git a/service/zidl/src/display_power_mgr_stub.cpp b/service/zidl/src/display_power_mgr_stub.cpp index 951114ecbec3e78b95ff90c11a160578f9869aa0..b9c6698c17dda41c30677d3d2fbb6e4ccddaf1b2 100644 --- a/service/zidl/src/display_power_mgr_stub.cpp +++ b/service/zidl/src/display_power_mgr_stub.cpp @@ -54,6 +54,15 @@ int32_t DisplayPowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case static_cast(IDisplayPowerMgr::SET_BRIGHTNESS): ret = SetBrightnessStub(data, reply); break; + case static_cast(IDisplayPowerMgr::OVERRIDE_BRIGHTNESS): + ret = OverrideBrightnessStub(data, reply); + break; + case static_cast(IDisplayPowerMgr::RESTORE_BRIGHTNESS): + ret = RestoreBrightnessStub(data, reply); + break; + case static_cast(IDisplayPowerMgr::GET_BRIGHTNESS): + ret = GetBrightnessStub(data, reply); + break; case static_cast(IDisplayPowerMgr::ADJUST_BRIGHTNESS): ret = AdjustBrightnessStub(data, reply); break; @@ -131,13 +140,13 @@ int32_t DisplayPowerMgrStub::GetMainDisplayIdStub(MessageParcel& data, MessagePa int32_t DisplayPowerMgrStub::SetBrightnessStub(MessageParcel& data, MessageParcel& reply) { - uint32_t id = 0; - int32_t value = 0; + uint32_t value = 0; + uint32_t displayId = 0; - READ_PARCEL_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR); - READ_PARCEL_WITH_RET(data, Int32, value, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Uint32, value, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR); - bool ret = SetBrightness(id, value); + bool ret = SetBrightness(value, displayId); if (!reply.WriteBool(ret)) { DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write SetBrightness return value"); return E_WRITE_PARCEL_ERROR; @@ -145,6 +154,50 @@ int32_t DisplayPowerMgrStub::SetBrightnessStub(MessageParcel& data, MessageParce return ERR_OK; } +int32_t DisplayPowerMgrStub::OverrideBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t value = 0; + uint32_t displayId = 0; + + READ_PARCEL_WITH_RET(data, Uint32, value, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR); + + bool ret = OverrideBrightness(value, displayId); + if (!reply.WriteBool(ret)) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write OverrideBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::RestoreBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t displayId = 0; + + READ_PARCEL_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR); + + bool ret = RestoreBrightness(displayId); + if (!reply.WriteBool(ret)) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write RestoreBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::GetBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t displayId = 0; + + READ_PARCEL_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR); + + uint32_t ret = GetBrightness(displayId); + if (!reply.WriteUint32(ret)) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write GetBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + int32_t DisplayPowerMgrStub::AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply) { uint32_t id = 0; diff --git a/test/native/unittest/BUILD.gn b/test/native/unittest/BUILD.gn index 7ab4d05089bd8bd323e8f5df512ff99c92884577..b34ee36f7a046b1ac2be579fd202b9867a876af0 100644 --- a/test/native/unittest/BUILD.gn +++ b/test/native/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -33,7 +33,10 @@ config("module_private_config") { ohos_unittest("unittest_display_mgr_service") { module_out_path = module_output_path - sources = [ "src/display_power_mgr_service_test.cpp" ] + sources = [ + "src/display_power_mgr_brightness_test.cpp", + "src/display_power_mgr_service_test.cpp", + ] configs = [ "${displaymgr_utils_path}:utils_config", diff --git a/test/native/unittest/src/display_power_mgr_brightness_test.cpp b/test/native/unittest/src/display_power_mgr_brightness_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a9cc25db3050d6fec8378f4599805f33e34c29e1 --- /dev/null +++ b/test/native/unittest/src/display_power_mgr_brightness_test.cpp @@ -0,0 +1,130 @@ +/* + * 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 +#include "display_power_mgr_client.h" +#include "hilog_wrapper.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::DisplayPowerMgr; + +class DisplayPowerMgrBrightnessTest : public Test { +public: + void SetUp() + { + DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON); + } + + void TearDown() + { + DisplayPowerMgrClient::GetInstance().RestoreBrightness(); + sleep(1); // wait for gradual animation + } +}; + +namespace { +/** + * @tc.name: DisplayPowerMgrBrightness001 + * @tc.desc: Test SetBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBrightness001, TestSize.Level0) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness001: fun is start"); + bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(100); + EXPECT_TRUE(ret); + sleep(1); // wait for gradual animation + uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + EXPECT_EQ(value, 100); + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness001: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrBrightness002 + * @tc.desc: Test OverrideBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBrightness002, TestSize.Level0) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness002: fun is start"); + bool ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(255); + EXPECT_TRUE(ret); + sleep(1); // wait for gradual animation + uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + EXPECT_EQ(value, 255); + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness002: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrBrightness003 + * @tc.desc: Test RestoreBrightness after OverrideBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBrightness003, TestSize.Level0) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness003: fun is start"); + bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(100); + EXPECT_TRUE(ret); + sleep(1); // wait for gradual animation + ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(255); + EXPECT_TRUE(ret); + sleep(1); // wait for gradual animation + uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + EXPECT_EQ(value, 255); + ret = DisplayPowerMgrClient::GetInstance().RestoreBrightness(); // restore + EXPECT_TRUE(ret); + sleep(1); // wait for gradual animation + value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + EXPECT_EQ(value, 100); + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness003: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrBrightness004 + * @tc.desc: Test SetBrightness after OverrideBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBrightness004, TestSize.Level0) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness004: fun is start"); + bool ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(255); + EXPECT_TRUE(ret); + sleep(1); // wait for gradual animation + ret = DisplayPowerMgrClient::GetInstance().SetBrightness(100); + EXPECT_FALSE(ret); + sleep(1); // wait for gradual animation + uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + EXPECT_EQ(value, 255); + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness004: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrBrightness005 + * @tc.desc: Test RestoreBrightness after not override + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBrightness005, TestSize.Level0) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness005: fun is start"); + bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(100); + EXPECT_TRUE(ret); + sleep(1); // wait for gradual animation + uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + EXPECT_EQ(value, 100); + DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrBrightness005: fun is end"); +} +} \ No newline at end of file diff --git a/test/native/unittest/src/display_power_mgr_service_test.cpp b/test/native/unittest/src/display_power_mgr_service_test.cpp index 2835727373be8598b6df26dcf0a2777fe696eb83..2dc86071beac7b0d86fddc7c573ac69551dfacc9 100644 --- a/test/native/unittest/src/display_power_mgr_service_test.cpp +++ b/test/native/unittest/src/display_power_mgr_service_test.cpp @@ -48,7 +48,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService01, TestSize.Level0) HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService002, TestSize.Level0) { auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); - sleep(5); + sleep(1); EXPECT_TRUE(ret); } @@ -60,7 +60,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService002, TestSize.Level0) HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService003, TestSize.Level0) { auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON); - sleep(5); + sleep(1); EXPECT_TRUE(ret); } @@ -72,7 +72,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService003, TestSize.Level0) HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService004, TestSize.Level0) { auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_DIM); - sleep(5); + sleep(1); EXPECT_TRUE(ret); } @@ -84,7 +84,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService004, TestSize.Level0) HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService005, TestSize.Level0) { auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_SUSPEND); - sleep(5); + sleep(1); EXPECT_TRUE(ret); } @@ -96,7 +96,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService005, TestSize.Level0) HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService006, TestSize.Level0) { auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_UNKNOWN); - sleep(5); + sleep(1); EXPECT_TRUE(ret); } @@ -111,15 +111,15 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService007, TestSize.Level0) DISPLAY_HILOGI(MODULE_SERVICE, "SetBrightness: fun is start"); DISPLAY_HILOGI(MODULE_SERVICE, "SetBrightness: set 5"); auto ret = DisplayPowerMgrClient::GetInstance().SetBrightness(5); - sleep(5); + sleep(1); EXPECT_TRUE(ret); DISPLAY_HILOGI(MODULE_SERVICE, "SetBrightness: set 155"); ret = DisplayPowerMgrClient::GetInstance().SetBrightness(155); - sleep(5); + sleep(1); EXPECT_TRUE(ret); DISPLAY_HILOGI(MODULE_SERVICE, "SetBrightness: set 255"); ret = DisplayPowerMgrClient::GetInstance().SetBrightness(255); - sleep(5); + sleep(1); EXPECT_TRUE(ret); } #endif @@ -134,7 +134,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService008, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService008: fun is start"); auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON); - sleep(5); + sleep(1); if (false) { EXPECT_TRUE(ret); DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); @@ -151,7 +151,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService009, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService009: fun is start"); auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_DIM); - sleep(5); + sleep(1); EXPECT_TRUE(ret); DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService009: GetDisplayState"); DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); @@ -167,7 +167,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService010, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService010: fun is start"); auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); - sleep(5); + sleep(1); EXPECT_TRUE(ret); DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService010: GetDisplayState"); DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); @@ -183,7 +183,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService011, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService011: fun is start"); auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_SUSPEND); - sleep(5); + sleep(1); EXPECT_TRUE(ret); DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService011: GetDisplayState"); DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); @@ -199,7 +199,7 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService012, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService012: fun is start"); auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_UNKNOWN); - sleep(5); + sleep(1); EXPECT_TRUE(ret); DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService012: GetDisplayState"); DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); @@ -215,33 +215,33 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService013, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService013: fun is start"); std::vector ret = DisplayPowerMgrClient::GetInstance().GetDisplayIds(); - sleep(5); + sleep(1); EXPECT_TRUE(ret.size() != 0); } /** * @tc.name: DisplayPowerMgrService014 - * @tc.desc: Test GetDisplayIds + * @tc.desc: Test GetMainDisplayId * @tc.type: FUNC */ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService014, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService014: fun is start"); int32_t ret = DisplayPowerMgrClient::GetInstance().GetMainDisplayId(); - sleep(5); + sleep(1); EXPECT_TRUE(ret == 0); } /** * @tc.name: DisplayPowerMgrService015 - * @tc.desc: Test GetDisplayIds + * @tc.desc: Test AutoAdjustBrightness * @tc.type: FUNC */ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService015, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService015: fun is start"); bool ret = DisplayPowerMgrClient::GetInstance().AutoAdjustBrightness(true); - sleep(5); + sleep(1); if (ret) { DISPLAY_HILOGI(MODULE_SERVICE, "AutoAdjustBrightness: is supported"); ret = DisplayPowerMgrClient::GetInstance().AutoAdjustBrightness(false); @@ -254,14 +254,14 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService015, TestSize.Level0) /** * @tc.name: DisplayPowerMgrService016 - * @tc.desc: Test GetDisplayIds + * @tc.desc: Test AdjustBrightness * @tc.type: FUNC */ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService016, TestSize.Level0) { DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService016: fun is start"); bool ret = DisplayPowerMgrClient::GetInstance().AdjustBrightness(0, 3000); - sleep(5); + sleep(1); EXPECT_TRUE(ret); DISPLAY_HILOGI(MODULE_SERVICE, "DisplayPowerMgrService016: fun is end"); }