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

Unverified Commit 2919024a authored by Michael Bestas's avatar Michael Bestas
Browse files

Revert "SystemUI: Port statusbar brightness control"

Needs to be refactored after QPR2

This reverts commit 54bf717d.

Change-Id: I888ba4bc5b2070e60419753c7c5bba9b6b79850c
parent 6a55b9db
Loading
Loading
Loading
Loading
+0 −123
Original line number Diff line number Diff line
@@ -70,10 +70,8 @@ import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Point;
import android.hardware.devicestate.DeviceStateManager;
import android.hardware.display.DisplayManager;
import android.metrics.LogMaker;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
@@ -96,13 +94,11 @@ import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.MathUtils;
import android.view.Display;
import android.view.HapticFeedbackConstants;
import android.view.IRemoteAnimationRunner;
import android.view.IWindowManager;
import android.view.KeyEvent;
import android.view.ThreadedRenderer;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewRootImpl;
import android.view.WindowInsetsController.Appearance;
@@ -283,10 +279,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune

    private static final String FORCE_SHOW_NAVBAR =
            "lineagesystem:" + LineageSettings.System.FORCE_SHOW_NAVBAR;
    private static final String SCREEN_BRIGHTNESS_MODE =
            "system:" + Settings.System.SCREEN_BRIGHTNESS_MODE;
    private static final String STATUS_BAR_BRIGHTNESS_CONTROL =
            "lineagesystem:" + LineageSettings.System.STATUS_BAR_BRIGHTNESS_CONTROL;

    private static final String BANNER_ACTION_CANCEL =
            "com.android.systemui.statusbar.banner_action_cancel";
@@ -295,7 +287,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune

    private static final int MSG_OPEN_SETTINGS_PANEL = 1002;
    private static final int MSG_LAUNCH_TRANSITION_TIMEOUT = 1003;
    private static final int MSG_LONG_PRESS_BRIGHTNESS_CHANGE = 1004;
    // 1020-1040 reserved for BaseStatusBar

    /**
@@ -304,10 +295,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune
     */
    private static final int HINT_RESET_DELAY_MS = 1200;

    private static final float BRIGHTNESS_CONTROL_PADDING = 0.15f;
    private static final int BRIGHTNESS_CONTROL_LONG_PRESS_TIMEOUT = 750; // ms
    private static final int BRIGHTNESS_CONTROL_LINGER_THRESHOLD = 20;

    private static final UiEventLogger sUiEventLogger = new UiEventLoggerImpl();

    /**
@@ -544,18 +531,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune

    private CentralSurfacesComponent mCentralSurfacesComponent;

    private DisplayManager mDisplayManager;

    private int mMinBrightness;
    private int mInitialTouchX;
    private int mInitialTouchY;
    private int mLinger;
    private int mQuickQsOffsetHeight;
    private boolean mAutomaticBrightness;
    private boolean mBrightnessControl;
    private boolean mBrightnessChanged;
    private boolean mJustPeeked;

    // Flags for disabling the status bar
    // Two variables because the first one evidently ran out of room for new flags.
    private int mDisabled1 = 0;
@@ -907,8 +882,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune
                data -> mCommandQueueCallbacks.animateExpandSettingsPanel(data.mSubpanel));
        mMessageRouter.subscribeTo(MSG_LAUNCH_TRANSITION_TIMEOUT,
                id -> onLaunchTransitionTimeout());
        mMessageRouter.subscribeTo(MSG_LONG_PRESS_BRIGHTNESS_CHANGE,
                id -> onLongPressBrightnessChange());

        deviceStateManager.registerCallback(mMainExecutor,
                new FoldStateListener(mContext, this::onFoldedStateChanged));
@@ -921,7 +894,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune
    public void start() {
        mScreenLifecycle.addObserver(mScreenObserver);
        mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
        mDisplayManager = mContext.getSystemService(DisplayManager.class);
        mUiModeManager = mContext.getSystemService(UiModeManager.class);
        if (mBubblesOptional.isPresent()) {
            mBubblesOptional.get().setExpandListener(mBubbleExpandListener);
@@ -949,8 +921,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune
        }

        mTunerService.addTunable(this, FORCE_SHOW_NAVBAR);
        mTunerService.addTunable(this, SCREEN_BRIGHTNESS_MODE);
        mTunerService.addTunable(this, STATUS_BAR_BRIGHTNESS_CONTROL);

        mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);

@@ -1237,9 +1207,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune
        mNotificationShadeWindowView.setOnTouchListener(getStatusBarWindowTouchListener());
        mWallpaperController.setRootView(mNotificationShadeWindowView);

        mMinBrightness = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_screenBrightnessDim);

        // TODO: Deal with the ugliness that comes from having some of the status bar broken out
        // into fragments, but the rest here, it leaves some awkward lifecycle and whatnot.
        mNotificationIconAreaController.setupShelf(mNotificationShelfController);
@@ -2101,90 +2068,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune
        }
    }

    private void adjustBrightness(int x) {
        mBrightnessChanged = true;
        float raw = ((float) x) / getDisplayWidth();

        // Add a padding to the brightness control on both sides to
        // make it easier to reach min/max brightness
        float padded = Math.min(1.0f - BRIGHTNESS_CONTROL_PADDING,
                Math.max(BRIGHTNESS_CONTROL_PADDING, raw));
        float value = (padded - BRIGHTNESS_CONTROL_PADDING) /
                (1 - (2.0f * BRIGHTNESS_CONTROL_PADDING));
        if (mAutomaticBrightness) {
            float adj = (2 * value) - 1;
            adj = Math.max(adj, -1);
            adj = Math.min(adj, 1);
            final float val = adj;
            mDisplayManager.setTemporaryAutoBrightnessAdjustment(val);
            AsyncTask.execute(() -> {
                Settings.System.putFloatForUser(mContext.getContentResolver(),
                        Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, val,
                        UserHandle.USER_CURRENT);
            });
        } else {
            int newBrightness = mMinBrightness + (int) Math.round(value *
                    (PowerManager.BRIGHTNESS_ON - mMinBrightness));
            newBrightness = Math.min(newBrightness, PowerManager.BRIGHTNESS_ON);
            newBrightness = Math.max(newBrightness, mMinBrightness);
            final int val = newBrightness;
            mDisplayManager.setTemporaryBrightness(mDisplayId, val);
            AsyncTask.execute(() -> {
                Settings.System.putIntForUser(mContext.getContentResolver(),
                        Settings.System.SCREEN_BRIGHTNESS, val,
                        UserHandle.USER_CURRENT);
            });
        }
    }

    private void brightnessControl(MotionEvent event) {
        final int action = event.getAction();
        final int x = (int) event.getRawX();
        final int y = (int) event.getRawY();
        mQuickQsOffsetHeight = mContext.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.quick_qs_offset_height);
        if (action == MotionEvent.ACTION_DOWN) {
            if (y < mQuickQsOffsetHeight) {
                mLinger = 0;
                mInitialTouchX = x;
                mInitialTouchY = y;
                mJustPeeked = true;
                mMessageRouter.cancelMessages(MSG_LONG_PRESS_BRIGHTNESS_CHANGE);
                mMessageRouter.sendMessageDelayed(MSG_LONG_PRESS_BRIGHTNESS_CHANGE,
                        BRIGHTNESS_CONTROL_LONG_PRESS_TIMEOUT);
            }
        } else if (action == MotionEvent.ACTION_MOVE) {
            if (y < mQuickQsOffsetHeight && mJustPeeked) {
                if (mLinger > BRIGHTNESS_CONTROL_LINGER_THRESHOLD) {
                    adjustBrightness(x);
                } else {
                    final int xDiff = Math.abs(x - mInitialTouchX);
                    final int yDiff = Math.abs(y - mInitialTouchY);
                    final int touchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
                    if (xDiff > yDiff) {
                        mLinger++;
                    }
                    if (xDiff > touchSlop || yDiff > touchSlop) {
                        mMessageRouter.cancelMessages(MSG_LONG_PRESS_BRIGHTNESS_CHANGE);
                    }
                }
            } else {
                if (y > mQuickQsOffsetHeight) {
                    mJustPeeked = false;
                }
                mMessageRouter.cancelMessages(MSG_LONG_PRESS_BRIGHTNESS_CHANGE);
            }
        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            mMessageRouter.cancelMessages(MSG_LONG_PRESS_BRIGHTNESS_CHANGE);
        }
    }

    void onLongPressBrightnessChange() {
        mStatusBarView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        adjustBrightness(mInitialTouchX);
        mLinger = BRIGHTNESS_CONTROL_LINGER_THRESHOLD + 1;
    }

    @Override
    public boolean getCommandQueuePanelsEnabled() {
        return mCommandQueue.panelsEnabled();
@@ -4240,12 +4123,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces, Tune
                    mNavigationBarController.onDisplayRemoved(mDisplayId);
                }
            }
        } else if (SCREEN_BRIGHTNESS_MODE.equals(key)) {
            mAutomaticBrightness = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC ==
                    TunerService.parseInteger(newValue,
                            Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        } else if (STATUS_BAR_BRIGHTNESS_CONTROL.equals(key)) {
            mBrightnessControl = TunerService.parseIntegerSwitch(newValue, false);
        }
    }

+1 −2
Original line number Diff line number Diff line
@@ -74,8 +74,7 @@ public class TunerServiceImpl extends TunerService {
            QSTileHost.TILES_SETTING,
            Settings.Secure.DOZE_ALWAYS_ON,
            Settings.Secure.MEDIA_CONTROLS_RESUME,
            Settings.Secure.MEDIA_CONTROLS_RECOMMENDATION,
            Settings.System.SCREEN_BRIGHTNESS_MODE,
            Settings.Secure.MEDIA_CONTROLS_RECOMMENDATION
    };

    private final Observer mObserver = new Observer();