• 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_stub.h"
16 #include "takeover_suspend_callback_proxy.h"
17 #include "message_parcel.h"
18 #include "power_common.h"
19 #include "take_over_callback_ipc_interface_code.h"
20 #include "xcollie/xcollie.h"
21 #include "xcollie/xcollie_define.h"
22 
23 namespace OHOS {
24 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)25 int TakeOverSuspendCallbackStub::OnRemoteRequest(
26     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
27 {
28     const int32_t DFX_DELAY_S = 60;
29     int32_t id = HiviewDFX::XCollie::GetInstance().SetTimer(
30         "PowerSuspendCallback", DFX_DELAY_S, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG);
31     std::u16string descripter = TakeOverSuspendCallbackStub::GetDescriptor();
32     std::u16string remoteDescripter = data.ReadInterfaceToken();
33     if (descripter != remoteDescripter) {
34         POWER_HILOGE(COMP_SVC, "Descriptor is not match");
35         HiviewDFX::XCollie::GetInstance().CancelTimer(id);
36         return E_GET_POWER_SERVICE_FAILED;
37     }
38 
39     int32_t ret = ERR_OK;
40     if (code == static_cast<uint32_t>(TakeOverSuspendCallbackInterfaceCode::CMD_ON_TAKEOVER_SUSPEND)) {
41         ret = OnTakeOverSuspendCallbackStub(data, reply);
42     } else {
43         ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
44     }
45     HiviewDFX::XCollie::GetInstance().CancelTimer(id);
46     return ret;
47 }
48 
OnTakeOverSuspendCallbackStub(MessageParcel & data,MessageParcel & reply)49 int32_t TakeOverSuspendCallbackStub::OnTakeOverSuspendCallbackStub(MessageParcel& data, MessageParcel& reply)
50 {
51     uint32_t rawType = 0;
52     RETURN_IF_READ_PARCEL_FAILED_WITH_RET(data, Uint32, rawType, E_READ_PARCEL_ERROR);
53     SuspendDeviceType type = static_cast<SuspendDeviceType>(rawType);
54     bool isSuspendDeviceType =
55         type >= SuspendDeviceType::SUSPEND_DEVICE_REASON_MIN &&
56         type <= SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX;
57 
58     if (!isSuspendDeviceType) {
59         return E_INNER_ERR;
60     }
61     bool isTakeOver = OnTakeOverSuspend(type);
62     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isTakeOver, E_WRITE_PARCEL_ERROR);
63     return ERR_OK;
64 }
65 } // namespace PowerMgr
66 } // namespace OHOS