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

Commit 878c8538 authored by Evan Laird's avatar Evan Laird
Browse files

Add dozing state listening to classes that care

Remove some of the classes which had setDozing called directly on them
from the status bar. They are now
StatusBarStateController.StateListeners and can manage their own state.

Test: atest SystemUITests
Change-Id: I71602bda27b34b73f2eff119ab6b0f968011de1e
parent 07e8416f
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.settingslib.Utils;
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.phone.KeyguardIndicationTextView;
import com.android.systemui.statusbar.phone.LockIcon;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
@@ -66,7 +67,7 @@ import java.util.IllegalFormatConversionException;
/**
 * Controls the indications and error messages shown on the Keyguard
 */
public class KeyguardIndicationController {
public class KeyguardIndicationController implements StateListener {

    private static final String TAG = "KeyguardIndication";
    private static final boolean DEBUG_CHARGING_SPEED = false;
@@ -154,6 +155,19 @@ public class KeyguardIndicationController {
        mContext.registerReceiverAsUser(mTickReceiver, UserHandle.SYSTEM,
                new IntentFilter(Intent.ACTION_TIME_TICK), null,
                Dependency.get(Dependency.TIME_TICK_HANDLER));

        Dependency.get(StatusBarStateController.class).addListener(this);
    }

    /**
     * Used by {@link com.android.systemui.statusbar.phone.StatusBar} to give the indication
     * controller a chance to unregister itself as a receiver.
     *
     * //TODO: This can probably be converted to a fragment and not have to be manually recreated
     */
    public void destroy() {
        mContext.unregisterReceiver(mTickReceiver);
        Dependency.get(StatusBarStateController.class).removeListener(this);
    }

    /**
@@ -518,6 +532,16 @@ public class KeyguardIndicationController {
        updateAlphas();
    }

    @Override
    public void onStateChanged(int newState) {
        // don't care
    }

    @Override
    public void onDozingChanged(boolean isDozing) {
        setDozing(isDozing);
    }

    protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback {
        public static final int HIDE_DELAY_MS = 5000;
        private int mLastSuccessiveErrorMessage = -1;
+18 −4
Original line number Diff line number Diff line
@@ -29,9 +29,11 @@ import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.systemui.Dependency;
import com.android.systemui.UiOffloadThread;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.statusbar.notification.NotificationData;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;

import java.util.ArrayList;
@@ -42,7 +44,7 @@ import java.util.Collections;
 * Handles notification logging, in particular, logging which notifications are visible and which
 * are not.
 */
public class NotificationLogger {
public class NotificationLogger implements StateListener {
    private static final String TAG = "NotificationLogger";

    /** The minimum delay in ms between reports of notification visibility. */
@@ -63,7 +65,7 @@ public class NotificationLogger {
    protected IStatusBarService mBarService;
    private long mLastVisibilityReportUptimeMs;
    private NotificationListContainer mListContainer;
    private Object mDozingLock = new Object();
    private final Object mDozingLock = new Object();
    private boolean mDozing;

    protected final OnChildLocationsChangedListener mNotificationLocationsChangedListener =
@@ -146,6 +148,8 @@ public class NotificationLogger {
    public NotificationLogger() {
        mBarService = IStatusBarService.Stub.asInterface(
                ServiceManager.getService(Context.STATUS_BAR_SERVICE));
        // Not expected to be destroyed, don't need to unsubscribe
        Dependency.get(StatusBarStateController.class).addListener(this);
    }

    public void setUpWithContainer(NotificationListContainer listContainer) {
@@ -175,7 +179,7 @@ public class NotificationLogger {
        mNotificationLocationsChangedListener.onChildLocationsChanged();
    }

    public void setDozing(boolean dozing) {
    private void setDozing(boolean dozing) {
        synchronized (mDozingLock) {
            mDozing = dozing;
        }
@@ -258,6 +262,16 @@ public class NotificationLogger {
        return mVisibilityReporter;
    }

    @Override
    public void onStateChanged(int newState) {
        // don't care about state change
    }

    @Override
    public void onDozingChanged(boolean isDozing) {
        setDozing(isDozing);
    }

    /**
     * A listener that is notified when some child locations might have changed.
     */
+18 −1
Original line number Diff line number Diff line
@@ -20,13 +20,17 @@ import android.annotation.NonNull;
import android.os.Handler;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
import com.android.systemui.doze.DozeHost;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarStateController.StateListener;

/**
 * Controller which handles all the doze animations of the scrims.
 */
public class DozeScrimController {
public class DozeScrimController implements StateListener {
    private static final String TAG = "DozeScrimController";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

@@ -83,8 +87,11 @@ public class DozeScrimController {

    public DozeScrimController(DozeParameters dozeParameters) {
        mDozeParameters = dozeParameters;
        //Never expected to be destroyed
        Dependency.get(StatusBarStateController.class).addListener(this);
    }

    @VisibleForTesting
    public void setDozing(boolean dozing) {
        if (mDozing == dozing) return;
        mDozing = dozing;
@@ -181,4 +188,14 @@ public class DozeScrimController {
    public ScrimController.Callback getScrimCallback() {
        return mScrimCallback;
    }

    @Override
    public void onStateChanged(int newState) {
        // don't care
    }

    @Override
    public void onDozingChanged(boolean isDozing) {
        setDozing(isDozing);
    }
}
 No newline at end of file
+19 −8
Original line number Diff line number Diff line
@@ -16,22 +16,24 @@

package com.android.systemui.statusbar.phone;

import android.annotation.NonNull;
import android.app.Notification;
import android.os.SystemClock;
import android.service.notification.StatusBarNotification;
import androidx.annotation.Nullable;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
import com.android.systemui.statusbar.AlertingNotificationManager;
import com.android.systemui.statusbar.AmbientPulseManager;
import com.android.systemui.statusbar.AmbientPulseManager.OnAmbientChangedListener;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.StatusBarStateController.StateListener;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.NotificationData;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;

@@ -48,7 +50,7 @@ import java.util.Objects;
 * A class to handle notifications and their corresponding groups.
 */
public class NotificationGroupManager implements OnHeadsUpChangedListener,
        OnAmbientChangedListener {
        OnAmbientChangedListener, StateListener {

    private static final String TAG = "NotificationGroupManager";
    private static final long ALERT_TRANSFER_TIMEOUT = 300;
@@ -62,10 +64,8 @@ public class NotificationGroupManager implements OnHeadsUpChangedListener,
    private boolean mIsUpdatingUnchangedGroup;
    private HashMap<String, NotificationData.Entry> mPendingNotifications;

    private final StateListener mStateListener = this::setStatusBarState;

    public NotificationGroupManager() {
        Dependency.get(StatusBarStateController.class).addListener(mStateListener);
        Dependency.get(StatusBarStateController.class).addListener(this);
    }

    public void setOnGroupChangeListener(OnGroupChangeListener listener) {
@@ -185,6 +185,7 @@ public class NotificationGroupManager implements OnHeadsUpChangedListener,
     * specific alert state logic based off when the state changes.
     * @param isDozing if the device is dozing.
     */
    @VisibleForTesting
    public void setDozing(boolean isDozing) {
        if (mIsDozing != isDozing) {
            for (NotificationGroup group : mGroupMap.values()) {
@@ -732,6 +733,16 @@ public class NotificationGroupManager implements OnHeadsUpChangedListener,
        mPendingNotifications = pendingNotifications;
    }

    @Override
    public void onStateChanged(int newState) {
        setStatusBarState(newState);
    }

    @Override
    public void onDozingChanged(boolean isDozing) {
        setDozing(isDozing);
    }

    public static class NotificationGroup {
        public final HashMap<String, NotificationData.Entry> children = new HashMap<>();
        public NotificationData.Entry summary;
+3 −13
Original line number Diff line number Diff line
@@ -586,7 +586,6 @@ public class StatusBar extends SystemUI implements DemoMode,
        mNotificationLogger = Dependency.get(NotificationLogger.class);
        mRemoteInputManager = Dependency.get(NotificationRemoteInputManager.class);
        mNotificationListener =  Dependency.get(NotificationListener.class);
        mGroupManager = Dependency.get(NotificationGroupManager.class);
        mNetworkController = Dependency.get(NetworkController.class);
        mUserSwitcherController = Dependency.get(UserSwitcherController.class);
        mScreenLifecycle = Dependency.get(ScreenLifecycle.class);
@@ -1096,6 +1095,9 @@ public class StatusBar extends SystemUI implements DemoMode,
    @Override
    public void onThemeChanged() {
        // Recreate Indication controller because internal references changed
        if (mKeyguardIndicationController != null) {
            mKeyguardIndicationController.destroy();
        }
        mKeyguardIndicationController =
                SystemUIFactory.getInstance().createKeyguardIndicationController(mContext,
                        mStatusBarWindow.findViewById(R.id.keyguard_indication_area),
@@ -1104,7 +1106,6 @@ public class StatusBar extends SystemUI implements DemoMode,
        mKeyguardIndicationController
                .setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
        mKeyguardIndicationController.setVisible(mState == StatusBarState.KEYGUARD);
        mKeyguardIndicationController.setDozing(mDozing);
        if (mStatusBarKeyguardViewManager != null) {
            mStatusBarKeyguardViewManager.onThemeChanged();
        }
@@ -3247,12 +3248,8 @@ public class StatusBar extends SystemUI implements DemoMode,
        boolean animate = (!mDozing && mDozeServiceHost.shouldAnimateWakeup())
                || (mDozing && mDozeServiceHost.shouldAnimateScreenOff() && sleepingFromKeyguard);

        mDozeScrimController.setDozing(mDozing);
        mKeyguardIndicationController.setDozing(mDozing);
        mNotificationPanel.setDozing(mDozing, animate, mWakeUpTouchLocation,
                mDozeServiceHost.wasPassivelyInterrupted());
        mNotificationLogger.setDozing(mDozing);
        mGroupManager.setDozing(mDozing);
        updateQsExpansionEnabled();
        Trace.endSection();
    }
@@ -3442,13 +3439,6 @@ public class StatusBar extends SystemUI implements DemoMode,
        updateQsExpansionEnabled();
        mKeyguardViewMediator.setAodShowing(mDozing);

        //TODO: make these folks listeners of StatusBarStateController.onDozingChanged
        mStatusBarWindowController.setDozing(mDozing);
        mStatusBarKeyguardViewManager.setDozing(mDozing);
        if (mAmbientIndicationContainer instanceof DozeReceiver) {
            ((DozeReceiver) mAmbientIndicationContainer).setDozing(mDozing);
        }

        mEntryManager.updateNotifications();
        updateDozingState();
        updateScrimController();
Loading