• 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_S = 60;
31     const int32_t INVALID_ID = 0;
32     int32_t id = HiviewDFX::XCollie::GetInstance().SetTimer(
33         "PowerShutdownCallback", DFX_DELAY_S, nullptr, nullptr, HiviewDFX::XCOLLIE_FLAG_LOG);
34     if (id <= INVALID_ID) {
35         POWER_HILOGE(COMP_SVC, "SetTimer failed");
36     }
37     std::u16string descripter = TakeOverShutdownCallbackStub::GetDescriptor();
38     std::u16string remoteDescripter = data.ReadInterfaceToken();
39     if (descripter != remoteDescripter) {
40         POWER_HILOGE(COMP_SVC, "Descriptor is not match");
41         HiviewDFX::XCollie::GetInstance().CancelTimer(id);
42         return E_GET_POWER_SERVICE_FAILED;
43     }
44 
45     int32_t ret = ERR_OK;
46     if (code == static_cast<uint32_t>(PowerMgr::TakeoverShutdownCallbackInterfaceCode::CMD_ON_TAKEOVER_SHUTDOWN)) {
47         ret = OnTakeOverShutdownCallbackStub(data, reply);
48     } else if (code ==
49         static_cast<uint32_t>(PowerMgr::TakeoverShutdownCallbackInterfaceCode::CMD_ON_TAKEOVER_HIBERNATE)) {
50         ret = OnTakeOverHibernateCallbackStub(data, reply);
51     } else {
52         ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53     }
54     HiviewDFX::XCollie::GetInstance().CancelTimer(id);
55     return ret;
56 }
57 
OnTakeOverShutdownCallbackStub(MessageParcel & data,MessageParcel & reply)58 int32_t TakeOverShutdownCallbackStub::OnTakeOverShutdownCallbackStub(MessageParcel& data, MessageParcel& reply)
59 {
60     TakeOverInfo *info = data.ReadParcelable<TakeOverInfo>();
61     bool isTakeOver = false;
62     if (info != nullptr) {
63         isTakeOver = OnTakeOverShutdown(*info);
64         delete info;
65     }
66     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isTakeOver, E_WRITE_PARCEL_ERROR);
67     return ERR_OK;
68 }
69 
OnTakeOverHibernateCallbackStub(MessageParcel & data,MessageParcel & reply)70 int32_t TakeOverShutdownCallbackStub::OnTakeOverHibernateCallbackStub(MessageParcel& data, MessageParcel& reply)
71 {
72     TakeOverInfo *info = data.ReadParcelable<TakeOverInfo>();
73     bool isTakeOver = false;
74     if (info != nullptr) {
75         isTakeOver = OnTakeOverHibernate(*info);
76         delete info;
77     }
78     RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(reply, Bool, isTakeOver, E_WRITE_PARCEL_ERROR);
79     return ERR_OK;
80 }
81 
82 } // namespace PowerMgr
83 } // namespace OHOS
84