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_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/sync_shutdown_callback_ipc_interface_code.h"
23 
24 namespace OHOS {
25 namespace PowerMgr {
OnSyncShutdown()26 void SyncShutdownCallbackProxy::OnSyncShutdown()
27 {
28     sptr<IRemoteObject> remote = Remote();
29     RETURN_IF(remote == nullptr);
30 
31     MessageParcel data;
32     MessageParcel reply;
33     MessageOption option;
34 
35     if (!data.WriteInterfaceToken(SyncShutdownCallbackProxy::GetDescriptor())) {
36         POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed");
37         return;
38     }
39 
40     int ret = remote->SendRequest(
41         static_cast<int32_t>(PowerMgr::SyncShutdownCallbackInterfaceCode::CMD_ON_SYNC_SHUTDOWN),
42         data, reply, option);
43     if (ret != ERR_OK) {
44         POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret);
45     }
46 }
47 
OnSyncShutdownOrReboot(bool isReboot)48 void SyncShutdownCallbackProxy::OnSyncShutdownOrReboot(bool isReboot)
49 {
50     sptr<IRemoteObject> remote = Remote();
51     RETURN_IF(remote == nullptr);
52 
53     MessageParcel data;
54     MessageParcel reply;
55     MessageOption option;
56 
57     if (!data.WriteInterfaceToken(SyncShutdownCallbackProxy::GetDescriptor())) {
58         POWER_HILOGE(FEATURE_SHUTDOWN, "Write descriptor failed");
59         return;
60     }
61 
62     RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(data, Bool, isReboot);
63 
64     int ret = remote->SendRequest(
65         static_cast<int32_t>(PowerMgr::SyncShutdownCallbackInterfaceCode::CMD_ON_SYNC_SHUTDOWN_OR_REBOOT),
66         data, reply, option);
67     if (ret != ERR_OK) {
68         POWER_HILOGE(FEATURE_SHUTDOWN, "SendRequest is failed, ret=%{public}d", ret);
69     }
70 }
71 
72 } // namespace PowerMgr
73 } // namespace OHOS
74