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
250 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, value, E_READ_PARCEL_ERROR);
251 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
252
253 bool ret = OverrideBrightness(value, displayId);
254 if (!reply.WriteBool(ret)) {
255 DISPLAY_HILOGE(COMP_SVC, "Failed to write OverrideBrightness return value");
256 return E_WRITE_PARCEL_ERROR;
257 }
258 return ERR_OK;
259 }
260
OverrideDisplayOffDelayStub(MessageParcel & data,MessageParcel & reply)261 int32_t DisplayPowerMgrStub::OverrideDisplayOffDelayStub(MessageParcel& data, MessageParcel& reply)
262 {
263 uint32_t delayMs = 0;
264
265 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, delayMs, E_READ_PARCEL_ERROR);
266
267 bool ret = OverrideDisplayOffDelay(delayMs);
268 if (!reply.WriteBool(ret)) {
269 DISPLAY_HILOGE(COMP_SVC, "Failed to write OverrideDisplayOffDelay return value");
270 return E_WRITE_PARCEL_ERROR;
271 }
272 return ERR_OK;
273 }
274
RestoreBrightnessStub(MessageParcel & data,MessageParcel & reply)275 int32_t DisplayPowerMgrStub::RestoreBrightnessStub(MessageParcel& data, MessageParcel& reply)
276 {
277 uint32_t displayId = 0;
278
279 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
280
281 bool ret = RestoreBrightness(displayId);
282 if (!reply.WriteBool(ret)) {
283 DISPLAY_HILOGE(COMP_SVC, "Failed to write RestoreBrightness return value");
284 return E_WRITE_PARCEL_ERROR;
285 }
286 return ERR_OK;
287 }
288
GetBrightnessStub(MessageParcel & data,MessageParcel & reply)289 int32_t DisplayPowerMgrStub::GetBrightnessStub(MessageParcel& data, MessageParcel& reply)
290 {
291 uint32_t displayId = 0;
292
293 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
294
295 uint32_t ret = GetBrightness(displayId);
296 if (!reply.WriteUint32(ret)) {
297 DISPLAY_HILOGE(COMP_SVC, "Failed to write GetBrightness return value");
298 return E_WRITE_PARCEL_ERROR;
299 }
300 return ERR_OK;
301 }
302
GetDefaultBrightnessStub(MessageParcel & data,MessageParcel & reply)303 int32_t DisplayPowerMgrStub::GetDefaultBrightnessStub(MessageParcel& data, MessageParcel& reply)
304 {
305 uint32_t ret = GetDefaultBrightness();
306 if (!reply.WriteUint32(ret)) {
307 DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDefaultBrightness return value");
308 return E_WRITE_PARCEL_ERROR;
309 }
310 return ERR_OK;
311 }
312
GetMaxBrightnessStub(MessageParcel & data,MessageParcel & reply)313 int32_t DisplayPowerMgrStub::GetMaxBrightnessStub(MessageParcel& data, MessageParcel& reply)
314 {
315 uint32_t ret = GetMaxBrightness();
316 if (!reply.WriteUint32(ret)) {
317 DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMaxBrightness return value");
318 return E_WRITE_PARCEL_ERROR;
319 }
320 return ERR_OK;
321 }
322
GetMinBrightnessStub(MessageParcel & data,MessageParcel & reply)323 int32_t DisplayPowerMgrStub::GetMinBrightnessStub(MessageParcel& data, MessageParcel& reply)
324 {
325 uint32_t ret = GetMinBrightness();
326 if (!reply.WriteUint32(ret)) {
327 DISPLAY_HILOGE(COMP_SVC, "Failed to write GetMinBrightness return value");
328 return E_WRITE_PARCEL_ERROR;
329 }
330 return ERR_OK;
331 }
332
AdjustBrightnessStub(MessageParcel & data,MessageParcel & reply)333 int32_t DisplayPowerMgrStub::AdjustBrightnessStub(MessageParcel& data, MessageParcel& reply)
334 {
335 uint32_t id = 0;
336 int32_t value = 0;
337 uint32_t duration = 0;
338
339 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR);
340 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, value, E_READ_PARCEL_ERROR);
341 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, duration, E_READ_PARCEL_ERROR);
342
343 bool ret = AdjustBrightness(id, value, duration);
344 if (!reply.WriteBool(ret)) {
345 DISPLAY_HILOGE(COMP_SVC, "Failed to write AdjustBrightnessStub return value");
346 return E_WRITE_PARCEL_ERROR;
347 }
348 return ERR_OK;
349 }
350
AutoAdjustBrightnessStub(MessageParcel & data,MessageParcel & reply)351 int32_t DisplayPowerMgrStub::AutoAdjustBrightnessStub(MessageParcel& data, MessageParcel& reply)
352 {
353 bool enable = 0;
354
355 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, enable, E_READ_PARCEL_ERROR);
356
357 bool ret = AutoAdjustBrightness(enable);
358 if (!reply.WriteBool(ret)) {
359 DISPLAY_HILOGE(COMP_SVC, "Failed to write AutoAdjustBrightnessStub return value");
360 return E_WRITE_PARCEL_ERROR;
361 }
362 return ERR_OK;
363 }
364
IsAutoAdjustBrightnessStub(MessageParcel & data,MessageParcel & reply)365 int32_t DisplayPowerMgrStub::IsAutoAdjustBrightnessStub(MessageParcel& data, MessageParcel& reply)
366 {
367 bool ret = IsAutoAdjustBrightness();
368 if (!reply.WriteBool(ret)) {
369 DISPLAY_HILOGE(COMP_SVC, "Failed to write IsAutoAdjustBrightnessStub return value");
370 return E_WRITE_PARCEL_ERROR;
371 }
372 return ERR_OK;
373 }
374
RegisterCallbackStub(MessageParcel & data,MessageParcel & reply)375 int32_t DisplayPowerMgrStub::RegisterCallbackStub(MessageParcel& data, MessageParcel& reply)
376 {
377 sptr<IRemoteObject> obj = data.ReadRemoteObject();
378 RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
379 sptr<IDisplayPowerCallback> callback = iface_cast<IDisplayPowerCallback>(obj);
380 RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
381 bool isSucc = RegisterCallback(callback);
382 RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isSucc, E_WRITE_PARCEL_ERROR);
383 return ERR_OK;
384 }
385
BoostBrightnessStub(MessageParcel & data,MessageParcel & reply)386 int32_t DisplayPowerMgrStub::BoostBrightnessStub(MessageParcel& data, MessageParcel& reply)
387 {
388 int32_t timeoutMs = -1;
389 uint32_t id = 0;
390 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32, timeoutMs, E_READ_PARCEL_ERROR);
391 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR);
392
393 bool isScuu = BoostBrightness(timeoutMs, id);
394 if (!reply.WriteBool(isScuu)) {
395 DISPLAY_HILOGW(COMP_SVC, "Failed to write BoostBrightness return value");
396 return E_WRITE_PARCEL_ERROR;
397 }
398 return ERR_OK;
399 }
400
CancelBoostBrightnessStub(MessageParcel & data,MessageParcel & reply)401 int32_t DisplayPowerMgrStub::CancelBoostBrightnessStub(MessageParcel& data, MessageParcel& reply)
402 {
403 uint32_t displayId = 0;
404
405 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
406
407 bool isScuu = CancelBoostBrightness(displayId);
408 if (!reply.WriteBool(isScuu)) {
409 DISPLAY_HILOGW(COMP_SVC, "Failed to write CancelBoostBrightness return value");
410 return E_WRITE_PARCEL_ERROR;
411 }
412 return ERR_OK;
413 }
414
GetDeviceBrightnessStub(MessageParcel & data,MessageParcel & reply)415 int32_t DisplayPowerMgrStub::GetDeviceBrightnessStub(MessageParcel& data, MessageParcel& reply)
416 {
417 uint32_t displayId = 0;
418
419 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
420
421 uint32_t ret = GetDeviceBrightness(displayId);
422 if (!reply.WriteUint32(ret)) {
423 DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDeviceBrightness return value");
424 return E_WRITE_PARCEL_ERROR;
425 }
426 return ERR_OK;
427 }
428
SetCoordinatedStub(MessageParcel & data,MessageParcel & reply)429 int32_t DisplayPowerMgrStub::SetCoordinatedStub(MessageParcel& data, MessageParcel& reply)
430 {
431 bool coordinated = false;
432 uint32_t displayId = 0;
433
434 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, coordinated, E_READ_PARCEL_ERROR);
435 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR);
436
437 bool ret = SetCoordinated(coordinated, displayId);
438 if (!reply.WriteBool(ret)) {
439 DISPLAY_HILOGE(COMP_SVC, "Failed to write SetCoordinatedStub return value");
440 return E_WRITE_PARCEL_ERROR;
441 }
442 return ERR_OK;
443 }
444
SetLightBrightnessThresholdStub(MessageParcel & data,MessageParcel & reply)445 int32_t DisplayPowerMgrStub::SetLightBrightnessThresholdStub(MessageParcel& data, MessageParcel& reply)
446 {
447 std::vector<int32_t> threshold;
448 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Int32Vector, &threshold, E_READ_PARCEL_ERROR);
449 sptr<IRemoteObject> obj = data.ReadRemoteObject();
450 RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR);
451 sptr<IDisplayBrightnessCallback> callback = iface_cast<IDisplayBrightnessCallback>(obj);
452 RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR);
453 uint32_t ret = SetLightBrightnessThreshold(threshold, callback);
454 if (!reply.WriteUint32(ret)) {
455 DISPLAY_HILOGE(COMP_SVC, "Failed to write SetLightBrightnessThresholdStub return value");
456 return E_WRITE_PARCEL_ERROR;
457 }
458 return ERR_OK;
459 }
460
SetMaxBrightnessStub(MessageParcel & data,MessageParcel & reply)461 int32_t DisplayPowerMgrStub::SetMaxBrightnessStub(MessageParcel& data, MessageParcel& reply)
462 {
463 double value = 0;
464 uint32_t enterTestMode = 0;
465
466 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Double, value, E_READ_PARCEL_ERROR);
467 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, enterTestMode, E_READ_PARCEL_ERROR);
468
469 bool ret = SetMaxBrightness(value, enterTestMode);
470 if (!reply.WriteBool(ret)) {
471 DISPLAY_HILOGE(COMP_SVC, "Failed to write SetMaxBrightness return value");
472 return E_WRITE_PARCEL_ERROR;
473 }
474 int32_t error = static_cast<int32_t>(GetError());
475 RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, error, E_WRITE_PARCEL_ERROR);
476 return ERR_OK;
477 }
478
SetMaxBrightnessNitStub(MessageParcel & data,MessageParcel & reply)479 int32_t DisplayPowerMgrStub::SetMaxBrightnessNitStub(MessageParcel& data, MessageParcel& reply)
480 {
481 uint32_t value = 0;
482 uint32_t enterTestMode = 0;
483
484 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, value, E_READ_PARCEL_ERROR);
485 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, enterTestMode, E_READ_PARCEL_ERROR);
486
487 bool ret = SetMaxBrightnessNit(value, enterTestMode);
488 if (!reply.WriteBool(ret)) {
489 DISPLAY_HILOGE(COMP_SVC, "Failed to write SetMaxBrightness return value");
490 return E_WRITE_PARCEL_ERROR;
491 }
492 int32_t error = static_cast<int32_t>(GetError());
493 RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Int32, error, E_WRITE_PARCEL_ERROR);
494 return ERR_OK;
495 }
496 } // namespace DisplayPowerMgr
497 } // namespace OHOS
498