• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_callback_stub.h"
17 
18 #include <message_parcel.h>
19 #include "errors.h"
20 #include "display_common.h"
21 #include "display_log.h"
22 #include "display_mgr_errors.h"
23 #include "display_power_info.h"
24 #include "idisplay_power_callback.h"
25 #include "ipc_object_stub.h"
26 #include "message_option.h"
27 #include "xcollie.h"
28 #include "xcollie_define.h"
29 
30 namespace OHOS {
31 namespace DisplayPowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t DisplayPowerCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
33     MessageOption &option)
34 {
35     DISPLAY_HILOGD(COMP_SVC, "DisplayPowerCallbackStub::OnRemoteRequest, cmd = %d, flags= %d",
36         code, option.GetFlags());
37     std::u16string descripter = DisplayPowerCallbackStub::GetDescriptor();
38     std::u16string remoteDescripter = data.ReadInterfaceToken();
39     if (descripter != remoteDescripter) {
40         DISPLAY_HILOGE(COMP_SVC, "descriptor is not matched!");
41         return E_GET_POWER_SERVICE_FAILED;
42     }
43 
44     const int DFX_DELAY_MS = 10000;
45     int id = HiviewDFX::XCollie::GetInstance().SetTimer("DisplayPowerCallbackStub", DFX_DELAY_MS, nullptr, nullptr,
46         HiviewDFX::XCOLLIE_FLAG_NOOP);
47     int32_t ret = ERR_OK;
48     switch (code) {
49         case static_cast<int32_t>(IDisplayPowerCallback::ON_DISPLAY_STATE_CHANGED):
50             ret = OnDisplayStateChangedStub(data, reply);
51             break;
52         default:
53             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
54             break;
55     }
56     HiviewDFX::XCollie::GetInstance().CancelTimer(id);
57     return ret;
58 }
59 
OnDisplayStateChangedStub(MessageParcel & data,MessageParcel & reply)60 int32_t DisplayPowerCallbackStub::OnDisplayStateChangedStub(MessageParcel& data, MessageParcel& reply)
61 {
62     uint32_t id = 0;
63     uint32_t state = 0;
64 
65     READ_PARCEL_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR);
66     READ_PARCEL_WITH_RET(data, Uint32, state, E_READ_PARCEL_ERROR);
67 
68     OnDisplayStateChanged(id, static_cast<DisplayState>(state));
69     return ERR_OK;
70 }
71 } // namespace DisplayPowerMgr
72 } // namespace OHOS
73