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