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
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateControllerImpl.java
index b082481..73ad0e5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateControllerImpl.java
@@ -728,20 +728,23 @@
         // 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.
         //
-        // 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:
         // 1. deviceUnlockStatus.isUnlocked is false.
-        // 2. We are on (currentScene equals) a locked-ish scene (Lockscreen, Bouncer, or Communal).
-        // 3. We are over (backStack contains) a locked-ish scene (Lockscreen or Communal).
+        // 2. currentScene is a keyguardish scene (Lockscreen, Bouncer, or Communal).
+        // 3. backStack contains a keyguardish scene (Lockscreen or Communal).
+
+        final boolean onKeyguardish = onLockscreen || onBouncer || onCommunal;
+        final boolean overKeyguardish = overLockscreen || overCommunal;
 
         if (isOccluded) {
             // Occlusion is special; even though the device is still technically on the lockscreen,
             // the UI behaves as if it is unlocked.
             newState = StatusBarState.SHADE;
-        } else if (onLockscreen || onBouncer || onCommunal || overLockscreen || overCommunal) {
-            // We get here if we are on or over a locked-ish scene, even if isUnlocked is true; we
+        } else if (onKeyguardish || overKeyguardish) {
+            // 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
-            // locked-ish scene.
+            // keyguardish scene.
             if (onShade || onQuickSettings || overShade || overlaidShade || overlaidQuickSettings) {
                 newState = StatusBarState.SHADE_LOCKED;
             } else {
@@ -751,7 +754,7 @@
             newState = StatusBarState.SHADE;
         } else if (onShade || onQuickSettings) {
             // 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;
         } else {
             throw new IllegalArgumentException(
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java
index b1754fd..d1f88ac1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarRemoteInputCallback.java
@@ -117,16 +117,13 @@
 
     @Override
     public void onStateChanged(int state) {
-        boolean hasPendingRemoteInput = mPendingRemoteInputView != null;
-        if (state == StatusBarState.SHADE
-                && (mStatusBarStateController.leaveOpenOnKeyguardHide() || hasPendingRemoteInput)) {
-            if (!mStatusBarStateController.isKeyguardRequested()
-                    && mKeyguardStateController.isUnlocked()) {
-                if (hasPendingRemoteInput) {
-                    mExecutor.execute(mPendingRemoteInputView::callOnClick);
-                }
-                mPendingRemoteInputView = null;
-            }
+        if (mPendingRemoteInputView == null) {
+            return;
+        }
+
+        if (state == StatusBarState.SHADE && canRetryPendingRemoteInput()) {
+            mExecutor.execute(mPendingRemoteInputView::callOnClick);
+            mPendingRemoteInputView = null;
         }
     }
 
@@ -320,6 +317,14 @@
         }
     }
 
+    /**
+     * 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 {
         @Override
         public void onReceive(Context context, Intent intent) {