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

Commit 1fd3fc3e authored by Jason Monk's avatar Jason Monk
Browse files

Refactor StatusBarState out of StatusBar

Test: tests gonna test
Change-Id: Id8d8eb5124e542eac9f3b785a7011a22e758e20b
parent 0eaa26ad
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.classifier.FalsingManager;
import com.android.systemui.keyguard.DismissCallbackRegistry;
import com.android.systemui.qs.QSTileHost;
import com.android.systemui.statusbar.KeyguardIndicationController;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.row.NotificationBlockingHelperManager;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
@@ -129,6 +130,7 @@ public class SystemUIFactory {

    public void injectDependencies(ArrayMap<Object, DependencyProvider> providers,
            Context context) {
        providers.put(StatusBarStateController.class, StatusBarStateController::new);
        providers.put(NotificationLockscreenUserManager.class,
                () -> new NotificationLockscreenUserManager(context));
        providers.put(VisualStabilityManager.class, VisualStabilityManager::new);
+6 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import com.android.systemui.Dependency;
import com.android.systemui.UiOffloadThread;
import com.android.systemui.analytics.DataCollector;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.util.AsyncSensorManager;

import java.io.PrintWriter;
@@ -82,6 +84,8 @@ public class FalsingManager implements SensorEventListener {
    private boolean mShowingAod;
    private Runnable mPendingWtf;

    private final StateListener mStateListener = this::setStatusBarState;

    protected final ContentObserver mSettingsObserver = new ContentObserver(mHandler) {
        @Override
        public void onChange(boolean selfChange) {
@@ -104,6 +108,7 @@ public class FalsingManager implements SensorEventListener {
                UserHandle.USER_ALL);

        updateConfiguration();
        Dependency.get(StatusBarStateController.class).addListener(mStateListener);
    }

    public static FalsingManager getInstance(Context context) {
@@ -274,7 +279,7 @@ public class FalsingManager implements SensorEventListener {
        updateSessionActive();
    }

    public void setStatusBarState(int state) {
    private void setStatusBarState(int state) {
        if (FalsingLog.ENABLED) {
            FalsingLog.i("setStatusBarState", new StringBuilder()
                    .append("from=").append(StatusBarState.toShortString(mState))
+19 −5
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@ import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityNodeInfo;

import com.android.systemui.Dependency;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.statusbar.notification.NotificationUtils;
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
@@ -94,6 +96,8 @@ public class NotificationShelf extends ActivatableNotificationView implements
    private Rect mClipRect = new Rect();
    private int mCutoutHeight;

    private final StateListener mStateListener = this::setStatusBarState;

    public NotificationShelf(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
@@ -114,6 +118,18 @@ public class NotificationShelf extends ActivatableNotificationView implements
        initDimens();
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        Dependency.get(StatusBarStateController.class).addListener(mStateListener);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        Dependency.get(StatusBarStateController.class).removeListener(mStateListener);
    }

    public void bind(AmbientState ambientState, NotificationStackScrollLayout hostLayout) {
        mAmbientState = ambientState;
        mHostLayout = hostLayout;
@@ -836,12 +852,10 @@ public class NotificationShelf extends ActivatableNotificationView implements
        mCollapsedIcons.addOnLayoutChangeListener(this);
    }

    public void setStatusBarState(int statusBarState) {
        if (mStatusBarState != statusBarState) {
    private void setStatusBarState(int statusBarState) {
        mStatusBarState = statusBarState;
        updateInteractiveness();
    }
    }

    private void updateInteractiveness() {
        mInteractive = mStatusBarState == StatusBarState.KEYGUARD && mHasItemsInStableShelf
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.systemui.statusbar;

import android.util.ArraySet;

/**
 * Tracks and reports on {@link StatusBarState}.
 */
public class StatusBarStateController {

    private static final int MAX_STATE = StatusBarState.FULLSCREEN_USER_SWITCHER;
    private static final int MIN_STATE = StatusBarState.SHADE;

    private final ArraySet<StateListener> mListeners = new ArraySet<>();
    private int mState;
    private int mLastState;
    private boolean mLeaveOpenOnKeyguardHide;

    public int getState() {
        return mState;
    }

    public void setState(int state) {
        if (state > MAX_STATE || state < MIN_STATE) {
            throw new IllegalArgumentException("Invalid state " + state);
        }
        if (state == mState) {
            return;
        }
        synchronized (mListeners) {
            for (StateListener listener : mListeners) {
                listener.onStatePreChange(mState, state);
            }
            mLastState = mState;
            mState = state;
            for (StateListener listener : mListeners) {
                listener.onStateChanged(mState);
            }
        }
    }

    public boolean goingToFullShade() {
        return mState == StatusBarState.SHADE && mLeaveOpenOnKeyguardHide;
    }

    public void setLeaveOpenOnKeyguardHide(boolean leaveOpen) {
        mLeaveOpenOnKeyguardHide = leaveOpen;
    }

    public boolean leaveOpenOnKeyguardHide() {
        return mLeaveOpenOnKeyguardHide;
    }

    public boolean fromShadeLocked() {
        return mLastState == StatusBarState.SHADE_LOCKED;
    }

    public void addListener(StateListener listener) {
        synchronized (mListeners) {
            mListeners.add(listener);
        }
    }

    public void removeListener(StateListener listener) {
        synchronized (mListeners) {
            mListeners.remove(listener);
        }
    }

    public interface StateListener {
        public default void onStatePreChange(int oldState, int newState) {
        }

        public void onStateChanged(int newState);
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.statusbar.car;

import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.car.user.CarUserManagerHelper;
import android.graphics.PixelFormat;
@@ -504,8 +503,8 @@ public class CarStatusBar extends StatusBar implements
    }

    @Override
    public void updateKeyguardState(boolean goingToFullShade, boolean fromShadeLocked) {
        super.updateKeyguardState(goingToFullShade, fromShadeLocked);
    public void onStateChanged(int newState) {
        super.onStateChanged(newState);
        CarUserManagerHelper helper = new CarUserManagerHelper(mContext);
        if (!helper.isHeadlessSystemUser()) {
            showUserSwitcher();
Loading