1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DISPLAYMGR_DISPLAY_MGR_CLIENT_H 17 #define DISPLAYMGR_DISPLAY_MGR_CLIENT_H 18 19 #include <iremote_object.h> 20 #include <singleton.h> 21 #include <vector> 22 23 #include "display_power_info.h" 24 #include "idisplay_power_callback.h" 25 #include "idisplay_power_mgr.h" 26 #include "power_state_machine_info.h" 27 28 namespace OHOS { 29 namespace DisplayPowerMgr { 30 class DisplayPowerMgrClient : public DelayedRefSingleton<DisplayPowerMgrClient> { 31 DECLARE_DELAYED_REF_SINGLETON(DisplayPowerMgrClient); 32 33 public: 34 bool SetDisplayState(DisplayState state, 35 PowerMgr::StateChangeReason reason = PowerMgr::StateChangeReason::STATE_CHANGE_REASON_UNKNOWN, 36 uint32_t id = 0); 37 DisplayState GetDisplayState(uint32_t id = 0); 38 std::vector<uint32_t> GetDisplayIds(); 39 int32_t GetMainDisplayId(); 40 bool SetBrightness(uint32_t value, uint32_t displayId = 0, bool continuous = false); 41 bool SetMaxBrightness(double value, uint32_t enterTestMode = 0); 42 bool SetMaxBrightnessNit(uint32_t maxNit, uint32_t enterTestMode = 0); 43 bool DiscountBrightness(double discount, uint32_t displayId = 0); 44 bool OverrideBrightness(uint32_t value, uint32_t displayId = 0, uint32_t duration = 500); 45 bool OverrideDisplayOffDelay(uint32_t delayMs); 46 bool RestoreBrightness(uint32_t displayId = 0, uint32_t duration = 500); 47 uint32_t GetBrightness(uint32_t displayId = 0); 48 uint32_t GetDefaultBrightness(); 49 uint32_t GetMaxBrightness(); 50 uint32_t GetMinBrightness(); 51 bool AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id = 0); 52 bool AutoAdjustBrightness(bool enable); 53 bool IsAutoAdjustBrightness(); 54 bool RegisterCallback(sptr<IDisplayPowerCallback> callback); 55 bool BoostBrightness(int32_t timeoutMs, uint32_t displayId = 0); 56 bool CancelBoostBrightness(uint32_t displayId = 0); 57 uint32_t GetDeviceBrightness(uint32_t displayId = 0); 58 bool SetCoordinated(bool coordinated, uint32_t displayId = 0); 59 uint32_t SetLightBrightnessThreshold(std::vector<int32_t> threshold, sptr<IDisplayBrightnessCallback> callback); 60 DisplayErrors GetError(); 61 62 #ifndef DISPLAY_SERVICE_DEATH_UT 63 private: 64 #endif 65 class DisplayDeathRecipient : public IRemoteObject::DeathRecipient { 66 public: DisplayDeathRecipient(DisplayPowerMgrClient & client)67 explicit DisplayDeathRecipient(DisplayPowerMgrClient& client) : client_(client) {} 68 ~DisplayDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)69 void OnRemoteDied(const wptr<IRemoteObject>& remote) override 70 { 71 client_.OnRemoteDied(remote); 72 } 73 74 private: 75 DisplayPowerMgrClient& client_; 76 }; 77 78 sptr<IDisplayPowerMgr> GetProxy(); 79 void OnRemoteDied(const wptr<IRemoteObject>& remote); 80 static constexpr int32_t INVALID_DISPLAY_ID {-1}; 81 static constexpr uint32_t BRIGHTNESS_OFF {0}; 82 static constexpr uint32_t BRIGHTNESS_DEFAULT {102}; 83 static constexpr uint32_t BRIGHTNESS_MAX {255}; 84 static constexpr uint32_t BRIGHTNESS_MIN {1}; 85 86 DisplayErrors lastError_ {DisplayErrors::ERR_OK}; 87 std::mutex mutex_; 88 sptr<IDisplayPowerMgr> proxy_ {nullptr}; 89 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 90 }; 91 } // namespace DisplayPowerMgr 92 } // namespace OHOS 93 #endif // DISPLAYMGR_GRADUAL_ANIMATOR_H 94