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 "sync_sleep_callback_stub.h"
17
18 #include <message_parcel.h>
19
20 #include "power_common.h"
21 #include "suspend/sync_sleep_callback_ipc_interface_code.h"
22 #include "sync_sleep_callback_proxy.h"
23 #include "xcollie/xcollie.h"
24
25 namespace OHOS {
26 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int SyncSleepCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
28 MessageOption &option)
29 {
30 POWER_HILOGD(COMP_SVC, "cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
31 const int DFX_DELAY_MS = 10000;
32 int id = HiviewDFX::XCollie::GetInstance().SetTimer("SyncSleepCallbackStub", DFX_DELAY_MS, nullptr, nullptr,
33 HiviewDFX::XCOLLIE_FLAG_NOOP);
34 std::u16string descripter = SyncSleepCallbackStub::GetDescriptor();
35 std::u16string remoteDescripter = data.ReadInterfaceToken();
36 if (descripter != remoteDescripter) {
37 POWER_HILOGE(COMP_SVC, "Descriptor is not match");
38 return E_GET_POWER_SERVICE_FAILED;
39 }
40
41 int ret = ERR_OK;
42 if (code == static_cast<uint32_t>(PowerMgr::SyncSleepCallbackInterfaceCode::CMD_ON_SYNC_SLEEP)) {
43 ret = OnSyncSleepStub(data);
44 } else if (code == static_cast<uint32_t>(PowerMgr::SyncSleepCallbackInterfaceCode::CMD_ON_SYNC_WAKEUP)) {
45 ret = OnSyncWakeupStub(data);
46 } else {
47 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 }
49 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
50 return ret;
51 }
52
OnSyncSleepStub(MessageParcel & data)53 int32_t SyncSleepCallbackStub::OnSyncSleepStub(MessageParcel& data)
54 {
55 bool onForceSleep;
56 READ_PARCEL_WITH_RET(data, Bool, onForceSleep, E_READ_PARCEL_ERROR);
57 OnSyncSleep(static_cast<bool>(onForceSleep));
58 return ERR_OK;
59 }
60
OnSyncWakeupStub(MessageParcel & data)61 int32_t SyncSleepCallbackStub::OnSyncWakeupStub(MessageParcel& data)
62 {
63 bool onForceSleep;
64 READ_PARCEL_WITH_RET(data, Bool, onForceSleep, E_READ_PARCEL_ERROR);
65 OnSyncWakeup(static_cast<bool>(onForceSleep));
66 return ERR_OK;
67 }
68 } // namespace PowerMgr
69 } // namespace OHOS
70