forked from zuk-devs/android_device_zuk_msm8996-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.cpp
256 lines (220 loc) · 9.7 KB
/
service.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
* Copyright (C) 2018 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "[email protected]_8996"
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include <utils/Errors.h>
#include "Light.h"
// libhwbinder:
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
// Generated HIDL files
using android::hardware::light::V2_0::ILight;
using android::hardware::light::V2_0::implementation::Light;
const static std::string kLcdBacklightPath = "/sys/class/leds/lcd-backlight/brightness";
const static std::string kLcdMaxBacklightPath = "/sys/class/leds/lcd-backlight/max_brightness";
const static std::string kRedLedPath = "/sys/class/leds/red/brightness";
const static std::string kGreenLedPath = "/sys/class/leds/green/brightness";
const static std::string kBlueLedPath = "/sys/class/leds/blue/brightness";
const static std::string kRedDutyPctsPath = "/sys/class/leds/red/duty_pcts";
const static std::string kGreenDutyPctsPath = "/sys/class/leds/green/duty_pcts";
const static std::string kBlueDutyPctsPath = "/sys/class/leds/blue/duty_pcts";
const static std::string kRedStartIdxPath = "/sys/class/leds/red/start_idx";
const static std::string kGreenStartIdxPath = "/sys/class/leds/green/start_idx";
const static std::string kBlueStartIdxPath = "/sys/class/leds/blue/start_idx";
const static std::string kRedPauseLoPath = "/sys/class/leds/red/pause_lo";
const static std::string kGreenPauseLoPath = "/sys/class/leds/green/pause_lo";
const static std::string kBluePauseLoPath = "/sys/class/leds/blue/pause_lo";
const static std::string kRedPauseHiPath = "/sys/class/leds/red/pause_hi";
const static std::string kGreenPauseHiPath = "/sys/class/leds/green/pause_hi";
const static std::string kBluePauseHiPath = "/sys/class/leds/blue/pause_hi";
const static std::string kRedRampStepMsPath = "/sys/class/leds/red/ramp_step_ms";
const static std::string kGreenRampStepMsPath = "/sys/class/leds/green/ramp_step_ms";
const static std::string kBlueRampStepMsPath = "/sys/class/leds/blue/ramp_step_ms";
const static std::string kRedBlinkPath = "/sys/class/leds/red/blink";
const static std::string kGreenBlinkPath = "/sys/class/leds/green/blink";
const static std::string kBlueBlinkPath = "/sys/class/leds/blue/blink";
const static std::string kRgbBlinkPath = "/sys/class/leds/rgb/rgb_blink";
int main() {
uint32_t lcdMaxBrightness = 255;
std::ofstream lcdBacklight(kLcdBacklightPath);
if (!lcdBacklight) {
LOG(ERROR) << "Failed to open " << kLcdBacklightPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ifstream lcdMaxBacklight(kLcdMaxBacklightPath);
if (!lcdMaxBacklight) {
LOG(ERROR) << "Failed to open " << kLcdMaxBacklightPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
} else {
lcdMaxBacklight >> lcdMaxBrightness;
}
std::ofstream redLed(kRedLedPath);
if (!redLed) {
LOG(ERROR) << "Failed to open " << kRedLedPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream greenLed(kGreenLedPath);
if (!greenLed) {
LOG(ERROR) << "Failed to open " << kGreenLedPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream blueLed(kBlueLedPath);
if (!blueLed) {
LOG(ERROR) << "Failed to open " << kBlueLedPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream redDutyPcts(kRedDutyPctsPath);
if (!redDutyPcts) {
LOG(ERROR) << "Failed to open " << kRedDutyPctsPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream greenDutyPcts(kGreenDutyPctsPath);
if (!greenDutyPcts) {
LOG(ERROR) << "Failed to open " << kGreenDutyPctsPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream blueDutyPcts(kBlueDutyPctsPath);
if (!blueDutyPcts) {
LOG(ERROR) << "Failed to open " << kBlueDutyPctsPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream redStartIdx(kRedStartIdxPath);
if (!redStartIdx) {
LOG(ERROR) << "Failed to open " << kRedStartIdxPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream greenStartIdx(kGreenStartIdxPath);
if (!greenStartIdx) {
LOG(ERROR) << "Failed to open " << kGreenStartIdxPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream blueStartIdx(kBlueStartIdxPath);
if (!blueStartIdx) {
LOG(ERROR) << "Failed to open " << kBlueStartIdxPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream redPauseLo(kRedPauseLoPath);
if (!redPauseLo) {
LOG(ERROR) << "Failed to open " << kRedPauseLoPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream greenPauseLo(kGreenPauseLoPath);
if (!greenPauseLo) {
LOG(ERROR) << "Failed to open " << kGreenPauseLoPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream bluePauseLo(kBluePauseLoPath);
if (!bluePauseLo) {
LOG(ERROR) << "Failed to open " << kBluePauseLoPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream redPauseHi(kRedPauseHiPath);
if (!redPauseHi) {
LOG(ERROR) << "Failed to open " << kRedPauseHiPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream greenPauseHi(kGreenPauseHiPath);
if (!greenPauseHi) {
LOG(ERROR) << "Failed to open " << kGreenPauseHiPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream bluePauseHi(kBluePauseHiPath);
if (!bluePauseHi) {
LOG(ERROR) << "Failed to open " << kBluePauseHiPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream redRampStepMs(kRedRampStepMsPath);
if (!redRampStepMs) {
LOG(ERROR) << "Failed to open " << kRedRampStepMsPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream greenRampStepMs(kGreenRampStepMsPath);
if (!greenRampStepMs) {
LOG(ERROR) << "Failed to open " << kGreenRampStepMsPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream blueRampStepMs(kBlueRampStepMsPath);
if (!blueRampStepMs) {
LOG(ERROR) << "Failed to open " << kBlueRampStepMsPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream redBlink(kRedBlinkPath);
if (!redBlink) {
LOG(ERROR) << "Failed to open " << kRedBlinkPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream greenBlink(kGreenBlinkPath);
if (!greenBlink) {
LOG(ERROR) << "Failed to open " << kGreenBlinkPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream blueBlink(kBlueBlinkPath);
if (!blueBlink) {
LOG(ERROR) << "Failed to open " << kBlueBlinkPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
std::ofstream rgbBlink(kRgbBlinkPath);
if (!rgbBlink) {
LOG(ERROR) << "Failed to open " << kRgbBlinkPath << ", error=" << errno
<< " (" << strerror(errno) << ")";
return -errno;
}
android::sp<ILight> service = new Light(
{std::move(lcdBacklight), lcdMaxBrightness},
std::move(redLed), std::move(greenLed), std::move(blueLed),
std::move(redDutyPcts), std::move(greenDutyPcts), std::move(blueDutyPcts),
std::move(redStartIdx), std::move(greenStartIdx), std::move(blueStartIdx),
std::move(redPauseLo), std::move(greenPauseLo), std::move(bluePauseLo),
std::move(redPauseHi), std::move(greenPauseHi), std::move(bluePauseHi),
std::move(redRampStepMs), std::move(greenRampStepMs), std::move(blueRampStepMs),
std::move(redBlink), std::move(greenBlink), std::move(blueBlink),
std::move(rgbBlink));
configureRpcThreadpool(1, true);
android::status_t status = service->registerAsService();
if (status != android::OK) {
LOG(ERROR) << "Cannot register Light HAL service";
return 1;
}
LOG(INFO) << "Light HAL Ready.";
joinRpcThreadpool();
// Under normal cases, execution will not reach this line.
LOG(ERROR) << "Light HAL failed to join thread pool.";
return 1;
}