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

Commit 3527645d authored by Michael W's avatar Michael W Committed by Luca Stefani
Browse files

SystemUI: Fix for auto brightness icon being shown when disabled

* With commit 9d42c48c the case of a
  manually disabled auto brightness icon got lost
* Re-implement it by also respecting the Settings value instead of just
  the build time flag

Change-Id: I991977be7e1f7c33947073dbd3ce7a800fb158bf
parent e97d340d
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -27,9 +27,13 @@ import android.widget.FrameLayout;
import android.widget.ImageView;

import com.android.internal.util.Preconditions;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.NotificationPanelView;
import com.android.systemui.statusbar.phone.StatusBarWindowView;
import com.android.systemui.tuner.TunerService;

import lineageos.providers.LineageSettings;

import java.util.function.Consumer;

@@ -39,12 +43,26 @@ import java.util.function.Consumer;
public class BrightnessMirrorController
        implements CallbackController<BrightnessMirrorController.BrightnessMirrorListener> {

    private static final String QS_SHOW_AUTO_BRIGHTNESS =
            "lineagesecure:" + LineageSettings.Secure.QS_SHOW_AUTO_BRIGHTNESS;

    private final StatusBarWindowView mStatusBarWindow;
    private final Consumer<Boolean> mVisibilityCallback;
    private final NotificationPanelView mNotificationPanel;
    private final ArraySet<BrightnessMirrorListener> mBrightnessMirrorListeners = new ArraySet<>();
    private final int[] mInt2Cache = new int[2];
    private View mBrightnessMirror;
    private boolean mShouldShowAutoBrightness;

    private final TunerService.Tunable mTunable = new TunerService.Tunable() {
            @Override
            public void onTuningChanged(String key, String newValue) {
                if (QS_SHOW_AUTO_BRIGHTNESS.equals(key)) {
                    mShouldShowAutoBrightness = TunerService.parseIntegerSwitch(newValue, true);
                    updateIcon();
                }
            }
        };

    public BrightnessMirrorController(StatusBarWindowView statusBarWindow,
            @NonNull Consumer<Boolean> visibilityCallback) {
@@ -55,6 +73,8 @@ public class BrightnessMirrorController
            mBrightnessMirror.setVisibility(View.INVISIBLE);
        });
        mVisibilityCallback = visibilityCallback;

        Dependency.get(TunerService.class).addTunable(mTunable, QS_SHOW_AUTO_BRIGHTNESS);
    }

    public void showMirror() {
@@ -142,7 +162,7 @@ public class BrightnessMirrorController
        ImageView iv = mBrightnessMirror.findViewById(R.id.brightness_icon);
        boolean autoBrightnessAvailable = mBrightnessMirror.getContext().getResources().getBoolean(
                com.android.internal.R.bool.config_automatic_brightness_available);
        if (autoBrightnessAvailable) {
        if (autoBrightnessAvailable && mShouldShowAutoBrightness) {
            int automatic = Settings.System.getIntForUser(mBrightnessMirror.getContext()
                            .getContentResolver(),
                    Settings.System.SCREEN_BRIGHTNESS_MODE,
@@ -153,6 +173,8 @@ public class BrightnessMirrorController
                    ? com.android.systemui.R.drawable.ic_qs_brightness_auto_on
                    : com.android.systemui.R.drawable.ic_qs_brightness_auto_off);
            iv.setVisibility(View.VISIBLE);
        } else {
            iv.setVisibility(View.GONE);
        }
    }
}