1 /* 2 * Copyright 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 17 package com.android.server.input; 18 19 import android.sysprop.InputProperties; 20 21 import java.util.Optional; 22 23 /** 24 * A component of {@link InputManagerService} responsible for managing the input sysprop flags 25 * 26 * @hide 27 */ 28 @SuppressWarnings("OptionalUsedAsFieldOrParameterType") 29 public final class InputFeatureFlagProvider { 30 31 // To disable Keyboard backlight control via Framework, run: 32 // 'adb shell setprop persist.input.keyboard_backlight_control.enabled false' (requires restart) 33 private static final boolean KEYBOARD_BACKLIGHT_CONTROL_ENABLED = 34 InputProperties.enable_keyboard_backlight_control().orElse(true); 35 36 // To disable Framework controlled keyboard backlight animation run: 37 // adb shell setprop persist.input.keyboard.backlight_animation.enabled false (requires restart) 38 private static final boolean KEYBOARD_BACKLIGHT_ANIMATION_ENABLED = 39 InputProperties.enable_keyboard_backlight_animation().orElse(false); 40 41 // To disable Custom keyboard backlight levels support via IDC files run: 42 // adb shell setprop persist.input.keyboard.backlight_custom_levels.enabled false (requires 43 // restart) 44 private static final boolean KEYBOARD_BACKLIGHT_CUSTOM_LEVELS_ENABLED = 45 InputProperties.enable_keyboard_backlight_custom_levels().orElse(true); 46 47 // To disable als based ambient keyboard backlight control run: 48 // adb shell setprop persist.input.keyboard.ambient_backlight_control.enabled false (requires 49 // restart) 50 private static final boolean AMBIENT_KEYBOARD_BACKLIGHT_CONTROL_ENABLED = 51 InputProperties.enable_ambient_keyboard_backlight_control().orElse(true); 52 53 private static Optional<Boolean> sKeyboardBacklightControlOverride = Optional.empty(); 54 private static Optional<Boolean> sKeyboardBacklightAnimationOverride = Optional.empty(); 55 private static Optional<Boolean> sKeyboardBacklightCustomLevelsOverride = Optional.empty(); 56 private static Optional<Boolean> sAmbientKeyboardBacklightControlOverride = Optional.empty(); 57 isKeyboardBacklightControlEnabled()58 public static boolean isKeyboardBacklightControlEnabled() { 59 return sKeyboardBacklightControlOverride.orElse(KEYBOARD_BACKLIGHT_CONTROL_ENABLED); 60 } 61 isKeyboardBacklightAnimationEnabled()62 public static boolean isKeyboardBacklightAnimationEnabled() { 63 return sKeyboardBacklightAnimationOverride.orElse(KEYBOARD_BACKLIGHT_ANIMATION_ENABLED); 64 } 65 isKeyboardBacklightCustomLevelsEnabled()66 public static boolean isKeyboardBacklightCustomLevelsEnabled() { 67 return sKeyboardBacklightCustomLevelsOverride.orElse( 68 KEYBOARD_BACKLIGHT_CUSTOM_LEVELS_ENABLED); 69 } 70 isAmbientKeyboardBacklightControlEnabled()71 public static boolean isAmbientKeyboardBacklightControlEnabled() { 72 return sAmbientKeyboardBacklightControlOverride.orElse( 73 AMBIENT_KEYBOARD_BACKLIGHT_CONTROL_ENABLED); 74 } 75 setKeyboardBacklightControlEnabled(boolean enabled)76 public static void setKeyboardBacklightControlEnabled(boolean enabled) { 77 sKeyboardBacklightControlOverride = Optional.of(enabled); 78 } 79 setKeyboardBacklightAnimationEnabled(boolean enabled)80 public static void setKeyboardBacklightAnimationEnabled(boolean enabled) { 81 sKeyboardBacklightAnimationOverride = Optional.of(enabled); 82 } 83 setKeyboardBacklightCustomLevelsEnabled(boolean enabled)84 public static void setKeyboardBacklightCustomLevelsEnabled(boolean enabled) { 85 sKeyboardBacklightCustomLevelsOverride = Optional.of(enabled); 86 } 87 setAmbientKeyboardBacklightControlEnabled(boolean enabled)88 public static void setAmbientKeyboardBacklightControlEnabled(boolean enabled) { 89 sAmbientKeyboardBacklightControlOverride = Optional.of(enabled); 90 } 91 92 /** 93 * Clears all input feature flag overrides. 94 */ clearOverrides()95 public static void clearOverrides() { 96 sKeyboardBacklightControlOverride = Optional.empty(); 97 sKeyboardBacklightAnimationOverride = Optional.empty(); 98 sKeyboardBacklightCustomLevelsOverride = Optional.empty(); 99 sAmbientKeyboardBacklightControlOverride = Optional.empty(); 100 } 101 } 102