blob: 1e97aee0dbe458df056bfd5ecdb014675a7a4b47 [file] [log] [blame]
Jan Altensen4e47a0b2019-01-20 02:40:07 +01001/*
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
33using android::hardware::configureRpcThreadpool;
34using android::hardware::joinRpcThreadpool;
35using android::sp;
36using android::status_t;
37using android::OK;
38
39using vendor::lineage::livedisplay::V2_0::samsung::AdaptiveBacklight;
40using vendor::lineage::livedisplay::V2_0::samsung::DisplayColorCalibration;
41using vendor::lineage::livedisplay::V2_0::samsung::DisplayModes;
42using vendor::lineage::livedisplay::V2_0::samsung::ReadingEnhancement;
43using vendor::lineage::livedisplay::V2_0::samsung::SunlightEnhancement;
44
45int 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 Altensen0003f592019-07-20 01:01:03 +020057 LOG(ERROR)
58 << "Can not create an instance of LiveDisplay HAL AdaptiveBacklight Iface, exiting.";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010059 goto shutdown;
60 }
61
62 displayColorCalibration = new DisplayColorCalibration();
63 if (displayColorCalibration == nullptr) {
Jan Altensen0003f592019-07-20 01:01:03 +020064 LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayColorCalibration "
65 "Iface, exiting.";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010066 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 Altensen0003f592019-07-20 01:01:03 +020077 LOG(ERROR)
78 << "Can not create an instance of LiveDisplay HAL ReadingEnhancement Iface, exiting.";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010079 goto shutdown;
80 }
81
82 sunlightEnhancement = new SunlightEnhancement();
83 if (sunlightEnhancement == nullptr) {
Jan Altensen0003f592019-07-20 01:01:03 +020084 LOG(ERROR)
85 << "Can not create an instance of LiveDisplay HAL SunlightEnhancement Iface, exiting.";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010086 goto shutdown;
87 }
88
89 configureRpcThreadpool(1, true /*callerWillJoin*/);
90
91 if (adaptiveBacklight->isSupported()) {
92 status = adaptiveBacklight->registerAsService();
93 if (status != OK) {
Jan Altensen0003f592019-07-20 01:01:03 +020094 LOG(ERROR) << "Could not register service for LiveDisplay HAL AdaptiveBacklight Iface ("
95 << status << ")";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010096 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 Altensen0003f592019-07-20 01:01:03 +0200113 LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayModes Iface ("
114 << status << ")";
Jan Altensen4e47a0b2019-01-20 02:40:07 +0100115 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 Altensen0003f592019-07-20 01:01:03 +0200141// Should not pass this line
Jan Altensen4e47a0b2019-01-20 02:40:07 +0100142
143shutdown:
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}