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

Commit 9e5c45cb authored by Dave Mankoff's avatar Dave Mankoff
Browse files

Move BatteryStateChangeCallback internal to StatusBar.

Removes one of the "does not crash" tests. This test should be
more specific.

Bug: 190746471
Test: atest SystemUITests
Change-Id: I4ed380308f5231949034e927cf015bc3cdb671d0
parent 858d81a5
Loading
Loading
Loading
Loading
+81 −79
Original line number Original line Diff line number Diff line
@@ -252,8 +252,7 @@ import dagger.Lazy;
/** */
/** */
public class StatusBar extends SystemUI implements
public class StatusBar extends SystemUI implements
        ActivityStarter,
        ActivityStarter,
        StatusBarStateController.StateListener,
        LifecycleOwner,
        LifecycleOwner, BatteryController.BatteryStateChangeCallback,
        ActivityLaunchAnimator.Callback {
        ActivityLaunchAnimator.Callback {
    public static final boolean MULTIUSER_DEBUG = false;
    public static final boolean MULTIUSER_DEBUG = false;


@@ -842,6 +841,84 @@ public class StatusBar extends SystemUI implements
            }
            }
        }
        }
    };
    };

    private StatusBarStateController.StateListener mStateListener =
            new StatusBarStateController.StateListener() {
        @Override
        public void onStatePreChange(int oldState, int newState) {
            // If we're visible and switched to SHADE_LOCKED (the user dragged
            // down on the lockscreen), clear notification LED, vibration,
            // ringing.
            // Other transitions are covered in handleVisibleToUserChanged().
            if (mVisible && (newState == StatusBarState.SHADE_LOCKED
                    || mStatusBarStateController.goingToFullShade())) {
                clearNotificationEffects();
            }
            if (newState == StatusBarState.KEYGUARD) {
                mRemoteInputManager.onPanelCollapsed();
                maybeEscalateHeadsUp();
            }
        }

        @Override
        public void onStateChanged(int newState) {
            mState = newState;
            updateReportRejectedTouchVisibility();
            mDozeServiceHost.updateDozing();
            updateTheme();
            mNavigationBarController.touchAutoDim(mDisplayId);
            Trace.beginSection("StatusBar#updateKeyguardState");
            if (mState == StatusBarState.KEYGUARD && mStatusBarView != null) {
                mStatusBarView.removePendingHideExpandedRunnables();
            }
            updateDozingState();
            checkBarModes();
            updateScrimController();
            mPresenter.updateMediaMetaData(false, mState != StatusBarState.KEYGUARD);
            updateKeyguardState();
            Trace.endSection();
        }

        @Override
        public void onDozeAmountChanged(float linear, float eased) {
            if (mFeatureFlags.useNewLockscreenAnimations()
                    && !(mLightRevealScrim.getRevealEffect() instanceof CircleReveal)) {
                mLightRevealScrim.setRevealAmount(1f - linear);
            }
        }

        @Override
        public void onDozingChanged(boolean isDozing) {
            Trace.beginSection("StatusBar#updateDozing");
            mDozing = isDozing;

            // Collapse the notification panel if open
            boolean dozingAnimated = mDozeServiceHost.getDozingRequested()
                    && mDozeParameters.shouldControlScreenOff();
            mNotificationPanelViewController.resetViews(dozingAnimated);

            updateQsExpansionEnabled();
            mKeyguardViewMediator.setDozing(mDozing);

            mNotificationsController.requestNotificationUpdate("onDozingChanged");
            updateDozingState();
            mDozeServiceHost.updateDozing();
            updateScrimController();
            updateReportRejectedTouchVisibility();
            Trace.endSection();
        }
    };

    private final BatteryController.BatteryStateChangeCallback mBatteryStateChangeCallback =
            new BatteryController.BatteryStateChangeCallback() {
                @Override
                public void onPowerSaveChanged(boolean isPowerSave) {
                    mHandler.post(mCheckBarModes);
                    if (mDozeServiceHost != null) {
                        mDozeServiceHost.firePowerSaveChanged(isPowerSave);
                    }
                }
            };
    /**
    /**
     * Public constructor for StatusBar.
     * Public constructor for StatusBar.
     *
     *
@@ -1058,7 +1135,7 @@ public class StatusBar extends SystemUI implements
        mKeyguardIndicationController.init();
        mKeyguardIndicationController.init();


        mColorExtractor.addOnColorsChangedListener(mOnColorsChangedListener);
        mColorExtractor.addOnColorsChangedListener(mOnColorsChangedListener);
        mStatusBarStateController.addCallback(this,
        mStatusBarStateController.addCallback(mStateListener,
                SysuiStatusBarStateController.RANK_STATUS_BAR);
                SysuiStatusBarStateController.RANK_STATUS_BAR);


        mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
@@ -1174,7 +1251,7 @@ public class StatusBar extends SystemUI implements


        mConfigurationController.addCallback(mConfigurationListener);
        mConfigurationController.addCallback(mConfigurationListener);


        mBatteryController.observe(mLifecycle, this);
        mBatteryController.observe(mLifecycle, mBatteryStateChangeCallback);
        mLifecycle.setCurrentState(RESUMED);
        mLifecycle.setCurrentState(RESUMED);


        // set the initial view visibility
        // set the initial view visibility
@@ -1542,19 +1619,6 @@ public class StatusBar extends SystemUI implements
        return mLifecycle;
        return mLifecycle;
    }
    }


    @Override
    public void onPowerSaveChanged(boolean isPowerSave) {
        mHandler.post(mCheckBarModes);
        if (mDozeServiceHost != null) {
            mDozeServiceHost.firePowerSaveChanged(isPowerSave);
        }
    }

    @Override
    public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
        // noop
    }

    @VisibleForTesting
    @VisibleForTesting
    protected void registerBroadcastReceiver() {
    protected void registerBroadcastReceiver() {
        IntentFilter filter = new IntentFilter();
        IntentFilter filter = new IntentFilter();
@@ -3515,69 +3579,7 @@ public class StatusBar extends SystemUI implements
        mNotificationPanelViewController.collapseWithDuration(duration);
        mNotificationPanelViewController.collapseWithDuration(duration);
    }
    }


    @Override
    public void onStatePreChange(int oldState, int newState) {
        // If we're visible and switched to SHADE_LOCKED (the user dragged
        // down on the lockscreen), clear notification LED, vibration,
        // ringing.
        // Other transitions are covered in handleVisibleToUserChanged().
        if (mVisible && (newState == StatusBarState.SHADE_LOCKED
                || mStatusBarStateController.goingToFullShade())) {
            clearNotificationEffects();
        }
        if (newState == StatusBarState.KEYGUARD) {
            mRemoteInputManager.onPanelCollapsed();
            maybeEscalateHeadsUp();
        }
    }


    @Override
    public void onStateChanged(int newState) {
        mState = newState;
        updateReportRejectedTouchVisibility();
        mDozeServiceHost.updateDozing();
        updateTheme();
        mNavigationBarController.touchAutoDim(mDisplayId);
        Trace.beginSection("StatusBar#updateKeyguardState");
        if (mState == StatusBarState.KEYGUARD && mStatusBarView != null) {
            mStatusBarView.removePendingHideExpandedRunnables();
        }
        updateDozingState();
        checkBarModes();
        updateScrimController();
        mPresenter.updateMediaMetaData(false, mState != StatusBarState.KEYGUARD);
        updateKeyguardState();
        Trace.endSection();
    }

    @Override
    public void onDozeAmountChanged(float linear, float eased) {
        if (mFeatureFlags.useNewLockscreenAnimations()
                && !(mLightRevealScrim.getRevealEffect() instanceof CircleReveal)) {
            mLightRevealScrim.setRevealAmount(1f - linear);
        }
    }

    @Override
    public void onDozingChanged(boolean isDozing) {
        Trace.beginSection("StatusBar#updateDozing");
        mDozing = isDozing;

        // Collapse the notification panel if open
        boolean dozingAnimated = mDozeServiceHost.getDozingRequested()
                && mDozeParameters.shouldControlScreenOff();
        mNotificationPanelViewController.resetViews(dozingAnimated);

        updateQsExpansionEnabled();
        mKeyguardViewMediator.setDozing(mDozing);

        mNotificationsController.requestNotificationUpdate("onDozingChanged");
        updateDozingState();
        mDozeServiceHost.updateDozing();
        updateScrimController();
        updateReportRejectedTouchVisibility();
        Trace.endSection();
    }


    /**
    /**
     * Updates the light reveal effect to reflect the reason we're waking or sleeping (for example,
     * Updates the light reveal effect to reflect the reason we're waking or sleeping (for example,
+0 −9
Original line number Original line Diff line number Diff line
@@ -753,15 +753,6 @@ public class StatusBarTest extends SysuiTestCase {
                new PrintWriter(new ByteArrayOutputStream()), "var", /* transitions= */ null);
                new PrintWriter(new ByteArrayOutputStream()), "var", /* transitions= */ null);
    }
    }


    @Test
    @RunWithLooper(setAsMainLooper = true)
    public void testUpdateKeyguardState_DoesNotCrash() {
        mStatusBar.setBarStateForTest(StatusBarState.KEYGUARD);
        when(mLockscreenUserManager.getCurrentProfiles()).thenReturn(
                new SparseArray<>());
        mStatusBar.onStateChanged(StatusBarState.SHADE);
    }

    @Test
    @Test
    public void testFingerprintNotification_UpdatesScrims() {
    public void testFingerprintNotification_UpdatesScrims() {
        mStatusBar.notifyBiometricAuthModeChanged();
        mStatusBar.notifyBiometricAuthModeChanged();