Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 1 | /* |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 2 | * Copyright (C) 2019-2020 The LineageOS Project |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 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-sysfs" |
| 19 | #else |
| 20 | #define LOG_TAG "vendor.lineage.livedisplay@2.0-service-sysfs" |
| 21 | #endif |
| 22 | |
| 23 | #include <android-base/logging.h> |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 24 | #include <hidl/HidlTransportSupport.h> |
dianlujitao | b8ca32c | 2020-06-25 13:24:44 +0800 | [diff] [blame] | 25 | #include <livedisplay/sysfs/AdaptiveBacklight.h> |
dianlujitao | b8ca32c | 2020-06-25 13:24:44 +0800 | [diff] [blame] | 26 | #include <livedisplay/sysfs/DisplayColorCalibration.h> |
dianlujitao | ce63fc9 | 2020-07-12 23:21:16 +0800 | [diff] [blame] | 27 | #include <livedisplay/sysfs/SimpleMode.h> |
dianlujitao | b8ca32c | 2020-06-25 13:24:44 +0800 | [diff] [blame] | 28 | #include <livedisplay/sysfs/SunlightEnhancement.h> |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 29 | |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 30 | using ::android::OK; |
| 31 | using ::android::sp; |
| 32 | using ::android::status_t; |
| 33 | using ::android::hardware::configureRpcThreadpool; |
| 34 | using ::android::hardware::joinRpcThreadpool; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 35 | |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 36 | using ::vendor::lineage::livedisplay::V2_0::sysfs::AdaptiveBacklight; |
| 37 | using ::vendor::lineage::livedisplay::V2_0::sysfs::AutoContrast; |
| 38 | using ::vendor::lineage::livedisplay::V2_0::sysfs::ColorEnhancement; |
| 39 | using ::vendor::lineage::livedisplay::V2_0::sysfs::DisplayColorCalibration; |
| 40 | using ::vendor::lineage::livedisplay::V2_0::sysfs::ReadingEnhancement; |
| 41 | using ::vendor::lineage::livedisplay::V2_0::sysfs::SunlightEnhancement; |
| 42 | |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 43 | status_t RegisterAsServices() { |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 44 | status_t status = OK; |
| 45 | |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 46 | sp<AdaptiveBacklight> ab = new AdaptiveBacklight(); |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 47 | if (ab->isSupported()) { |
| 48 | status = ab->registerAsService(); |
| 49 | if (status != OK) { |
| 50 | LOG(ERROR) << "Could not register service for LiveDisplay HAL AdaptiveBacklight Iface (" |
| 51 | << status << ")"; |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 52 | return status; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 56 | if (AutoContrast::isSupported()) { |
| 57 | sp<AutoContrast> ac = new AutoContrast(); |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 58 | status = ac->registerAsService(); |
| 59 | if (status != OK) { |
| 60 | LOG(ERROR) << "Could not register service for LiveDisplay HAL AutoContrast Iface (" |
| 61 | << status << ")"; |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 62 | return status; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 66 | if (ColorEnhancement::isSupported()) { |
| 67 | sp<ColorEnhancement> ce = new ColorEnhancement(); |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 68 | status = ce->registerAsService(); |
| 69 | if (status != OK) { |
| 70 | LOG(ERROR) << "Could not register service for LiveDisplay HAL ColorEnhancement Iface (" |
| 71 | << status << ")"; |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 72 | return status; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 76 | if (DisplayColorCalibration::isSupported()) { |
| 77 | sp<DisplayColorCalibration> dcc = new DisplayColorCalibration(); |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 78 | status = dcc->registerAsService(); |
| 79 | if (status != OK) { |
| 80 | LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayColorCalibration" |
| 81 | << " Iface (" << status << ")"; |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 82 | return status; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 86 | if (ReadingEnhancement::isSupported()) { |
| 87 | sp<ReadingEnhancement> re = new ReadingEnhancement(); |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 88 | status = re->registerAsService(); |
| 89 | if (status != OK) { |
| 90 | LOG(ERROR) << "Could not register service for LiveDisplay HAL ReadingEnhancement Iface" |
| 91 | << " (" << status << ")"; |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 92 | return status; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 96 | sp<SunlightEnhancement> se = new SunlightEnhancement(); |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 97 | if (se->isSupported()) { |
| 98 | status = se->registerAsService(); |
| 99 | if (status != OK) { |
| 100 | LOG(ERROR) << "Could not register service for LiveDisplay HAL SunlightEnhancement Iface" |
| 101 | << " (" << status << ")"; |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 102 | return status; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 106 | return OK; |
| 107 | } |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 108 | |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 109 | int main() { |
| 110 | LOG(DEBUG) << "LiveDisplay HAL service is starting."; |
| 111 | |
| 112 | configureRpcThreadpool(1, true /*callerWillJoin*/); |
| 113 | |
| 114 | if (RegisterAsServices() == OK) { |
| 115 | LOG(DEBUG) << "LiveDisplay HAL service is ready."; |
| 116 | joinRpcThreadpool(); |
| 117 | } else { |
| 118 | LOG(ERROR) << "Could not register service for LiveDisplay HAL"; |
| 119 | } |
| 120 | |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 121 | // In normal operation, we don't expect the thread pool to shutdown |
| 122 | LOG(ERROR) << "LiveDisplay HAL service is shutting down."; |
| 123 | return 1; |
| 124 | } |