1 /*
2 * Copyright (c) 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 "thermal_action_callback_stub.h"
17 #include <message_parcel.h>
18
19 #include "constants.h"
20 #include "thermal_common.h"
21 #include "xcollie.h"
22
23 namespace OHOS {
24 namespace PowerMgr {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)25 int ThermalActionCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
26 MessageOption &option)
27 {
28 THERMAL_HILOGD(COMP_SVC,
29 "ThermalActionCallbackStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d", code, option.GetFlags());
30 std::u16string descripter = ThermalActionCallbackStub::GetDescriptor();
31 std::u16string remoteDescripter = data.ReadInterfaceToken();
32 if (descripter != remoteDescripter) {
33 THERMAL_HILOGE(COMP_SVC, "ThermalTempCallbackStub::OnRemoteRequest failed, \
34 descriptor is not matched!");
35 return E_GET_THERMAL_SERVICE_FAILED;
36 }
37 const int DFX_DELAY_MS = 10000;
38 int id = HiviewDFX::XCollie::GetInstance().SetTimer("ThermalActionCallbackStub", DFX_DELAY_MS, nullptr, nullptr,
39 HiviewDFX::XCOLLIE_FLAG_NOOP);
40 int ret = ERR_OK;
41 switch (code) {
42 case static_cast<int>(IThermalActionCallback::THERMAL_ACTION_CHANGD): {
43 ret = OnThermalActionChangedStub(data);
44 break;
45 }
46 default:
47 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 break;
49 }
50 HiviewDFX::XCollie::GetInstance().CancelTimer(id);
51 return ret;
52 }
53
OnThermalActionChangedStub(MessageParcel & data)54 int32_t ThermalActionCallbackStub::OnThermalActionChangedStub(MessageParcel& data)
55 {
56 std::map<std::string, float> actionMapCb;
57 uint32_t size = 0;
58 THERMAL_READ_PARCEL_WITH_RET(data, Uint32, size, E_READ_PARCEL_ERROR_THERMAL);
59 for (uint32_t i = 0; i < size; i++) {
60 std::string type;
61 float action = INVALID_ACTION_VALUE;
62 THERMAL_READ_PARCEL_WITH_RET(data, String, type, E_READ_PARCEL_ERROR_THERMAL);
63 THERMAL_READ_PARCEL_WITH_RET(data, Float, action, E_READ_PARCEL_ERROR_THERMAL);
64 actionMapCb[type] = action;
65 }
66 OnThermalActionChanged(actionMapCb);
67 return ERR_OK;
68 }
69 } // namespace PowerMgr
70 } // namespace OHOS
71