diff --git a/bundle.json b/bundle.json index 5c1fac17beef95592c36a823a77f69996d40df67..61eae12808d9dd1cde00c7251fcd67871e51bdda 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 5a53aa5da88ce7c78dc64e78a99a7836f209e832..024b58264720dec4da44bb97a182b26672d02e18 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 0ec87528602f96e78b19347c2fc6689569bdb5aa..976045e6eac5c4decec279417f4fac1eca34a8e1 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 2bbda9c9775641589c1b5756946ba1d42136e5ab..bba82fe9d3efccbf1cb03774e10a9c397ee070c9 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 da617b55c8c51985ac370b14a8ae375c606f551a..255ab42bf77bbd348b422e5dbb208ae2d7cf0d79 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 @@ -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/etc/BUILD.gn b/service/etc/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..59e98638093585231fe86555f8e22a12fa365018 --- /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 0000000000000000000000000000000000000000..e4f1da00a6352e882db9333f660604ced1ae4188 --- /dev/null +++ b/service/etc/display.para @@ -0,0 +1,17 @@ +# 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 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/service/native/include/display_param_helper.h b/service/native/include/display_param_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..f55ee291bb9ca2e152ae519ffe9ed2befd5cbcb1 --- /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 faf556aac0f225baa4331dacd7492fdf29255a8f..9bf6c174eceece1b5326dbe52dd8d38c7bc99b0d 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 0000000000000000000000000000000000000000..ea04efbafed3893ea891545bfce59ecc8720efce --- /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 f6b1417d4da47c616d436105149418f3aa3873f2..d52d976beb9384986d103b0fa42804eaa8129a98 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", @@ -285,6 +300,12 @@ int32_t DisplayPowerMgrService::Dump(int32_t fd, const std::vector 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 a1ba4481be5c76b9c69d8faa3150eee4532f97b8..86e3f9afba9c74ea390027b409f79cfd41144034 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; 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 7a7f0f45d8692ce58e0cdc5eacb6c2d3c7b885a9..5cecc61ae43cfc14f835995e29791edaa336a6b5 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