blob: 28d262ad91840c72f7d4744416f0a35e92905d35 [file] [log] [blame]
Wei Wang086a2b22018-10-22 13:54:33 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <android-base/logging.h>
17#include <hidl/HidlTransportSupport.h>
18#include "Thermal.h"
19
TeYuan Wangdcee68c2020-10-21 16:29:37 +080020constexpr std::string_view kThermalLogTag("pixel-thermal");
21
Wei Wang086a2b22018-10-22 13:54:33 -070022using ::android::OK;
23using ::android::status_t;
24
25// libhwbinder:
26using ::android::hardware::configureRpcThreadpool;
27using ::android::hardware::joinRpcThreadpool;
28
29// Generated HIDL files:
30using ::android::hardware::thermal::V2_0::IThermal;
31using ::android::hardware::thermal::V2_0::implementation::Thermal;
32
33static int shutdown() {
34 LOG(ERROR) << "Pixel Thermal HAL Service is shutting down.";
35 return 1;
36}
37
38int main(int /* argc */, char ** /* argv */) {
TeYuan Wangdcee68c2020-10-21 16:29:37 +080039 android::base::SetDefaultTag(kThermalLogTag.data());
Wei Wang086a2b22018-10-22 13:54:33 -070040 status_t status;
41 android::sp<IThermal> service = nullptr;
42
43 LOG(INFO) << "Pixel Thermal HAL Service 2.0 starting...";
44
45 service = new Thermal();
46 if (service == nullptr) {
47 LOG(ERROR) << "Error creating an instance of Thermal HAL. Exiting...";
48 return shutdown();
49 }
50
51 configureRpcThreadpool(1, true /* callerWillJoin */);
52
Wei Wang5ad0a752022-04-20 15:22:12 -070053 android::hardware::setMinSchedulerPolicy(service, SCHED_NORMAL, -20);
54
Wei Wang086a2b22018-10-22 13:54:33 -070055 status = service->registerAsService();
56 if (status != OK) {
57 LOG(ERROR) << "Could not register service for ThermalHAL (" << status << ")";
58 return shutdown();
59 }
60
61 LOG(INFO) << "Pixel Thermal HAL Service 2.0 started successfully.";
62 joinRpcThreadpool();
63 // We should not get past the joinRpcThreadpool().
64 return shutdown();
65}