blob: 724e0eefae790e5bea823d6305eca8dd2d293e4c [file] [log] [blame]
Steven Moreland64a7afb2018-01-19 12:59:09 -08001/*
2 * Copyright (C) 2017 The Android Open Source 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#include <iostream>
18#include <string>
19
20#include <android-base/logging.h>
21#include <android/hardware/light/2.0/ILight.h>
22
23void error(const std::string& msg) {
24 LOG(ERROR) << msg;
25 std::cerr << msg << std::endl;
26}
27
28int main() {
Steven Moreland04f859a2018-03-16 10:27:18 -070029 using ::android::hardware::hidl_vec;
Steven Moreland64a7afb2018-01-19 12:59:09 -080030 using ::android::hardware::light::V2_0::Brightness;
31 using ::android::hardware::light::V2_0::Flash;
32 using ::android::hardware::light::V2_0::ILight;
33 using ::android::hardware::light::V2_0::LightState;
34 using ::android::hardware::light::V2_0::Status;
35 using ::android::hardware::light::V2_0::Type;
36 using ::android::sp;
37
38 sp<ILight> service = ILight::getService();
39 if (service == nullptr) {
40 error("Could not retrieve light service.");
41 return -1;
42 }
43
44 const static LightState off = {
45 .color = 0u, .flashMode = Flash::NONE, .brightnessMode = Brightness::USER,
46 };
47
Steven Moreland04f859a2018-03-16 10:27:18 -070048 service->getSupportedTypes([&](const hidl_vec<Type>& types) {
49 for (Type type : types) {
50 Status ret = service->setLight(type, off);
51 if (ret != Status::SUCCESS) {
52 error("Failed to shut off screen for type " +
53 std::to_string(static_cast<int>(type)));
54 }
55 }
56 });
57
Steven Moreland73ba34f2018-05-22 15:23:41 -070058 // b/77934844: Avoid running static destructors.
59 _exit(1);
Steven Moreland64a7afb2018-01-19 12:59:09 -080060}