• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/takeover_shutdown_callback_stub.h"
17 
18 #include "message_parcel.h"
19 #include "power_common.h"
20 #include "shutdown/takeover_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 TakeOverShutdownCallbackStub::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 = TakeOverShutdownCallbackStub::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::TakeoverShutdownCallbackInterfaceCode::CMD_ON_TAKEOVER_SHUTDOWN)) {
42         ret = OnTakeOverShutdownCallbackStub(data, reply);
43     } else {
44         ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45     }
46     HiviewDFX::XCollie::GetInstance().CancelTimer(id);
47     return ret;
48 }
49 
OnTakeOverShutdownCallbackStub(MessageParcel & data,MessageParcel & reply)50 int32_t TakeOverShutdownCallbackStub::OnTakeOverShutdownCallbackStub(MessageParcel& data, MessageParcel& reply)
51 {
52     bool isReboot;
53     READ_PARCEL_WITH_RET(data, Bool, isReboot, E_READ_PARCEL_ERROR);
54     int32_t isTakeOver = OnTakeOverShutdown(isReboot);
55     WRITE_PARCEL_WITH_RET(reply, Bool, isTakeOver, E_WRITE_PARCEL_ERROR);
56     return ERR_OK;
57 }
58 
59 } // namespace PowerMgr
60 } // namespace OHOS
61