Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92e3fd38 authored by Bruno Martins's avatar Bruno Martins
Browse files

ButtonSettings: Rework buttons/keyboard backlight control enablement

Let's end once and for all with the nonsense of using floats
config_{button,keyboard}BrightnessSettingDefaultFloat to enable
button and keyboard brightness control, respectively.
Instead, just move over to the recently introduced integers
config_deviceSupports{Button,Keyboard}BrightnessControl.

This avoids people with devices with hardware keys having to
overlay config_{button,keyboard}BrightnessSettingDefaultFloat to
a value of 0.0 just to disable the unsupported features.

Change-Id: I0dfd0b5fa51c51398face208f17df70419ef00ca
parent 6c8187c2
Loading
Loading
Loading
Loading
+6 −24
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import lineageos.providers.LineageSettings;

public class ButtonBacklightBrightness extends CustomDialogPreference<AlertDialog> implements
        SeekBar.OnSeekBarChangeListener {
    private static final int BUTTON_BRIGHTNESS_TOGGLE_MODE_ONLY = 1;
    private static final int DEFAULT_BUTTON_TIMEOUT = 5;

    public static final String KEY_BUTTON_BACKLIGHT = "pre_navbar_button_backlight";
@@ -67,15 +68,15 @@ public class ButtonBacklightBrightness extends CustomDialogPreference<AlertDialo

        setDialogLayoutResource(R.layout.button_backlight);

        if (isKeyboardSupported(context)) {
        if (DeviceUtils.hasKeyboardBacklightSupport(context)) {
            mKeyboardBrightness = new BrightnessControl(
                    LineageSettings.Secure.KEYBOARD_BRIGHTNESS, false);
            mActiveControl = mKeyboardBrightness;
        }
        if (isButtonSupported(context)) {
            boolean isSingleValue = !context.getResources().getBoolean(
                    org.lineageos.platform.internal.R.bool
                            .config_deviceHasVariableButtonBrightness);
        if (DeviceUtils.hasButtonBacklightSupport(context)) {
            final boolean isSingleValue = BUTTON_BRIGHTNESS_TOGGLE_MODE_ONLY ==
                    context.getResources().getInteger(org.lineageos.platform.internal.R.integer
                            .config_deviceSupportsButtonBrightnessControl);

            float defaultBrightness = context.getResources().getFloat(
                    org.lineageos.platform.internal.R.dimen
@@ -225,25 +226,6 @@ public class ButtonBacklightBrightness extends CustomDialogPreference<AlertDialo
        }
    }

    public static boolean isButtonSupported(Context context) {
        final Resources res = context.getResources();
        // All hardware keys besides volume and camera can possibly have a backlight
        boolean hasBacklightKey = DeviceUtils.hasHomeKey(context)
                || DeviceUtils.hasBackKey(context)
                || DeviceUtils.hasMenuKey(context)
                || DeviceUtils.hasAssistKey(context)
                || DeviceUtils.hasAppSwitchKey(context);
        boolean hasBacklight = res.getFloat(org.lineageos.platform.internal.R.dimen
                .config_buttonBrightnessSettingDefaultFloat) > 0.0f;

        return hasBacklightKey && hasBacklight;
    }

    public static boolean isKeyboardSupported(Context context) {
        return context.getResources().getFloat(org.lineageos.platform.internal.R.dimen
                .config_keyboardBrightnessSettingDefaultFloat) > 0.0f;
    }

    public void updateSummary() {
        if (mButtonBrightness != null) {
            float buttonBrightness = mButtonBrightness.getBrightness(true);
+4 −4
Original line number Diff line number Diff line
@@ -398,8 +398,8 @@ public class ButtonSettings extends SettingsPreferenceFragment
        }

        final ButtonBacklightBrightness backlight = findPreference(KEY_BUTTON_BACKLIGHT);
        if (!backlight.isButtonSupported(getActivity())
                && !backlight.isKeyboardSupported(getActivity())) {
        if (!DeviceUtils.hasButtonBacklightSupport(getActivity())
                && !DeviceUtils.hasKeyboardBacklightSupport(getActivity())) {
            prefScreen.removePreference(backlight);
        }

@@ -841,8 +841,8 @@ public class ButtonSettings extends SettingsPreferenceFragment
                result.add(KEY_DISABLE_NAV_KEYS);
            }

            if (!ButtonBacklightBrightness.isButtonSupported(context)
                    && !ButtonBacklightBrightness.isKeyboardSupported(context)) {
            if (!DeviceUtils.hasButtonBacklightSupport(context)
                    && !DeviceUtils.hasKeyboardBacklightSupport(context)) {
                result.add(KEY_BUTTON_BACKLIGHT);
            }

+18 −0
Original line number Diff line number Diff line
@@ -135,6 +135,24 @@ public class DeviceUtils {
        return (getDeviceWakeKeys(context) & KEY_MASK_VOLUME) != 0;
    }

    /* returns whether the device supports button backlight adjusment or not. */
    public static boolean hasButtonBacklightSupport(Context context) {
        final boolean buttonBrightnessControlSupported = context.getResources().getInteger(
                org.lineageos.platform.internal.R.integer
                        .config_deviceSupportsButtonBrightnessControl) != 0;

        // All hardware keys besides volume and camera can possibly have a backlight
        return buttonBrightnessControlSupported
                && (hasHomeKey(context) || hasBackKey(context) || hasMenuKey(context)
                || hasAssistKey(context) || hasAppSwitchKey(context));
    }

    /* returns whether the device supports keyboard backlight adjusment or not. */
    public static boolean hasKeyboardBacklightSupport(Context context) {
        return context.getResources().getInteger(org.lineageos.platform.internal.R.integer
                .config_deviceSupportsKeyboardBrightnessControl) != 0;
    }

    public static boolean isPackageInstalled(Context context, String pkg, boolean ignoreState) {
        if (pkg != null) {
            try {