blob: b83413246bca4ae2778709443c4c18090f5f6874 [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
Dmitry Shmidt34ed3872019-10-07 12:43:36 -070028int main(int argc, char* argv[]) {
Steven Morelandb944d692018-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
Dmitry Shmidt34ed3872019-10-07 12:43:36 -070044 static LightState off = {
45 .color = 0u,
46 .flashMode = Flash::NONE,
47 .brightnessMode = Brightness::USER,
Steven Moreland64a7afb2018-01-19 12:59:09 -080048 };
49
Dmitry Shmidt34ed3872019-10-07 12:43:36 -070050 if (argc > 2) {
51 error("Usage: blank_screen [color]");
52 return -1;
53 }
54
55 if (argc > 1) {
56 char* col_ptr;
57 unsigned int col_new;
58
59 col_new = strtoul(argv[1], &col_ptr, 0);
60 if (*col_ptr != '\0') {
61 error("Failed to convert " + std::string(argv[1]) + " to number");
62 return -1;
63 }
64 off.color = col_new;
65 }
66
Steven Morelandb944d692018-03-16 10:27:18 -070067 service->getSupportedTypes([&](const hidl_vec<Type>& types) {
68 for (Type type : types) {
69 Status ret = service->setLight(type, off);
70 if (ret != Status::SUCCESS) {
71 error("Failed to shut off screen for type " +
72 std::to_string(static_cast<int>(type)));
73 }
74 }
75 });
76
Steven Moreland64a7afb2018-01-19 12:59:09 -080077 return 0;
78}