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

Commit 3ab73e99 authored by Julia Tuttle's avatar Julia Tuttle
Browse files

StatusBarRemoteInputCallback: simplify onStateChanged

It's been modified enough that the control flow is more complicated than
the actual logic, so rewrite it to simplify the control flow.

Bug: 359530769
Test: presubmit
Flag: EXEMPT simple refactor
Change-Id: I8fb141b82f9aa602ba3bc58be4c7ce170174c879
parent 453f286b
Loading
Loading
Loading
Loading
+10 −7
Original line number Original line Diff line number Diff line
@@ -728,20 +728,23 @@ public class StatusBarStateControllerImpl implements
        // doesn't work well for clients of this class (like remote input) that expect the device to
        // doesn't work well for clients of this class (like remote input) that expect the device to
        // be fully and properly unlocked when the state changes to SHADE.
        // be fully and properly unlocked when the state changes to SHADE.
        //
        //
        // Therefore, we calculate the device to be in a locked-ish state (KEYGUARD or SHADE_LOCKED,
        // Therefore, we consider the device to be in a keyguardish state (KEYGUARD or SHADE_LOCKED,
        // but not SHADE) if *any* of these are still true:
        // but not SHADE) if *any* of these are still true:
        // 1. deviceUnlockStatus.isUnlocked is false.
        // 1. deviceUnlockStatus.isUnlocked is false.
        // 2. We are on (currentScene equals) a locked-ish scene (Lockscreen, Bouncer, or Communal).
        // 2. currentScene is a keyguardish scene (Lockscreen, Bouncer, or Communal).
        // 3. We are over (backStack contains) a locked-ish scene (Lockscreen or Communal).
        // 3. backStack contains a keyguardish scene (Lockscreen or Communal).

        final boolean onKeyguardish = onLockscreen || onBouncer || onCommunal;
        final boolean overKeyguardish = overLockscreen || overCommunal;


        if (isOccluded) {
        if (isOccluded) {
            // Occlusion is special; even though the device is still technically on the lockscreen,
            // Occlusion is special; even though the device is still technically on the lockscreen,
            // the UI behaves as if it is unlocked.
            // the UI behaves as if it is unlocked.
            newState = StatusBarState.SHADE;
            newState = StatusBarState.SHADE;
        } else if (onLockscreen || onBouncer || onCommunal || overLockscreen || overCommunal) {
        } else if (onKeyguardish || overKeyguardish) {
            // We get here if we are on or over a locked-ish scene, even if isUnlocked is true; we
            // We get here if we are on or over a keyguardish scene, even if isUnlocked is true; we
            // want to return SHADE_LOCKED or KEYGUARD until we are also neither on nor over a
            // want to return SHADE_LOCKED or KEYGUARD until we are also neither on nor over a
            // locked-ish scene.
            // keyguardish scene.
            if (onShade || onQuickSettings || overShade || overlaidShade || overlaidQuickSettings) {
            if (onShade || onQuickSettings || overShade || overlaidShade || overlaidQuickSettings) {
                newState = StatusBarState.SHADE_LOCKED;
                newState = StatusBarState.SHADE_LOCKED;
            } else {
            } else {
@@ -751,7 +754,7 @@ public class StatusBarStateControllerImpl implements
            newState = StatusBarState.SHADE;
            newState = StatusBarState.SHADE;
        } else if (onShade || onQuickSettings) {
        } else if (onShade || onQuickSettings) {
            // We get here if deviceUnlockStatus.isUnlocked is false but we are no longer on or over
            // We get here if deviceUnlockStatus.isUnlocked is false but we are no longer on or over
            // a locked-ish scene; we want to return SHADE_LOCKED until isUnlocked is also true.
            // a keyguardish scene; we want to return SHADE_LOCKED until isUnlocked is also true.
            newState = StatusBarState.SHADE_LOCKED;
            newState = StatusBarState.SHADE_LOCKED;
        } else {
        } else {
            throw new IllegalArgumentException(
            throw new IllegalArgumentException(
+15 −10
Original line number Original line Diff line number Diff line
@@ -117,18 +117,15 @@ public class StatusBarRemoteInputCallback implements Callback, Callbacks,


    @Override
    @Override
    public void onStateChanged(int state) {
    public void onStateChanged(int state) {
        boolean hasPendingRemoteInput = mPendingRemoteInputView != null;
        if (mPendingRemoteInputView == null) {
        if (state == StatusBarState.SHADE
            return;
                && (mStatusBarStateController.leaveOpenOnKeyguardHide() || hasPendingRemoteInput)) {
            if (!mStatusBarStateController.isKeyguardRequested()
                    && mKeyguardStateController.isUnlocked()) {
                if (hasPendingRemoteInput) {
                    mExecutor.execute(mPendingRemoteInputView::callOnClick);
        }
        }

        if (state == StatusBarState.SHADE && canRetryPendingRemoteInput()) {
            mExecutor.execute(mPendingRemoteInputView::callOnClick);
            mPendingRemoteInputView = null;
            mPendingRemoteInputView = null;
        }
        }
    }
    }
    }


    @Override
    @Override
    public void onLockedRemoteInput(ExpandableNotificationRow row, View clicked) {
    public void onLockedRemoteInput(ExpandableNotificationRow row, View clicked) {
@@ -320,6 +317,14 @@ public class StatusBarRemoteInputCallback implements Callback, Callbacks,
        }
        }
    }
    }


    /**
     * Returns {@code true} if it is safe to retry a pending remote input.
     */
    private boolean canRetryPendingRemoteInput() {
        return mKeyguardStateController.isUnlocked()
                && !mStatusBarStateController.isKeyguardRequested();
    }

    protected class ChallengeReceiver extends BroadcastReceiver {
    protected class ChallengeReceiver extends BroadcastReceiver {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {