Steven Moreland | 64a7afb | 2018-01-19 12:59:09 -0800 | [diff] [blame] | 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 | |
| 23 | void error(const std::string& msg) { |
| 24 | LOG(ERROR) << msg; |
| 25 | std::cerr << msg << std::endl; |
| 26 | } |
| 27 | |
Dmitry Shmidt | 34ed387 | 2019-10-07 12:43:36 -0700 | [diff] [blame] | 28 | int main(int argc, char* argv[]) { |
Steven Moreland | b944d69 | 2018-03-16 10:27:18 -0700 | [diff] [blame] | 29 | using ::android::hardware::hidl_vec; |
Steven Moreland | 64a7afb | 2018-01-19 12:59:09 -0800 | [diff] [blame] | 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 | |
Dmitry Shmidt | 34ed387 | 2019-10-07 12:43:36 -0700 | [diff] [blame] | 44 | static LightState off = { |
| 45 | .color = 0u, |
| 46 | .flashMode = Flash::NONE, |
| 47 | .brightnessMode = Brightness::USER, |
Steven Moreland | 64a7afb | 2018-01-19 12:59:09 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
Dmitry Shmidt | 34ed387 | 2019-10-07 12:43:36 -0700 | [diff] [blame] | 50 | 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 Moreland | b944d69 | 2018-03-16 10:27:18 -0700 | [diff] [blame] | 67 | 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 Moreland | 64a7afb | 2018-01-19 12:59:09 -0800 | [diff] [blame] | 77 | return 0; |
| 78 | } |