blob: 60e98d72bc1670097a9ac50319a8ec121e8a520d [file] [log] [blame]
Jesus Sanchez-Palencia531b5ba2023-06-16 00:13:04 +00001/*
2 * Copyright (C) 2023 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//! This module implements the ILights AIDL interface.
17
18use log::info;
19
20use android_hardware_light::aidl::android::hardware::light::{
21 HwLight::HwLight, HwLightState::HwLightState, ILights::ILights, LightType::LightType,
22};
23
24use binder::{ExceptionCode, Interface, Status};
25
26/// Defined so we can implement the ILights AIDL interface.
27pub struct LightsService;
28
29impl Interface for LightsService {}
30
31const NUM_DEFAULT_LIGHTS: i32 = 3;
32
33impl ILights for LightsService {
34 fn setLightState(&self, id: i32, state: &HwLightState) -> binder::Result<()> {
35 info!("Lights setting state for id={} to color {:x}", id, state.color);
36 if id <= 0 || id > NUM_DEFAULT_LIGHTS {
37 return Err(Status::new_exception(ExceptionCode::UNSUPPORTED_OPERATION, None));
38 }
39
40 Ok(())
41 }
42
43 fn getLights(&self) -> binder::Result<Vec<HwLight>> {
44 let mut lights: Vec<HwLight> = Vec::with_capacity(NUM_DEFAULT_LIGHTS.try_into().unwrap());
45
46 for i in 1..=NUM_DEFAULT_LIGHTS {
47 let light = HwLight { id: i, ordinal: i, r#type: LightType::BACKLIGHT };
48
49 lights.push(light);
50 }
51
52 info!("Lights reporting supported lights");
53 Ok(lights)
54 }
55}