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 "power_shutdown_callback_stub.h"
17
18 #include <message_parcel.h>
19 #include "errors.h"
20 #include "ipc_object_stub.h"
21
22 #include "power_log.h"
23 #include "power_mgr_errors.h"
24 #include "xcollie.h"
25 #include "xcollie_define.h"
26
27 namespace OHOS {
28 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int PowerShutdownCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
30 MessageOption &option)
31 {
32 POWER_HILOGD(COMP_SVC, "cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
33 const int DFX_DELAY_MS = 10000;
34 int id = HiviewDFX::XCollie::GetInstance().SetTimer("PowerShutdownCallback", DFX_DELAY_MS, nullptr, nullptr,
35 HiviewDFX::XCOLLIE_FLAG_NOOP);
36 std::u16string descripter = PowerShutdownCallbackStub::GetDescriptor();
37 std::u16string remoteDescripter = data.ReadInterfaceToken();
38 if (descripter != remoteDescripter) {
39 POWER_HILOGE(COMP_SVC, "Descriptor is not match");
40 return E_GET_POWER_SERVICE_FAILED;
41 }
42
43 int ret = ERR_OK;
44 switch (code) {
45 case static_cast<uint32_t>(IShutdownCallback::POWER_SHUTDOWN_CHANGED):
46 ret = OnPowerShutdownCallbackStub();
47 break;
48 default:
49 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
52 return ret;
53 }
54
OnPowerShutdownCallbackStub()55 int32_t PowerShutdownCallbackStub::OnPowerShutdownCallbackStub()
56 {
57 ShutdownCallback();
58 return ERR_OK;
59 }
60 } // namespace PowerMgr
61 } // namespace OHOS
62