1 /*
2 * Copyright (c) 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 "shutdown/sync_shutdown_callback_stub.h"
17
18 #include "message_parcel.h"
19 #include "power_common.h"
20 #include "shutdown/sync_shutdown_callback_ipc_interface_code.h"
21 #include "xcollie/xcollie.h"
22 #include "xcollie/xcollie_define.h"
23
24 namespace OHOS {
25 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int SyncShutdownCallbackStub::OnRemoteRequest(
27 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
28 {
29 POWER_HILOGD(FEATURE_SHUTDOWN, "cmd=%{public}d, flags=%{public}d", code, option.GetFlags());
30 const int32_t DFX_DELAY_MS = 10000;
31 int32_t id = HiviewDFX::XCollie::GetInstance().SetTimer(
32 "PowerShutdownCallback", DFX_DELAY_MS, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_NOOP);
33 std::u16string descripter = SyncShutdownCallbackStub::GetDescriptor();
34 std::u16string remoteDescripter = data.ReadInterfaceToken();
35 if (descripter != remoteDescripter) {
36 POWER_HILOGE(COMP_SVC, "Descriptor is not match");
37 return E_GET_POWER_SERVICE_FAILED;
38 }
39
40 int32_t ret = ERR_OK;
41 if (code == static_cast<uint32_t>(PowerMgr::SyncShutdownCallbackInterfaceCode::CMD_ON_SYNC_SHUTDOWN)) {
42 ret = OnSyncShutdownCallbackStub(data, reply);
43 } else {
44 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45 }
46 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
47 return ret;
48 }
49
OnSyncShutdownCallbackStub(MessageParcel & data,MessageParcel & reply)50 int32_t SyncShutdownCallbackStub::OnSyncShutdownCallbackStub(MessageParcel& data, MessageParcel& reply)
51 {
52 OnSyncShutdown();
53 return ERR_OK;
54 }
55
56 } // namespace PowerMgr
57 } // namespace OHOS
58