• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
19 #include "Thermal.h"
20 
21 constexpr std::string_view kThermalLogTag("pixel-thermal");
22 
23 using ::android::OK;
24 using ::android::status_t;
25 
26 // libhwbinder:
27 using ::android::hardware::configureRpcThreadpool;
28 using ::android::hardware::joinRpcThreadpool;
29 
30 // Generated HIDL files:
31 using ::android::hardware::thermal::V2_0::IThermal;
32 using ::android::hardware::thermal::V2_0::implementation::Thermal;
33 
shutdown()34 static int shutdown() {
35     LOG(ERROR) << "Pixel Thermal HAL Service is shutting down.";
36     return 1;
37 }
38 
main(int,char **)39 int main(int /* argc */, char ** /* argv */) {
40     android::base::SetDefaultTag(kThermalLogTag.data());
41     status_t status;
42     android::sp<IThermal> service = nullptr;
43 
44     LOG(INFO) << "Pixel Thermal HAL Service 2.0 starting...";
45 
46     service = new Thermal();
47     if (service == nullptr) {
48         LOG(ERROR) << "Error creating an instance of Thermal HAL. Exiting...";
49         return shutdown();
50     }
51 
52     configureRpcThreadpool(1, true /* callerWillJoin */);
53 
54     android::hardware::setMinSchedulerPolicy(service, SCHED_NORMAL, -20);
55 
56     status = service->registerAsService();
57     if (status != OK) {
58         LOG(ERROR) << "Could not register service for ThermalHAL (" << status << ")";
59         return shutdown();
60     }
61 
62     LOG(INFO) << "Pixel Thermal HAL Service 2.0 started successfully.";
63     joinRpcThreadpool();
64     // We should not get past the joinRpcThreadpool().
65     return shutdown();
66 }
67