1 /* 2 * Copyright (c) 2021-2022 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); 41 bool DiscountBrightness(double discount, uint32_t displayId = 0); 42 bool OverrideBrightness(uint32_t value, uint32_t displayId = 0); 43 bool OverrideDisplayOffDelay(uint32_t delayMs); 44 bool RestoreBrightness(uint32_t displayId = 0); 45 uint32_t GetBrightness(uint32_t displayId = 0); 46 uint32_t GetDefaultBrightness(); 47 uint32_t GetMaxBrightness(); 48 uint32_t GetMinBrightness(); 49 bool AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id = 0); 50 bool AutoAdjustBrightness(bool enable); 51 bool IsAutoAdjustBrightness(); 52 bool RegisterCallback(sptr<IDisplayPowerCallback> callback); 53 bool BoostBrightness(int32_t timeoutMs, uint32_t displayId = 0); 54 bool CancelBoostBrightness(uint32_t displayId = 0); 55 uint32_t GetDeviceBrightness(uint32_t displayId = 0); 56 DisplayErrors GetError(); 57 58 #ifndef DISPLAY_SERVICE_DEATH_UT 59 private: 60 #endif 61 class DisplayDeathRecipient : public IRemoteObject::DeathRecipient { 62 public: DisplayDeathRecipient(DisplayPowerMgrClient & client)63 explicit DisplayDeathRecipient(DisplayPowerMgrClient& client) : client_(client) {} 64 ~DisplayDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)65 void OnRemoteDied(const wptr<IRemoteObject>& remote) override 66 { 67 client_.OnRemoteDied(remote); 68 } 69 70 private: 71 DisplayPowerMgrClient& client_; 72 }; 73 74 sptr<IDisplayPowerMgr> GetProxy(); 75 void OnRemoteDied(const wptr<IRemoteObject>& remote); 76 static constexpr int32_t INVALID_DISPLAY_ID {-1}; 77 static constexpr uint32_t BRIGHTNESS_OFF {0}; 78 static constexpr uint32_t BRIGHTNESS_DEFAULT {102}; 79 static constexpr uint32_t BRIGHTNESS_MAX {255}; 80 static constexpr uint32_t BRIGHTNESS_MIN {1}; 81 82 DisplayErrors lastError_ {DisplayErrors::ERR_OK}; 83 std::mutex mutex_; 84 sptr<IDisplayPowerMgr> proxy_ {nullptr}; 85 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 86 }; 87 } // namespace DisplayPowerMgr 88 } // namespace OHOS 89 #endif // DISPLAYMGR_GRADUAL_ANIMATOR_H 90