• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
error(const std::string & msg)23 void error(const std::string& msg) {
24     LOG(ERROR) << msg;
25     std::cerr << msg << std::endl;
26 }
27 
main()28 int main() {
29     using ::android::hardware::hidl_vec;
30     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 
48     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 
58     // b/77934844: Avoid running static destructors.
59     _exit(1);
60 }
61