1 /*
2 * Copyright (c) 2021 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 "thermal_level_callback_stub.h"
17 #include <message_parcel.h>
18 #include "thermal_common.h"
19 #include "xcollie.h"
20
21 namespace OHOS {
22 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int ThermalLevelCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
24 MessageOption &option)
25 {
26 THERMAL_HILOGD(COMP_SVC,
27 "ThermalLevelCallbackStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
28 code, option.GetFlags());
29 std::u16string descripter = ThermalLevelCallbackStub::GetDescriptor();
30 std::u16string remoteDescripter = data.ReadInterfaceToken();
31 if (descripter != remoteDescripter) {
32 THERMAL_HILOGE(COMP_SVC,
33 "ThermalLevelCallbackStub::OnRemoteRequest failed, descriptor is not matched!");
34 return E_GET_THERMAL_SERVICE_FAILED;
35 }
36 const int DFX_DELAY_MS = 10000;
37 int id = HiviewDFX::XCollie::GetInstance().SetTimer("ThermalLevelCallbackStub", DFX_DELAY_MS, nullptr, nullptr,
38 HiviewDFX::XCOLLIE_FLAG_NOOP);
39 int ret = ERR_OK;
40 switch (code) {
41 case static_cast<int>(IThermalLevelCallback::GET_THERMAL_LEVEL): {
42 ret = GetThermalLevelStub(data);
43 break;
44 }
45 default:
46 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47 break;
48 }
49 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
50 return ret;
51 }
52
GetThermalLevelStub(MessageParcel & data)53 int32_t ThermalLevelCallbackStub::GetThermalLevelStub(MessageParcel& data)
54 {
55 int32_t level;
56 THERMAL_READ_PARCEL_WITH_RET(data, Int32, level, E_READ_PARCEL_ERROR_THERMAL);
57 GetThermalLevel(static_cast<ThermalLevel>(level));
58 return ERR_OK;
59 }
60 } // namespace PowerMgr
61 } // namespace OHOS