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_brightness_callback_stub.h"
17
18 #include "display_brightness_callback_ipc_interface_code.h"
19 #include "display_common.h"
20 #include "display_log.h"
21 #include "display_mgr_errors.h"
22 #include "display_power_info.h"
23 #include "errors.h"
24 #include "idisplay_brightness_callback.h"
25 #include "ipc_object_stub.h"
26 #include "message_option.h"
27 #include "xcollie/xcollie.h"
28 #include "xcollie/xcollie_define.h"
29 #include <message_parcel.h>
30
31 namespace OHOS {
32 namespace DisplayPowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int32_t DisplayBrightnessCallbackStub::OnRemoteRequest(
34 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
35 {
36 DISPLAY_HILOGD(
37 COMP_SVC, "DisplayBrightnessCallbackStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags());
38 std::u16string descripter = DisplayBrightnessCallbackStub::GetDescriptor();
39 std::u16string remoteDescripter = data.ReadInterfaceToken();
40 if (descripter != remoteDescripter) {
41 DISPLAY_HILOGE(COMP_SVC, "descriptor is not matched!");
42 return E_GET_POWER_SERVICE_FAILED;
43 }
44
45 const int DFX_DELAY_S = 60;
46 const int INVALID_ID = 0;
47 int id = HiviewDFX::XCollie::GetInstance().SetTimer(
48 "DisplayBrightnessCallbackStub", DFX_DELAY_S, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG);
49 if (id <= INVALID_ID) {
50 DISPLAY_HILOGE(COMP_SVC, "SetTimer failed");
51 }
52 int32_t ret = ERR_OK;
53 if (code ==
54 static_cast<uint32_t>(
55 PowerMgr::DisplayBrightnessCallbackInterfaceCode::ON_NOTIFY_APS_LIGHT_BRIGHTNESS_CHANGE)) {
56 ret = OnNotifyApsLightBrightnessChangeStub(data, reply);
57 } else {
58 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59 }
60 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
61 return ret;
62 }
63
OnNotifyApsLightBrightnessChangeStub(MessageParcel & data,MessageParcel & reply)64 int32_t DisplayBrightnessCallbackStub::OnNotifyApsLightBrightnessChangeStub(MessageParcel& data, MessageParcel& reply)
65 {
66 uint32_t type = 0;
67 bool state = false;
68
69 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR);
70 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Bool, state, E_READ_PARCEL_ERROR);
71
72 OnNotifyApsLightBrightnessChange(type, state);
73 return ERR_OK;
74 }
75
OnNotifyApsLightBrightnessChange(uint32_t type,bool state)76 void DisplayBrightnessCallbackStub::OnNotifyApsLightBrightnessChange(uint32_t type, bool state) {}
77
78 } // namespace DisplayPowerMgr
79 } // namespace OHOS
80