diff --git a/displaymgr.gni b/displaymgr.gni index be864029485b7b715fb534468f33798c2538dfa2..af29775bd40f25d967702986f52e3eea7ea5165d 100644 --- a/displaymgr.gni +++ b/displaymgr.gni @@ -17,6 +17,8 @@ displaymgr_native_part_name = "display_manager_native" displaymgr_root_path = "//base/powermgr/display_manager" +displaymgr_framework_path = "${displaymgr_root_path}/frameworks" + displaymgr_service_path = "${displaymgr_root_path}/service" displaymgr_interfaces_path = "${displaymgr_root_path}/interfaces" diff --git a/interfaces/kits/js/napi/brightness.cpp b/frameworks/napi/brightness.cpp similarity index 95% rename from interfaces/kits/js/napi/brightness.cpp rename to frameworks/napi/brightness.cpp index fa1bb0bcda4c945cf0c9f4c8af5414d58b0d3e15..b4bc8caa3915f167417974657382011e13027172 100644 --- a/interfaces/kits/js/napi/brightness.cpp +++ b/frameworks/napi/brightness.cpp @@ -20,10 +20,10 @@ #include #include -#include "display_manager.h" +#include "display_power_mgr_client.h" #include "hilog_wrapper.h" -using namespace OHOS::DisplayMgr; +using namespace OHOS::DisplayPowerMgr; struct BrightnessAsyncCallbackInfo { napi_env env; @@ -66,7 +66,7 @@ static napi_value SetValue(napi_env env, napi_callback_info info) resourceName, [](napi_env env, void *data) { BrightnessAsyncCallbackInfo* asyncCallbackInfo = (BrightnessAsyncCallbackInfo *)data; - if (!DisplayManager::SetBrightness(asyncCallbackInfo->value)) { + if (!DisplayPowerMgrClient::GetInstance().SetBrightness(asyncCallbackInfo->value)) { DISPLAY_HILOGE(MODULE_JS_NAPI, "Failed to set brightness"); } else { DISPLAY_HILOGD(MODULE_JS_NAPI, "Succeed to set brightness"); diff --git a/interfaces/innerkits/native/src/display_mgr_client.cpp b/frameworks/native/display_power_mgr_client.cpp similarity index 63% rename from interfaces/innerkits/native/src/display_mgr_client.cpp rename to frameworks/native/display_power_mgr_client.cpp index e3ee056db87db8198172f5fc6fc345f054a5c654..94e59c8bd1466f17d6d2eb767969be3808b2c749 100644 --- a/interfaces/innerkits/native/src/display_mgr_client.cpp +++ b/frameworks/native/display_power_mgr_client.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "display_mgr_client.h" +#include "display_power_mgr_client.h" #include #include @@ -22,11 +22,11 @@ #include "display_common.h" namespace OHOS { -namespace DisplayMgr { -DisplayMgrClient::DisplayMgrClient() = default; -DisplayMgrClient::~DisplayMgrClient() = default; +namespace DisplayPowerMgr { +DisplayPowerMgrClient::DisplayPowerMgrClient() = default; +DisplayPowerMgrClient::~DisplayPowerMgrClient() = default; -sptr DisplayMgrClient::GetProxy() +sptr DisplayPowerMgrClient::GetProxy() { std::lock_guard lock(mutex_); if (proxy_ != nullptr) { @@ -49,13 +49,13 @@ sptr DisplayMgrClient::GetProxy() return nullptr; } - proxy_ = iface_cast(obj); + proxy_ = iface_cast(obj); deathRecipient_ = dr; DISPLAY_HILOGI(MODULE_INNERKIT, "Succeed to connect display manager service"); return proxy_; } -void DisplayMgrClient::OnRemoteDied(const wptr& remote) +void DisplayPowerMgrClient::OnRemoteDied(const wptr& remote) { if (remote == nullptr) { DISPLAY_HILOGE(MODULE_INNERKIT, "OnRemoteDied failed, remote is nullptr"); @@ -72,22 +72,49 @@ void DisplayMgrClient::OnRemoteDied(const wptr& remote) } } -bool DisplayMgrClient::SetScreenState(ScreenState state) +bool DisplayPowerMgrClient::SetDisplayState(DisplayState state, uint32_t id) { auto proxy = GetProxy(); if (proxy == nullptr) { return false; } - return proxy->SetScreenState(state); + return proxy->SetDisplayState(id, state); } -bool DisplayMgrClient::SetBrightness(int32_t value) +DisplayState DisplayPowerMgrClient::GetDisplayState(uint32_t id) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return DisplayState::DISPLAY_UNKNOWN; + } + return proxy->GetDisplayState(id); +} + +bool DisplayPowerMgrClient::SetBrightness(uint32_t value, uint32_t id) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return false; + } + return proxy->SetBrightness(id, value); +} + +bool DisplayPowerMgrClient::AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return false; + } + return proxy->AdjustBrightness(id, value, duration); +} + +bool DisplayPowerMgrClient::SetStateConfig(DisplayState state, uint32_t value, uint32_t id) { auto proxy = GetProxy(); if (proxy == nullptr) { return false; } - return proxy->SetBrightness(value); + return proxy->SetStateConfig(id, state, value); } -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index b236aad4a38537e0f59dad33fc88e52da693420f..92cf72677b05820d461796c047fd9a0c8bbe42ca 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -26,9 +26,8 @@ config("displaymgr_public_config") { ohos_shared_library("displaymgr") { sources = [ - "${displaymgr_service_path}/zidl/src/display_mgr_proxy.cpp", - "native/src/display_manager.cpp", - "native/src/display_mgr_client.cpp", + "${displaymgr_framework_path}/native/display_power_mgr_client.cpp", + "${displaymgr_service_path}/zidl/src/display_power_mgr_proxy.cpp", ] configs = [ diff --git a/interfaces/innerkits/native/include/display_info.h b/interfaces/innerkits/native/include/display_info.h index c578038a2e1e30b71a8fbbf0c684a7c4c61b7542..5117781d72160754d113997022efd27998a480c9 100644 --- a/interfaces/innerkits/native/include/display_info.h +++ b/interfaces/innerkits/native/include/display_info.h @@ -17,11 +17,17 @@ #define DISPLAYMGR_DISPLAY_INFO_H namespace OHOS { -namespace DisplayMgr { -enum class ScreenState : uint32_t { - SCREEN_STATE_OFF = 0, - SCREEN_STATE_ON = 1, +namespace DisplayPowerMgr { +/** + * Display State + */ +enum class DisplayState : uint32_t { + DISPLAY_OFF = 0, + DISPLAY_DIM = 1, + DISPLAY_ON = 2, + DISPLAY_SUSPEND = 3, + DISPLAY_UNKNOWN = 4, }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS #endif // DISPLAYMGR_DISPLAY_INFO_H diff --git a/interfaces/innerkits/native/include/display_manager.h b/interfaces/innerkits/native/include/display_manager.h deleted file mode 100644 index e23a44a0c6c69e4fff13430f057969846455fbef..0000000000000000000000000000000000000000 --- a/interfaces/innerkits/native/include/display_manager.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISPLAYMGR_DISPLAY_MANAGER_H -#define DISPLAYMGR_DISPLAY_MANAGER_H - -#include - -#include "display_info.h" - -namespace OHOS { -namespace DisplayMgr { -class DisplayManager { -public: - /** - * Set screen state. - */ - static bool SetScreenState(ScreenState state); - - /** - * Set brightness. - */ - static bool SetBrightness(int32_t value); -}; -} // namespace DisplayMgr -} // namespace OHOS -#endif // DISPLAYMGR_DISPLAY_MANAGER_H diff --git a/interfaces/innerkits/native/src/display_mgr_client.h b/interfaces/innerkits/native/include/display_power_mgr_client.h similarity index 57% rename from interfaces/innerkits/native/src/display_mgr_client.h rename to interfaces/innerkits/native/include/display_power_mgr_client.h index 5f24e7affdf9f1f8885cfa52159adb4a0d631c65..3478eb3e870fbbd7f048767914b56557acdad7d3 100644 --- a/interfaces/innerkits/native/src/display_mgr_client.h +++ b/interfaces/innerkits/native/include/display_power_mgr_client.h @@ -20,21 +20,24 @@ #include #include "display_info.h" -#include "idisplay_mgr.h" +#include "idisplay_power_mgr.h" namespace OHOS { -namespace DisplayMgr { -class DisplayMgrClient : public DelayedRefSingleton { - DECLARE_DELAYED_REF_SINGLETON(DisplayMgrClient); +namespace DisplayPowerMgr { +class DisplayPowerMgrClient : public DelayedRefSingleton { + DECLARE_DELAYED_REF_SINGLETON(DisplayPowerMgrClient); public: - bool SetScreenState(ScreenState state); - bool SetBrightness(int32_t value); + bool SetDisplayState(DisplayState state, uint32_t id = 0); + DisplayState GetDisplayState(uint32_t id = 0); + bool SetBrightness(uint32_t value, uint32_t id = 0); + bool AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id = 0); + bool SetStateConfig(DisplayState state, uint32_t value, uint32_t id = 0); private: class DisplayDeathRecipient : public IRemoteObject::DeathRecipient { public: - explicit DisplayDeathRecipient(DisplayMgrClient& client) : client_(client) {} + explicit DisplayDeathRecipient(DisplayPowerMgrClient& client) : client_(client) {} ~DisplayDeathRecipient() override = default; void OnRemoteDied(const wptr& remote) override { @@ -42,16 +45,16 @@ private: } private: - DisplayMgrClient& client_; + DisplayPowerMgrClient& client_; }; - sptr GetProxy(); + sptr GetProxy(); void OnRemoteDied(const wptr& remote); std::mutex mutex_; - sptr proxy_{nullptr}; - sptr deathRecipient_{nullptr}; + sptr proxy_ {nullptr}; + sptr deathRecipient_ {nullptr}; }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS -#endif // DISPLAYMGR_DISPLAY_MGR_CLIENT_H +#endif // DISPLAYMGR_GRADUAL_ANIMATOR_H diff --git a/interfaces/innerkits/native/include/idisplay_mgr.h b/interfaces/innerkits/native/include/idisplay_power_mgr.h similarity index 56% rename from interfaces/innerkits/native/include/idisplay_mgr.h rename to interfaces/innerkits/native/include/idisplay_power_mgr.h index f16a7eb87cfcbb98b57af00c5a11ef84b6371c16..cf2f5e9de9ad39943a121183b093e33073bc3cd9 100644 --- a/interfaces/innerkits/native/include/idisplay_mgr.h +++ b/interfaces/innerkits/native/include/idisplay_power_mgr.h @@ -21,19 +21,25 @@ #include "display_info.h" namespace OHOS { -namespace DisplayMgr { -class IDisplayMgr : public IRemoteBroker { +namespace DisplayPowerMgr { +class IDisplayPowerMgr : public IRemoteBroker { public: enum { - SET_POWER_STATE = 0, + SET_DISPLAY_STATE = 0, + GET_DISPLAY_STATE, SET_BRIGHTNESS, + ADJUST_BRIGHTNESS, + SET_STATE_CONFIG, }; - virtual bool SetScreenState(ScreenState state) = 0; - virtual bool SetBrightness(int32_t value) = 0; + virtual bool SetDisplayState(uint32_t id, DisplayState state) = 0; + virtual DisplayState GetDisplayState(uint32_t id) = 0; + virtual bool SetBrightness(uint32_t id, int32_t value) = 0; + virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) = 0; + virtual bool SetStateConfig(uint32_t id, DisplayState state, int32_t value) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.displaymgr.IDisplayMgr"); + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.displaypowermgr.IDisplayPowerMgr"); }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS #endif // DISPLAYMGR_IDISPLAY_MGR_H diff --git a/interfaces/kits/js/napi/BUILD.gn b/interfaces/kits/js/napi/BUILD.gn index febc1740a46e7a496bc8def947bd6717a08eaa4d..2636e269b132c113647bc02b3e7abbe5df922e23 100644 --- a/interfaces/kits/js/napi/BUILD.gn +++ b/interfaces/kits/js/napi/BUILD.gn @@ -14,7 +14,7 @@ import("//base/powermgr/display_manager/displaymgr.gni") ohos_shared_library("brightness") { - sources = [ "brightness.cpp" ] + sources = [ "${displaymgr_framework_path}/napi/brightness.cpp" ] include_dirs = [ "//foundation/ace/napi/native_engine", @@ -29,7 +29,10 @@ ohos_shared_library("brightness") { "//foundation/ace/napi:ace_napi", ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] relative_install_dir = "module" diff --git a/ohos.build b/ohos.build index 932c203cab2fe25c6406b20f53735b96193678ee..8a5963263eaa293c7389151a21cf3d7c04c161fc 100644 --- a/ohos.build +++ b/ohos.build @@ -14,7 +14,7 @@ "header": { "header_files": [ "display_info.h", - "display_manager.h" + "display_power_mgr_client.h" ], "header_base": "//base/powermgr/display_manager/interfaces/innerkits/native/include" } diff --git a/service/BUILD.gn b/service/BUILD.gn index 87282f737493c68f87302f284b5a38e693392e73..f9250ee876433d817a7785c5eaa2a9fdf4c14ecd 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -26,10 +26,12 @@ config("displaymgr_public_config") { ohos_shared_library("displaymgrservice") { sources = [ - "native/src/display_mgr_service.cpp", + "native/src/display_power_mgr_service.cpp", + "native/src/display_system_ability.cpp", + "native/src/gradual_animator.cpp", "native/src/screen_action.cpp", "native/src/screen_controller.cpp", - "zidl/src/display_mgr_stub.cpp", + "zidl/src/display_power_mgr_stub.cpp", ] configs = [ @@ -42,10 +44,13 @@ ohos_shared_library("displaymgrservice") { deps = [ "${displaymgr_native_innerkits_path}:displaymgr", "//drivers/peripheral/display/hal:hdi_display_device", + "//foundation/graphic/standard:libwmservice", "//utils/native/base:utils", ] external_deps = [ + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/service/native/include/display_power_mgr_service.h b/service/native/include/display_power_mgr_service.h new file mode 100644 index 0000000000000000000000000000000000000000..96a5fc5db9e69612b12c5c5fa95b5b3d2844e6d6 --- /dev/null +++ b/service/native/include/display_power_mgr_service.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISPLAYMGR_DISPLAY_MGR_SERVICE_H +#define DISPLAYMGR_DISPLAY_MGR_SERVICE_H + +#include +#include +#include + +#include "display_power_mgr_stub.h" +#include "screen_controller.h" +#include "display_common.h" + +namespace OHOS { +namespace DisplayPowerMgr { +class DisplayPowerMgrService : public DisplayPowerMgrStub { +public: + DisplayPowerMgrService(); + ~DisplayPowerMgrService() = default; + virtual bool SetDisplayState(uint32_t id, DisplayState state) override; + virtual DisplayState GetDisplayState(uint32_t id) override; + virtual bool SetBrightness(uint32_t id, int32_t value) override; + virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) override; + virtual bool SetStateConfig(uint32_t id, DisplayState state, int32_t value) override; + virtual int32_t Dump(int32_t fd, const std::vector& args) override; + + class DisplaySystemAbility : public SystemAbility { + DECLARE_SYSTEM_ABILITY(DisplaySystemAbility); + + public: + DisplaySystemAbility(int32_t id, bool runOnCreate) : SystemAbility(id, runOnCreate) {} + ~DisplaySystemAbility() override = default; + + void OnStart() override + { + DISPLAY_HILOGI(MODULE_SERVICE, "Start service"); + service_ = new DisplayPowerMgrService(); + if (!Publish(service_)) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to publish service"); + } + } + + void OnStop() override + { + DISPLAY_HILOGI(MODULE_SERVICE, "Stop service"); + } + + private: + sptr service_; + }; + REGISTER_SYSTEM_ABILITY_BY_ID(DisplaySystemAbility, DISPLAY_MANAGER_SERVICE_ID, true); + +private: + std::map> controllerMap_; +}; +} // namespace DisplayPowerMgr +} // namespace OHOS +#endif // DISPLAYMGR_DISPLAY_MGR_SERVICE_H diff --git a/service/native/include/display_mgr_service.h b/service/native/include/display_system_ability.h similarity index 54% rename from service/native/include/display_mgr_service.h rename to service/native/include/display_system_ability.h index b20688f2e0f3c88eea289bfa3e6cbe8dbe07514b..ec1b3afe7ea0590bcd3222a62d32148bd4511531 100644 --- a/service/native/include/display_mgr_service.h +++ b/service/native/include/display_system_ability.h @@ -13,25 +13,28 @@ * limitations under the License. */ -#ifndef DISPLAYMGR_DISPLAY_MGR_SERVICE_H -#define DISPLAYMGR_DISPLAY_MGR_SERVICE_H +#ifndef DISPLAY_SYSTEM_ABILITY_H +#define DISPLAY_SYSTEM_ABILITY_H -#include - -#include "display_mgr_stub.h" -#include "screen_controller.h" +#include +#include +#include "display_power_mgr_service.h" namespace OHOS { -namespace DisplayMgr { -class DisplayMgrService : public DisplayMgrStub { +namespace DisplayPowerMgr { +class DisplaySystemAbility : public SystemAbility { + DECLARE_SYSTEM_ABILITY(DisplaySystemAbility); + public: - bool SetScreenState(ScreenState state) override; - bool SetBrightness(int32_t value) override; - int32_t Dump(int32_t fd, const std::vector& args) override; + DisplaySystemAbility(int32_t id, bool runOnCreate) : SystemAbility(id, runOnCreate) {} + ~DisplaySystemAbility() override = default; + + void OnStart() override; + void OnStop() override; private: - ScreenController screenController_; + sptr service_; }; -} // namespace DisplayMgr -} // namespace OHOS -#endif // DISPLAYMGR_DISPLAY_MGR_SERVICE_H +} +} +#endif \ No newline at end of file diff --git a/service/native/include/gradual_animator.h b/service/native/include/gradual_animator.h new file mode 100644 index 0000000000000000000000000000000000000000..f592facf209951fcf1cceaabec88192bde68f7ea --- /dev/null +++ b/service/native/include/gradual_animator.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISPLAYMGR_GRADUAL_ANIMATOR_H +#define DISPLAYMGR_GRADUAL_ANIMATOR_H + +#include +#include +#include +#include + +namespace OHOS { +namespace DisplayPowerMgr { +class AnimateCallback { +public: + virtual void onStart() = 0; + virtual void onChanged(int32_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() = default; + void StartAnimation(int32_t from, int32_t to, uint32_t duration); + void StopAnimation(); + bool IsAnimating(); +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); + ~AnimatorHandler() = default; + void ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) override; + private: + std::weak_ptr owner_; + }; + void NextStep(); + std::string name_; + std::shared_ptr callback_; + std::shared_ptr eventRunner_; + std::shared_ptr handler_; + bool animating_ = false; + int32_t from_; + int32_t to_; + uint32_t duration_; + uint32_t updateTime_; + uint32_t steps_; + int32_t stride_; + int32_t current_; + uint32_t currentStep_; +}; +} // namespace DisplayPowerMgr +} // namespace OHOS +#endif // DISPLAYMGR_GRADUAL_ANIMATOR_H \ No newline at end of file diff --git a/service/native/include/screen_action.h b/service/native/include/screen_action.h index fbe3fa30f1883ee2702bc4faf8ec44a0b4315781..e9682becf59b3fdc62e23925dae6e89a1d15c0ae 100644 --- a/service/native/include/screen_action.h +++ b/service/native/include/screen_action.h @@ -18,18 +18,23 @@ #include #include +#include #include #include "display_info.h" namespace OHOS { -namespace DisplayMgr { +namespace DisplayPowerMgr { class ScreenAction { public: - void Init(); - bool SetPowerState(ScreenState state); - bool SetBrightness(int32_t value); + ScreenAction(); + ~ScreenAction() = default; + std::vector GetDisplayIds(); + DisplayState GetPowerState(uint32_t devId); + bool SetPowerState(uint32_t devId, DisplayState state); + uint32_t GetBrightness(uint32_t devId); + bool SetBrightness(uint32_t devId, uint32_t value); private: struct DeviceFuncCloser { @@ -48,8 +53,9 @@ private: static constexpr int32_t MAX_BRIGHTNESS = 255; static constexpr int32_t MIN_BRIGHTNESS = 6; + std::vector devIds_; DeviceFuncPtr hdiFuncs_; }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS #endif // DISPLAYMGR_SCREEN_ACTION_H diff --git a/service/native/include/screen_controller.h b/service/native/include/screen_controller.h index 16751502df9be29272522ee499defb5ccb38a5b3..3ad2c07d2d27d848f26d49672dc7981571bef962 100644 --- a/service/native/include/screen_controller.h +++ b/service/native/include/screen_controller.h @@ -16,33 +16,44 @@ #ifndef DISPLAYMGR_SCREEN_CONTROLLER_H #define DISPLAYMGR_SCREEN_CONTROLLER_H +#include #include #include "display_info.h" +#include "gradual_animator.h" #include "screen_action.h" namespace OHOS { -namespace DisplayMgr { -class ScreenController { +namespace DisplayPowerMgr { +class ScreenController : + public AnimateCallback, + public std::enable_shared_from_this { public: - ScreenController(); - ~ScreenController() = default; + ScreenController(uint32_t devId, std::shared_ptr action); + virtual ~ScreenController() = default; - bool UpdateState(ScreenState state); - bool UpdateBrightness(int32_t value); + DisplayState GetState() + { + return state_; + }; + bool UpdateState(DisplayState state); + bool UpdateStateConfig(DisplayState state, uint32_t value); + bool UpdateBrightness(uint32_t value, uint32_t duration = 0); bool IsScreenOn(); - + virtual void onStart() override; + virtual void onChanged(int32_t currentValue) override; + virtual void onEnd() override; private: - inline bool IsScreenStateLocked(ScreenState state) - { - return state_ == state; - } - + static const uint32_t SCREEN_BRIGHTNESS_UPDATE_DURATION = 200; std::mutex mutex_; - ScreenState state_{ScreenState::SCREEN_STATE_ON}; - int32_t brightness_{0}; - ScreenAction action_; + const uint32_t devId_; + DisplayState state_; + std::map stateValues_; + + uint32_t brightness_ {0}; + std::shared_ptr action_; + std::shared_ptr animator_; }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS -#endif // DISPLAYMGR_SCREEN_CONTROLLER_H +#endif // DISPLAYMGR_SCREEN_CONTROLLER_H \ No newline at end of file diff --git a/service/native/src/display_mgr_service.cpp b/service/native/src/display_power_mgr_service.cpp similarity index 32% rename from service/native/src/display_mgr_service.cpp rename to service/native/src/display_power_mgr_service.cpp index ace83dca334e5dc4caf9d8d2518d61e1a0b7a601..ef3c967f05d8dbaabc13c19ecbc646765ab3e4c4 100644 --- a/service/native/src/display_mgr_service.cpp +++ b/service/native/src/display_power_mgr_service.cpp @@ -13,56 +13,69 @@ * limitations under the License. */ -#include "display_mgr_service.h" +#include "display_power_mgr_service.h" #include #include -#include -#include - -#include "display_common.h" namespace OHOS { -namespace DisplayMgr { -namespace { -class DisplaySystemAbility : public SystemAbility { - DECLARE_SYSTEM_ABILITY(DisplaySystemAbility); - -public: - DisplaySystemAbility(int32_t id, bool runOnCreate) : SystemAbility(id, runOnCreate) {} - ~DisplaySystemAbility() override = default; +namespace DisplayPowerMgr { +DisplayPowerMgrService::DisplayPowerMgrService() +{ + std::shared_ptr screenAction = std::make_shared(); + std::vector devIds = screenAction->GetDisplayIds(); + int count = devIds.size(); + for (int i = 0; i < count; i++) { + controllerMap_.emplace(devIds[i], std::make_shared(devIds[i], screenAction)); + } +} - void OnStart() override - { - DISPLAY_HILOGI(MODULE_SERVICE, "Start service"); - service_ = new DisplayMgrService(); - if (!Publish(service_)) { - DISPLAY_HILOGE(MODULE_SERVICE, "Failed to publish service"); - } +bool DisplayPowerMgrService::SetDisplayState(uint32_t id, DisplayState state) +{ + auto iterater = controllerMap_.find(id); + if (iterater == controllerMap_.end()) { + return false; } + return iterater->second->UpdateState(state); +} - void OnStop() override - { - DISPLAY_HILOGI(MODULE_SERVICE, "Stop service"); +DisplayState DisplayPowerMgrService::GetDisplayState(uint32_t id) +{ + auto iterater = controllerMap_.find(id); + if (iterater == controllerMap_.end()) { + return DisplayState::DISPLAY_UNKNOWN; } + return iterater->second->GetState(); +} -private: - sptr service_; -}; -REGISTER_SYSTEM_ABILITY_BY_ID(DisplaySystemAbility, DISPLAY_MANAGER_SERVICE_ID, true); +bool DisplayPowerMgrService::SetBrightness(uint32_t id, int32_t value) +{ + auto iterater = controllerMap_.find(id); + if (iterater == controllerMap_.end()) { + return false; + } + return iterater->second->UpdateBrightness(value); } -bool DisplayMgrService::SetScreenState(ScreenState state) +bool DisplayPowerMgrService::AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) { - return screenController_.UpdateState(state); + auto iterater = controllerMap_.find(id); + if (iterater == controllerMap_.end()) { + return false; + } + return iterater->second->UpdateBrightness(value, duration); } -bool DisplayMgrService::SetBrightness(int32_t value) +bool DisplayPowerMgrService::SetStateConfig(uint32_t id, DisplayState state, int32_t value) { - return screenController_.UpdateBrightness(value); + auto iterater = controllerMap_.find(id); + if (iterater == controllerMap_.end()) { + return false; + } + return iterater->second->UpdateStateConfig(state, value); } -int32_t DisplayMgrService::Dump(int32_t fd, const std::vector& args) +int32_t DisplayPowerMgrService::Dump(int32_t fd, const std::vector& args) { std::string result("Empty dump info"); if (!SaveStringToFd(fd, result)) { @@ -70,5 +83,5 @@ int32_t DisplayMgrService::Dump(int32_t fd, const std::vector& a } return ERR_OK; } -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS diff --git a/interfaces/innerkits/native/src/display_manager.cpp b/service/native/src/display_system_ability.cpp similarity index 53% rename from interfaces/innerkits/native/src/display_manager.cpp rename to service/native/src/display_system_ability.cpp index 8c003e4619fafe54c8438fe5fca5f1cab0f7d4c6..496b357b26026a1fc73518535903f282cbbafe28 100644 --- a/interfaces/innerkits/native/src/display_manager.cpp +++ b/service/native/src/display_system_ability.cpp @@ -13,20 +13,26 @@ * limitations under the License. */ -#include "display_manager.h" - -#include "display_mgr_client.h" +#include "display_system_ability.h" +#include "display_common.h" namespace OHOS { -namespace DisplayMgr { -bool DisplayManager::SetScreenState(ScreenState state) +namespace DisplayPowerMgr { +namespace { +REGISTER_SYSTEM_ABILITY_BY_ID(DisplaySystemAbility, DISPLAY_MANAGER_SERVICE_ID, true); +} +void DisplaySystemAbility::OnStart() { - return DisplayMgrClient::GetInstance().SetScreenState(state); + DISPLAY_HILOGI(MODULE_SERVICE, "Start service"); + service_ = new DisplayPowerMgrService(); + if (!Publish(service_)) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to publish service"); + } } -bool DisplayManager::SetBrightness(int32_t value) +void DisplaySystemAbility::OnStop() { - return DisplayMgrClient::GetInstance().SetBrightness(value); + DISPLAY_HILOGI(MODULE_SERVICE, "Stop service"); +} } -} // namespace DisplayMgr -} // namespace OHOS +} \ No newline at end of file diff --git a/service/native/src/gradual_animator.cpp b/service/native/src/gradual_animator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..84b88ce7efbd12bf792c28b900187e5285050644 --- /dev/null +++ b/service/native/src/gradual_animator.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2021 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 "gradual_animator.h" + +#include "display_common.h" + +namespace OHOS { +namespace DisplayPowerMgr { +GradualAnimator::GradualAnimator(const std::string& name, + std::shared_ptr callback) +{ + DISPLAY_HILOGD(MODULE_SERVICE, "GradualAnimator construct start"); + name_ = name; + callback_ = callback; + eventRunner_ = AppExecFwk::EventRunner::Create(name_); + if (eventRunner_ == nullptr) { + DISPLAY_HILOGW(MODULE_SERVICE, "GradualAnimator failed due to create EventRunner"); + } + from_ = 0; + to_ = 0; + current_ = 0; + duration_ = 0; + steps_ = 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) +{ + DISPLAY_HILOGD(MODULE_SERVICE, + "StartAnimation from=%{public}d, to=%{public}d, duration=%{public}d", + from, to, duration); + if (callback_ == nullptr) { + DISPLAY_HILOGW(MODULE_SERVICE, "Callback is NULL"); + return; + } + from_ = from; + to_ = to; + current_ = from_; + duration_ = duration; + steps_ = duration_ / updateTime_; + if (steps_ < 1) { + steps_ = 1; + } + stride_ = (to_ - from_) / steps_; + currentStep_ = 0; + if (handler_ == nullptr) { + handler_ = std::make_shared(eventRunner_, shared_from_this()); + } + animating_ = true; + handler_->SendEvent(EVENT_STEP, 0, updateTime_); + DISPLAY_HILOGD(MODULE_SERVICE, "StartAnimation end"); +} + +void GradualAnimator::StopAnimation() +{ + DISPLAY_HILOGD(MODULE_SERVICE, "GradualAnimator StopAnimation start"); + animating_ = false; + handler_->RemoveEvent(EVENT_STEP); + if (callback_ == nullptr) { + DISPLAY_HILOGW(MODULE_SERVICE, "Callback is NULL"); + return; + } + callback_->onEnd(); + DISPLAY_HILOGD(MODULE_SERVICE, "GradualAnimator StopAnimation end"); +} + +bool GradualAnimator::IsAnimating() +{ + return animating_; +} + +void GradualAnimator::NextStep() +{ + if (!animating_) { + DISPLAY_HILOGW(MODULE_SERVICE, "NextStep, not animating"); + return; + } + if (callback_ == nullptr) { + DISPLAY_HILOGW(MODULE_SERVICE, "Callback is NULL"); + return; + } + currentStep_++; + if (currentStep_ == 1) { + callback_->onStart(); + } + if (currentStep_ < steps_) { + current_ = current_ + stride_; + callback_->onChanged(current_); + handler_->SendEvent(EVENT_STEP, 0, updateTime_); + } else { + current_ = to_; + callback_->onChanged(current_); + callback_->onEnd(); + animating_ = false; + } +} + +GradualAnimator::AnimatorHandler::AnimatorHandler( + const std::shared_ptr& runner, + std::shared_ptr owner) + : AppExecFwk::EventHandler(runner), owner_(owner) +{ + DISPLAY_HILOGD(MODULE_SERVICE, "AnimatorHandler is created"); +} + +void GradualAnimator::AnimatorHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer& event) +{ + DISPLAY_HILOGD(MODULE_SERVICE, "AnimatorHandler::%{public}s ,eventid = %d", __func__, + event->GetInnerEventId()); + std::shared_ptr animator = owner_.lock(); + switch (event->GetInnerEventId()) { + case EVENT_STEP: { + animator->NextStep(); + break; + } + default: + break; + } +} +} // namespace DisplayPowerMgr +} // namespace OHOS diff --git a/service/native/src/screen_action.cpp b/service/native/src/screen_action.cpp index 163a4c25adc4f332032988d0a1ed102b07e349fe..a37fb2b7db538cc88cdc1a68ca3b4a7f75e864b2 100644 --- a/service/native/src/screen_action.cpp +++ b/service/native/src/screen_action.cpp @@ -16,11 +16,13 @@ #include "screen_action.h" #include "display_common.h" +#include "display_type.h" #include "hilog_wrapper.h" +#include "window_manager_service_client.h" namespace OHOS { -namespace DisplayMgr { -void ScreenAction::Init() +namespace DisplayPowerMgr { +ScreenAction::ScreenAction() { DeviceFuncs *f = NULL; @@ -29,22 +31,114 @@ void ScreenAction::Init() DISPLAY_HILOGE(MODULE_SERVICE, "Failed to init device"); return; } + devIds_.push_back(0); hdiFuncs_ = DeviceFuncPtr(f); DISPLAY_HILOGI(MODULE_SERVICE, "Succeed to init"); } -bool ScreenAction::SetPowerState(ScreenState state __attribute__((__unused__))) +std::vector ScreenAction::GetDisplayIds() { + return devIds_; +} + +DisplayState ScreenAction::GetPowerState(uint32_t devId) +{ + DisplayState ret = DisplayState::DISPLAY_UNKNOWN; + + auto wmsc = WindowManagerServiceClient::GetInstance(); + wmsc->Init(); + sptr wms = wmsc->GetService(); + if (wms == nullptr) { + DISPLAY_HILOGE(MODULE_SERVICE, "FAILED to get service from WindowManager Client"); + return DisplayState::DISPLAY_UNKNOWN; + } + auto promise = wms->GetDisplayPower(devId)->Await(); + if (promise.wret != WM_OK) { + DISPLAY_HILOGE(MODULE_SERVICE, "GetPowerState failed: %{public}d", promise.wret); + return ret; + } + + switch (promise.status) { + case POWER_STATUS_ON: + ret = DisplayState::DISPLAY_ON; + break; + case POWER_STATUS_STANDBY: + ret = DisplayState::DISPLAY_DIM; + break; + case POWER_STATUS_SUSPEND: + ret = DisplayState::DISPLAY_SUSPEND; + break; + case POWER_STATUS_OFF: + ret = DisplayState::DISPLAY_OFF; + break; + default: + break; + } + + return ret; +} + +bool ScreenAction::SetPowerState(uint32_t devId, DisplayState state) +{ + DISPLAY_HILOGI(MODULE_SERVICE, "SetDisplayPower: devId=%{public}d, state=%{public}d", + devId, static_cast(state)); + auto wmsc = WindowManagerServiceClient::GetInstance(); + wmsc->Init(); + sptr wms = wmsc->GetService(); + if (wms == nullptr) { + DISPLAY_HILOGE(MODULE_SERVICE, "FAILED to get service from WindowManager Client"); + return false; + } + + DispPowerStatus status = POWER_STATUS_BUTT; + switch (state) { + case DisplayState::DISPLAY_ON: + status = POWER_STATUS_ON; + break; + case DisplayState::DISPLAY_DIM: + status = POWER_STATUS_STANDBY; + break; + case DisplayState::DISPLAY_SUSPEND: + status = POWER_STATUS_SUSPEND; + break; + case DisplayState::DISPLAY_OFF: + status = POWER_STATUS_OFF; + break; + default: + break; + } + + auto wret = wms->SetDisplayPower(devId, status)->Await(); + if (wret != WM_OK) { + DISPLAY_HILOGE(MODULE_SERVICE, "SetDisplayPower failed: %{public}d", wret); + return false; + } + return true; } -bool ScreenAction::SetBrightness(int32_t value) +uint32_t ScreenAction::GetBrightness(uint32_t devId) +{ + uint32_t level = 0; + if (!hdiFuncs_) { + DISPLAY_HILOGE(MODULE_SERVICE, "GetBrightness:Invalid device functions"); + return 0; + } + int32_t hdiRet = hdiFuncs_->GetDisplayBacklight(devId, &level); + if (hdiRet != DISPLAY_SUCCESS) { + DISPLAY_HILOGE(MODULE_SERVICE, "GetBrightness failed:%d", level); + return 0; + } + return level; +} + +bool ScreenAction::SetBrightness(uint32_t devId, uint32_t value) { if (!hdiFuncs_) { - DISPLAY_HILOGE(MODULE_SERVICE, "Invalid device functions"); + DISPLAY_HILOGE(MODULE_SERVICE, "SetBrightness: Invalid device functions"); return false; } - return hdiFuncs_->SetDisplayBacklight(0, GetValidBrightness(value)) == DISPLAY_SUCCESS; + return hdiFuncs_->SetDisplayBacklight(devId, GetValidBrightness(value)) == DISPLAY_SUCCESS; } -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/native/src/screen_controller.cpp b/service/native/src/screen_controller.cpp index 44c49876872f73c3ba38f0841aaabd64c637dc7b..93f34fe74cab65a0de8dc52a9e569cb3072a500c 100644 --- a/service/native/src/screen_controller.cpp +++ b/service/native/src/screen_controller.cpp @@ -19,37 +19,119 @@ #include "hilog_wrapper.h" namespace OHOS { -namespace DisplayMgr { -ScreenController::ScreenController() +namespace DisplayPowerMgr { +const int DISPLAY_FULL_BRIGHTNESS = 100; +const int DISPLAY_DIM_BRIGHTNESS = 50; +const int DISPLAY_OFF_BRIGHTNESS = 0; +const int DISPLAY_SUSPEND_BRIGHTNESS = 50; + +ScreenController::ScreenController(uint32_t devId, std::shared_ptr action) + : devId_(devId), state_(DisplayState::DISPLAY_UNKNOWN), action_(action) { - action_.Init(); + DISPLAY_HILOGI(MODULE_SERVICE, "ScreenController created: %{public}d", devId_); + stateValues_.emplace(DisplayState::DISPLAY_ON, DISPLAY_FULL_BRIGHTNESS); + stateValues_.emplace(DisplayState::DISPLAY_DIM, DISPLAY_DIM_BRIGHTNESS); + stateValues_.emplace(DisplayState::DISPLAY_OFF, DISPLAY_OFF_BRIGHTNESS); + stateValues_.emplace(DisplayState::DISPLAY_SUSPEND, DISPLAY_SUSPEND_BRIGHTNESS); + animator_ = nullptr; } -bool ScreenController::UpdateState(ScreenState state) +bool ScreenController::UpdateState(DisplayState state) { std::lock_guard lock(mutex_); - if (IsScreenStateLocked(state)) { + DISPLAY_HILOGI(MODULE_SERVICE, "ScreenController UpdateState: %{public}d, %{public}d", + devId_, static_cast(state)); + if (state == state_) { return true; } + + bool ret = action_->SetPowerState(devId_, state); + if (!ret) { + DISPLAY_HILOGW(MODULE_SERVICE, "SetPowerState failed state=%{public}d", state); + } state_ = state; - action_.SetPowerState(state); - DISPLAY_HILOGI(MODULE_SERVICE, "Update screen state to %{public}u", ToUnderlying(state)); + auto iterator = stateValues_.find(state); + if (iterator != stateValues_.end()) { + ret = action_->SetBrightness(devId_, iterator->second); + if (ret) { + brightness_ = iterator->second; + } else { + DISPLAY_HILOGI(MODULE_SERVICE, "set brightness falied! %{public}d", iterator->second); + } + } + DISPLAY_HILOGI(MODULE_SERVICE, "Update screen state to %{public}u", state); return true; } -bool ScreenController::UpdateBrightness(int32_t value) +bool ScreenController::UpdateBrightness(uint32_t value, uint32_t duraion) +{ + std::lock_guard lock(mutex_); + DISPLAY_HILOGI(MODULE_SERVICE, "ScreenController UpdateState: %{public}d, %{public}d", + devId_, value); + if (animator_ == nullptr) { + std::string name = "ScreenController_" + std::to_string(devId_); + 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, SCREEN_BRIGHTNESS_UPDATE_DURATION); + return true; + } + bool ret = action_->SetBrightness(devId_, value); + if (ret) { + brightness_ = value; + DISPLAY_HILOGI(MODULE_SERVICE, "Update brightness to %{public}d", value); + } else { + DISPLAY_HILOGI(MODULE_SERVICE, "Update brightness falied! %{public}d", value); + } + + return ret; +} + +bool ScreenController::UpdateStateConfig(DisplayState state, uint32_t value) { std::lock_guard lock(mutex_); - brightness_ = value; - action_.SetBrightness(value); - DISPLAY_HILOGI(MODULE_SERVICE, "Update brightness to %{public}d", value); + DISPLAY_HILOGI(MODULE_SERVICE, + "ScreenController UpdateStateConfig: Id=%{public}d, State=%{public}d, Value=%{public}d", + devId_, static_cast(state), value); + auto iterator = stateValues_.find(state); + if (iterator == stateValues_.end()) { + DISPLAY_HILOGI(MODULE_SERVICE, "UpdateStateConfig No such state"); + return false; + } + iterator->second = value; return true; } bool ScreenController::IsScreenOn() { std::lock_guard lock(mutex_); - return IsScreenStateLocked(ScreenState::SCREEN_STATE_ON); + return (state_ == DisplayState::DISPLAY_ON || state_ == DisplayState::DISPLAY_DIM); +} + +void ScreenController::onStart() +{ + DISPLAY_HILOGD(MODULE_SERVICE, "ScreenAnimatorCallback onStart"); +} + +void ScreenController::onChanged(int32_t currentValue) +{ + brightness_ = currentValue; + bool ret = action_->SetBrightness(devId_, currentValue); + if (ret) { + DISPLAY_HILOGD(MODULE_SERVICE, "Update brightness to %{public}d", currentValue); + } else { + DISPLAY_HILOGD(MODULE_SERVICE, "Update brightness falied! %{public}d", currentValue); + } +} + +void ScreenController::onEnd() +{ + DISPLAY_HILOGD(MODULE_SERVICE, "ScreenAnimatorCallback OnEnd"); } -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/zidl/include/display_mgr_proxy.h b/service/zidl/include/display_power_mgr_proxy.h similarity index 51% rename from service/zidl/include/display_mgr_proxy.h rename to service/zidl/include/display_power_mgr_proxy.h index eb2e54242bc616f825801122a2777c7acc27dec4..e27b0d08223d18b25ee67191e55c1336d5da3f06 100644 --- a/service/zidl/include/display_mgr_proxy.h +++ b/service/zidl/include/display_power_mgr_proxy.h @@ -18,22 +18,25 @@ #include -#include "idisplay_mgr.h" +#include "idisplay_power_mgr.h" namespace OHOS { -namespace DisplayMgr { -class DisplayMgrProxy : public IRemoteProxy { +namespace DisplayPowerMgr { +class DisplayPowerMgrProxy : public IRemoteProxy { public: - explicit DisplayMgrProxy(const sptr& impl) - : IRemoteProxy(impl) {} - ~DisplayMgrProxy() override = default; + explicit DisplayPowerMgrProxy(const sptr& impl) + : IRemoteProxy(impl) {} + ~DisplayPowerMgrProxy() override = default; - bool SetScreenState(ScreenState state) override; - bool SetBrightness(int32_t value) override; + virtual bool SetDisplayState(uint32_t id, DisplayState state) override; + virtual DisplayState GetDisplayState(uint32_t id) override; + virtual bool SetBrightness(uint32_t id, int32_t value) override; + virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) override; + virtual bool SetStateConfig(uint32_t id, DisplayState state, int32_t value) override; private: - static inline BrokerDelegator delegator_; + static inline BrokerDelegator delegator_; }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS #endif // DISPLAYMGR_DISPLAY_MGR_PROXY_H diff --git a/service/zidl/include/display_mgr_stub.h b/service/zidl/include/display_power_mgr_stub.h similarity index 69% rename from service/zidl/include/display_mgr_stub.h rename to service/zidl/include/display_power_mgr_stub.h index 50d3ba6c71343c1f6f643dd5c7406d10dc397bda..2a35eddfe75ad7e0d64fdbaf54eaae2ec7a8cc1a 100644 --- a/service/zidl/include/display_mgr_stub.h +++ b/service/zidl/include/display_power_mgr_stub.h @@ -18,18 +18,21 @@ #include -#include "idisplay_mgr.h" +#include "idisplay_power_mgr.h" namespace OHOS { -namespace DisplayMgr { -class DisplayMgrStub : public IRemoteStub { +namespace DisplayPowerMgr { +class DisplayPowerMgrStub : public IRemoteStub { public: int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: - int32_t SetScreenStateStub(MessageParcel& data, MessageParcel& reply); + int32_t SetDisplayStateStub(MessageParcel& data, MessageParcel& reply); + int32_t GetDisplayStateStub(MessageParcel& data, MessageParcel& reply); int32_t SetBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t SetStateConfigStub(MessageParcel& data, MessageParcel& reply); }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS #endif // DISPLAYMGR_DISPLAY_MGR_STUB_H diff --git a/service/zidl/src/display_mgr_proxy.cpp b/service/zidl/src/display_mgr_proxy.cpp deleted file mode 100644 index d54fd0da4017dca098fa7dc7318fbb0cb312f964..0000000000000000000000000000000000000000 --- a/service/zidl/src/display_mgr_proxy.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2021 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 "display_mgr_proxy.h" - -#include "display_common.h" - -namespace OHOS { -namespace DisplayMgr { -bool DisplayMgrProxy::SetScreenState(ScreenState state) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - bool result = false; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(DisplayMgrProxy::GetDescriptor())) { - DISPLAY_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); - return result; - } - - WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(state), false); - - int ret = remote->SendRequest(static_cast(IDisplayMgr::SET_POWER_STATE), data, reply, option); - if (ret != ERR_OK) { - DISPLAY_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); - return result; - } - if (!reply.ReadBool(result)) { - DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); - } - - return result; -} - -bool DisplayMgrProxy::SetBrightness(int32_t value) -{ - sptr remote = Remote(); - RETURN_IF_WITH_RET(remote == nullptr, false); - - bool result = false; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(DisplayMgrProxy::GetDescriptor())) { - DISPLAY_HILOGE(MODULE_INNERKIT, "write descriptor failed!"); - return result; - } - - WRITE_PARCEL_WITH_RET(data, Int32, value, false); - - int ret = remote->SendRequest(static_cast(IDisplayMgr::SET_BRIGHTNESS), data, reply, option); - if (ret != ERR_OK) { - DISPLAY_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %d", ret); - return result; - } - if (!reply.ReadBool(result)) { - DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); - } - - return result; -} -} // namespace DisplayMgr -} // namespace OHOS diff --git a/service/zidl/src/display_power_mgr_proxy.cpp b/service/zidl/src/display_power_mgr_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f0538f7824865602931ef8135c7fe319ce628abc --- /dev/null +++ b/service/zidl/src/display_power_mgr_proxy.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2021 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 "display_power_mgr_proxy.h" + +#include "display_common.h" + +namespace OHOS { +namespace DisplayPowerMgr { +bool DisplayPowerMgrProxy::SetDisplayState(uint32_t id, DisplayState state) +{ + 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, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return result; + } + + WRITE_PARCEL_WITH_RET(data, Uint32, id, false); + WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(state), false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::SET_DISPLAY_STATE), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s SendRequest is failed, error code: %d", + __func__, ret); + return result; + } + + if (!reply.ReadBool(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return result; + } + + return result; +} + +DisplayState DisplayPowerMgrProxy::GetDisplayState(uint32_t id) +{ + sptr remote = Remote(); + RETURN_IF_WITH_RET(remote == nullptr, DisplayState::DISPLAY_UNKNOWN); + + uint32_t result = 0; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(DisplayPowerMgrProxy::GetDescriptor())) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return DisplayState::DISPLAY_UNKNOWN; + } + + WRITE_PARCEL_WITH_RET(data, Uint32, id, DisplayState::DISPLAY_UNKNOWN); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::GET_DISPLAY_STATE), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(MODULE_INNERKIT, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return DisplayState::DISPLAY_UNKNOWN; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return DisplayState::DISPLAY_UNKNOWN; + } + + return static_cast(result); +} + +bool DisplayPowerMgrProxy::SetBrightness(uint32_t id, int32_t value) +{ + 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, id, false); + WRITE_PARCEL_WITH_RET(data, Int32, value, false); + + 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); + return result; + } + + if (!reply.ReadBool(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return result; + } + + return result; +} + +bool DisplayPowerMgrProxy::AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) +{ + 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, id, false); + WRITE_PARCEL_WITH_RET(data, Int32, value, false); + WRITE_PARCEL_WITH_RET(data, Int32, duration, false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::ADJUST_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.ReadBool(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return result; + } + + return result; +} + +bool DisplayPowerMgrProxy::SetStateConfig(uint32_t id, DisplayState state, int32_t value) +{ + 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, id, false); + WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(state), false); + WRITE_PARCEL_WITH_RET(data, Int32, value, false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::SET_STATE_CONFIG), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(MODULE_INNERKIT, "PowerMgrProxy::%{public}s SendRequest is failed, error code: %d", + __func__, ret); + return result; + } + + if (!reply.ReadBool(result)) { + DISPLAY_HILOGE(MODULE_INNERKIT, "Readback fail!"); + return result; + } + + return result; +} +} // namespace DisplayPowerMgr +} // namespace OHOS diff --git a/service/zidl/src/display_mgr_stub.cpp b/service/zidl/src/display_power_mgr_stub.cpp similarity index 33% rename from service/zidl/src/display_mgr_stub.cpp rename to service/zidl/src/display_power_mgr_stub.cpp index c4e619836a9dc413da3e9895de892b3bfaeadfa0..8fe9b53919ac52d809066bbc73fc3af2f48c5760 100644 --- a/service/zidl/src/display_mgr_stub.cpp +++ b/service/zidl/src/display_power_mgr_stub.cpp @@ -13,41 +13,51 @@ * limitations under the License. */ -#include "display_mgr_stub.h" +#include "display_power_mgr_stub.h" #include #include "display_common.h" namespace OHOS { -namespace DisplayMgr { -int32_t DisplayMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +namespace DisplayPowerMgr { +int32_t DisplayPowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) { - DISPLAY_HILOGD(MODULE_SERVICE, "DisplayMgrStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags()); - std::u16string descripter = DisplayMgrStub::GetDescriptor(); + DISPLAY_HILOGD(MODULE_SERVICE, "DisplayPowerMgrStub::OnRemoteRequest, cmd = %d, flags= %d", + code, option.GetFlags()); + std::u16string descripter = DisplayPowerMgrStub::GetDescriptor(); std::u16string remoteDescripter = data.ReadInterfaceToken(); if (descripter != remoteDescripter) { - DISPLAY_HILOGE(MODULE_SERVICE, "DisplayMgrStub::OnRemoteRequest failed, descriptor is not matched!"); + DISPLAY_HILOGE(MODULE_SERVICE, "DisplayPowerMgrStub::OnRemoteRequest failed, descriptor is not matched!"); return E_GET_POWER_SERVICE_FAILED; } switch (code) { - case static_cast(IDisplayMgr::SET_POWER_STATE): - return SetScreenStateStub(data, reply); - case static_cast(IDisplayMgr::SET_BRIGHTNESS): + case static_cast(IDisplayPowerMgr::SET_DISPLAY_STATE): + return SetDisplayStateStub(data, reply); + case static_cast(IDisplayPowerMgr::GET_DISPLAY_STATE): + return GetDisplayStateStub(data, reply); + case static_cast(IDisplayPowerMgr::SET_BRIGHTNESS): return SetBrightnessStub(data, reply); + case static_cast(IDisplayPowerMgr::ADJUST_BRIGHTNESS): + return AdjustBrightnessStub(data, reply); + case static_cast(IDisplayPowerMgr::SET_STATE_CONFIG): + return SetStateConfigStub(data, reply); default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } } -int32_t DisplayMgrStub::SetScreenStateStub(MessageParcel& data, MessageParcel& reply) +int32_t DisplayPowerMgrStub::SetDisplayStateStub(MessageParcel& data, MessageParcel& reply) { + uint32_t id = 0; uint32_t state = 0; + READ_PARCEL_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR); READ_PARCEL_WITH_RET(data, Uint32, state, E_READ_PARCEL_ERROR); - bool ret = SetScreenState(static_cast(state)); + bool ret = SetDisplayState(id, static_cast(state)); if (!reply.WriteBool(ret)) { DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write SetScreenState return value"); return E_WRITE_PARCEL_ERROR; @@ -55,18 +65,71 @@ int32_t DisplayMgrStub::SetScreenStateStub(MessageParcel& data, MessageParcel& r return ERR_OK; } -int32_t DisplayMgrStub::SetBrightnessStub(MessageParcel& data, MessageParcel& reply) +int32_t DisplayPowerMgrStub::GetDisplayStateStub(MessageParcel& data, MessageParcel& reply) { + uint32_t id = 0; + + READ_PARCEL_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR); + + DisplayState ret = GetDisplayState(id); + if (!reply.WriteUint32(static_cast(ret))) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write SetScreenState return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + + +int32_t DisplayPowerMgrStub::SetBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t id = 0; + int32_t value = 0; + + READ_PARCEL_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Int32, value, E_READ_PARCEL_ERROR); + + bool ret = SetBrightness(id, value); + if (!reply.WriteBool(ret)) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write SetBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t id = 0; + int32_t value = 0; + uint32_t duration = 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, duration, E_READ_PARCEL_ERROR); + + bool ret = AdjustBrightness(id, value, duration); + if (!reply.WriteBool(ret)) { + DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write SetBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::SetStateConfigStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t id = 0; + uint32_t state = 0; int32_t value = 0; + READ_PARCEL_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Uint32, state, E_READ_PARCEL_ERROR); READ_PARCEL_WITH_RET(data, Int32, value, E_READ_PARCEL_ERROR); - bool ret = SetBrightness(value); + bool ret = SetStateConfig(id, static_cast(state), value); if (!reply.WriteBool(ret)) { DISPLAY_HILOGE(MODULE_SERVICE, "Failed to write SetBrightness return value"); return E_WRITE_PARCEL_ERROR; } return ERR_OK; } -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS diff --git a/test/native/unittest/BUILD.gn b/test/native/unittest/BUILD.gn index ca5edf5d20df185d8b3a288e235b43f566d45131..3803f56e9f17b4aef655a3461016b91ff1823ac4 100644 --- a/test/native/unittest/BUILD.gn +++ b/test/native/unittest/BUILD.gn @@ -23,6 +23,7 @@ config("module_private_config") { include_dirs = [ "include", "//utils/system/safwk/native/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", ] } @@ -30,7 +31,7 @@ config("module_private_config") { ohos_unittest("unittest_display_mgr_service") { module_out_path = module_output_path - sources = [ "src/display_mgr_service_test.cpp" ] + sources = [ "src/display_power_mgr_service_test.cpp" ] configs = [ "${displaymgr_utils_path}:utils_config", diff --git a/test/native/unittest/include/display_mgr_service_test.h b/test/native/unittest/include/display_power_mgr_service_test.h similarity index 94% rename from test/native/unittest/include/display_mgr_service_test.h rename to test/native/unittest/include/display_power_mgr_service_test.h index 21d05a35bc0123ca7bf25da0fea7c476f4313c60..8b328603fdf2aaeca16f699ac52acca272e6ba0b 100644 --- a/test/native/unittest/include/display_mgr_service_test.h +++ b/test/native/unittest/include/display_power_mgr_service_test.h @@ -18,7 +18,7 @@ #include -class DisplayMgrServiceTest : public testing::Test { +class DisplayPowerMgrServiceTest : public testing::Test { public: static void SetUpTestCase(void) {} static void TearDownTestCase(void) {} diff --git a/test/native/unittest/src/display_mgr_service_test.cpp b/test/native/unittest/src/display_power_mgr_service_test.cpp similarity index 31% rename from test/native/unittest/src/display_mgr_service_test.cpp rename to test/native/unittest/src/display_power_mgr_service_test.cpp index 5cc893a435837a745dcc9215d9231eb068f045e8..fc0e17c3e0859bfa7491612b75c53669f206c246 100644 --- a/test/native/unittest/src/display_mgr_service_test.cpp +++ b/test/native/unittest/src/display_power_mgr_service_test.cpp @@ -13,66 +13,127 @@ * limitations under the License. */ -#include "display_mgr_service_test.h" +#include "display_power_mgr_service_test.h" #include #include -#include "display_manager.h" -#include "display_mgr_service.h" +#include "display_power_mgr_client.h" +#include "display_power_mgr_service.h" using namespace testing::ext; using namespace OHOS; -using namespace OHOS::DisplayMgr; +using namespace OHOS::DisplayPowerMgr; +namespace { +#ifdef IPC_AVAILABLE /** - * @tc.name: DisplayMgrService01 - * @tc.desc: Test DisplayMgrService service ready. + * @tc.name: DisplayPowerMgrService01 + * @tc.desc: Test DisplayPowerMgrService service ready. * @tc.type: FUNC */ -HWTEST_F(DisplayMgrServiceTest, DisplayMgrService01, TestSize.Level0) +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService01, TestSize.Level0) { sptr sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - EXPECT_TRUE(sam != nullptr) << "DisplayMgrService01 fail to get GetSystemAbilityManager"; + EXPECT_TRUE(sam != nullptr) << "DisplayPowerMgrService01 fail to get GetSystemAbilityManager"; sptr remoteObject_ = sam->CheckSystemAbility(DISPLAY_MANAGER_SERVICE_ID); EXPECT_TRUE(remoteObject_ != nullptr) << "GetSystemAbility failed."; } /** - * @tc.name: DisplayMgrService002 + * @tc.name: DisplayPowerMgrService002 * @tc.desc: Test set screen state off * @tc.type: FUNC */ -HWTEST_F(DisplayMgrServiceTest, DisplayMgrService002, TestSize.Level0) +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService002, TestSize.Level0) { - auto ret = DisplayManager::SetScreenState(ScreenState::SCREEN_STATE_OFF); + auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); sleep(5); EXPECT_TRUE(ret); } /** - * @tc.name: DisplayMgrService003 + * @tc.name: DisplayPowerMgrService003 * @tc.desc: Test set screen state on * @tc.type: FUNC */ -HWTEST_F(DisplayMgrServiceTest, DisplayMgrService003, TestSize.Level0) +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService003, TestSize.Level0) { - auto ret = DisplayManager::SetScreenState(ScreenState::SCREEN_STATE_ON); + auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON); sleep(5); EXPECT_TRUE(ret); } /** - * @tc.name: DisplayMgrService004 + * @tc.name: DisplayPowerMgrService004 * @tc.desc: Test set brightness * @tc.type: FUNC */ -HWTEST_F(DisplayMgrServiceTest, DisplayMgrService004, TestSize.Level0) +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService004, TestSize.Level0) { - auto ret = DisplayManager::SetBrightness(5); + auto ret = DisplayPowerMgrClient::GetInstance().SetBrightness(5); sleep(5); EXPECT_TRUE(ret); - ret = DisplayManager::SetBrightness(255); + ret = DisplayPowerMgrClient::GetInstance().SetBrightness(255); sleep(5); EXPECT_TRUE(ret); } + + +/** + * @tc.name: DisplayPowerMgrService005 + * @tc.desc: Test set screen state on + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService005, TestSize.Level0) +{ + auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON); + sleep(5); + EXPECT_TRUE(ret); + DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(state == DisplayState::DISPLAY_ON); +} + +/** + * @tc.name: DisplayPowerMgrService006 + * @tc.desc: Test set screen state dim + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService006, TestSize.Level0) +{ + auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_DIM); + sleep(5); + EXPECT_TRUE(ret); + DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(state == DisplayState::DISPLAY_DIM); +} + +/** + * @tc.name: DisplayPowerMgrService007 + * @tc.desc: Test set screen state off + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService007, TestSize.Level0) +{ + auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); + sleep(5); + EXPECT_TRUE(ret); + DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(state == DisplayState::DISPLAY_OFF); +} + +/** + * @tc.name: DisplayPowerMgrService008 + * @tc.desc: Test set screen state suspend + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService008, TestSize.Level0) +{ + auto ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_SUSPEND); + sleep(5); + EXPECT_TRUE(ret); + DisplayState state = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(state == DisplayState::DISPLAY_SUSPEND); +} +#endif // IPC_AVAILABLE +} \ No newline at end of file diff --git a/utils/native/include/display_mgr_errors.h b/utils/native/include/display_mgr_errors.h index 90ca4866a063eaeb2823e168a369869d22f003c0..33b776280cdf4839ae0cda799ad2bd4611201e9f 100644 --- a/utils/native/include/display_mgr_errors.h +++ b/utils/native/include/display_mgr_errors.h @@ -19,7 +19,7 @@ #include namespace OHOS { -namespace DisplayMgr { +namespace DisplayPowerMgr { enum { /** * Module type: Display Manager Service @@ -42,7 +42,7 @@ enum { E_ADD_DEATH_RECIPIENT_FAILED, E_INNER_ERR }; -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS #endif // DISPLAYMGR_DISPLAY_MGR_ERRORS_H diff --git a/utils/native/include/hilog_wrapper.h b/utils/native/include/hilog_wrapper.h index 8a95164a7de3ecf862017828aeece184aa4fab2b..e19a9869af5f0ad51b5815c1d4f2cccb4efaec25 100644 --- a/utils/native/include/hilog_wrapper.h +++ b/utils/native/include/hilog_wrapper.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef DISPLAYMGR_HILOG_WRAPPER_H -#define DISPLAYMGR_HILOG_WRAPPER_H +#ifndef DISPLAY_POWER_MGR_HILOG_WRAPPER_H +#define DISPLAY_POWER_MGR_HILOG_WRAPPER_H #define CONFIG_HILOG #ifdef CONFIG_HILOG #include "hilog/log.h" namespace OHOS { -namespace DisplayMgr { +namespace DisplayPowerMgr { #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) #define __FORMATED(fmt, ...) "[%{public}s] %{public}s# " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__ @@ -45,45 +45,45 @@ namespace DisplayMgr { #endif // param of log interface, such as DISPLAY_HILOGF. -enum DisplayMgrSubModule { +enum DisplayPowerMgrSubModule { MODULE_INNERKIT = 0, MODULE_SERVICE, MODULE_JAVAKIT, // java kit, defined to avoid repeated use of domain. MODULE_JNI, MODULE_COMMON, MODULE_JS_NAPI, - DISPLAYMGR_MODULE_BUTT, + DISPLAY_POWER_MGR_MODULE_BUTT, }; -// 0xD002900: subsystem:PowerMgr module:DisplayMgr, 8 bits reserved. -static constexpr unsigned int BASE_DISPLAYMGR_DOMAIN_ID = 0xD002910; +// 0xD002900: subsystem:PowerMgr module:DisplayPowerMgr, 8 bits reserved. +static constexpr unsigned int BASE_DisplayPowerMgr_DOMAIN_ID = 0xD002910; -enum DisplayMgrDomainId { - DISPLAYMGR_INNERKIT_DOMAIN = BASE_DISPLAYMGR_DOMAIN_ID + MODULE_INNERKIT, - DISPLAYMGR_SERVICE_DOMAIN, - DISPLAYMGR_JAVAKIT_DOMAIN, +enum DisplayPowerMgrDomainId { + DISPLAY_POWER_MGR_INNERKIT_DOMAIN = BASE_DisplayPowerMgr_DOMAIN_ID + MODULE_INNERKIT, + DISPLAY_POWER_MGR_SERVICE_DOMAIN, + DISPLAY_POWER_MGR_JAVAKIT_DOMAIN, COMMON_DOMAIN, - DISPLAYMGR_JS_NAPI, - DISPLAYMGR_BUTT, + DISPLAY_POWER_MGR_JS_NAPI, + DISPLAY_POWER_MGR_BUTT, }; -static constexpr OHOS::HiviewDFX::HiLogLabel DISPLAY_MGR_LABEL[DISPLAYMGR_MODULE_BUTT] = { - {LOG_CORE, DISPLAYMGR_INNERKIT_DOMAIN, "DisplayMgrClient"}, - {LOG_CORE, DISPLAYMGR_SERVICE_DOMAIN, "DisplayMgrService"}, - {LOG_CORE, DISPLAYMGR_JAVAKIT_DOMAIN, "DisplayMgrJavaService"}, - {LOG_CORE, DISPLAYMGR_INNERKIT_DOMAIN, "DisplayMgrJni"}, - {LOG_CORE, COMMON_DOMAIN, "DisplayMgrCommon"}, - {LOG_CORE, DISPLAYMGR_JS_NAPI, "DisplayMgrJSNAPI"}, +static constexpr OHOS::HiviewDFX::HiLogLabel DISPLAY_MGR_LABEL[DISPLAY_POWER_MGR_MODULE_BUTT] = { + {LOG_CORE, DISPLAY_POWER_MGR_INNERKIT_DOMAIN, "DisplayPowerMgrClient"}, + {LOG_CORE, DISPLAY_POWER_MGR_SERVICE_DOMAIN, "DisplayPowerMgrService"}, + {LOG_CORE, DISPLAY_POWER_MGR_JAVAKIT_DOMAIN, "DisplayPowerMgrJavaService"}, + {LOG_CORE, DISPLAY_POWER_MGR_INNERKIT_DOMAIN, "DisplayPowerMgrJni"}, + {LOG_CORE, COMMON_DOMAIN, "DisplayPowerMgrCommon"}, + {LOG_CORE, DISPLAY_POWER_MGR_JS_NAPI, "DisplayPowerMgrJSNAPI"}, }; // In order to improve performance, do not check the module range. -// Besides, make sure module is less than DISPLAYMGR_MODULE_BUTT. +// Besides, make sure module is less than DisplayPowerMgr_MODULE_BUTT. #define DISPLAY_HILOGF(m, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(DISPLAY_MGR_LABEL[m], __FORMATED(__VA_ARGS__)) #define DISPLAY_HILOGE(m, ...) (void)OHOS::HiviewDFX::HiLog::Error(DISPLAY_MGR_LABEL[m], __FORMATED(__VA_ARGS__)) #define DISPLAY_HILOGW(m, ...) (void)OHOS::HiviewDFX::HiLog::Warn(DISPLAY_MGR_LABEL[m], __FORMATED(__VA_ARGS__)) #define DISPLAY_HILOGI(m, ...) (void)OHOS::HiviewDFX::HiLog::Info(DISPLAY_MGR_LABEL[m], __FORMATED(__VA_ARGS__)) #define DISPLAY_HILOGD(m, ...) (void)OHOS::HiviewDFX::HiLog::Debug(DISPLAY_MGR_LABEL[m], __FORMATED(__VA_ARGS__)) -} // namespace DisplayMgr +} // namespace DisplayPowerMgr } // namespace OHOS #else @@ -96,4 +96,4 @@ static constexpr OHOS::HiviewDFX::HiLogLabel DISPLAY_MGR_LABEL[DISPLAYMGR_MODULE #endif // CONFIG_HILOG -#endif // DISPLAYMGR_HILOG_WRAPPER_H +#endif // DISPLAY_POWER_MGR_HILOG_WRAPPER_H