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