blob: 1f9cb9ce4526ff52cfeb94dffe6568c2543310eb [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() {
29 using ::android::hardware::light::V2_0::Brightness;
30 using ::android::hardware::light::V2_0::Flash;
31 using ::android::hardware::light::V2_0::ILight;
32 using ::android::hardware::light::V2_0::LightState;
33 using ::android::hardware::light::V2_0::Status;
34 using ::android::hardware::light::V2_0::Type;
35 using ::android::sp;
36
37 sp<ILight> service = ILight::getService();
38 if (service == nullptr) {
39 error("Could not retrieve light service.");
40 return -1;
41 }
42
43 const static LightState off = {
44 .color = 0u, .flashMode = Flash::NONE, .brightnessMode = Brightness::USER,
45 };
46
47 Status ret = service->setLight(Type::BACKLIGHT, off).withDefault(Status::UNKNOWN);
48 if (ret != Status::SUCCESS) {
49 error("Failed to shut off screen");
50 }
51 return 0;
52}