blob: 2da37156390b6270945056a4b06720ce306bc66e [file] [log] [blame]
Paul Keith8d138032019-02-07 09:57:05 -06001/*
dianlujitao8a01e722020-06-25 12:05:03 +08002 * Copyright (C) 2019-2020 The LineageOS Project
Paul Keith8d138032019-02-07 09:57:05 -06003 *
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 Keith8d138032019-02-07 09:57:05 -060024#include <hidl/HidlTransportSupport.h>
dianlujitaob8ca32c2020-06-25 13:24:44 +080025#include <livedisplay/sysfs/AdaptiveBacklight.h>
dianlujitaob8ca32c2020-06-25 13:24:44 +080026#include <livedisplay/sysfs/DisplayColorCalibration.h>
dianlujitaoce63fc92020-07-12 23:21:16 +080027#include <livedisplay/sysfs/SimpleMode.h>
dianlujitaob8ca32c2020-06-25 13:24:44 +080028#include <livedisplay/sysfs/SunlightEnhancement.h>
Paul Keith8d138032019-02-07 09:57:05 -060029
dianlujitao8a01e722020-06-25 12:05:03 +080030using ::android::OK;
31using ::android::sp;
32using ::android::status_t;
33using ::android::hardware::configureRpcThreadpool;
34using ::android::hardware::joinRpcThreadpool;
Paul Keith8d138032019-02-07 09:57:05 -060035
Paul Keith8d138032019-02-07 09:57:05 -060036using ::vendor::lineage::livedisplay::V2_0::sysfs::AdaptiveBacklight;
37using ::vendor::lineage::livedisplay::V2_0::sysfs::AutoContrast;
38using ::vendor::lineage::livedisplay::V2_0::sysfs::ColorEnhancement;
39using ::vendor::lineage::livedisplay::V2_0::sysfs::DisplayColorCalibration;
40using ::vendor::lineage::livedisplay::V2_0::sysfs::ReadingEnhancement;
41using ::vendor::lineage::livedisplay::V2_0::sysfs::SunlightEnhancement;
42
dianlujitao8a01e722020-06-25 12:05:03 +080043status_t RegisterAsServices() {
Paul Keith8d138032019-02-07 09:57:05 -060044 status_t status = OK;
45
dianlujitao8a01e722020-06-25 12:05:03 +080046 sp<AdaptiveBacklight> ab = new AdaptiveBacklight();
Paul Keith8d138032019-02-07 09:57:05 -060047 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 << ")";
dianlujitao8a01e722020-06-25 12:05:03 +080052 return status;
Paul Keith8d138032019-02-07 09:57:05 -060053 }
54 }
55
dianlujitao22462db2020-06-25 14:18:20 +080056 if (AutoContrast::isSupported()) {
57 sp<AutoContrast> ac = new AutoContrast();
Paul Keith8d138032019-02-07 09:57:05 -060058 status = ac->registerAsService();
59 if (status != OK) {
60 LOG(ERROR) << "Could not register service for LiveDisplay HAL AutoContrast Iface ("
61 << status << ")";
dianlujitao8a01e722020-06-25 12:05:03 +080062 return status;
Paul Keith8d138032019-02-07 09:57:05 -060063 }
64 }
65
dianlujitao22462db2020-06-25 14:18:20 +080066 if (ColorEnhancement::isSupported()) {
67 sp<ColorEnhancement> ce = new ColorEnhancement();
Paul Keith8d138032019-02-07 09:57:05 -060068 status = ce->registerAsService();
69 if (status != OK) {
70 LOG(ERROR) << "Could not register service for LiveDisplay HAL ColorEnhancement Iface ("
71 << status << ")";
dianlujitao8a01e722020-06-25 12:05:03 +080072 return status;
Paul Keith8d138032019-02-07 09:57:05 -060073 }
74 }
75
dianlujitao22462db2020-06-25 14:18:20 +080076 if (DisplayColorCalibration::isSupported()) {
77 sp<DisplayColorCalibration> dcc = new DisplayColorCalibration();
Paul Keith8d138032019-02-07 09:57:05 -060078 status = dcc->registerAsService();
79 if (status != OK) {
80 LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayColorCalibration"
81 << " Iface (" << status << ")";
dianlujitao8a01e722020-06-25 12:05:03 +080082 return status;
Paul Keith8d138032019-02-07 09:57:05 -060083 }
84 }
85
dianlujitao22462db2020-06-25 14:18:20 +080086 if (ReadingEnhancement::isSupported()) {
87 sp<ReadingEnhancement> re = new ReadingEnhancement();
Paul Keith8d138032019-02-07 09:57:05 -060088 status = re->registerAsService();
89 if (status != OK) {
90 LOG(ERROR) << "Could not register service for LiveDisplay HAL ReadingEnhancement Iface"
91 << " (" << status << ")";
dianlujitao8a01e722020-06-25 12:05:03 +080092 return status;
Paul Keith8d138032019-02-07 09:57:05 -060093 }
94 }
95
dianlujitao8a01e722020-06-25 12:05:03 +080096 sp<SunlightEnhancement> se = new SunlightEnhancement();
Paul Keith8d138032019-02-07 09:57:05 -060097 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 << ")";
dianlujitao8a01e722020-06-25 12:05:03 +0800102 return status;
Paul Keith8d138032019-02-07 09:57:05 -0600103 }
104 }
105
dianlujitao8a01e722020-06-25 12:05:03 +0800106 return OK;
107}
Paul Keith8d138032019-02-07 09:57:05 -0600108
dianlujitao8a01e722020-06-25 12:05:03 +0800109int 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 Keith8d138032019-02-07 09:57:05 -0600121 // 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}