1595d5899Sopenharmony_ci/*
2595d5899Sopenharmony_ci * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3595d5899Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4595d5899Sopenharmony_ci * you may not use this file except in compliance with the License.
5595d5899Sopenharmony_ci * You may obtain a copy of the License at
6595d5899Sopenharmony_ci *
7595d5899Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8595d5899Sopenharmony_ci *
9595d5899Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10595d5899Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11595d5899Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12595d5899Sopenharmony_ci * See the License for the specific language governing permissions and
13595d5899Sopenharmony_ci * limitations under the License.
14595d5899Sopenharmony_ci */
15595d5899Sopenharmony_ci
16595d5899Sopenharmony_ci#include <dlfcn.h>
17595d5899Sopenharmony_ci#include "brightness_manager_ext.h"
18595d5899Sopenharmony_ci
19595d5899Sopenharmony_cinamespace OHOS {
20595d5899Sopenharmony_cinamespace DisplayPowerMgr {
21595d5899Sopenharmony_ciBrightnessManagerExt::BrightnessManagerExt()
22595d5899Sopenharmony_ci{
23595d5899Sopenharmony_ci}
24595d5899Sopenharmony_ci
25595d5899Sopenharmony_ciBrightnessManagerExt::~BrightnessManagerExt()
26595d5899Sopenharmony_ci{
27595d5899Sopenharmony_ci    CloseBrightnessExtLibrary();
28595d5899Sopenharmony_ci}
29595d5899Sopenharmony_ci
30595d5899Sopenharmony_civoid BrightnessManagerExt::Init(uint32_t defaultMax, uint32_t defaultMin)
31595d5899Sopenharmony_ci{
32595d5899Sopenharmony_ci    if (!LoadBrightnessExtLibrary()) {
33595d5899Sopenharmony_ci        return;
34595d5899Sopenharmony_ci    }
35595d5899Sopenharmony_ci    auto init = reinterpret_cast<void (*)(uint32_t, uint32_t)>(mBrightnessManagerInitFunc);
36595d5899Sopenharmony_ci    init(defaultMax, defaultMin);
37595d5899Sopenharmony_ci}
38595d5899Sopenharmony_ci
39595d5899Sopenharmony_civoid BrightnessManagerExt::DeInit()
40595d5899Sopenharmony_ci{
41595d5899Sopenharmony_ci    auto deInit = reinterpret_cast<void (*)()>(mBrightnessManagerDeInitFunc);
42595d5899Sopenharmony_ci    if (deInit) {
43595d5899Sopenharmony_ci        deInit();
44595d5899Sopenharmony_ci    }
45595d5899Sopenharmony_ci    CloseBrightnessExtLibrary();
46595d5899Sopenharmony_ci}
47595d5899Sopenharmony_ci
48595d5899Sopenharmony_cibool BrightnessManagerExt::LoadBrightnessExtLibrary()
49595d5899Sopenharmony_ci{
50595d5899Sopenharmony_ci#ifndef FUZZ_TEST
51595d5899Sopenharmony_ci    mBrightnessManagerExtHandle = dlopen("libbrightness_wrapper.z.so", RTLD_NOW);
52595d5899Sopenharmony_ci#endif
53595d5899Sopenharmony_ci    if (!mBrightnessManagerExtHandle) {
54595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlopen libbrightness_wrapper.z.so failed!");
55595d5899Sopenharmony_ci        return false;
56595d5899Sopenharmony_ci    }
57595d5899Sopenharmony_ci    if (LoadBrightnessOps() && LoadBrightnessStatus() && LoadBrightnessControl()) {
58595d5899Sopenharmony_ci        mBrightnessManagerExtEnable = true;
59595d5899Sopenharmony_ci    } else {
60595d5899Sopenharmony_ci        mBrightnessManagerExtEnable = false;
61595d5899Sopenharmony_ci        CloseBrightnessExtLibrary();
62595d5899Sopenharmony_ci    }
63595d5899Sopenharmony_ci    return mBrightnessManagerExtEnable;
64595d5899Sopenharmony_ci}
65595d5899Sopenharmony_ci
66595d5899Sopenharmony_cibool BrightnessManagerExt::LoadBrightnessOps()
67595d5899Sopenharmony_ci{
68595d5899Sopenharmony_ci    mBrightnessManagerInitFunc = dlsym(mBrightnessManagerExtHandle, "Init");
69595d5899Sopenharmony_ci    if (!mBrightnessManagerInitFunc) {
70595d5899Sopenharmony_ci        return false;
71595d5899Sopenharmony_ci    }
72595d5899Sopenharmony_ci    mBrightnessManagerDeInitFunc = dlsym(mBrightnessManagerExtHandle, "DeInit");
73595d5899Sopenharmony_ci    if (!mBrightnessManagerDeInitFunc) {
74595d5899Sopenharmony_ci        return false;
75595d5899Sopenharmony_ci    }
76595d5899Sopenharmony_ci    mGetCurrentDisplayIdFunc = dlsym(mBrightnessManagerExtHandle, "GetCurrentDisplayId");
77595d5899Sopenharmony_ci    if (!mGetCurrentDisplayIdFunc) {
78595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym GetCurrentDisplayId func failed!");
79595d5899Sopenharmony_ci        return false;
80595d5899Sopenharmony_ci    }
81595d5899Sopenharmony_ci    mSetDisplayIdFunc = dlsym(mBrightnessManagerExtHandle, "SetDisplayId");
82595d5899Sopenharmony_ci    if (!mSetDisplayIdFunc) {
83595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym SetDisplayId func failed!");
84595d5899Sopenharmony_ci        return false;
85595d5899Sopenharmony_ci    }
86595d5899Sopenharmony_ci    mSetLightBrightnessThresholdFunc = dlsym(mBrightnessManagerExtHandle, "SetLightBrightnessThreshold");
87595d5899Sopenharmony_ci    if (!mSetLightBrightnessThresholdFunc) {
88595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym SetLightBrightnessThreshold func failed!");
89595d5899Sopenharmony_ci        return false;
90595d5899Sopenharmony_ci    }
91595d5899Sopenharmony_ci    mSetMaxBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "SetMaxBrightness");
92595d5899Sopenharmony_ci    if (!mSetMaxBrightnessFunc) {
93595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym SetMaxBrightness func failed!");
94595d5899Sopenharmony_ci        return false;
95595d5899Sopenharmony_ci    }
96595d5899Sopenharmony_ci    mSetMaxBrightnessNitFunc = dlsym(mBrightnessManagerExtHandle, "SetMaxBrightnessNit");
97595d5899Sopenharmony_ci    if (!mSetMaxBrightnessNitFunc) {
98595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym SetMaxBrightnessNit func failed!");
99595d5899Sopenharmony_ci        return false;
100595d5899Sopenharmony_ci    }
101595d5899Sopenharmony_ci    return true;
102595d5899Sopenharmony_ci}
103595d5899Sopenharmony_ci
104595d5899Sopenharmony_cibool BrightnessManagerExt::LoadBrightnessStatus()
105595d5899Sopenharmony_ci{
106595d5899Sopenharmony_ci    mSetDisplayStateFunc = dlsym(mBrightnessManagerExtHandle, "SetDisplayState");
107595d5899Sopenharmony_ci    if (!mSetDisplayStateFunc) {
108595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym SetDisplayState func failed!");
109595d5899Sopenharmony_ci        return false;
110595d5899Sopenharmony_ci    }
111595d5899Sopenharmony_ci    mGetDisplayStateFunc = dlsym(mBrightnessManagerExtHandle, "GetDisplayState");
112595d5899Sopenharmony_ci    if (!mGetDisplayStateFunc) {
113595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym GetDisplayState func failed!");
114595d5899Sopenharmony_ci        return false;
115595d5899Sopenharmony_ci    }
116595d5899Sopenharmony_ci    mGetDiscountFunc = dlsym(mBrightnessManagerExtHandle, "GetDiscount");
117595d5899Sopenharmony_ci    if (!mGetDiscountFunc) {
118595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym GetDiscount func failed!");
119595d5899Sopenharmony_ci        return false;
120595d5899Sopenharmony_ci    }
121595d5899Sopenharmony_ci    mGetScreenOnBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "GetScreenOnBrightness");
122595d5899Sopenharmony_ci    if (!mGetScreenOnBrightnessFunc) {
123595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym GetScreenOnBrightness func failed!");
124595d5899Sopenharmony_ci        return false;
125595d5899Sopenharmony_ci    }
126595d5899Sopenharmony_ci    mCancelBoostBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "CancelBoostBrightness");
127595d5899Sopenharmony_ci    if (!mCancelBoostBrightnessFunc) {
128595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym CancelBoostBrightness func failed!");
129595d5899Sopenharmony_ci        return false;
130595d5899Sopenharmony_ci    }
131595d5899Sopenharmony_ci    mIsBrightnessOverriddenFunc = dlsym(mBrightnessManagerExtHandle, "IsBrightnessOverridden");
132595d5899Sopenharmony_ci    if (!mIsBrightnessOverriddenFunc) {
133595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym IsBrightnessOverridden func failed!");
134595d5899Sopenharmony_ci        return false;
135595d5899Sopenharmony_ci    }
136595d5899Sopenharmony_ci    mIsBrightnessBoostedFunc = dlsym(mBrightnessManagerExtHandle, "IsBrightnessBoosted");
137595d5899Sopenharmony_ci    if (!mIsBrightnessBoostedFunc) {
138595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym IsBrightnessBoosted func failed!");
139595d5899Sopenharmony_ci        return false;
140595d5899Sopenharmony_ci    }
141595d5899Sopenharmony_ci    mGetBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "GetBrightness");
142595d5899Sopenharmony_ci    if (!mGetBrightnessFunc) {
143595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym GetBrightness func failed!");
144595d5899Sopenharmony_ci        return false;
145595d5899Sopenharmony_ci    }
146595d5899Sopenharmony_ci    mGetDeviceBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "GetDeviceBrightness");
147595d5899Sopenharmony_ci    if (!mGetDeviceBrightnessFunc) {
148595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym GetDeviceBrightness func failed!");
149595d5899Sopenharmony_ci        return false;
150595d5899Sopenharmony_ci    }
151595d5899Sopenharmony_ci    return true;
152595d5899Sopenharmony_ci}
153595d5899Sopenharmony_ci
154595d5899Sopenharmony_cibool BrightnessManagerExt::LoadBrightnessControl()
155595d5899Sopenharmony_ci{
156595d5899Sopenharmony_ci    mAutoAdjustBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "AutoAdjustBrightness");
157595d5899Sopenharmony_ci    if (!mAutoAdjustBrightnessFunc) {
158595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym AutoAdjustBrightness func failed!");
159595d5899Sopenharmony_ci        return false;
160595d5899Sopenharmony_ci    }
161595d5899Sopenharmony_ci    mSetBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "SetBrightness");
162595d5899Sopenharmony_ci    if (!mSetBrightnessFunc) {
163595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym SetBrightness func failed!");
164595d5899Sopenharmony_ci        return false;
165595d5899Sopenharmony_ci    }
166595d5899Sopenharmony_ci    mDiscountBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "DiscountBrightness");
167595d5899Sopenharmony_ci    if (!mDiscountBrightnessFunc) {
168595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym DiscountBrightness func failed!");
169595d5899Sopenharmony_ci        return false;
170595d5899Sopenharmony_ci    }
171595d5899Sopenharmony_ci    mSetScreenOnBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "SetScreenOnBrightness");
172595d5899Sopenharmony_ci    if (!mSetScreenOnBrightnessFunc) {
173595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym SetScreenOnBrightness func failed!");
174595d5899Sopenharmony_ci        return false;
175595d5899Sopenharmony_ci    }
176595d5899Sopenharmony_ci    mOverrideBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "OverrideBrightness");
177595d5899Sopenharmony_ci    if (!mOverrideBrightnessFunc) {
178595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym OverrideBrightness func failed!");
179595d5899Sopenharmony_ci        return false;
180595d5899Sopenharmony_ci    }
181595d5899Sopenharmony_ci    mRestoreBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "RestoreBrightness");
182595d5899Sopenharmony_ci    if (!mRestoreBrightnessFunc) {
183595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym RestoreBrightness func failed!");
184595d5899Sopenharmony_ci        return false;
185595d5899Sopenharmony_ci    }
186595d5899Sopenharmony_ci    mBoostBrightnessFunc = dlsym(mBrightnessManagerExtHandle, "BoostBrightness");
187595d5899Sopenharmony_ci    if (!mBoostBrightnessFunc) {
188595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym BoostBrightness func failed!");
189595d5899Sopenharmony_ci        return false;
190595d5899Sopenharmony_ci    }
191595d5899Sopenharmony_ci    mClearOffsetFunc = dlsym(mBrightnessManagerExtHandle, "ClearOffset");
192595d5899Sopenharmony_ci    if (!mClearOffsetFunc) {
193595d5899Sopenharmony_ci        DISPLAY_HILOGE(FEAT_BRIGHTNESS, "dlsym ClearOffset func failed!");
194595d5899Sopenharmony_ci        return false;
195595d5899Sopenharmony_ci    }
196595d5899Sopenharmony_ci    return true;
197595d5899Sopenharmony_ci}
198595d5899Sopenharmony_ci
199595d5899Sopenharmony_civoid BrightnessManagerExt::CloseBrightnessExtLibrary()
200595d5899Sopenharmony_ci{
201595d5899Sopenharmony_ci    if (mBrightnessManagerExtHandle) {
202595d5899Sopenharmony_ci#ifndef FUZZ_TEST
203595d5899Sopenharmony_ci        dlclose(mBrightnessManagerExtHandle);
204595d5899Sopenharmony_ci#endif
205595d5899Sopenharmony_ci        mBrightnessManagerExtHandle = nullptr;
206595d5899Sopenharmony_ci    }
207595d5899Sopenharmony_ci    mBrightnessManagerInitFunc = nullptr;
208595d5899Sopenharmony_ci    mBrightnessManagerDeInitFunc = nullptr;
209595d5899Sopenharmony_ci    mSetDisplayStateFunc = nullptr;
210595d5899Sopenharmony_ci    mGetDisplayStateFunc = nullptr;
211595d5899Sopenharmony_ci    mAutoAdjustBrightnessFunc = nullptr;
212595d5899Sopenharmony_ci    mSetBrightnessFunc = nullptr;
213595d5899Sopenharmony_ci    mDiscountBrightnessFunc = nullptr;
214595d5899Sopenharmony_ci    mGetDiscountFunc = nullptr;
215595d5899Sopenharmony_ci    mSetScreenOnBrightnessFunc = nullptr;
216595d5899Sopenharmony_ci    mGetScreenOnBrightnessFunc = nullptr;
217595d5899Sopenharmony_ci    mOverrideBrightnessFunc = nullptr;
218595d5899Sopenharmony_ci    mRestoreBrightnessFunc = nullptr;
219595d5899Sopenharmony_ci    mBoostBrightnessFunc = nullptr;
220595d5899Sopenharmony_ci    mCancelBoostBrightnessFunc = nullptr;
221595d5899Sopenharmony_ci    mIsBrightnessOverriddenFunc = nullptr;
222595d5899Sopenharmony_ci    mIsBrightnessBoostedFunc = nullptr;
223595d5899Sopenharmony_ci    mGetBrightnessFunc = nullptr;
224595d5899Sopenharmony_ci    mGetDeviceBrightnessFunc = nullptr;
225595d5899Sopenharmony_ci    mClearOffsetFunc = nullptr;
226595d5899Sopenharmony_ci    mGetCurrentDisplayIdFunc = nullptr;
227595d5899Sopenharmony_ci    mSetDisplayIdFunc = nullptr;
228595d5899Sopenharmony_ci    mSetMaxBrightnessFunc = nullptr;
229595d5899Sopenharmony_ci    mSetMaxBrightnessNitFunc = nullptr;
230595d5899Sopenharmony_ci}
231595d5899Sopenharmony_ci
232595d5899Sopenharmony_civoid BrightnessManagerExt::SetDisplayState(uint32_t id, DisplayState state, uint32_t reason)
233595d5899Sopenharmony_ci{
234595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
235595d5899Sopenharmony_ci        return;
236595d5899Sopenharmony_ci    }
237595d5899Sopenharmony_ci    auto setDisplayStateFunc = reinterpret_cast<void (*)(uint32_t, DisplayState state, uint32_t reason)>
238595d5899Sopenharmony_ci        (mSetDisplayStateFunc);
239595d5899Sopenharmony_ci    setDisplayStateFunc(id, state, reason);
240595d5899Sopenharmony_ci}
241595d5899Sopenharmony_ci
242595d5899Sopenharmony_ciDisplayState BrightnessManagerExt::GetState()
243595d5899Sopenharmony_ci{
244595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
245595d5899Sopenharmony_ci        return DisplayState::DISPLAY_UNKNOWN;
246595d5899Sopenharmony_ci    }
247595d5899Sopenharmony_ci    auto getDisplayStateFunc = reinterpret_cast<DisplayState (*)()>(mGetDisplayStateFunc);
248595d5899Sopenharmony_ci    return getDisplayStateFunc();
249595d5899Sopenharmony_ci}
250595d5899Sopenharmony_ci
251595d5899Sopenharmony_cibool BrightnessManagerExt::AutoAdjustBrightness(bool enable)
252595d5899Sopenharmony_ci{
253595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
254595d5899Sopenharmony_ci        return false;
255595d5899Sopenharmony_ci    }
256595d5899Sopenharmony_ci    auto autoAdjustBrightnessFunc = reinterpret_cast<bool (*)(bool)>(mAutoAdjustBrightnessFunc);
257595d5899Sopenharmony_ci    return autoAdjustBrightnessFunc(enable);
258595d5899Sopenharmony_ci}
259595d5899Sopenharmony_ci
260595d5899Sopenharmony_cibool BrightnessManagerExt::SetBrightness(uint32_t value, uint32_t gradualDuration, bool continuous)
261595d5899Sopenharmony_ci{
262595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
263595d5899Sopenharmony_ci        return false;
264595d5899Sopenharmony_ci    }
265595d5899Sopenharmony_ci    auto setBrightnessFunc = reinterpret_cast<bool (*)(uint32_t, uint32_t, bool)>(mSetBrightnessFunc);
266595d5899Sopenharmony_ci    return setBrightnessFunc(value, gradualDuration, continuous);
267595d5899Sopenharmony_ci}
268595d5899Sopenharmony_ci
269595d5899Sopenharmony_cibool BrightnessManagerExt::DiscountBrightness(double discount)
270595d5899Sopenharmony_ci{
271595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
272595d5899Sopenharmony_ci        return false;
273595d5899Sopenharmony_ci    }
274595d5899Sopenharmony_ci    auto discountBrightnessFunc = reinterpret_cast<bool (*)(double)>(mDiscountBrightnessFunc);
275595d5899Sopenharmony_ci    return discountBrightnessFunc(discount);
276595d5899Sopenharmony_ci}
277595d5899Sopenharmony_ci
278595d5899Sopenharmony_cidouble BrightnessManagerExt::GetDiscount() const
279595d5899Sopenharmony_ci{
280595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
281595d5899Sopenharmony_ci        return 1.0;
282595d5899Sopenharmony_ci    }
283595d5899Sopenharmony_ci    auto getDiscountFunc = reinterpret_cast<double (*)()>(mGetDiscountFunc);
284595d5899Sopenharmony_ci    return getDiscountFunc();
285595d5899Sopenharmony_ci}
286595d5899Sopenharmony_ci
287595d5899Sopenharmony_civoid BrightnessManagerExt::SetScreenOnBrightness()
288595d5899Sopenharmony_ci{
289595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
290595d5899Sopenharmony_ci        return;
291595d5899Sopenharmony_ci    }
292595d5899Sopenharmony_ci    auto setScreenOnBrightnessFunc = reinterpret_cast<void (*)()>(mSetScreenOnBrightnessFunc);
293595d5899Sopenharmony_ci    setScreenOnBrightnessFunc();
294595d5899Sopenharmony_ci}
295595d5899Sopenharmony_ci
296595d5899Sopenharmony_ciuint32_t BrightnessManagerExt::GetScreenOnBrightness() const
297595d5899Sopenharmony_ci{
298595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
299595d5899Sopenharmony_ci        return 0;
300595d5899Sopenharmony_ci    }
301595d5899Sopenharmony_ci    auto getScreenOnBrightnessFunc = reinterpret_cast<uint32_t (*)(bool)>(mGetScreenOnBrightnessFunc);
302595d5899Sopenharmony_ci    return getScreenOnBrightnessFunc(false);
303595d5899Sopenharmony_ci}
304595d5899Sopenharmony_ci
305595d5899Sopenharmony_civoid BrightnessManagerExt::ClearOffset()
306595d5899Sopenharmony_ci{
307595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
308595d5899Sopenharmony_ci        return;
309595d5899Sopenharmony_ci    }
310595d5899Sopenharmony_ci    auto clearOffsetFunc = reinterpret_cast<void (*)()>(mClearOffsetFunc);
311595d5899Sopenharmony_ci    clearOffsetFunc();
312595d5899Sopenharmony_ci}
313595d5899Sopenharmony_ci
314595d5899Sopenharmony_cibool BrightnessManagerExt::OverrideBrightness(uint32_t value, uint32_t gradualDuration)
315595d5899Sopenharmony_ci{
316595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
317595d5899Sopenharmony_ci        return false;
318595d5899Sopenharmony_ci    }
319595d5899Sopenharmony_ci    auto overrideBrightnessFunc = reinterpret_cast<bool (*)(uint32_t, uint32_t)>(mOverrideBrightnessFunc);
320595d5899Sopenharmony_ci    return overrideBrightnessFunc(value, gradualDuration);
321595d5899Sopenharmony_ci}
322595d5899Sopenharmony_ci
323595d5899Sopenharmony_cibool BrightnessManagerExt::RestoreBrightness(uint32_t gradualDuration)
324595d5899Sopenharmony_ci{
325595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
326595d5899Sopenharmony_ci        return false;
327595d5899Sopenharmony_ci    }
328595d5899Sopenharmony_ci    auto restoreBrightnessFunc = reinterpret_cast<bool (*)(uint32_t)>(mRestoreBrightnessFunc);
329595d5899Sopenharmony_ci    return restoreBrightnessFunc(gradualDuration);
330595d5899Sopenharmony_ci}
331595d5899Sopenharmony_ci
332595d5899Sopenharmony_cibool BrightnessManagerExt::BoostBrightness(uint32_t timeoutMs, uint32_t gradualDuration)
333595d5899Sopenharmony_ci{
334595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
335595d5899Sopenharmony_ci        return false;
336595d5899Sopenharmony_ci    }
337595d5899Sopenharmony_ci    auto boostBrightnessFunc = reinterpret_cast<bool (*)(uint32_t, uint32_t)>(mBoostBrightnessFunc);
338595d5899Sopenharmony_ci    return boostBrightnessFunc(timeoutMs, gradualDuration);
339595d5899Sopenharmony_ci}
340595d5899Sopenharmony_ci
341595d5899Sopenharmony_cibool BrightnessManagerExt::CancelBoostBrightness(uint32_t gradualDuration)
342595d5899Sopenharmony_ci{
343595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
344595d5899Sopenharmony_ci        return false;
345595d5899Sopenharmony_ci    }
346595d5899Sopenharmony_ci    auto cancelBoostBrightnessFunc = reinterpret_cast<bool (*)(uint32_t)>(mCancelBoostBrightnessFunc);
347595d5899Sopenharmony_ci    return cancelBoostBrightnessFunc(gradualDuration);
348595d5899Sopenharmony_ci}
349595d5899Sopenharmony_ci
350595d5899Sopenharmony_ciuint32_t BrightnessManagerExt::GetBrightness()
351595d5899Sopenharmony_ci{
352595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
353595d5899Sopenharmony_ci        return 0;
354595d5899Sopenharmony_ci    }
355595d5899Sopenharmony_ci    auto getBrightnessFunc = reinterpret_cast<uint32_t (*)()>(mGetBrightnessFunc);
356595d5899Sopenharmony_ci    return getBrightnessFunc();
357595d5899Sopenharmony_ci}
358595d5899Sopenharmony_ci
359595d5899Sopenharmony_ciuint32_t BrightnessManagerExt::GetDeviceBrightness()
360595d5899Sopenharmony_ci{
361595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
362595d5899Sopenharmony_ci        return 0;
363595d5899Sopenharmony_ci    }
364595d5899Sopenharmony_ci    auto getDeviceBrightnessFunc = reinterpret_cast<uint32_t (*)()>(mGetDeviceBrightnessFunc);
365595d5899Sopenharmony_ci    return getDeviceBrightnessFunc();
366595d5899Sopenharmony_ci}
367595d5899Sopenharmony_ci
368595d5899Sopenharmony_cibool BrightnessManagerExt::IsBrightnessOverridden() const
369595d5899Sopenharmony_ci{
370595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
371595d5899Sopenharmony_ci        return false;
372595d5899Sopenharmony_ci    }
373595d5899Sopenharmony_ci    auto isBrightnessOverriddenFunc = reinterpret_cast<bool (*)()>(mIsBrightnessOverriddenFunc);
374595d5899Sopenharmony_ci    return isBrightnessOverriddenFunc();
375595d5899Sopenharmony_ci}
376595d5899Sopenharmony_ci
377595d5899Sopenharmony_cibool BrightnessManagerExt::IsBrightnessBoosted() const
378595d5899Sopenharmony_ci{
379595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
380595d5899Sopenharmony_ci        return false;
381595d5899Sopenharmony_ci    }
382595d5899Sopenharmony_ci    auto isBrightnessBoostedFunc = reinterpret_cast<bool (*)()>(mIsBrightnessBoostedFunc);
383595d5899Sopenharmony_ci    return isBrightnessBoostedFunc();
384595d5899Sopenharmony_ci}
385595d5899Sopenharmony_ci
386595d5899Sopenharmony_ciuint32_t BrightnessManagerExt::GetCurrentDisplayId(uint32_t defaultId) const
387595d5899Sopenharmony_ci{
388595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
389595d5899Sopenharmony_ci        return defaultId;
390595d5899Sopenharmony_ci    }
391595d5899Sopenharmony_ci    auto getCurrentDisplayIdFunc = reinterpret_cast<uint32_t (*)(uint32_t)>(mGetCurrentDisplayIdFunc);
392595d5899Sopenharmony_ci    return getCurrentDisplayIdFunc(defaultId);
393595d5899Sopenharmony_ci}
394595d5899Sopenharmony_ci
395595d5899Sopenharmony_civoid BrightnessManagerExt::SetDisplayId(uint32_t id)
396595d5899Sopenharmony_ci{
397595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
398595d5899Sopenharmony_ci        return;
399595d5899Sopenharmony_ci    }
400595d5899Sopenharmony_ci    auto setDisplayIdFunc = reinterpret_cast<void (*)(uint32_t)>(mSetDisplayIdFunc);
401595d5899Sopenharmony_ci    setDisplayIdFunc(id);
402595d5899Sopenharmony_ci}
403595d5899Sopenharmony_ci
404595d5899Sopenharmony_ciuint32_t BrightnessManagerExt::SetLightBrightnessThreshold(
405595d5899Sopenharmony_ci    std::vector<int32_t> threshold, sptr<IDisplayBrightnessCallback> callback)
406595d5899Sopenharmony_ci{
407595d5899Sopenharmony_ci    uint32_t result = 0;
408595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
409595d5899Sopenharmony_ci        return result;
410595d5899Sopenharmony_ci    }
411595d5899Sopenharmony_ci    auto setLightBrightnessThresholdFunc =
412595d5899Sopenharmony_ci        reinterpret_cast<uint32_t (*)(std::vector<int32_t>, sptr<IDisplayBrightnessCallback>)>(
413595d5899Sopenharmony_ci        mSetLightBrightnessThresholdFunc);
414595d5899Sopenharmony_ci    if (!setLightBrightnessThresholdFunc) {
415595d5899Sopenharmony_ci        return result;
416595d5899Sopenharmony_ci    }
417595d5899Sopenharmony_ci    return setLightBrightnessThresholdFunc(threshold, callback);
418595d5899Sopenharmony_ci}
419595d5899Sopenharmony_ci
420595d5899Sopenharmony_cibool BrightnessManagerExt::SetMaxBrightness(double value)
421595d5899Sopenharmony_ci{
422595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
423595d5899Sopenharmony_ci        return false;
424595d5899Sopenharmony_ci    }
425595d5899Sopenharmony_ci    auto setMaxBrightnessFunc = reinterpret_cast<bool (*)(double)>(mSetMaxBrightnessFunc);
426595d5899Sopenharmony_ci    return setMaxBrightnessFunc(value);
427595d5899Sopenharmony_ci}
428595d5899Sopenharmony_ci
429595d5899Sopenharmony_cibool BrightnessManagerExt::SetMaxBrightnessNit(uint32_t nit)
430595d5899Sopenharmony_ci{
431595d5899Sopenharmony_ci    if (!mBrightnessManagerExtEnable) {
432595d5899Sopenharmony_ci        return false;
433595d5899Sopenharmony_ci    }
434595d5899Sopenharmony_ci    auto setMaxBrightnessNitFunc = reinterpret_cast<bool (*)(uint32_t)>(mSetMaxBrightnessNitFunc);
435595d5899Sopenharmony_ci    return setMaxBrightnessNitFunc(nit);
436595d5899Sopenharmony_ci}
437595d5899Sopenharmony_ci} // namespace DisplayPowerMgr
438595d5899Sopenharmony_ci} // namespace OHOS