• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "display_mgr_errors.h"
28 
29 namespace OHOS {
30 namespace DisplayPowerMgr {
31 class DisplayPowerMgrClient : public DelayedRefSingleton<DisplayPowerMgrClient> {
32     DECLARE_DELAYED_REF_SINGLETON(DisplayPowerMgrClient);
33 
34 public:
35     bool SetDisplayState(DisplayState state,
36         PowerMgr::StateChangeReason reason = PowerMgr::StateChangeReason::STATE_CHANGE_REASON_UNKNOWN,
37         uint32_t id = 0);
38     DisplayState GetDisplayState(uint32_t id = 0);
39     std::vector<uint32_t> GetDisplayIds();
40     int32_t GetMainDisplayId();
41     bool SetBrightness(uint32_t value, uint32_t displayId = 0, bool continuous = false);
42     bool SetMaxBrightness(double value, uint32_t enterTestMode = 0);
43     bool SetMaxBrightnessNit(uint32_t maxNit, uint32_t enterTestMode = 0);
44     bool DiscountBrightness(double discount, uint32_t displayId = 0);
45     bool OverrideBrightness(uint32_t value, uint32_t displayId = 0, uint32_t duration = 500);
46     bool OverrideDisplayOffDelay(uint32_t delayMs);
47     bool RestoreBrightness(uint32_t displayId = 0, uint32_t duration = 500);
48     uint32_t GetBrightness(uint32_t displayId = 0);
49     uint32_t GetDefaultBrightness();
50     uint32_t GetMaxBrightness();
51     uint32_t GetMinBrightness();
52     bool AdjustBrightness(uint32_t value, uint32_t duration, uint32_t id = 0);
53     bool AutoAdjustBrightness(bool enable);
54     bool IsAutoAdjustBrightness();
55     bool SetScreenOnBrightness();
56     bool RegisterCallback(sptr<IDisplayPowerCallback> callback);
57     bool BoostBrightness(int32_t timeoutMs, uint32_t displayId = 0);
58     bool CancelBoostBrightness(uint32_t displayId = 0);
59     uint32_t GetDeviceBrightness(uint32_t displayId = 0);
60     bool SetCoordinated(bool coordinated, uint32_t displayId = 0);
61     uint32_t SetLightBrightnessThreshold(std::vector<int32_t> threshold, sptr<IDisplayBrightnessCallback> callback);
62     DisplayErrors GetError();
63     int NotifyBrightnessManagerScreenPowerStatus(uint32_t displayId, uint32_t status);
64 
65 #ifndef DISPLAY_SERVICE_DEATH_UT
66 private:
67 #endif
68     class DisplayDeathRecipient : public IRemoteObject::DeathRecipient {
69     public:
DisplayDeathRecipient(DisplayPowerMgrClient & client)70         explicit DisplayDeathRecipient(DisplayPowerMgrClient& client) : client_(client) {}
71         ~DisplayDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)72         void OnRemoteDied(const wptr<IRemoteObject>& remote) override
73         {
74             client_.OnRemoteDied(remote);
75         }
76 
77     private:
78         DisplayPowerMgrClient& client_;
79     };
80 
81     sptr<IDisplayPowerMgr> GetProxy();
82     void OnRemoteDied(const wptr<IRemoteObject>& remote);
83     static constexpr int32_t INVALID_DISPLAY_ID {-1};
84     static constexpr int32_t DEFAULT_MAIN_DISPLAY_ID {0};
85     static constexpr uint32_t BRIGHTNESS_OFF {0};
86     static constexpr uint32_t BRIGHTNESS_DEFAULT {102};
87     static constexpr uint32_t BRIGHTNESS_MAX {255};
88     static constexpr uint32_t BRIGHTNESS_MIN {1};
89 
90     DisplayErrors lastError_ {DisplayErrors::ERR_OK};
91     std::mutex mutex_;
92     sptr<IDisplayPowerMgr> proxy_ {nullptr};
93     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
94 };
95 } // namespace DisplayPowerMgr
96 } // namespace OHOS
97 #endif // DISPLAYMGR_GRADUAL_ANIMATOR_H
98