Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The LineageOS 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 | |
| 17 | #ifdef LIVES_IN_SYSTEM |
| 18 | #define LOG_TAG "lineage.livedisplay@2.0-service.samsung-qcom" |
| 19 | #else |
| 20 | #define LOG_TAG "vendor.lineage.livedisplay@2.0-service.samsung-qcom" |
| 21 | #endif |
| 22 | |
| 23 | #include <android-base/logging.h> |
| 24 | #include <binder/ProcessState.h> |
| 25 | #include <hidl/HidlTransportSupport.h> |
| 26 | |
| 27 | #include "AdaptiveBacklight.h" |
| 28 | #include "DisplayColorCalibration.h" |
| 29 | #include "DisplayModes.h" |
| 30 | #include "ReadingEnhancement.h" |
| 31 | #include "SunlightEnhancement.h" |
| 32 | |
| 33 | using android::hardware::configureRpcThreadpool; |
| 34 | using android::hardware::joinRpcThreadpool; |
| 35 | using android::sp; |
| 36 | using android::status_t; |
| 37 | using android::OK; |
| 38 | |
| 39 | using vendor::lineage::livedisplay::V2_0::samsung::AdaptiveBacklight; |
| 40 | using vendor::lineage::livedisplay::V2_0::samsung::DisplayColorCalibration; |
| 41 | using vendor::lineage::livedisplay::V2_0::samsung::DisplayModes; |
| 42 | using vendor::lineage::livedisplay::V2_0::samsung::ReadingEnhancement; |
| 43 | using vendor::lineage::livedisplay::V2_0::samsung::SunlightEnhancement; |
| 44 | |
| 45 | int main() { |
| 46 | sp<AdaptiveBacklight> adaptiveBacklight; |
| 47 | sp<DisplayColorCalibration> displayColorCalibration; |
| 48 | sp<DisplayModes> displayModes; |
| 49 | sp<ReadingEnhancement> readingEnhancement; |
| 50 | sp<SunlightEnhancement> sunlightEnhancement; |
| 51 | status_t status; |
| 52 | |
| 53 | LOG(INFO) << "LiveDisplay HAL service is starting."; |
| 54 | |
| 55 | adaptiveBacklight = new AdaptiveBacklight(); |
| 56 | if (adaptiveBacklight == nullptr) { |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 57 | LOG(ERROR) |
| 58 | << "Can not create an instance of LiveDisplay HAL AdaptiveBacklight Iface, exiting."; |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 59 | goto shutdown; |
| 60 | } |
| 61 | |
| 62 | displayColorCalibration = new DisplayColorCalibration(); |
| 63 | if (displayColorCalibration == nullptr) { |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 64 | LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayColorCalibration " |
| 65 | "Iface, exiting."; |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 66 | goto shutdown; |
| 67 | } |
| 68 | |
| 69 | displayModes = new DisplayModes(); |
| 70 | if (displayModes == nullptr) { |
| 71 | LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayModes Iface, exiting."; |
| 72 | goto shutdown; |
| 73 | } |
| 74 | |
| 75 | readingEnhancement = new ReadingEnhancement(); |
| 76 | if (readingEnhancement == nullptr) { |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 77 | LOG(ERROR) |
| 78 | << "Can not create an instance of LiveDisplay HAL ReadingEnhancement Iface, exiting."; |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 79 | goto shutdown; |
| 80 | } |
| 81 | |
| 82 | sunlightEnhancement = new SunlightEnhancement(); |
| 83 | if (sunlightEnhancement == nullptr) { |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 84 | LOG(ERROR) |
| 85 | << "Can not create an instance of LiveDisplay HAL SunlightEnhancement Iface, exiting."; |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 86 | goto shutdown; |
| 87 | } |
| 88 | |
| 89 | configureRpcThreadpool(1, true /*callerWillJoin*/); |
| 90 | |
| 91 | if (adaptiveBacklight->isSupported()) { |
| 92 | status = adaptiveBacklight->registerAsService(); |
| 93 | if (status != OK) { |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 94 | LOG(ERROR) << "Could not register service for LiveDisplay HAL AdaptiveBacklight Iface (" |
| 95 | << status << ")"; |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 96 | goto shutdown; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (displayColorCalibration->isSupported()) { |
| 101 | status = displayColorCalibration->registerAsService(); |
| 102 | if (status != OK) { |
| 103 | LOG(ERROR) |
| 104 | << "Could not register service for LiveDisplay HAL DisplayColorCalibration Iface (" |
| 105 | << status << ")"; |
| 106 | goto shutdown; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (displayModes->isSupported()) { |
| 111 | status = displayModes->registerAsService(); |
| 112 | if (status != OK) { |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 113 | LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayModes Iface (" |
| 114 | << status << ")"; |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 115 | goto shutdown; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if (readingEnhancement->isSupported()) { |
| 120 | status = readingEnhancement->registerAsService(); |
| 121 | if (status != OK) { |
| 122 | LOG(ERROR) |
| 123 | << "Could not register service for LiveDisplay HAL ReadingEnhancement Iface (" |
| 124 | << status << ")"; |
| 125 | goto shutdown; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | if (sunlightEnhancement->isSupported()) { |
| 130 | status = sunlightEnhancement->registerAsService(); |
| 131 | if (status != OK) { |
| 132 | LOG(ERROR) |
| 133 | << "Could not register service for LiveDisplay HAL SunlightEnhancement Iface (" |
| 134 | << status << ")"; |
| 135 | goto shutdown; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | LOG(INFO) << "LiveDisplay HAL service is ready."; |
| 140 | joinRpcThreadpool(); |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 141 | // Should not pass this line |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 142 | |
| 143 | shutdown: |
| 144 | // In normal operation, we don't expect the thread pool to shutdown |
| 145 | LOG(ERROR) << "LiveDisplay HAL service is shutting down."; |
| 146 | return 1; |
| 147 | } |