From 20aee5f6033600d7ad2f9e7cef3896291219e195 Mon Sep 17 00:00:00 2001 From: aqxyjay Date: Fri, 29 Apr 2022 15:55:41 +0800 Subject: [PATCH 1/4] feat: add brightness para file Signed-off-by: aqxyjay --- service/etc/BUILD.gn | 23 +++++++++++++++++++++++ service/etc/display.para | 4 ++++ 2 files changed, 27 insertions(+) create mode 100644 service/etc/BUILD.gn create mode 100644 service/etc/display.para diff --git a/service/etc/BUILD.gn b/service/etc/BUILD.gn new file mode 100644 index 0000000..59e9863 --- /dev/null +++ b/service/etc/BUILD.gn @@ -0,0 +1,23 @@ +# 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. + +import("//base/powermgr/display_manager/displaymgr.gni") +import("//build/ohos.gni") + +## Install display.para to /system/etc/param/display.para +ohos_prebuilt_etc("display.para") { + source = "display.para" + relative_install_dir = "param" + part_name = "${displaymgr_native_part_name}" + subsystem_name = "powermgr" +} diff --git a/service/etc/display.para b/service/etc/display.para new file mode 100644 index 0000000..45a81cc --- /dev/null +++ b/service/etc/display.para @@ -0,0 +1,4 @@ +# Brightness +const.display.brightness.min=1 +const.display.brightness.default=102 +const.display.brightness.max=255 \ No newline at end of file -- Gitee From 1b680da40ddc473221065a4378255c9f245e9b92 Mon Sep 17 00:00:00 2001 From: aqxyjay Date: Fri, 29 Apr 2022 17:23:25 +0800 Subject: [PATCH 2/4] feat: impl brightness para helper to query brightness values Signed-off-by: aqxyjay --- bundle.json | 1 + .../native/display_power_mgr_client.cpp | 28 ++++++ .../native/include/display_power_mgr_client.h | 6 ++ .../native/include/idisplay_power_mgr.h | 6 ++ service/BUILD.gn | 2 + service/native/include/display_param_helper.h | 44 +++++++++ .../include/display_power_mgr_service.h | 3 + service/native/src/display_param_helper.cpp | 55 +++++++++++ .../native/src/display_power_mgr_service.cpp | 17 +++- .../zidl/include/display_power_mgr_proxy.h | 3 + service/zidl/include/display_power_mgr_stub.h | 3 + service/zidl/src/display_power_mgr_proxy.cpp | 93 +++++++++++++++++++ service/zidl/src/display_power_mgr_stub.cpp | 39 ++++++++ 13 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 service/native/include/display_param_helper.h create mode 100644 service/native/src/display_param_helper.cpp diff --git a/bundle.json b/bundle.json index 5c1fac1..61eae12 100755 --- a/bundle.json +++ b/bundle.json @@ -43,6 +43,7 @@ "//base/powermgr/display_manager/interfaces/innerkits:displaymgr", "//base/powermgr/display_manager/sa_profile:displaymgr_sa_profile", "//base/powermgr/display_manager/service:displaymgrservice", + "//base/powermgr/display_manager/service/etc:display.para", "//base/powermgr/display_manager/interfaces/kits/js/napi:brightness" ], "inner_kits": [ diff --git a/frameworks/native/display_power_mgr_client.cpp b/frameworks/native/display_power_mgr_client.cpp index 5a53aa5..024b582 100644 --- a/frameworks/native/display_power_mgr_client.cpp +++ b/frameworks/native/display_power_mgr_client.cpp @@ -145,6 +145,34 @@ uint32_t DisplayPowerMgrClient::GetBrightness(uint32_t displayId) return proxy->GetBrightness(displayId); } +uint32_t DisplayPowerMgrClient::GetDefaultBrightness() +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return BRIGHTNESS_DEFAULT; + } + return proxy->GetDefaultBrightness(); +} + +uint32_t DisplayPowerMgrClient::GetMaxBrightness() +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return BRIGHTNESS_MAX; + } + return proxy->GetMaxBrightness(); +} + +uint32_t DisplayPowerMgrClient::GetMinBrightness() +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return BRIGHTNESS_MIN; + } + return proxy->GetMinBrightness(); +} + + bool DisplayPowerMgrClient::AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id) { auto proxy = GetProxy(); diff --git a/interfaces/innerkits/native/include/display_power_mgr_client.h b/interfaces/innerkits/native/include/display_power_mgr_client.h index 0ec8752..976045e 100644 --- a/interfaces/innerkits/native/include/display_power_mgr_client.h +++ b/interfaces/innerkits/native/include/display_power_mgr_client.h @@ -41,6 +41,9 @@ public: bool OverrideBrightness(uint32_t value, uint32_t displayId = 0); bool RestoreBrightness(uint32_t displayId = 0); uint32_t GetBrightness(uint32_t displayId = 0); + uint32_t GetDefaultBrightness(); + uint32_t GetMaxBrightness(); + uint32_t GetMinBrightness(); 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); @@ -65,6 +68,9 @@ private: void OnRemoteDied(const wptr& remote); static constexpr int32_t INVALID_DISPLAY_ID {-1}; static constexpr uint32_t BRIGHTNESS_OFF {0}; + static constexpr uint32_t BRIGHTNESS_DEFAULT {102}; + static constexpr uint32_t BRIGHTNESS_MAX {255}; + static constexpr uint32_t BRIGHTNESS_MIN {1}; 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 2bbda9c..bba82fe 100644 --- a/interfaces/innerkits/native/include/idisplay_power_mgr.h +++ b/interfaces/innerkits/native/include/idisplay_power_mgr.h @@ -35,6 +35,9 @@ public: OVERRIDE_BRIGHTNESS, RESTORE_BRIGHTNESS, GET_BRIGHTNESS, + GET_DEFAULT_BRIGHTNESS, + GET_MAX_BRIGHTNESS, + GET_MIN_BRIGHTNESS, ADJUST_BRIGHTNESS, AUTO_ADJUST_BRIGHTNESS, IS_AUTO_ADJUST_BRIGHTNESS, @@ -50,6 +53,9 @@ public: 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 uint32_t GetDefaultBrightness() = 0; + virtual uint32_t GetMaxBrightness() = 0; + virtual uint32_t GetMinBrightness() = 0; virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) = 0; virtual bool AutoAdjustBrightness(bool enable) = 0; virtual bool IsAutoAdjustBrightness() = 0; diff --git a/service/BUILD.gn b/service/BUILD.gn index da617b5..a3ddf25 100644 --- a/service/BUILD.gn +++ b/service/BUILD.gn @@ -32,6 +32,7 @@ config("displaymgr_public_config") { ohos_shared_library("displaymgrservice") { sources = [ + "native/src/display_param_helper.cpp", "native/src/display_power_mgr_service.cpp", "native/src/display_system_ability.cpp", "native/src/gradual_animator.cpp", @@ -68,6 +69,7 @@ ohos_shared_library("displaymgrservice") { "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", "sensor:sensor_interface_native", + "startup_l2:syspara", "window_manager:libdm", ] diff --git a/service/native/include/display_param_helper.h b/service/native/include/display_param_helper.h new file mode 100644 index 0000000..0a4dc85 --- /dev/null +++ b/service/native/include/display_param_helper.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef POWERMGR_DISPLAY_MANAGER_DISPLAY_PARAM_HELPER_H +#define POWERMGR_DISPLAY_MANAGER_DISPLAY_PARAM_HELPER_H + +#include + +namespace OHOS { +namespace DisplayPowerMgr { +class DisplayParamHelper : public DelayedRefSingleton { + DECLARE_DELAYED_REF_SINGLETON(DisplayParamHelper); +public: + uint32_t GetDefaultBrightness(); + uint32_t GetMaxBrightness(); + uint32_t GetMinBrightness(); + +private: + const std::string KEY_DEFAULT_BRIGHTNESS = "const.display.brightness.default"; + const std::string KEY_MAX_BRIGHTNESS = "const.display.brightness.max"; + const std::string KEY_MIN_BRIGHTNESS = "const.display.brightness.min"; + static constexpr uint32_t BRIGHTNESS_MIN = 1; + static constexpr uint32_t BRIGHTNESS_DEFAULT = 102; + static constexpr uint32_t BRIGHTNESS_MAX = 255; + static constexpr int32_t VALUE_MAX_LEN = 32; + + int32_t QueryIntValue(const std::string& key, int32_t def); +}; +} // namespace DisplayPowerMgr +} // namespace OHOS + +#endif //POWERMGR_DISPLAY_MANAGER_DISPLAY_PARAM_HELPER_H diff --git a/service/native/include/display_power_mgr_service.h b/service/native/include/display_power_mgr_service.h index faf556a..9bf6c17 100644 --- a/service/native/include/display_power_mgr_service.h +++ b/service/native/include/display_power_mgr_service.h @@ -39,6 +39,9 @@ public: 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 uint32_t GetDefaultBrightness() override; + virtual uint32_t GetMaxBrightness() override; + virtual uint32_t GetMinBrightness() override; virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) override; virtual bool AutoAdjustBrightness(bool enable) override; virtual bool IsAutoAdjustBrightness() override; diff --git a/service/native/src/display_param_helper.cpp b/service/native/src/display_param_helper.cpp new file mode 100644 index 0000000..ea04efb --- /dev/null +++ b/service/native/src/display_param_helper.cpp @@ -0,0 +1,55 @@ +/* + * 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 "display_param_helper.h" + +#include +#include "display_log.h" + +namespace OHOS { +namespace DisplayPowerMgr { +DisplayParamHelper::DisplayParamHelper() = default; +DisplayParamHelper::~DisplayParamHelper() = default; + +uint32_t DisplayParamHelper::GetDefaultBrightness() +{ + int32_t value = QueryIntValue(KEY_DEFAULT_BRIGHTNESS, BRIGHTNESS_DEFAULT); + return static_cast(value); +} + +uint32_t DisplayParamHelper::GetMaxBrightness() +{ + int32_t value = QueryIntValue(KEY_MAX_BRIGHTNESS, BRIGHTNESS_MAX); + return static_cast(value); +} + +uint32_t DisplayParamHelper::GetMinBrightness() +{ + int32_t value = QueryIntValue(KEY_MIN_BRIGHTNESS, BRIGHTNESS_MIN); + return static_cast(value); +} + +int32_t DisplayParamHelper::QueryIntValue(const std::string& key, int32_t def) +{ + char value[VALUE_MAX_LEN] = {0}; + int32_t ret = GetParameter(key.c_str(), std::to_string(def).c_str(), value, VALUE_MAX_LEN); + if (ret < 0) { + DISPLAY_HILOGW(COMP_SVC, "GetParameter failed, return default value, ret=%{public}d, def=%{public}d", ret, def); + return def; + } + return atoi(value); +} +} // namespace DisplayPowerMgr +} // namespace OHOS \ No newline at end of file diff --git a/service/native/src/display_power_mgr_service.cpp b/service/native/src/display_power_mgr_service.cpp index f6b1417..523ff49 100644 --- a/service/native/src/display_power_mgr_service.cpp +++ b/service/native/src/display_power_mgr_service.cpp @@ -18,7 +18,7 @@ #include #include #include - +#include "display_param_helper.h" #include "display_log.h" namespace OHOS { @@ -128,6 +128,21 @@ uint32_t DisplayPowerMgrService::GetBrightness(uint32_t displayId) return iter->second->GetBrightness(); } +uint32_t DisplayPowerMgrService::GetDefaultBrightness() +{ + return DisplayParamHelper::GetInstance().GetDefaultBrightness(); +} + +uint32_t DisplayPowerMgrService::GetMaxBrightness() +{ + return DisplayParamHelper::GetInstance().GetMaxBrightness(); +} + +uint32_t DisplayPowerMgrService::GetMinBrightness() +{ + return DisplayParamHelper::GetInstance().GetMinBrightness(); +} + bool DisplayPowerMgrService::AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) { DISPLAY_HILOGI(FEAT_BRIGHTNESS, "SetDisplayState %{public}d, %{public}d, %{public}d", diff --git a/service/zidl/include/display_power_mgr_proxy.h b/service/zidl/include/display_power_mgr_proxy.h index 60a6519..22711cc 100644 --- a/service/zidl/include/display_power_mgr_proxy.h +++ b/service/zidl/include/display_power_mgr_proxy.h @@ -37,6 +37,9 @@ public: 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 uint32_t GetDefaultBrightness() override; + virtual uint32_t GetMaxBrightness() override; + virtual uint32_t GetMinBrightness() override; virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) override; virtual bool AutoAdjustBrightness(bool enable) override; virtual bool IsAutoAdjustBrightness() override; diff --git a/service/zidl/include/display_power_mgr_stub.h b/service/zidl/include/display_power_mgr_stub.h index 042bccc..38b33c9 100644 --- a/service/zidl/include/display_power_mgr_stub.h +++ b/service/zidl/include/display_power_mgr_stub.h @@ -35,6 +35,9 @@ private: int32_t OverrideBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t RestoreBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t GetBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t GetDefaultBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t GetMaxBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t GetMinBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t AutoAdjustBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t IsAutoAdjustBrightnessStub(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 fd20ba4..059a09d 100644 --- a/service/zidl/src/display_power_mgr_proxy.cpp +++ b/service/zidl/src/display_power_mgr_proxy.cpp @@ -291,6 +291,99 @@ uint32_t DisplayPowerMgrProxy::GetBrightness(uint32_t displayId) return result; } +uint32_t DisplayPowerMgrProxy::GetDefaultBrightness() +{ + 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(COMP_FWK, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return result; + } + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::GET_DEFAULT_BRIGHTNESS), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return result; + } + + return result; +} + +uint32_t DisplayPowerMgrProxy::GetMaxBrightness() +{ + 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(COMP_FWK, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return result; + } + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::GET_MAX_BRIGHTNESS), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return result; + } + + return result; +} + +uint32_t DisplayPowerMgrProxy::GetMinBrightness() +{ + 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(COMP_FWK, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return result; + } + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::GET_MIN_BRIGHTNESS), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return result; + } + + return result; +} + bool DisplayPowerMgrProxy::AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) { sptr remote = Remote(); diff --git a/service/zidl/src/display_power_mgr_stub.cpp b/service/zidl/src/display_power_mgr_stub.cpp index a1ba448..86e3f9a 100644 --- a/service/zidl/src/display_power_mgr_stub.cpp +++ b/service/zidl/src/display_power_mgr_stub.cpp @@ -63,6 +63,15 @@ int32_t DisplayPowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case static_cast(IDisplayPowerMgr::GET_BRIGHTNESS): ret = GetBrightnessStub(data, reply); break; + case static_cast(IDisplayPowerMgr::GET_DEFAULT_BRIGHTNESS): + ret = GetDefaultBrightnessStub(data, reply); + break; + case static_cast(IDisplayPowerMgr::GET_MAX_BRIGHTNESS): + ret = GetMaxBrightnessStub(data, reply); + break; + case static_cast(IDisplayPowerMgr::GET_MIN_BRIGHTNESS): + ret = GetMinBrightnessStub(data, reply); + break; case static_cast(IDisplayPowerMgr::ADJUST_BRIGHTNESS): ret = AdjustBrightnessStub(data, reply); break; @@ -201,6 +210,36 @@ int32_t DisplayPowerMgrStub::GetBrightnessStub(MessageParcel& data, MessageParce return ERR_OK; } +int32_t DisplayPowerMgrStub::GetDefaultBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t ret = GetDefaultBrightness(); + if (!reply.WriteUint32(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDefaultBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::GetMaxBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t ret = GetMaxBrightness(); + if (!reply.WriteUint32(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMaxBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::GetMinBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t ret = GetMinBrightness(); + if (!reply.WriteUint32(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMinBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + int32_t DisplayPowerMgrStub::AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply) { uint32_t id = 0; -- Gitee From cc19d3ef67facc57b3fef465e0a551099d9b42ad Mon Sep 17 00:00:00 2001 From: aqxyjay Date: Sat, 30 Apr 2022 16:16:03 +0800 Subject: [PATCH 3/4] feat: add brightness limits to dump Signed-off-by: aqxyjay --- service/BUILD.gn | 2 +- service/etc/display.para | 13 +++++++++++++ service/native/include/display_param_helper.h | 2 +- service/native/src/display_power_mgr_service.cpp | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/service/BUILD.gn b/service/BUILD.gn index a3ddf25..255ab42 100644 --- a/service/BUILD.gn +++ b/service/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 diff --git a/service/etc/display.para b/service/etc/display.para index 45a81cc..49023db 100644 --- a/service/etc/display.para +++ b/service/etc/display.para @@ -1,3 +1,16 @@ +# 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. + # Brightness const.display.brightness.min=1 const.display.brightness.default=102 diff --git a/service/native/include/display_param_helper.h b/service/native/include/display_param_helper.h index 0a4dc85..f55ee29 100644 --- a/service/native/include/display_param_helper.h +++ b/service/native/include/display_param_helper.h @@ -41,4 +41,4 @@ private: } // namespace DisplayPowerMgr } // namespace OHOS -#endif //POWERMGR_DISPLAY_MANAGER_DISPLAY_PARAM_HELPER_H +#endif // POWERMGR_DISPLAY_MANAGER_DISPLAY_PARAM_HELPER_H diff --git a/service/native/src/display_power_mgr_service.cpp b/service/native/src/display_power_mgr_service.cpp index 523ff49..d52d976 100644 --- a/service/native/src/display_power_mgr_service.cpp +++ b/service/native/src/display_power_mgr_service.cpp @@ -300,6 +300,12 @@ int32_t DisplayPowerMgrService::Dump(int32_t fd, const std::vector Date: Sat, 30 Apr 2022 22:46:14 +0800 Subject: [PATCH 4/4] feat: add brightness limits ut Signed-off-by: aqxyjay --- service/etc/display.para | 2 +- .../src/display_power_mgr_brightness_test.cpp | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/service/etc/display.para b/service/etc/display.para index 49023db..e4f1da0 100644 --- a/service/etc/display.para +++ b/service/etc/display.para @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Brightness +# Brightness limits is 0-255. const.display.brightness.min=1 const.display.brightness.default=102 const.display.brightness.max=255 \ No newline at end of file diff --git a/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp b/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp index 7a7f0f4..5cecc61 100644 --- a/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp +++ b/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp @@ -127,4 +127,44 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBrightness005, TestSize.L EXPECT_EQ(value, 100); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBrightness005: fun is end"); } + +/** + * @tc.name: DisplayPowerMgrMaxBrightness001 + * @tc.desc: Test GetMaxBrightness less equals 255 + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrMaxBrightness001, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMaxBrightness001: fun is start"); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetMaxBrightness(); + EXPECT_LE(value, 255); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMaxBrightness001: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrMinBrightness001 + * @tc.desc: Test GetMinBrightness greater equals 0 + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrMinBrightness001, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMinBrightness001: fun is start"); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetMinBrightness(); + EXPECT_GE(value, 0); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMinBrightness001: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDefaultBrightness001 + * @tc.desc: Test GetDefaultnBrightness greater equals 0 and less equals 255 + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDefaultBrightness001, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDefaultBrightness001: fun is start"); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDefaultBrightness(); + EXPECT_GE(value, 0); + EXPECT_LE(value, 255); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDefaultBrightness001: fun is end"); +} } \ No newline at end of file -- Gitee