Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 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 | #include "Thermal.h" |
| 19 | |
TeYuan Wang | dcee68c | 2020-10-21 16:29:37 +0800 | [diff] [blame] | 20 | constexpr std::string_view kThermalLogTag("pixel-thermal"); |
| 21 | |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 22 | using ::android::OK; |
| 23 | using ::android::status_t; |
| 24 | |
| 25 | // libhwbinder: |
| 26 | using ::android::hardware::configureRpcThreadpool; |
| 27 | using ::android::hardware::joinRpcThreadpool; |
| 28 | |
| 29 | // Generated HIDL files: |
| 30 | using ::android::hardware::thermal::V2_0::IThermal; |
| 31 | using ::android::hardware::thermal::V2_0::implementation::Thermal; |
| 32 | |
| 33 | static int shutdown() { |
| 34 | LOG(ERROR) << "Pixel Thermal HAL Service is shutting down."; |
| 35 | return 1; |
| 36 | } |
| 37 | |
| 38 | int main(int /* argc */, char ** /* argv */) { |
TeYuan Wang | dcee68c | 2020-10-21 16:29:37 +0800 | [diff] [blame] | 39 | android::base::SetDefaultTag(kThermalLogTag.data()); |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 40 | 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 Wang | 5ad0a75 | 2022-04-20 15:22:12 -0700 | [diff] [blame] | 53 | android::hardware::setMinSchedulerPolicy(service, SCHED_NORMAL, -20); |
| 54 | |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 55 | 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 | } |