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