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_proxy.h"
17
18 #include "iremote_object.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 #include "power_common.h"
22 #include "shutdown/takeover_shutdown_callback_ipc_interface_code.h"
23
24 namespace OHOS {
25 namespace PowerMgr {
OnTakeOverShutdown(bool isReboot)26 bool TakeOverShutdownCallbackProxy::OnTakeOverShutdown(bool isReboot)
27 {
28 sptr<IRemoteObject> remote = Remote();
29 RETURN_IF_WITH_RET(remote == nullptr, false);
30
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option;
34
35 if (!data.WriteInterfaceToken(TakeOverShutdownCallbackProxy::GetDescriptor())) {
36 POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed");
37 return false;
38 }
39
40 RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Bool, isReboot, false);
41
42 int ret = remote->SendRequest(
43 static_cast<int32_t>(PowerMgr::TakeoverShutdownCallbackInterfaceCode::CMD_ON_TAKEOVER_SHUTDOWN),
44 data, reply, option);
45 if (ret != ERR_OK) {
46 POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret);
47 return false;
48 }
49
50 bool isTakeOver = false;
51 RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, isTakeOver, false);
52 return isTakeOver;
53 }
54
55 } // namespace PowerMgr
56 } // namespace OHOS
57