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 #include "display_power_mgr_stub.h"
17 
18 #include <message_parcel.h>
19 #include "errors.h"
20 #include "ipc_object_stub.h"
21 #include "iremote_broker.h"
22 #include "iremote_object.h"
23 #include "idisplay_power_callback.h"
24 #include "display_log.h"
25 #include "display_common.h"
26 #include "display_mgr_errors.h"
27 #include "display_power_info.h"
28 #include "display_power_mgr_ipc_interface_code.h"
29 #include "xcollie/xcollie.h"
30 #include "xcollie/xcollie_define.h"
31 
32 namespace OHOS {
33 namespace DisplayPowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t DisplayPowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
35     MessageOption &option)
36 {
37     DISPLAY_HILOGD(COMP_SVC, "DisplayPowerMgrStub::OnRemoteRequest, cmd = %d, flags= %d",
38         code, option.GetFlags());
39     std::u16string descripter = DisplayPowerMgrStub::GetDescriptor();
40     std::u16string remoteDescripter = data.ReadInterfaceToken();
41     if (descripter != remoteDescripter) {
42         DISPLAY_HILOGE(COMP_SVC, "DisplayPowerMgrStub::OnRemoteRequest failed, descriptor is not matched!");
43         return E_GET_POWER_SERVICE_FAILED;
44     }
45 
46     constexpr int dfxDelayS = 60;
47     int id = HiviewDFX::XCollie::GetInstance().SetTimer("DisplayPowerMgrStub", dfxDelayS, nullptr, nullptr,
48         HiviewDFX::XCOLLIE_FLAG_LOG);
49 
50     int32_t ret = ProcessMessage(code, data, reply, option);
51     HiviewDFX::XCollie::GetInstance().CancelTimer(id);
52     return ret;
53 }
54 
ProcessMessage(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)55 int32_t DisplayPowerMgrStub::ProcessMessage(uint32_t code, MessageParcel &data, MessageParcel &reply,
56     MessageOption &option)
57 {
58     int32_t ret = ERR_OK;
59     switch (code) {
60         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::SET_DISPLAY_STATE):
61             ret = SetDisplayStateStub(data, reply);
62             break;
63         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_DISPLAY_STATE):
64             ret = GetDisplayStateStub(data, reply);
65             break;
66         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_DISPLAY_IDS):
67             ret = GetDisplayIdsStub(data, reply);
68             break;
69         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_MAIN_DISPLAY_ID):
70             ret = GetMainDisplayIdStub(data, reply);
71             break;
72         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::SET_BRIGHTNESS):
73             ret = SetBrightnessStub(data, reply);
74             break;
75         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::DISCOUNT_BRIGHTNESS):
76             ret = DiscountBrightnessStub(data, reply);
77             break;
78         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::OVERRIDE_BRIGHTNESS):
79             ret = OverrideBrightnessStub(data, reply);
80             break;
81         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::OVERRIDE_DISPLAY_OFF_DELAY):
82             ret = OverrideDisplayOffDelayStub(data, reply);
83             break;
84         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::SET_APS_LIGHT_AND_BRIGHTNESS_THRESOLD):
85             ret = SetLightBrightnessThresholdStub(data, reply);
86             break;
87         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::SET_MAX_BRIGHTNESS):
88             ret = SetMaxBrightnessStub(data, reply);
89             break;
90         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::SET_MAX_BRIGHTNESS_NIT):
91             ret = SetMaxBrightnessNitStub(data, reply);
92             break;
93         default:
94             ret = RemoteRequest(code, data, reply, option);
95             break;
96     }
97     return ret;
98 }
99 
RemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)100 int32_t DisplayPowerMgrStub::RemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
101     MessageOption &option)
102 {
103     int32_t ret = ERR_OK;
104     switch (code) {
105         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::RESTORE_BRIGHTNESS):
106             ret = RestoreBrightnessStub(data, reply);
107             break;
108         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_BRIGHTNESS):
109             ret = GetBrightnessStub(data, reply);
110             break;
111         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_DEFAULT_BRIGHTNESS):
112             ret = GetDefaultBrightnessStub(data, reply);
113             break;
114         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_MAX_BRIGHTNESS):
115             ret = GetMaxBrightnessStub(data, reply);
116             break;
117         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_MIN_BRIGHTNESS):
118             ret = GetMinBrightnessStub(data, reply);
119             break;
120         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::ADJUST_BRIGHTNESS):
121             ret = AdjustBrightnessStub(data, reply);
122             break;
123         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::AUTO_ADJUST_BRIGHTNESS):
124             ret = AutoAdjustBrightnessStub(data, reply);
125             break;
126         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::IS_AUTO_ADJUST_BRIGHTNESS):
127             ret = IsAutoAdjustBrightnessStub(data, reply);
128             break;
129         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::REGISTER_CALLBACK):
130             ret = RegisterCallbackStub(data, reply);
131             break;
132         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::BOOST_BRIGHTNESS):
133             ret = BoostBrightnessStub(data, reply);
134             break;
135         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::CANCEL_BOOST_BRIGHTNESS):
136             ret = CancelBoostBrightnessStub(data, reply);
137             break;
138         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::GET_DEVICE_BRIGHTNESS):
139             ret = GetDeviceBrightnessStub(data, reply);
140             break;
141         case static_cast<int32_t>(PowerMgr::DisplayPowerMgrInterfaceCode::SET_COORDINATED):
142             ret = SetCoordinatedStub(data, reply);
143             break;
144         default:
145             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
146             break;
147     }
148 
149     return ret;
150 }
151 
SetDisplayStateStub(MessageParcel & data,MessageParcel & reply)152 int32_t DisplayPowerMgrStub::SetDisplayStateStub(MessageParcel& data, MessageParcel& reply)
153 {
154     uint32_t id = 0;
155     uint32_t state = 0;
156     uint32_t reason = 0;
157 
158     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR);
159     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, state, E_READ_PARCEL_ERROR);
160     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, reason, E_READ_PARCEL_ERROR);
161 
162     bool ret = SetDisplayState(id, static_cast<DisplayState>(state), reason);
163     if (!reply.WriteBool(ret)) {
164         DISPLAY_HILOGE(COMP_SVC, "Failed to write SetDisplayStateStub return value");
165         return E_WRITE_PARCEL_ERROR;
166     }
167     return ERR_OK;
168 }
169 
GetDisplayStateStub(MessageParcel & data,MessageParcel & reply)170 int32_t DisplayPowerMgrStub::GetDisplayStateStub(MessageParcel& data, MessageParcel& reply)
171 {
172     uint32_t id = 0;
173 
174     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR);
175 
176     DisplayState ret = GetDisplayState(id);
177     if (!reply.WriteUint32(static_cast<uint32_t>(ret))) {
178         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDisplayStateStub return value");
179         return E_WRITE_PARCEL_ERROR;
180     }
181     return ERR_OK;
182 }
183 
GetDisplayIdsStub(MessageParcel & data,MessageParcel & reply)184 int32_t DisplayPowerMgrStub::GetDisplayIdsStub(MessageParcel& data, MessageParcel& reply)
185 {
186     std::vector<uint32_t> result = GetDisplayIds();
187     if (!reply.WriteUint32(static_cast<uint32_t>(result.size()))) {
188         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDisplayIdsStub return value");
189         return E_WRITE_PARCEL_ERROR;
190     }
191     for (uint32_t i = 0; i < result.size(); i++) {
192         if (!reply.WriteUint32(static_cast<uint32_t>(result[i]))) {
193             DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDisplayIdsStub");
194         }
195     }
196     return ERR_OK;
197 }
198 
GetMainDisplayIdStub(MessageParcel & data,MessageParcel & reply)199 int32_t DisplayPowerMgrStub::GetMainDisplayIdStub(MessageParcel& data, MessageParcel& reply)
200 {
201     uint32_t result = GetMainDisplayId();
202     if (!reply.WriteUint32(result)) {
203         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMainDisplayIdStub return value");
204         return E_WRITE_PARCEL_ERROR;
205     }
206     return ERR_OK;
207 }
208 
SetBrightnessStub(MessageParcel & data,MessageParcel & reply)209 int32_t DisplayPowerMgrStub::SetBrightnessStub(MessageParcel& data, MessageParcel& reply)
210 {
211     uint32_t value = 0;
212     uint32_t displayId = 0;
213     bool continuous = false;
214 
215     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, value, E_READ_PARCEL_ERROR);
216     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
217     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, continuous, E_READ_PARCEL_ERROR);
218 
219     bool ret = SetBrightness(value, displayId, continuous);
220     if (!reply.WriteBool(ret)) {
221         DISPLAY_HILOGE(COMP_SVC, "Failed to write SetBrightness return value");
222         return E_WRITE_PARCEL_ERROR;
223     }
224     int32_t error = static_cast<int32_t>(GetError());
225     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, error, E_WRITE_PARCEL_ERROR);
226     return ERR_OK;
227 }
228 
DiscountBrightnessStub(MessageParcel & data,MessageParcel & reply)229 int32_t DisplayPowerMgrStub::DiscountBrightnessStub(MessageParcel& data, MessageParcel& reply)
230 {
231     double discount = 0;
232     uint32_t displayId = 0;
233 
234     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Double, discount, E_READ_PARCEL_ERROR);
235     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
236 
237     bool ret = DiscountBrightness(discount, displayId);
238     if (!reply.WriteBool(ret)) {
239         DISPLAY_HILOGE(COMP_SVC, "Failed to wirte DiscountBrightness return value");
240         return E_WRITE_PARCEL_ERROR;
241     }
242     return ERR_OK;
243 }
244 
OverrideBrightnessStub(MessageParcel & data,MessageParcel & reply)245 int32_t DisplayPowerMgrStub::OverrideBrightnessStub(MessageParcel& data, MessageParcel& reply)
246 {
247     uint32_t value = 0;
248     uint32_t displayId = 0;
249     uint32_t duration = 0;
250 
251     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, value, E_READ_PARCEL_ERROR);
252     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
253     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, duration, E_READ_PARCEL_ERROR);
254 
255     bool ret = OverrideBrightness(value, displayId, duration);
256     if (!reply.WriteBool(ret)) {
257         DISPLAY_HILOGE(COMP_SVC, "Failed to write OverrideBrightness return value");
258         return E_WRITE_PARCEL_ERROR;
259     }
260     return ERR_OK;
261 }
262 
OverrideDisplayOffDelayStub(MessageParcel & data,MessageParcel & reply)263 int32_t DisplayPowerMgrStub::OverrideDisplayOffDelayStub(MessageParcel& data, MessageParcel& reply)
264 {
265     uint32_t delayMs = 0;
266 
267     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, delayMs, E_READ_PARCEL_ERROR);
268 
269     bool ret = OverrideDisplayOffDelay(delayMs);
270     if (!reply.WriteBool(ret)) {
271         DISPLAY_HILOGE(COMP_SVC, "Failed to write OverrideDisplayOffDelay return value");
272         return E_WRITE_PARCEL_ERROR;
273     }
274     return ERR_OK;
275 }
276 
RestoreBrightnessStub(MessageParcel & data,MessageParcel & reply)277 int32_t DisplayPowerMgrStub::RestoreBrightnessStub(MessageParcel& data, MessageParcel& reply)
278 {
279     uint32_t displayId = 0;
280     uint32_t duration = 0;
281 
282     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
283     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, duration, E_READ_PARCEL_ERROR);
284 
285     bool ret = RestoreBrightness(displayId, duration);
286     if (!reply.WriteBool(ret)) {
287         DISPLAY_HILOGE(COMP_SVC, "Failed to write RestoreBrightness return value");
288         return E_WRITE_PARCEL_ERROR;
289     }
290     return ERR_OK;
291 }
292 
GetBrightnessStub(MessageParcel & data,MessageParcel & reply)293 int32_t DisplayPowerMgrStub::GetBrightnessStub(MessageParcel& data, MessageParcel& reply)
294 {
295     uint32_t displayId = 0;
296 
297     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
298 
299     uint32_t ret = GetBrightness(displayId);
300     if (!reply.WriteUint32(ret)) {
301         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetBrightness return value");
302         return E_WRITE_PARCEL_ERROR;
303     }
304     return ERR_OK;
305 }
306 
GetDefaultBrightnessStub(MessageParcel & data,MessageParcel & reply)307 int32_t DisplayPowerMgrStub::GetDefaultBrightnessStub(MessageParcel& data, MessageParcel& reply)
308 {
309     uint32_t ret = GetDefaultBrightness();
310     if (!reply.WriteUint32(ret)) {
311         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDefaultBrightness return value");
312         return E_WRITE_PARCEL_ERROR;
313     }
314     return ERR_OK;
315 }
316 
GetMaxBrightnessStub(MessageParcel & data,MessageParcel & reply)317 int32_t DisplayPowerMgrStub::GetMaxBrightnessStub(MessageParcel& data, MessageParcel& reply)
318 {
319     uint32_t ret = GetMaxBrightness();
320     if (!reply.WriteUint32(ret)) {
321         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMaxBrightness return value");
322         return E_WRITE_PARCEL_ERROR;
323     }
324     return ERR_OK;
325 }
326 
GetMinBrightnessStub(MessageParcel & data,MessageParcel & reply)327 int32_t DisplayPowerMgrStub::GetMinBrightnessStub(MessageParcel& data, MessageParcel& reply)
328 {
329     uint32_t ret = GetMinBrightness();
330     if (!reply.WriteUint32(ret)) {
331         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMinBrightness return value");
332         return E_WRITE_PARCEL_ERROR;
333     }
334     return ERR_OK;
335 }
336 
AdjustBrightnessStub(MessageParcel & data,MessageParcel & reply)337 int32_t DisplayPowerMgrStub::AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply)
338 {
339     uint32_t id = 0;
340     int32_t value = 0;
341     uint32_t duration = 0;
342 
343     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR);
344     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, value, E_READ_PARCEL_ERROR);
345     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, duration, E_READ_PARCEL_ERROR);
346 
347     bool ret = AdjustBrightness(id, value, duration);
348     if (!reply.WriteBool(ret)) {
349         DISPLAY_HILOGE(COMP_SVC, "Failed to write AdjustBrightnessStub return value");
350         return E_WRITE_PARCEL_ERROR;
351     }
352     return ERR_OK;
353 }
354 
AutoAdjustBrightnessStub(MessageParcel & data,MessageParcel & reply)355 int32_t DisplayPowerMgrStub::AutoAdjustBrightnessStub(MessageParcel& data, MessageParcel& reply)
356 {
357     bool enable = 0;
358 
359     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enable, E_READ_PARCEL_ERROR);
360 
361     bool ret = AutoAdjustBrightness(enable);
362     if (!reply.WriteBool(ret)) {
363         DISPLAY_HILOGE(COMP_SVC, "Failed to write AutoAdjustBrightnessStub return value");
364         return E_WRITE_PARCEL_ERROR;
365     }
366     return ERR_OK;
367 }
368 
IsAutoAdjustBrightnessStub(MessageParcel & data,MessageParcel & reply)369 int32_t DisplayPowerMgrStub::IsAutoAdjustBrightnessStub(MessageParcel& data, MessageParcel& reply)
370 {
371     bool ret = IsAutoAdjustBrightness();
372     if (!reply.WriteBool(ret)) {
373         DISPLAY_HILOGE(COMP_SVC, "Failed to write IsAutoAdjustBrightnessStub return value");
374         return E_WRITE_PARCEL_ERROR;
375     }
376     return ERR_OK;
377 }
378 
RegisterCallbackStub(MessageParcel & data,MessageParcel & reply)379 int32_t DisplayPowerMgrStub::RegisterCallbackStub(MessageParcel& data, MessageParcel& reply)
380 {
381     sptr<IRemoteObject> obj = data.ReadRemoteObject();
382     RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
383     sptr<IDisplayPowerCallback> callback = iface_cast<IDisplayPowerCallback>(obj);
384     RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
385     bool isSucc = RegisterCallback(callback);
386     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isSucc, E_WRITE_PARCEL_ERROR);
387     return ERR_OK;
388 }
389 
BoostBrightnessStub(MessageParcel & data,MessageParcel & reply)390 int32_t DisplayPowerMgrStub::BoostBrightnessStub(MessageParcel& data, MessageParcel& reply)
391 {
392     int32_t timeoutMs = -1;
393     uint32_t id = 0;
394     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, timeoutMs, E_READ_PARCEL_ERROR);
395     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR);
396 
397     bool isScuu = BoostBrightness(timeoutMs, id);
398     if (!reply.WriteBool(isScuu)) {
399         DISPLAY_HILOGW(COMP_SVC, "Failed to write BoostBrightness return value");
400         return E_WRITE_PARCEL_ERROR;
401     }
402     return ERR_OK;
403 }
404 
CancelBoostBrightnessStub(MessageParcel & data,MessageParcel & reply)405 int32_t DisplayPowerMgrStub::CancelBoostBrightnessStub(MessageParcel& data, MessageParcel& reply)
406 {
407     uint32_t displayId = 0;
408 
409     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
410 
411     bool isScuu = CancelBoostBrightness(displayId);
412     if (!reply.WriteBool(isScuu)) {
413         DISPLAY_HILOGW(COMP_SVC, "Failed to write CancelBoostBrightness return value");
414         return E_WRITE_PARCEL_ERROR;
415     }
416     return ERR_OK;
417 }
418 
GetDeviceBrightnessStub(MessageParcel & data,MessageParcel & reply)419 int32_t DisplayPowerMgrStub::GetDeviceBrightnessStub(MessageParcel& data, MessageParcel& reply)
420 {
421     uint32_t displayId = 0;
422 
423     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
424 
425     uint32_t ret = GetDeviceBrightness(displayId);
426     if (!reply.WriteUint32(ret)) {
427         DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDeviceBrightness return value");
428         return E_WRITE_PARCEL_ERROR;
429     }
430     return ERR_OK;
431 }
432 
SetCoordinatedStub(MessageParcel & data,MessageParcel & reply)433 int32_t DisplayPowerMgrStub::SetCoordinatedStub(MessageParcel& data, MessageParcel& reply)
434 {
435     bool coordinated = false;
436     uint32_t displayId = 0;
437 
438     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, coordinated, E_READ_PARCEL_ERROR);
439     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
440 
441     bool ret = SetCoordinated(coordinated, displayId);
442     if (!reply.WriteBool(ret)) {
443         DISPLAY_HILOGE(COMP_SVC, "Failed to write SetCoordinatedStub return value");
444         return E_WRITE_PARCEL_ERROR;
445     }
446     return ERR_OK;
447 }
448 
SetLightBrightnessThresholdStub(MessageParcel & data,MessageParcel & reply)449 int32_t DisplayPowerMgrStub::SetLightBrightnessThresholdStub(MessageParcel& data, MessageParcel& reply)
450 {
451     std::vector<int32_t> threshold;
452     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32Vector, &threshold, E_READ_PARCEL_ERROR);
453     sptr<IRemoteObject> obj = data.ReadRemoteObject();
454     RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
455     sptr<IDisplayBrightnessCallback> callback = iface_cast<IDisplayBrightnessCallback>(obj);
456     RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
457     uint32_t ret = SetLightBrightnessThreshold(threshold, callback);
458     if (!reply.WriteUint32(ret)) {
459         DISPLAY_HILOGE(COMP_SVC, "Failed to write SetLightBrightnessThresholdStub return value");
460         return E_WRITE_PARCEL_ERROR;
461     }
462     return ERR_OK;
463 }
464 
SetMaxBrightnessStub(MessageParcel & data,MessageParcel & reply)465 int32_t DisplayPowerMgrStub::SetMaxBrightnessStub(MessageParcel& data, MessageParcel& reply)
466 {
467     double value = 0;
468     uint32_t enterTestMode = 0;
469 
470     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Double, value, E_READ_PARCEL_ERROR);
471     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, enterTestMode, E_READ_PARCEL_ERROR);
472 
473     bool ret = SetMaxBrightness(value, enterTestMode);
474     if (!reply.WriteBool(ret)) {
475         DISPLAY_HILOGE(COMP_SVC, "Failed to write SetMaxBrightness return value");
476         return E_WRITE_PARCEL_ERROR;
477     }
478     int32_t error = static_cast<int32_t>(GetError());
479     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, error, E_WRITE_PARCEL_ERROR);
480     return ERR_OK;
481 }
482 
SetMaxBrightnessNitStub(MessageParcel & data,MessageParcel & reply)483 int32_t DisplayPowerMgrStub::SetMaxBrightnessNitStub(MessageParcel& data, MessageParcel& reply)
484 {
485     uint32_t value = 0;
486     uint32_t enterTestMode = 0;
487 
488     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, value, E_READ_PARCEL_ERROR);
489     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, enterTestMode, E_READ_PARCEL_ERROR);
490 
491     bool ret = SetMaxBrightnessNit(value, enterTestMode);
492     if (!reply.WriteBool(ret)) {
493         DISPLAY_HILOGE(COMP_SVC, "Failed to write SetMaxBrightness return value");
494         return E_WRITE_PARCEL_ERROR;
495     }
496     int32_t error = static_cast<int32_t>(GetError());
497     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, error, E_WRITE_PARCEL_ERROR);
498     return ERR_OK;
499 }
500 } // namespace DisplayPowerMgr
501 } // namespace OHOS
502