platform_hardware_interfaces/light/utils/main.cpp
Steven Moreland b944d69508 blank_screen: shut off all lights
This is used to make the phone appear off by init
during late boot (e.x. fsck for disk health), so
it should shut off all lights (not just the screen).

Bug: 74976325
Test: blank_screen
Change-Id: I790cc3dd856c2c2095fa3cf82519fd30834304ca
Merged-In: I790cc3dd856c2c2095fa3cf82519fd30834304ca
2018-03-16 13:04:53 -07:00

59 lines
1.8 KiB
C++

/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include <string>
#include <android-base/logging.h>
#include <android/hardware/light/2.0/ILight.h>
void error(const std::string& msg) {
LOG(ERROR) << msg;
std::cerr << msg << std::endl;
}
int main() {
using ::android::hardware::hidl_vec;
using ::android::hardware::light::V2_0::Brightness;
using ::android::hardware::light::V2_0::Flash;
using ::android::hardware::light::V2_0::ILight;
using ::android::hardware::light::V2_0::LightState;
using ::android::hardware::light::V2_0::Status;
using ::android::hardware::light::V2_0::Type;
using ::android::sp;
sp<ILight> service = ILight::getService();
if (service == nullptr) {
error("Could not retrieve light service.");
return -1;
}
const static LightState off = {
.color = 0u, .flashMode = Flash::NONE, .brightnessMode = Brightness::USER,
};
service->getSupportedTypes([&](const hidl_vec<Type>& types) {
for (Type type : types) {
Status ret = service->setLight(type, off);
if (ret != Status::SUCCESS) {
error("Failed to shut off screen for type " +
std::to_string(static_cast<int>(type)));
}
}
});
return 0;
}