• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "takeover_suspend_callback_proxy.h"
16 #include "iremote_object.h"
17 #include "message_option.h"
18 #include "message_parcel.h"
19 #include "power_common.h"
20 #include "take_over_callback_ipc_interface_code.h"
21 
22 namespace OHOS {
23 namespace PowerMgr {
OnTakeOverSuspend(SuspendDeviceType type)24 bool TakeOverSuspendCallbackProxy::OnTakeOverSuspend(SuspendDeviceType type)
25 {
26     sptr<IRemoteObject> remote = Remote();
27     if (remote == nullptr) {
28         POWER_HILOGE(FEATURE_SUSPEND, "remote is nullptr");
29         return false;
30     }
31 
32     MessageParcel data;
33     MessageParcel reply;
34     MessageOption option;
35 
36     if (!data.WriteInterfaceToken(TakeOverSuspendCallbackProxy::GetDescriptor())) {
37         POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed");
38         return false;
39     }
40     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(data, Uint32, static_cast<uint32_t>(type), false);
41     int ret = remote->SendRequest(
42         static_cast<int32_t>(PowerMgr::TakeOverSuspendCallbackInterfaceCode::CMD_ON_TAKEOVER_SUSPEND),
43         data, reply, option);
44     if (ret != ERR_OK) {
45         POWER_HILOGE(FEATURE_SUSPEND, "SendRequest is failed, ret=%{public}d", ret);
46         return false;
47     }
48 
49     bool isTakeOver = false;
50     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(reply, Bool, isTakeOver, false);
51     return isTakeOver;
52 }
53 } // namespace PowerMgr
54 } // namespace OHOS