diff --git a/brightness_manager/include/brightness_manager.h b/brightness_manager/include/brightness_manager.h index d36c0dcf8b95734bcd4c0493c7be2cc3cedbbf13..80849748db7bee6869463c85575b6bd6ab4da19e 100644 --- a/brightness_manager/include/brightness_manager.h +++ b/brightness_manager/include/brightness_manager.h @@ -48,6 +48,7 @@ public: uint32_t GetBrightness(); uint32_t GetDeviceBrightness(); void ClearOffset(); + uint32_t SetLightBrightnessThreshold(std::vector threshold, sptr callback); uint32_t GetCurrentDisplayId(uint32_t defaultId) const; void SetDisplayId(uint32_t id = 0); diff --git a/brightness_manager/include/brightness_service.h b/brightness_manager/include/brightness_service.h index 0a7b643e49b3d41dd079960e327099a57aa95673..f5cae15c430b4f517b7ef064827fd3803b57c050 100644 --- a/brightness_manager/include/brightness_service.h +++ b/brightness_manager/include/brightness_service.h @@ -36,6 +36,7 @@ #include "dm_common.h" #include "event_runner.h" #include "iremote_object.h" +#include "idisplay_brightness_callback.h" #include "light_lux_manager.h" #include "refbase.h" #include "ffrt_utils.h" @@ -137,6 +138,7 @@ public: void UpdateBrightnessSceneMode(BrightnessSceneMode mode); uint32_t GetDisplayId(); void SetDisplayId(uint32_t displayId); + uint32_t SetLightBrightnessThreshold(std::vector threshold, sptr callback); uint32_t GetCurrentDisplayId(uint32_t defaultId) const; bool IsDimming(); void ReportBrightnessBigData(uint32_t brightness); @@ -180,6 +182,7 @@ private: void RegisterFoldStatusListener(); void UnRegisterFoldStatusListener(); std::string GetReason(); + void NotifyLightChangeToAps(uint32_t type, float value); bool mIsFoldDevice{false}; bool mIsAutoBrightnessEnabled{false}; @@ -204,6 +207,11 @@ private: std::shared_ptr queue_; bool mIsUserMode{false}; std::atomic mIsSleepStatus{false}; + std::vector mLightBrightnessThreshold; + sptr mApsListenLightChangeCallback = nullptr; + bool mIsBrightnessValidate = false; + bool mIsLightValidate = false; + time_t mLastCallApsTime {0}; }; } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/brightness_manager/src/brightness_manager.cpp b/brightness_manager/src/brightness_manager.cpp index 2ada0acb4f9ad855cad5e68f89d02020a446437f..287d3bae21db572c0269c17bc45f4f0506d56819 100644 --- a/brightness_manager/src/brightness_manager.cpp +++ b/brightness_manager/src/brightness_manager.cpp @@ -112,6 +112,11 @@ uint32_t BrightnessManager::GetDeviceBrightness() return BrightnessService::Get().GetDeviceBrightness(); } +uint32_t BrightnessManager::SetLightBrightnessThreshold( + std::vector threshold, sptr callback) +{ + return BrightnessService::Get().SetLightBrightnessThreshold(threshold, callback); +} bool BrightnessManager::IsBrightnessOverridden() const { return BrightnessService::Get().IsBrightnessOverridden(); diff --git a/brightness_manager/src/brightness_service.cpp b/brightness_manager/src/brightness_service.cpp index 67eb294bc8bb60699e2167109586f50cd91be2ba..76ec155268d1f28502d13a03692140aebf9c3052 100644 --- a/brightness_manager/src/brightness_service.cpp +++ b/brightness_manager/src/brightness_service.cpp @@ -57,6 +57,10 @@ constexpr uint32_t MIN_DEFAULT_HIGH_BRGIHTNESS_LEVEL = 156; constexpr uint32_t DEFAULT_ANIMATING_DURATION = 500; constexpr uint32_t DEFAULT_BRIGHTEN_DURATION = 2000; constexpr uint32_t DEFAULT_DARKEN_DURATION = 5000; +constexpr uint32_t BRIGHTNESS_TYPE = 0; +constexpr uint32_t AMBIENT_LIGHT_TYPE = 1; +constexpr uint32_t APS_LISTEN_PARAMS_LENGHT = 3; +constexpr time_t CALL_APS_INTERVAL = 2; FFRTHandle g_cancelBoostTaskHandle{}; } @@ -182,6 +186,57 @@ uint32_t BrightnessService::GetDisplayId() return mDisplayId; } +void BrightnessService::NotifyLightChangeToAps(uint32_t type, float value) +{ + // Check whether APS callback interface exists + if (!mApsListenLightChangeCallback) { + DISPLAY_HILOGD(FEAT_BRIGHTNESS, "BrightnessService::NotifyLightChangeToAps function is null"); + return; + } + + // Check Whether APS is initialized + if (mLightBrightnessThreshold.size() != APS_LISTEN_PARAMS_LENGHT) { + DISPLAY_HILOGD(FEAT_BRIGHTNESS, "BrightnessService::NotifyLightChangeToAps not init yet"); + return; + } + + // brightness + if (type == BRIGHTNESS_TYPE) { + int32_t nitValue = static_cast(GetMappingBrightnessNit(static_cast(value))); + int32_t brightness = mLightBrightnessThreshold[0]; + if (!mIsBrightnessValidate && nitValue >= brightness) { + mIsBrightnessValidate = true; + mApsListenLightChangeCallback->OnNotifyApsLightBrightnessChange(type, mIsBrightnessValidate); + } else if (mIsBrightnessValidate && nitValue < brightness) { + mIsBrightnessValidate = false; + mApsListenLightChangeCallback->OnNotifyApsLightBrightnessChange(type, mIsBrightnessValidate); + } + return; + } + + // amlient light + if (type == AMBIENT_LIGHT_TYPE) { + // Check the interval for invoking the APS interface + time_t currentTime = time(0); + if (currentTime - mLastCallApsTime < CALL_APS_INTERVAL) { + DISPLAY_HILOGD( + FEAT_BRIGHTNESS, "BrightnessService::NotifyLightChangeToAps interface is invoked frequently"); + return; + } + mLastCallApsTime = currentTime; + + int32_t light = mLightBrightnessThreshold[1]; + int32_t range = mLightBrightnessThreshold[2]; + if (!mIsLightValidate && value >= light) { + mIsLightValidate = true; + mApsListenLightChangeCallback->OnNotifyApsLightBrightnessChange(type, mIsLightValidate); + } else if (mIsLightValidate && value < (light - range)) { + mIsLightValidate = false; + mApsListenLightChangeCallback->OnNotifyApsLightBrightnessChange(type, mIsLightValidate); + } + } +} + uint32_t BrightnessService::GetCurrentDisplayId(uint32_t defaultId) const { return mAction->GetCurrentDisplayId(defaultId); @@ -300,6 +355,21 @@ void BrightnessService::SetSettingAutoBrightness(bool enable) BrightnessSettingHelper::SetSettingAutoBrightness(enable); } +uint32_t BrightnessService::SetLightBrightnessThreshold( + std::vector threshold, sptr callback) +{ + uint32_t result = 0; + if (threshold.size() != APS_LISTEN_PARAMS_LENGHT || !callback) { + DISPLAY_HILOGW(FEAT_BRIGHTNESS, "BrightnessService::SetLightBrightnessThreshold params verify faild."); + return result; + } + result = 1; + mLightBrightnessThreshold = threshold; + mApsListenLightChangeCallback = callback; + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "BrightnessService::SetLightBrightnessThreshold set listener success"); + return result; +} + #ifdef ENABLE_SENSOR_PART bool BrightnessService::AutoAdjustBrightness(bool enable) { @@ -446,6 +516,7 @@ void BrightnessService::ProcessLightLux(float lux) { DISPLAY_HILOGD(FEAT_BRIGHTNESS, "ProcessLightLux, lux=%{public}f, mLightLux=%{public}f", lux, mLightLuxManager.GetSmoothedLux()); + NotifyLightChangeToAps(AMBIENT_LIGHT_TYPE, lux); if (mLightLuxManager.IsNeedUpdateBrightness(lux)) { DISPLAY_HILOGI(FEAT_BRIGHTNESS, "UpdateLightLux, lux=%{public}f, mLightLux=%{public}f, isFirst=%{public}d", lux, mLightLuxManager.GetSmoothedLux(), mLightLuxManager.GetIsFirstLux()); @@ -531,6 +602,7 @@ bool BrightnessService::SetBrightness(uint32_t value, uint32_t gradualDuration, } } mBrightnessTarget.store(value); + NotifyLightChangeToAps(BRIGHTNESS_TYPE, static_cast(value)); bool isSuccess = UpdateBrightness(value, gradualDuration, !continuous); DISPLAY_HILOGD(FEAT_BRIGHTNESS, "SetBrightness val=%{public}d, isSuccess=%{public}d", value, isSuccess); mIsUserMode = false; diff --git a/state_manager/frameworks/native/display_power_mgr_client.cpp b/state_manager/frameworks/native/display_power_mgr_client.cpp index 34c30385bfc6017cdf08d61e10d8b0d22d833e48..cc0109a780a33552c655f1281d331713f862d08a 100644 --- a/state_manager/frameworks/native/display_power_mgr_client.cpp +++ b/state_manager/frameworks/native/display_power_mgr_client.cpp @@ -240,6 +240,14 @@ bool DisplayPowerMgrClient::SetCoordinated(bool coordinated, uint32_t displayId) return proxy->SetCoordinated(coordinated, displayId); } +uint32_t DisplayPowerMgrClient::SetLightBrightnessThreshold( + std::vector threshold, sptr callback) +{ + auto proxy = GetProxy(); + RETURN_IF_WITH_RET(proxy == nullptr, 0); + return proxy->SetLightBrightnessThreshold(threshold, callback); +} + DisplayErrors DisplayPowerMgrClient::GetError() { if (lastError_ != DisplayErrors::ERR_OK) { diff --git a/state_manager/interfaces/inner_api/BUILD.gn b/state_manager/interfaces/inner_api/BUILD.gn index daaa1074e9c06d2d5f44e79ccd2344033c03ff7f..307dd56a9fa51beca155a198350983cb553ada2e 100644 --- a/state_manager/interfaces/inner_api/BUILD.gn +++ b/state_manager/interfaces/inner_api/BUILD.gn @@ -24,6 +24,7 @@ config("displaymgr_public_config") { ohos_shared_library("displaymgr") { sources = [ "${displaymgr_framework_path}/native/display_power_mgr_client.cpp", + "${displaymgr_service_zidl}/src/display_brightness_callback_stub.cpp", "${displaymgr_service_zidl}/src/display_power_callback_stub.cpp", "${displaymgr_service_zidl}/src/display_power_mgr_proxy.cpp", ] diff --git a/state_manager/interfaces/inner_api/native/include/display_brightness_callback_ipc_interface_code.h b/state_manager/interfaces/inner_api/native/include/display_brightness_callback_ipc_interface_code.h new file mode 100644 index 0000000000000000000000000000000000000000..60fee00d3210a415254007f65bc23789c7720304 --- /dev/null +++ b/state_manager/interfaces/inner_api/native/include/display_brightness_callback_ipc_interface_code.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 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 DISPLAY_BRIGHTNESS_CALLBACK_IPC_INTERFACE_DODE_H +#define DISPLAY_BRIGHTNESS_CALLBACK_IPC_INTERFACE_DODE_H + +/* SAID: 3308 */ +namespace OHOS { +namespace PowerMgr { +enum class DisplayBrightnessCallbackInterfaceCode { + ON_NOTIFY_APS_LIGHT_BRIGHTNESS_CHANGE = 0, +}; +} // namespace PowerMgr +} // namespace OHOS + +#endif // DISPLAY_POWER_CALLBACK_IPC_INTERFACE_DODE_H \ No newline at end of file diff --git a/state_manager/interfaces/inner_api/native/include/display_brightness_callback_stub.h b/state_manager/interfaces/inner_api/native/include/display_brightness_callback_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..a622f67d832af315be7abdedebc8e35148d4dd8b --- /dev/null +++ b/state_manager/interfaces/inner_api/native/include/display_brightness_callback_stub.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023-2024 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_BRIGHTNESS_CALLBACK_STUB_H +#define DISPLAYMGR_DISPLAY_BRIGHTNESS_CALLBACK_STUB_H + +#include + +#include "idisplay_brightness_callback.h" + +namespace OHOS { +namespace DisplayPowerMgr { +class DisplayBrightnessCallbackStub : public IRemoteStub { +public: + int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; + + void OnNotifyApsLightBrightnessChange(uint32_t type, bool state) override; + +private: + int32_t OnNotifyApsLightBrightnessChangeStub(MessageParcel& data, MessageParcel& reply); +}; +} // namespace DisplayPowerMgr +} // namespace OHOS +#endif // DISPLAYMGR_DISPLAY_BRIGHTNESS_CALLBACK_STUB_H diff --git a/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h b/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h index ab7296c21adbcdfaa17708f0e525f6ff63f71331..9e17fbd1e52948961b2909cada8704766d46a48e 100644 --- a/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h +++ b/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h @@ -54,6 +54,7 @@ public: bool CancelBoostBrightness(uint32_t displayId = 0); uint32_t GetDeviceBrightness(uint32_t displayId = 0); bool SetCoordinated(bool coordinated, uint32_t displayId = 0); + uint32_t SetLightBrightnessThreshold(std::vector threshold, sptr callback); DisplayErrors GetError(); #ifndef DISPLAY_SERVICE_DEATH_UT diff --git a/state_manager/interfaces/inner_api/native/include/display_power_mgr_ipc_interface_code.h b/state_manager/interfaces/inner_api/native/include/display_power_mgr_ipc_interface_code.h index 2802ea0d5d38d07c426f3eff20a38bd6e98b92ca..e811616d9fbac37b59972cd10f368df5d8553aaf 100644 --- a/state_manager/interfaces/inner_api/native/include/display_power_mgr_ipc_interface_code.h +++ b/state_manager/interfaces/inner_api/native/include/display_power_mgr_ipc_interface_code.h @@ -40,7 +40,8 @@ enum class DisplayPowerMgrInterfaceCode { BOOST_BRIGHTNESS, CANCEL_BOOST_BRIGHTNESS, GET_DEVICE_BRIGHTNESS, - SET_COORDINATED + SET_COORDINATED, + SET_APS_LIGHT_AND_BRIGHTNESS_THRESOLD = 21, }; } // space PowerMgr } // namespace OHOS diff --git a/state_manager/interfaces/inner_api/native/include/idisplay_brightness_callback.h b/state_manager/interfaces/inner_api/native/include/idisplay_brightness_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..3eaa3891a6bf4a313c8b0f7067349d8d6caff2a5 --- /dev/null +++ b/state_manager/interfaces/inner_api/native/include/idisplay_brightness_callback.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021-2023 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_IDISPLAY_BRIGHTNESS_CALLBACK_H +#define POWERMGR_IDISPLAY_BRIGHTNESS_CALLBACK_H + +#include +#include + +namespace OHOS { +namespace DisplayPowerMgr { +class IDisplayBrightnessCallback : public IRemoteBroker { +public: + virtual void OnNotifyApsLightBrightnessChange(uint32_t type, bool state) = 0; + + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.IDisplayBrightnessCallback"); +}; +} // namespace DisplayPowerMgr +} // namespace OHOS +#endif // POWERMGR_IDISPLAY_POWER_CALLBACK_H \ No newline at end of file diff --git a/state_manager/interfaces/inner_api/native/include/idisplay_power_mgr.h b/state_manager/interfaces/inner_api/native/include/idisplay_power_mgr.h index 92c4a563057854224296fdf08c12eedd9ba29746..7b6116b7bb1130544df9b59840b7e6a3ee6ba16c 100644 --- a/state_manager/interfaces/inner_api/native/include/idisplay_power_mgr.h +++ b/state_manager/interfaces/inner_api/native/include/idisplay_power_mgr.h @@ -21,6 +21,7 @@ #include "display_mgr_errors.h" #include "display_power_info.h" +#include "idisplay_brightness_callback.h" #include "idisplay_power_callback.h" namespace OHOS { @@ -48,6 +49,8 @@ public: virtual bool CancelBoostBrightness(uint32_t displayId) = 0; virtual uint32_t GetDeviceBrightness(uint32_t displayId) = 0; virtual bool SetCoordinated(bool coordinated, uint32_t displayId) = 0; + virtual uint32_t SetLightBrightnessThreshold( + std::vector threshold, sptr callback) = 0; virtual DisplayErrors GetError() = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.displaypowermgr.IDisplayPowerMgr"); diff --git a/state_manager/service/BUILD.gn b/state_manager/service/BUILD.gn index 901a8a9c11127580013c53cc05c76f6eb9489e14..82a7f8ef1017f477874bf5518dc706d12ece6161 100644 --- a/state_manager/service/BUILD.gn +++ b/state_manager/service/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("displaymgrservice") { "native/src/gradual_animator.cpp", "native/src/screen_action.cpp", "native/src/screen_controller.cpp", + "zidl/src/display_brightness_callback_proxy.cpp", "zidl/src/display_power_callback_proxy.cpp", "zidl/src/display_power_mgr_stub.cpp", ] diff --git a/state_manager/service/native/include/display_power_mgr_service.h b/state_manager/service/native/include/display_power_mgr_service.h index 3465907548ae30b7b243bc2351943291cf42fba2..a544b0ecc2214f32aa00b8c004c0ee86585fae88 100644 --- a/state_manager/service/native/include/display_power_mgr_service.h +++ b/state_manager/service/native/include/display_power_mgr_service.h @@ -65,6 +65,8 @@ public: virtual bool CancelBoostBrightness(uint32_t displayId) override; virtual uint32_t GetDeviceBrightness(uint32_t displayId) override; virtual bool SetCoordinated(bool coordinated, uint32_t displayId) override; + virtual uint32_t SetLightBrightnessThreshold( + std::vector threshold, sptr callback) override; virtual int32_t Dump(int32_t fd, const std::vector& args) override; virtual DisplayErrors GetError() override; void NotifyStateChangeCallback(uint32_t displayId, DisplayState state, uint32_t reason); diff --git a/state_manager/service/native/src/display_power_mgr_service.cpp b/state_manager/service/native/src/display_power_mgr_service.cpp index b492e2654f55cc5c0122842e1cb1c4216f3a0f83..669d1ce5cf87a2d76615d7eda9c4091f5484cf85 100644 --- a/state_manager/service/native/src/display_power_mgr_service.cpp +++ b/state_manager/service/native/src/display_power_mgr_service.cpp @@ -561,6 +561,15 @@ bool DisplayPowerMgrService::SetCoordinated(bool coordinated, uint32_t displayId return true; } +uint32_t DisplayPowerMgrService::SetLightBrightnessThreshold( + std::vector threshold, sptr callback) +{ + if (!Permission::IsSystem()) { + return static_cast(ERR_PERMISSION_DENIED); + } + return BrightnessManager::Get().SetLightBrightnessThreshold(threshold, callback); +} + void DisplayPowerMgrService::NotifyStateChangeCallback(uint32_t displayId, DisplayState state, uint32_t reason) { std::lock_guard lock(mutex_); diff --git a/state_manager/service/zidl/include/display_brightness_callback_proxy.h b/state_manager/service/zidl/include/display_brightness_callback_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..031c4b4fd13cb73613781b1c3219fe9fd899a494 --- /dev/null +++ b/state_manager/service/zidl/include/display_brightness_callback_proxy.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023-2024 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_BRIGHTNESS_CALLBACK_PROXY_H +#define DISPLAYMGR_DISPLAY_BRIGHTNESS_CALLBACK_PROXY_H + +#include +#include +#include + +#include "idisplay_brightness_callback.h" +#include "iremote_broker.h" +#include "iremote_object.h" +#include "refbase.h" + +namespace OHOS { +namespace DisplayPowerMgr { +class DisplayBrightnessCallbackProxy : public IRemoteProxy { +public: + explicit DisplayBrightnessCallbackProxy(const sptr& impl) + : IRemoteProxy(impl) {} + ~DisplayBrightnessCallbackProxy() override = default; + virtual void OnNotifyApsLightBrightnessChange(uint32_t type, bool state) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DisplayPowerMgr +} // namespace OHOS + +#endif // DISPLAYMGR_DISPLAY_BRIGHTNESS_CALLBACK_PROXY_H \ No newline at end of file diff --git a/state_manager/service/zidl/include/display_power_mgr_proxy.h b/state_manager/service/zidl/include/display_power_mgr_proxy.h index 2fe5c4412d9cb0eaaa67014c06fb5067eb742553..c6f8d5192b4071a162cb2b16901ef64a4c8e183e 100644 --- a/state_manager/service/zidl/include/display_power_mgr_proxy.h +++ b/state_manager/service/zidl/include/display_power_mgr_proxy.h @@ -57,6 +57,8 @@ public: virtual bool CancelBoostBrightness(uint32_t displayId) override; virtual uint32_t GetDeviceBrightness(uint32_t displayId) override; virtual bool SetCoordinated(bool coordinated, uint32_t displayId) override; + virtual uint32_t SetLightBrightnessThreshold( + std::vector threshold, sptr callback) override; virtual DisplayErrors GetError() override; private: diff --git a/state_manager/service/zidl/include/display_power_mgr_stub.h b/state_manager/service/zidl/include/display_power_mgr_stub.h index 7202a0ce1a1d4a73e753c3cad3932de07e89829c..81a3943ec1454340d04e028de7faf5ba7743e59d 100644 --- a/state_manager/service/zidl/include/display_power_mgr_stub.h +++ b/state_manager/service/zidl/include/display_power_mgr_stub.h @@ -52,6 +52,7 @@ private: int32_t CancelBoostBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t GetDeviceBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t SetCoordinatedStub(MessageParcel& data, MessageParcel& reply); + int32_t SetLightBrightnessThresholdStub(MessageParcel& data, MessageParcel& reply); }; } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/state_manager/service/zidl/src/display_brightness_callback_proxy.cpp b/state_manager/service/zidl/src/display_brightness_callback_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bb4ab656bff433b980d0235636889d8ecfb487f2 --- /dev/null +++ b/state_manager/service/zidl/src/display_brightness_callback_proxy.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023-2024 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_brightness_callback_proxy.h" + +#include "display_brightness_callback_ipc_interface_code.h" +#include "display_common.h" +#include "display_log.h" +#include "errors.h" +#include "message_option.h" +#include "message_parcel.h" + +namespace OHOS { +namespace DisplayPowerMgr { +void DisplayBrightnessCallbackProxy::OnNotifyApsLightBrightnessChange(uint32_t type, bool state) +{ + sptr remote = Remote(); + RETURN_IF(remote == nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + if (!data.WriteInterfaceToken(DisplayBrightnessCallbackProxy::GetDescriptor())) { + DISPLAY_HILOGE(COMP_FWK, "write descriptor failed!"); + return; + } + + WRITE_PARCEL_NO_RET(data, Uint32, type); + WRITE_PARCEL_NO_RET(data, Bool, state); + + int ret = remote->SendRequest( + static_cast(PowerMgr::DisplayBrightnessCallbackInterfaceCode::ON_NOTIFY_APS_LIGHT_BRIGHTNESS_CHANGE), data, + reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "SendRequest is failed, error code: %d", ret); + return; + } +} +} // namespace DisplayPowerMgr +} // namespace OHOS \ No newline at end of file diff --git a/state_manager/service/zidl/src/display_brightness_callback_stub.cpp b/state_manager/service/zidl/src/display_brightness_callback_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d4c0735b0a97d854da142c100b1abf65e0b42d1 --- /dev/null +++ b/state_manager/service/zidl/src/display_brightness_callback_stub.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021-2023 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_brightness_callback_stub.h" + +#include "display_brightness_callback_ipc_interface_code.h" +#include "display_common.h" +#include "display_log.h" +#include "display_mgr_errors.h" +#include "display_power_info.h" +#include "errors.h" +#include "idisplay_brightness_callback.h" +#include "ipc_object_stub.h" +#include "message_option.h" +#include "xcollie/xcollie.h" +#include "xcollie/xcollie_define.h" +#include + +namespace OHOS { +namespace DisplayPowerMgr { +int32_t DisplayBrightnessCallbackStub::OnRemoteRequest( + uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) +{ + DISPLAY_HILOGD( + COMP_SVC, "DisplayBrightnessCallbackStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags()); + std::u16string descripter = DisplayBrightnessCallbackStub::GetDescriptor(); + std::u16string remoteDescripter = data.ReadInterfaceToken(); + if (descripter != remoteDescripter) { + DISPLAY_HILOGE(COMP_SVC, "descriptor is not matched!"); + return E_GET_POWER_SERVICE_FAILED; + } + + const int DFX_DELAY_MS = 10000; + int id = HiviewDFX::XCollie::GetInstance().SetTimer( + "DisplayBrightnessCallbackStub", DFX_DELAY_MS, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_NOOP); + int32_t ret = ERR_OK; + if (code == + static_cast( + PowerMgr::DisplayBrightnessCallbackInterfaceCode::ON_NOTIFY_APS_LIGHT_BRIGHTNESS_CHANGE)) { + ret = OnNotifyApsLightBrightnessChangeStub(data, reply); + } else { + ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + HiviewDFX::XCollie::GetInstance().CancelTimer(id); + return ret; +} + +int32_t DisplayBrightnessCallbackStub::OnNotifyApsLightBrightnessChangeStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t type = 0; + bool state = false; + + READ_PARCEL_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Bool, state, E_READ_PARCEL_ERROR); + + OnNotifyApsLightBrightnessChange(type, state); + return ERR_OK; +} + +void DisplayBrightnessCallbackStub::OnNotifyApsLightBrightnessChange(uint32_t type, bool state) {} + +} // namespace DisplayPowerMgr +} // namespace OHOS diff --git a/state_manager/service/zidl/src/display_power_mgr_proxy.cpp b/state_manager/service/zidl/src/display_power_mgr_proxy.cpp index fe7093aab2a3b97d060e1d827c2c57c1cccd6373..dcf4e8c1d721a70ba89e50cb9883802198c86a10 100644 --- a/state_manager/service/zidl/src/display_power_mgr_proxy.cpp +++ b/state_manager/service/zidl/src/display_power_mgr_proxy.cpp @@ -734,6 +734,41 @@ bool DisplayPowerMgrProxy::SetCoordinated(bool coordinated, uint32_t displayId) return result; } +uint32_t DisplayPowerMgrProxy::SetLightBrightnessThreshold( + std::vector threshold, sptr callback) +{ + 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, "write descriptor failed!"); + return result; + } + + WRITE_PARCEL_WITH_RET(data, Int32Vector, threshold, result); + WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), result); + + int ret = remote->SendRequest( + static_cast(PowerMgr::DisplayPowerMgrInterfaceCode::SET_APS_LIGHT_AND_BRIGHTNESS_THRESOLD), data, reply, + option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "SendRequest is failed, error code: %d", ret); + return result; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return result; + } + + return result; +} + DisplayErrors DisplayPowerMgrProxy::GetError() { return lastError_; diff --git a/state_manager/service/zidl/src/display_power_mgr_stub.cpp b/state_manager/service/zidl/src/display_power_mgr_stub.cpp index 8ddd68cd3f48dae1ef049f7e01622948a1c48b39..8bb07ea4a30f3c38f4960ae22e1f9c2c4eab9047 100644 --- a/state_manager/service/zidl/src/display_power_mgr_stub.cpp +++ b/state_manager/service/zidl/src/display_power_mgr_stub.cpp @@ -72,6 +72,9 @@ int32_t DisplayPowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case static_cast(PowerMgr::DisplayPowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_DELAY): ret = OverrideDisplayOffDelayStub(data, reply); break; + case static_cast(PowerMgr::DisplayPowerMgrInterfaceCode::SET_APS_LIGHT_AND_BRIGHTNESS_THRESOLD): + ret = SetLightBrightnessThresholdStub(data, reply); + break; default: ret = RemoteRequest(code, data, reply, option); break; @@ -425,5 +428,22 @@ int32_t DisplayPowerMgrStub::SetCoordinatedStub(MessageParcel& data, MessageParc } return ERR_OK; } + +int32_t DisplayPowerMgrStub::SetLightBrightnessThresholdStub(MessageParcel& data, MessageParcel& reply) +{ + std::vector threshold; + READ_PARCEL_WITH_RET(data, Int32Vector, &threshold, E_READ_PARCEL_ERROR); + sptr obj = data.ReadRemoteObject(); + RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); + sptr callback = iface_cast(obj); + RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); + uint32_t ret = SetLightBrightnessThreshold(threshold, callback); + if (!reply.WriteUint32(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write SetLightBrightnessThresholdStub return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} + } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp b/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp index 50fe1a4977ee3938ac8f148505ea7a7074a6b32a..08811958744a6781a64b37d6880eef601d48d9a0 100644 --- a/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp +++ b/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp @@ -14,6 +14,7 @@ */ #include +#include "display_brightness_callback_stub.h" #include "display_power_mgr_client.h" #include "setting_provider.h" #include "system_ability_definition.h" @@ -922,4 +923,44 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrSleepBrightness001, TestS DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSleepBrightness001: fun is end"); } +/** + * @tc.name: DisplayPowerMgrSetLightBrightnessThreshold001 + * @tc.desc: Test the Function of setting Ambient Light Monitor (success is returned) + * @tc.type: FUNC + * @tc.require: issueI8ZHFN + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrSetLightBrightnessThreshold001, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSetLightBrightnessThreshold001: fun is start"); + std::vector threshold = {200, 200, 20}; + uint32_t type = 1; + bool state = false; + const uint32_t SUCCESS_RESULT = 1; + sptr callback = new DisplayBrightnessCallbackStub(); + callback->OnNotifyApsLightBrightnessChange(type, state); + uint32_t result = DisplayPowerMgrClient::GetInstance().SetLightBrightnessThreshold(threshold, callback); + EXPECT_EQ(result, SUCCESS_RESULT); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSetLightBrightnessThreshold001: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrSetLightBrightnessThreshold002 + * @tc.desc: Test the Function of setting Ambient Light Monitor (success is returned) + * @tc.type: FUNC + * @tc.require: issueI8ZHFN + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrSetLightBrightnessThreshold002, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSetLightBrightnessThreshold002: fun is start"); + std::vector threshold = {}; + uint32_t type = 1; + bool state = false; + const uint32_t FAILD_RESULT = 0; + sptr callback = new DisplayBrightnessCallbackStub(); + callback->OnNotifyApsLightBrightnessChange(type, state); + uint32_t result = DisplayPowerMgrClient::GetInstance().SetLightBrightnessThreshold(threshold, callback); + EXPECT_EQ(result, FAILD_RESULT); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSetLightBrightnessThreshold002: fun is end"); +} + } // namespace