blob: b59eab1c83a2edb22cc9eff3869e2a22a54ffcd5 [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) {
57 LOG(ERROR) << "Can not create an instance of LiveDisplay HAL AdaptiveBacklight Iface, exiting.";
58 goto shutdown;
59 }
60
61 displayColorCalibration = new DisplayColorCalibration();
62 if (displayColorCalibration == nullptr) {
63 LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayColorCalibration Iface, exiting.";
64 goto shutdown;
65 }
66
67 displayModes = new DisplayModes();
68 if (displayModes == nullptr) {
69 LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayModes Iface, exiting.";
70 goto shutdown;
71 }
72
73 readingEnhancement = new ReadingEnhancement();
74 if (readingEnhancement == nullptr) {
75 LOG(ERROR) << "Can not create an instance of LiveDisplay HAL ReadingEnhancement Iface, exiting.";
76 goto shutdown;
77 }
78
79 sunlightEnhancement = new SunlightEnhancement();
80 if (sunlightEnhancement == nullptr) {
81 LOG(ERROR) << "Can not create an instance of LiveDisplay HAL SunlightEnhancement Iface, exiting.";
82 goto shutdown;
83 }
84
85 configureRpcThreadpool(1, true /*callerWillJoin*/);
86
87 if (adaptiveBacklight->isSupported()) {
88 status = adaptiveBacklight->registerAsService();
89 if (status != OK) {
90 LOG(ERROR)
91 << "Could not register service for LiveDisplay HAL AdaptiveBacklight Iface ("
92 << status << ")";
93 goto shutdown;
94 }
95 }
96
97 if (displayColorCalibration->isSupported()) {
98 status = displayColorCalibration->registerAsService();
99 if (status != OK) {
100 LOG(ERROR)
101 << "Could not register service for LiveDisplay HAL DisplayColorCalibration Iface ("
102 << status << ")";
103 goto shutdown;
104 }
105 }
106
107 if (displayModes->isSupported()) {
108 status = displayModes->registerAsService();
109 if (status != OK) {
110 LOG(ERROR)
111 << "Could not register service for LiveDisplay HAL DisplayModes Iface ("
112 << status << ")";
113 goto shutdown;
114 }
115 }
116
117 if (readingEnhancement->isSupported()) {
118 status = readingEnhancement->registerAsService();
119 if (status != OK) {
120 LOG(ERROR)
121 << "Could not register service for LiveDisplay HAL ReadingEnhancement Iface ("
122 << status << ")";
123 goto shutdown;
124 }
125 }
126
127 if (sunlightEnhancement->isSupported()) {
128 status = sunlightEnhancement->registerAsService();
129 if (status != OK) {
130 LOG(ERROR)
131 << "Could not register service for LiveDisplay HAL SunlightEnhancement Iface ("
132 << status << ")";
133 goto shutdown;
134 }
135 }
136
137 LOG(INFO) << "LiveDisplay HAL service is ready.";
138 joinRpcThreadpool();
139 // Should not pass this line
140
141shutdown:
142 // In normal operation, we don't expect the thread pool to shutdown
143 LOG(ERROR) << "LiveDisplay HAL service is shutting down.";
144 return 1;
145}