diff --git a/frameworks/native/display_power_mgr_client.cpp b/frameworks/native/display_power_mgr_client.cpp index 599d28f078d058af0fb21ea92699b4c0c12a6464..c27be99013101474f0e553ea19114200c76643ce 100644 --- a/frameworks/native/display_power_mgr_client.cpp +++ b/frameworks/native/display_power_mgr_client.cpp @@ -118,6 +118,15 @@ bool DisplayPowerMgrClient::SetBrightness(uint32_t value, uint32_t displayId) return proxy->SetBrightness(value, displayId); } +bool DisplayPowerMgrClient::DiscountBrightness(double discount, uint32_t displayId) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return false; + } + return proxy->DiscountBrightness(discount, displayId); +} + bool DisplayPowerMgrClient::OverrideBrightness(uint32_t value, uint32_t displayId) { auto proxy = GetProxy(); @@ -172,6 +181,32 @@ uint32_t DisplayPowerMgrClient::GetMinBrightness() return proxy->GetMinBrightness(); } +double DisplayPowerMgrClient::GetDefaultDiscount() +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return DISCOUNT_DEFAULT; + } + return proxy->GetDefaultDiscount(); +} + +double DisplayPowerMgrClient::GetMaxDiscount() +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return DISCOUNT_MAX; + } + return proxy->GetMaxDiscount(); +} + +double DisplayPowerMgrClient::GetMinDiscount() +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return DISCOUNT_MIN; + } + return proxy->GetMinDiscount(); +} bool DisplayPowerMgrClient::AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id) { diff --git a/interfaces/innerkits/native/include/display_power_mgr_client.h b/interfaces/innerkits/native/include/display_power_mgr_client.h index 087dbe04a5612753bd7b389f97354f461177fcbf..747c4da4d84bae79c84c6dbf0751b403fe9489cd 100644 --- a/interfaces/innerkits/native/include/display_power_mgr_client.h +++ b/interfaces/innerkits/native/include/display_power_mgr_client.h @@ -38,12 +38,16 @@ public: std::vector GetDisplayIds(); int32_t GetMainDisplayId(); bool SetBrightness(uint32_t value, uint32_t displayId = 0); + bool DiscountBrightness(double discount, uint32_t displayId = 0); bool OverrideBrightness(uint32_t value, uint32_t displayId = 0); bool RestoreBrightness(uint32_t displayId = 0); uint32_t GetBrightness(uint32_t displayId = 0); uint32_t GetDefaultBrightness(); uint32_t GetMaxBrightness(); uint32_t GetMinBrightness(); + double GetDefaultDiscount(); + double GetMaxDiscount(); + double GetMinDiscount(); bool AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id = 0); bool AutoAdjustBrightness(bool enable); bool IsAutoAdjustBrightness(); @@ -72,6 +76,9 @@ private: static constexpr uint32_t BRIGHTNESS_DEFAULT {102}; static constexpr uint32_t BRIGHTNESS_MAX {255}; static constexpr uint32_t BRIGHTNESS_MIN {1}; + static constexpr double DISCOUNT_DEFAULT {1.00}; + static constexpr double DISCOUNT_MAX {1.00}; + static constexpr double DISCOUNT_MIN {0.01}; 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 f7cda6d28091286cf8e10a758821db794cc6dcf0..3df65f45997883877350f83939f68ec56aacee10 100644 --- a/interfaces/innerkits/native/include/idisplay_power_mgr.h +++ b/interfaces/innerkits/native/include/idisplay_power_mgr.h @@ -32,12 +32,16 @@ public: GET_DISPLAY_IDS, GET_MAIN_DISPLAY_ID, SET_BRIGHTNESS, + DISCOUNT_BRIGHTNESS, OVERRIDE_BRIGHTNESS, RESTORE_BRIGHTNESS, GET_BRIGHTNESS, GET_DEFAULT_BRIGHTNESS, GET_MAX_BRIGHTNESS, GET_MIN_BRIGHTNESS, + GET_DEFAULT_DISCOUNT, + GET_MAX_DISCOUNT, + GET_MIN_DISCOUNT, ADJUST_BRIGHTNESS, AUTO_ADJUST_BRIGHTNESS, IS_AUTO_ADJUST_BRIGHTNESS, @@ -51,12 +55,16 @@ public: virtual std::vector GetDisplayIds() = 0; virtual uint32_t GetMainDisplayId() = 0; virtual bool SetBrightness(uint32_t value, uint32_t displayId) = 0; + virtual bool DiscountBrightness(double discount, uint32_t displayId) = 0; virtual bool OverrideBrightness(uint32_t value, uint32_t displayId) = 0; virtual bool RestoreBrightness(uint32_t displayId) = 0; virtual uint32_t GetBrightness(uint32_t displayId) = 0; virtual uint32_t GetDefaultBrightness() = 0; virtual uint32_t GetMaxBrightness() = 0; virtual uint32_t GetMinBrightness() = 0; + virtual double GetDefaultDiscount() = 0; + virtual double GetMaxDiscount() = 0; + virtual double GetMinDiscount() = 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/native/include/display_param_helper.h b/service/native/include/display_param_helper.h index f55ee291bb9ca2e152ae519ffe9ed2befd5cbcb1..39405c1652a4b93283ba33f7ce455cd5a18a3808 100644 --- a/service/native/include/display_param_helper.h +++ b/service/native/include/display_param_helper.h @@ -26,6 +26,9 @@ public: uint32_t GetDefaultBrightness(); uint32_t GetMaxBrightness(); uint32_t GetMinBrightness(); + double GetDefaultDiscount(); + double GetMaxDiscount(); + double GetMinDiscount(); private: const std::string KEY_DEFAULT_BRIGHTNESS = "const.display.brightness.default"; @@ -34,9 +37,16 @@ private: static constexpr uint32_t BRIGHTNESS_MIN = 1; static constexpr uint32_t BRIGHTNESS_DEFAULT = 102; static constexpr uint32_t BRIGHTNESS_MAX = 255; + const std::string KEY_DEFAULT_DISCOUNT = "const.display.discount.default"; + const std::string KEY_MAX_DISCOUNT = "const.display.discount.max"; + const std::string KEY_MIN_DISCOUNT = "const.display.discount.min"; + static constexpr double DISCOUNT_DEFAULT = 1.00; + static constexpr double DISCOUNT_MAX = 1.00; + static constexpr double DISCOUNT_MIN = 0.01; static constexpr int32_t VALUE_MAX_LEN = 32; int32_t QueryIntValue(const std::string& key, int32_t def); + double QueryDoubleValue(const std::string& key, double def); }; } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/native/include/display_power_mgr_service.h b/service/native/include/display_power_mgr_service.h index bfc6650d683a1d726b40f4c4dac140549fe6a57f..8e36b9924700a3416b86c7c3fd1468a40d7564b1 100644 --- a/service/native/include/display_power_mgr_service.h +++ b/service/native/include/display_power_mgr_service.h @@ -37,12 +37,16 @@ public: virtual std::vector GetDisplayIds() override; virtual uint32_t GetMainDisplayId() override; virtual bool SetBrightness(uint32_t value, uint32_t displayId) override; + virtual bool DiscountBrightness(double discount, uint32_t displayId) override; virtual bool OverrideBrightness(uint32_t value, uint32_t displayId) override; virtual bool RestoreBrightness(uint32_t displayId) override; virtual uint32_t GetBrightness(uint32_t displayId) override; virtual uint32_t GetDefaultBrightness() override; virtual uint32_t GetMaxBrightness() override; virtual uint32_t GetMinBrightness() override; + virtual double GetDefaultDiscount() override; + virtual double GetMaxDiscount() override; + virtual double GetMinDiscount() override; virtual bool AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) override; virtual bool AutoAdjustBrightness(bool enable) override; virtual bool IsAutoAdjustBrightness() override; @@ -72,6 +76,8 @@ private: static const uint32_t BRIGHTNESS_OFF = 0; static const uint32_t BRIGHTNESS_MIN = 1; static const uint32_t BRIGHTNESS_MAX = 255; + static constexpr const double DISCOUNT_MIN = 0.01; + static constexpr const double DISCOUNT_MAX = 1.00; static void AmbientLightCallback(SensorEvent *event); friend DelayedSpSingleton; @@ -80,6 +86,7 @@ private: void InitSensors(); bool IsChangedLux(float scalar); static uint32_t GetSafeBrightness(uint32_t value); + static double GetSafeDiscount(double discount); bool CalculateBrightness(float scalar, int32_t& brightness); int32_t GetBrightnessFromLightScalar(float scalar); void ActivateAmbientSensor(); diff --git a/service/native/include/screen_controller.h b/service/native/include/screen_controller.h index 9779a778d2e06e86562909d0c8680431f972f690..1a06dbbaa3dce1547e6d942f208269dd87b2f5c8 100644 --- a/service/native/include/screen_controller.h +++ b/service/native/include/screen_controller.h @@ -44,6 +44,8 @@ public: const std::shared_ptr& action_; }; + class OverrideController; + class SharedController { public: SharedController(const uint32_t displayId); @@ -58,6 +60,7 @@ public: std::atomic isAllow_ { true }; std::shared_ptr action_ { nullptr }; std::shared_ptr animator_; + std::shared_ptr overrideContro_; }; class DisplayStateController { @@ -88,6 +91,7 @@ public: OverrideController(const std::shared_ptr& sharedControl, const std::shared_ptr& stateControl, const std::shared_ptr& handler); + bool DiscountBrightness(double discount, uint32_t gradualDuration = 0); bool OverrideBrightness(uint32_t value, uint32_t gradualDuration = SCREEN_BRIGHTNESS_UPDATE_DURATION); bool RestoreBrightness(uint32_t gradualDuration = SCREEN_BRIGHTNESS_UPDATE_DURATION); bool IsBrightnessOverride() const; @@ -95,6 +99,7 @@ public: bool BoostBrightness(uint32_t timeoutMs, uint32_t gradualDuration = SCREEN_BRIGHTNESS_UPDATE_DURATION); bool CancelBoostBrightness(); bool IsBoostBrightness() const; + double GetDiscount() const; private: void SaveBeforeBrightness(std::atomic& isOverride); bool BrightnessBeforeRestore(std::atomic& isOverride, uint32_t gradualDuration); @@ -102,6 +107,7 @@ public: std::mutex mutexOverride_; std::atomic isBrightnessOverride_ { false }; std::atomic isBoostBrightness_ { false }; + double discount_ { 1.0 }; const std::shared_ptr& sharedControl_; const std::shared_ptr& stateControl_; const std::shared_ptr& handler_; diff --git a/service/native/src/display_param_helper.cpp b/service/native/src/display_param_helper.cpp index ea04efbafed3893ea891545bfce59ecc8720efce..1c035abe4fd7d0d9fd21cba4a447ce35f10c9c52 100644 --- a/service/native/src/display_param_helper.cpp +++ b/service/native/src/display_param_helper.cpp @@ -41,6 +41,24 @@ uint32_t DisplayParamHelper::GetMinBrightness() return static_cast(value); } +double DisplayParamHelper::GetDefaultDiscount() +{ + double value = QueryDoubleValue(KEY_DEFAULT_DISCOUNT, DISCOUNT_DEFAULT); + return value; +} + +double DisplayParamHelper::GetMaxDiscount() +{ + double value = QueryDoubleValue(KEY_MAX_DISCOUNT, DISCOUNT_MAX); + return value; +} + +double DisplayParamHelper::GetMinDiscount() +{ + double value = QueryDoubleValue(KEY_MIN_DISCOUNT, DISCOUNT_MIN); + return value; +} + int32_t DisplayParamHelper::QueryIntValue(const std::string& key, int32_t def) { char value[VALUE_MAX_LEN] = {0}; @@ -51,5 +69,16 @@ int32_t DisplayParamHelper::QueryIntValue(const std::string& key, int32_t def) } return atoi(value); } + +double DisplayParamHelper::QueryDoubleValue(const std::string& key, double 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}f", 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 2bda7323c7b7c9a66f6aa88f7ba9bd11f2372607..afeb69bebc43720fa3321cc3fb28fd94390ba223 100644 --- a/service/native/src/display_power_mgr_service.cpp +++ b/service/native/src/display_power_mgr_service.cpp @@ -119,6 +119,17 @@ bool DisplayPowerMgrService::SetBrightness(uint32_t value, uint32_t displayId) return iter->second->SharedControl()->SetBrightness(brightness); } +bool DisplayPowerMgrService::DiscountBrightness(double discount, uint32_t displayId) +{ + auto safeDiscount = GetSafeDiscount(discount); + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "DiscountBrightness displayId=%{public}u, discount-%{public}f", displayId, safeDiscount); + auto iter = controllerMap_.find(displayId); + if (iter == controllerMap_.end()) { + return false; + } + return iter->second->OverrideControl()->DiscountBrightness(discount); +} + bool DisplayPowerMgrService::OverrideBrightness(uint32_t value, uint32_t displayId) { auto brightness = GetSafeBrightness(value); @@ -165,6 +176,21 @@ uint32_t DisplayPowerMgrService::GetMinBrightness() return DisplayParamHelper::GetInstance().GetMinBrightness(); } +double DisplayPowerMgrService::GetDefaultDiscount() +{ + return DisplayParamHelper::GetInstance().GetDefaultDiscount(); +} + +double DisplayPowerMgrService::GetMaxDiscount() +{ + return DisplayParamHelper::GetInstance().GetMaxDiscount(); +} + +double DisplayPowerMgrService::GetMinDiscount() +{ + return DisplayParamHelper::GetInstance().GetMinDiscount(); +} + bool DisplayPowerMgrService::AdjustBrightness(uint32_t id, int32_t value, uint32_t duration) { DISPLAY_HILOGI(FEAT_BRIGHTNESS, "SetDisplayState %{public}d, %{public}d, %{public}d", @@ -301,6 +327,8 @@ int32_t DisplayPowerMgrService::Dump(int32_t fd, const std::vector DISCOUNT_MAX) { + DISPLAY_HILOGW(COMP_SVC, "discount value is greater than max, discount=%{public}f", discount); + safeDiscount = DISCOUNT_MAX; + } + if (safeDiscount < DISCOUNT_MIN) { + DISPLAY_HILOGW(COMP_SVC, "discount value is less than min, discount=%{public}f", discount); + safeDiscount = DISCOUNT_MIN; + } + return safeDiscount; +} + bool DisplayPowerMgrService::CalculateBrightness(float scalar, int32_t& brightness) { const float lastLux = lastLux_; diff --git a/service/native/src/screen_controller.cpp b/service/native/src/screen_controller.cpp index f649a802dbe77e7c1c9193d28764bf369313bd66..70737e3d2cf4fa64a6e62e8c15f0aedb2e1aaa9f 100644 --- a/service/native/src/screen_controller.cpp +++ b/service/native/src/screen_controller.cpp @@ -73,6 +73,12 @@ bool ScreenController::SharedController::SetBrightness(uint32_t value, uint32_t DISPLAY_HILOGI(FEAT_BRIGHTNESS, "brightness is not allowed, ignore the change"); return false; } + double discount = overrideContro_->GetDiscount(); + if (discount != 1) { + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "discountBrightness value=%{public}u, discount=%{public}f", + value, discount); + return overrideContro_->DiscountBrightness(discount, gradualDuration); + } return UpdateBrightness(value, gradualDuration); } @@ -121,6 +127,22 @@ ScreenController::OverrideController::OverrideController(const shared_ptrEmplaceCallBack(DisplayEventHandler::Event::EVENT_CANCEL_BOOST_BRIGHTNESS, callback); } +bool ScreenController::OverrideController::DiscountBrightness(double discount, uint32_t gradualDuration) +{ + lock_guard lock(mutexOverride_); + bool screenOn = stateControl_->IsScreenOn(); + if (isBoostBrightness_ || !screenOn) { + DISPLAY_HILOGW(FEAT_BRIGHTNESS, "Cannot discount brightness. isBoost: %{public}d, screenOn: %{public}d", + isBoostBrightness_.load(), screenOn); + return false; + } + uint32_t discountBrightness = static_cast(sharedControl_->GetBrightness() * discount); + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "discount brightness, value=%{public}u, discount=%{public}f", + sharedControl_->GetBrightness(), discount); + beforeBrightness_ = discountBrightness; + return sharedControl_->UpdateBrightness(discountBrightness, gradualDuration); +} + bool ScreenController::OverrideController::OverrideBrightness(uint32_t value, uint32_t gradualDuration) { lock_guard lock(mutexOverride_); @@ -131,11 +153,13 @@ bool ScreenController::OverrideController::OverrideBrightness(uint32_t value, ui isBoostBrightness_.load(), screenOn); return false; } - DISPLAY_HILOGI(FEAT_BRIGHTNESS, "Override brightness, value=%{public}u", value); + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "Override brightness, value=%{public}u, discount=%{public}f", + value, discount_); if (!isBrightnessOverride_) { SaveBeforeBrightness(isBrightnessOverride_); } - return sharedControl_->UpdateBrightness(value, gradualDuration); + uint32_t brightness = static_cast(discount_ * value); + return sharedControl_->UpdateBrightness(brightness, gradualDuration); } bool ScreenController::OverrideController::RestoreBrightness(uint32_t gradualDuration) @@ -169,8 +193,9 @@ bool ScreenController::OverrideController::BoostBrightness(uint32_t timeoutMs, u return false; } if (!isBoostBrightness_) { - uint32_t maxBrightness = DisplayParamHelper::GetInstance().GetMaxBrightness(); - DISPLAY_HILOGI(FEAT_BRIGHTNESS, "Boost brightness, maxBrightness: %{public}d", maxBrightness); + uint32_t maxBrightness = static_cast(DisplayParamHelper::GetInstance().GetMaxBrightness() * discount_); + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "Boost brightness, maxBrightness: %{public}d, discount: %{public}f", + maxBrightness, discount_); SaveBeforeBrightness(isBoostBrightness_); sharedControl_->UpdateBrightness(maxBrightness, gradualDuration); } @@ -199,6 +224,11 @@ bool ScreenController::OverrideController::IsBoostBrightness() const return isBoostBrightness_; } +double ScreenController::OverrideController::GetDiscount() const +{ + return discount_; +} + void ScreenController::OverrideController::SaveBeforeBrightness(atomic& isOverride) { isOverride = true; diff --git a/service/zidl/include/display_power_mgr_proxy.h b/service/zidl/include/display_power_mgr_proxy.h index 20ad361067426a927c2dfd1e68be3fe88ba36a5a..e1a8e819d40bd63fb5f4ca80e94ef53a3d73b729 100644 --- a/service/zidl/include/display_power_mgr_proxy.h +++ b/service/zidl/include/display_power_mgr_proxy.h @@ -34,12 +34,16 @@ public: virtual uint32_t GetMainDisplayId() override; virtual bool SetBrightness(uint32_t value, uint32_t displayId) override; + virtual bool DiscountBrightness(double value, uint32_t displayId) override; virtual bool OverrideBrightness(uint32_t value, uint32_t displayId) override; virtual bool RestoreBrightness(uint32_t displayId) override; virtual uint32_t GetBrightness(uint32_t displayId) override; virtual uint32_t GetDefaultBrightness() override; virtual uint32_t GetMaxBrightness() override; virtual uint32_t GetMinBrightness() override; + virtual double GetDefaultDiscount() override; + virtual double GetMaxDiscount() override; + virtual double GetMinDiscount() 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 ee6232d05e869951fdbc05185d4da0e50824c90a..7b17bb242f33816b2d4e97a64eae6aa29daed0f0 100644 --- a/service/zidl/include/display_power_mgr_stub.h +++ b/service/zidl/include/display_power_mgr_stub.h @@ -32,12 +32,16 @@ private: int32_t GetDisplayIdsStub(MessageParcel& data, MessageParcel& reply); int32_t GetMainDisplayIdStub(MessageParcel& data, MessageParcel& reply); int32_t SetBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t DiscountBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t OverrideBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t RestoreBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t GetBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t GetDefaultBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t GetMaxBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t GetMinBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t GetDefaultDiscountStub(MessageParcel& data, MessageParcel& reply); + int32_t GetMaxDiscountStub(MessageParcel& data, MessageParcel& reply); + int32_t GetMinDiscountStub(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 e7c643635f11643875e00a39e0b97aab79d171f1..97acb55eb0435e1e29bae425c942f58060857fca 100644 --- a/service/zidl/src/display_power_mgr_proxy.cpp +++ b/service/zidl/src/display_power_mgr_proxy.cpp @@ -192,6 +192,40 @@ bool DisplayPowerMgrProxy::SetBrightness(uint32_t value, uint32_t displayId) return result; } +bool DisplayPowerMgrProxy::DiscountBrightness(double discount, uint32_t displayId) +{ + sptr remote = Remote(); + RETURN_IF_WITH_RET(remote == nullptr, false); + + bool result = false; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(DisplayPowerMgrProxy::GetDescriptor())) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s write descriptor failed!", __func__); + return result; + } + + WRITE_PARCEL_WITH_RET(data, Double, discount, false); + WRITE_PARCEL_WITH_RET(data, Uint32, displayId, false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::DISCOUNT_BRIGHTNESS), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed: %{public}d", __func__, + ret); + return false; + } + + if(!reply.ReadBool(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return false; + } + + return result; +} + bool DisplayPowerMgrProxy::OverrideBrightness(uint32_t value, uint32_t displayId) { sptr remote = Remote(); @@ -384,6 +418,99 @@ uint32_t DisplayPowerMgrProxy::GetMinBrightness() return result; } +double DisplayPowerMgrProxy::GetDefaultDiscount() +{ + sptr remote = Remote(); + double result = 1.00; + + 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_DISCOUNT), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadDouble(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return result; + } + + return result; +} + +double DisplayPowerMgrProxy::GetMaxDiscount() +{ + sptr remote = Remote(); + double result = 1.00; + + 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_DISCOUNT), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadDouble(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return result; + } + + return result; +} + +double DisplayPowerMgrProxy::GetMinDiscount() +{ + sptr remote = Remote(); + double result = 1.00; + + 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_DISCOUNT), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadDouble(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 aefa70fd8c37b7a21f65c7416fe7036db029d317..efe324233da46856d75f02a8fe8dcbd0550eb954 100644 --- a/service/zidl/src/display_power_mgr_stub.cpp +++ b/service/zidl/src/display_power_mgr_stub.cpp @@ -54,6 +54,9 @@ int32_t DisplayPowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case static_cast(IDisplayPowerMgr::SET_BRIGHTNESS): ret = SetBrightnessStub(data, reply); break; + case static_cast(IDisplayPowerMgr::DISCOUNT_BRIGHTNESS): + ret = DiscountBrightnessStub(data, reply); + break; case static_cast(IDisplayPowerMgr::OVERRIDE_BRIGHTNESS): ret = OverrideBrightnessStub(data, reply); break; @@ -169,6 +172,22 @@ int32_t DisplayPowerMgrStub::SetBrightnessStub(MessageParcel& data, MessageParce return ERR_OK; } +int32_t DisplayPowerMgrStub::DiscountBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + double discount = 0; + uint32_t displayId = 0; + + READ_PARCEL_WITH_RET(data, Double, discount, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR); + + bool ret = DiscountBrightness(discount, displayId); + if (!reply.WriteBool(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to wirte DiscountBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + int32_t DisplayPowerMgrStub::OverrideBrightnessStub(MessageParcel& data, MessageParcel& reply) { uint32_t value = 0; @@ -243,6 +262,37 @@ int32_t DisplayPowerMgrStub::GetMinBrightnessStub(MessageParcel& data, MessagePa return ERR_OK; } +int32_t DisplayPowerMgrStub::GetDefaultDiscountStub(MessageParcel& data, MessageParcel& reply) +{ + double ret = GetDefaultDiscount(); + if (!reply.WriteDouble(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDefaultBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::GetMaxDiscountStub(MessageParcel& data, MessageParcel& reply) +{ + double ret = GetMaxDiscount(); + if (!reply.WriteDouble(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMaxBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + +int32_t DisplayPowerMgrStub::GetMinDiscountStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t ret = GetMinDiscount(); + if (!reply.WriteDouble(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMaxBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + + int32_t DisplayPowerMgrStub::AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply) { uint32_t id = 0;