ui: Check external disk status on selecting "Back"

Consider the series of user actions in developer UI:

0. Screen DEVLOPER_MODE is shown
1. Insert an invalid external disk
2. Press Ctrl+U to trigger external boot
   => INVALID_DISK screen is shown
3. Unplug the invalid external disk
   => BOOT_EXTERNAL screen is shown
4. Select the "Back" button

Then, the screen will temporarily change to INVALID_DISK because it is
the previous screen in the history stack. However, in the next UI loop,
the action function of INVALID_DISK will change the screen to
BOOT_EXTERNAL because there is no external disk plugged in. This bug
causes the user to be stuck in INVALID_DISK and INVALID_DISK screens.

To solve the problem, add init() and reinit() hooks for these two
polling screens, so that when we enter either of the screens, the status
of the external disk will be checked. If it doesn't match the meaning of
the target screen, ui_screen_back() will be called to go back to the
previous screen.

This solution elegantly handles more complex situations like this:

0. Screen DEVLOPER_MODE is shown
   Stack: [DEVELOPER_MODE]
1. Insert an invalid external disk
2. Press Ctrl+U to trigger external boot
   => INVALID_DISK screen is shown
   Stack: [DEVELOPER_MODE, INVALID_DISK]
3. Press TAB
   => DEBUG_INFO screen is shown
   Stack: [DEVELOPER_MODE, INVALID_DISK, DEBUG_INFO]
4. Unplug the invalid external disk and press Ctrl+U
   => BOOT_EXTERNAL screen is shown
   Stack: [DEVELOPER_MODE, INVALID_DISK, DEBUG_INFO, BOOT_EXTERNAL]
5. Select "Back"
   => DEBUG_INFO screen is shown
   Stack: [DEVELOPER_MODE, INVALID_DISK, DEBUG_INFO]
6. Select "Back"
   => DEVELOPER_MODE screen is shown (because INVALID_DISK is skipped)
   Stack: [DEVELOPER_MODE]

BUG=b:201510767
TEST=make unit-tests
TEST=emerge-brya depthcharge
TEST=Ran the steps above on brya
BRANCH=none

Change-Id: Ib2cece3bdebfbe2f50216b4fe0057afb5cb7d420
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/depthcharge/+/3195521
Reviewed-by: Hsuan Ting Chen <roccochen@chromium.org>
2 files changed