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_proxy.h"
17 #include "thermal_common.h"
18 #include "thermal_level_callback_ipc_interface_code.h"
19 #include <ipc_types.h>
20 #include <message_parcel.h>
21
22 namespace OHOS {
23 namespace PowerMgr {
GetThermalLevel(ThermalLevel level)24 bool ThermalLevelCallbackProxy::GetThermalLevel(ThermalLevel level)
25 {
26 sptr<IRemoteObject> remote = Remote();
27 THERMAL_RETURN_IF_WITH_RET((remote == nullptr), false);
28
29 MessageParcel data;
30 MessageParcel reply;
31 MessageOption option;
32
33 if (!data.WriteInterfaceToken(ThermalLevelCallbackProxy::GetDescriptor())) {
34 THERMAL_HILOGE(COMP_FWK, "ThermalLevelCallbackProxy::GetThermalLevel write descriptor failed!");
35 return false;
36 }
37
38 THERMAL_WRITE_PARCEL_WITH_RET(data, Int32, static_cast<int32_t>(level), false);
39
40 int ret = remote->SendRequest(
41 static_cast<int>(PowerMgr::ThermalLevelCallbackInterfaceCode::GET_THERMAL_LEVEL), data, reply, option);
42 if (ret != ERR_OK) {
43 THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret);
44 return false;
45 }
46 return true;
47 }
48 } // namespace PowerMgr
49 } // namespace OHOS
50