• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "power_state_callback_stub.h"
17 
18 #include <message_parcel.h>
19 
20 #include "power_common.h"
21 #include "power_state_callback_proxy.h"
22 #include "xcollie.h"
23 
24 namespace OHOS {
25 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int PowerStateCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
27     MessageOption &option)
28 {
29     POWER_HILOGD(COMP_SVC, "cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
30     const int DFX_DELAY_MS = 10000;
31     int id = HiviewDFX::XCollie::GetInstance().SetTimer("PowerStateCallbackStub", DFX_DELAY_MS, nullptr, nullptr,
32         HiviewDFX::XCOLLIE_FLAG_NOOP);
33     std::u16string descripter = PowerStateCallbackStub::GetDescriptor();
34     std::u16string remoteDescripter = data.ReadInterfaceToken();
35     if (descripter != remoteDescripter) {
36         POWER_HILOGE(COMP_SVC, "Descriptor is not match");
37         return E_GET_POWER_SERVICE_FAILED;
38     }
39 
40     int ret = ERR_OK;
41     switch (code) {
42         case static_cast<int>(IPowerStateCallback::POWER_STATE_CHANGED):
43             ret = OnPowerStateChangedStub(data);
44             break;
45         default:
46             ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47     }
48     HiviewDFX::XCollie::GetInstance().CancelTimer(id);
49     return ret;
50 }
51 
OnPowerStateChangedStub(MessageParcel & data)52 int32_t PowerStateCallbackStub::OnPowerStateChangedStub(MessageParcel& data)
53 {
54     uint32_t type;
55     READ_PARCEL_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR);
56     OnPowerStateChanged(static_cast<PowerState>(type));
57     return ERR_OK;
58 }
59 } // namespace PowerMgr
60 } // namespace OHOS
61