Repository: beeware/briefcase

Issue:
The Use of `stream_output=False` is not Respected within a Controlled Console
### Describe the bug

For `subprocess.run()`, `stream_output=False` is not respected when the console is controlled. This is most likely to happen when a Wait Bar is started and a nested subprocess call uses `stream_output=False`.

I noticed this when building an APK without the Android emulator available. The `Building...` Wait Bar is started for the APK build and the emulator is now checked for and [installed](https://github.com/beeware/briefcase/blob/main/src/briefcase/platforms/android/gradle.py#L125) in-line. Because the `sdkmanager` script uses a progress bar, this installation [uses](https://github.com/beeware/briefcase/blob/main/src/briefcase/integrations/android_sdk.py#L439) `stream_output=False`....but it is in fact streamed.

### Steps to reproduce

```
briefcase build android && rm -rf ~/.cache/briefcase/tools/android_sdk/emulator && briefcase build android -v
```

### Expected behavior

`stream_output=False` should always take priority and be respected.

One fix is to update `briefcase.integrations.subprocess.ensure_console_is_safe()` to release control of the console if `kwargs` contains `stream_output=False` the same way it does for batch scripts on Windows.

It isn't enough just to not stream the output of the command; control of the console must be released for the command so e.g. the Wait Bar doesn't interfere with the command's own output.

### Screenshots

_No response_

### Environment

- Operating System: pop os 22.04
- Python version: `3.11.1`
- Software versions:
  - Briefcase: `0.3.12.dev333+gc9409bd9`


### Logs

<details>
<summary>APK Build Log</summary>

```
Date/Time:       2023-01-22 12:56:21 
Command line:    /home/russell/github/beeware/briefcase/venv-3.11-briefcase/bin/briefcase build android -v --log

OS Release:      Linux 6.0.12-76060006-generic
OS Version:      #202212290932~1671652965~22.04~452ea9d SMP PREEMPT_DYNAMIC Wed D
Architecture:    x86_64
Platform:        Linux-6.0.12-76060006-generic-x86_64-with-glibc2.35

Python exe:      /home/russell/github/beeware/briefcase/venv-3.11-briefcase/bin/python
Python version:  3.11.1 (main, Jan 21 2023, 11:32:20) [GCC 11.3.0]
Virtual env:     True
Conda env:       False

Briefcase:       0.3.12.dev333+gc9409bd9
Target platform: android
Target format:   gradle

Environment Variables:
    COLORTERM=truecolor
    CONDA_DEFAULT_ENV=base
    CONDA_EXE=/home/russell/anaconda3/bin/conda
    CONDA_PREFIX=/home/russell/anaconda3
    CONDA_PROMPT_MODIFIER=(base) 
    CONDA_PYTHON_EXE=/home/russell/anaconda3/bin/python
    CONDA_SHLVL=1
    DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
    DEFAULTS_PATH=/usr/share/gconf/pop.default.path
    DESKTOP_SESSION=pop
    DISPLAY=:1
    GDMSESSION=pop
    GIO_LAUNCHED_DESKTOP_FILE_PID=14212
    GNOME_DESKTOP_SESSION_ID=this-is-deprecated
    GNOME_SHELL_SESSION_MODE=pop
    GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
    GTK_IM_MODULE=ibus
    GTK_MODULES=gail:atk-bridge
    HOME=/home/russell
    IBUS_DISABLE_SNOOPER=1
    INVOCATION_ID=fac4f554679b428ca37eb6f29970e105
    JOURNAL_STREAM=8:42865
    LANG=en_US.UTF-8
    LESSCLOSE=/usr/bin/lesspipe %s %s
    LESSOPEN=| /usr/bin/lesspipe %s
    LIBVIRT_DEFAULT_URI=qemu:///system
    LOGNAME=russell
    LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
    MANAGERPID=3263
    MANDATORY_PATH=/usr/share/gconf/pop.mandatory.path
    OLDPWD=/home/russell/tmp/beeware
    PATH=/home/russell/github/beeware/briefcase/venv-3.11-briefcase/bin:/home/russell/.pyenv/plugins/pyenv-virtualenv/shims:/home/russell/.pyenv/shims:/home/russell/anaconda3/bin:/home/russell/anaconda3/condabin:/home/russell/.pyenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/russell/.local/share/JetBrains/Toolbox/scripts
    PS1=
\[[1;36m\]tmp/beeware/testfs\[[0m\] via \[[1;33m\]🐍 \[[0m\]\[[1;33m\]\[[0m\]\[[1;33m\]v3.11.1\[[0m\]\[[1;33m\] \[[0m\]\[[1;33m\](\[[0m\]\[[1;33m\]venv-3.11-briefcase\[[0m\]\[[1;33m\]) \[[0m\]took \[[1;33m\]11s\[[0m\] 
\[[1;31m\]❯\[[0m\] 
    PWD=/home/russell/tmp/beeware/testfs
    PYENV_ROOT=/home/russell/.pyenv
    PYENV_SHELL=bash
    PYENV_VIRTUALENV_INIT=1
    QT_ACCESSIBILITY=1
    QT_IM_MODULE=ibus
    SESSION_MANAGER=local/jupiter:@/tmp/.ICE-unix/3537,unix/jupiter:/tmp/.ICE-unix/3537
    SHELL=/bin/bash
    SHLVL=1
    SSH_AGENT_LAUNCHER=gnome-keyring
    SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
    STARSHIP_SESSION_KEY=********************
    STARSHIP_SHELL=bash
    SYSTEMD_EXEC_PID=3687
    TERM=xterm-256color
    TERMINATOR_DBUS_NAME=net.tenshu.Terminator23558193cd9818af7fe4d2c2f5bd9d00f
    TERMINATOR_DBUS_PATH=/net/tenshu/Terminator2
    TERMINATOR_UUID=urn:uuid:d29abd5b-b2d9-4128-80ca-19292a162e80
    USER=russell
    USERNAME=russell
    VIRTUAL_ENV=/home/russell/github/beeware/briefcase/venv-3.11-briefcase
    VIRTUAL_ENV_PROMPT=(venv-3.11-briefcase) 
    VTE_VERSION=6800
    WINDOWPATH=2
    XAUTHORITY=/run/user/1000/gdm/Xauthority
    XDG_CONFIG_DIRS=/etc/xdg/xdg-pop:/etc/xdg
    XDG_CURRENT_DESKTOP=pop:GNOME
    XDG_DATA_DIRS=/usr/share/pop:/usr/share/gnome:/home/russell/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/
    XDG_MENU_PREFIX=gnome-
    XDG_RUNTIME_DIR=/run/user/1000
    XDG_SESSION_CLASS=user
    XDG_SESSION_DESKTOP=pop
    XDG_SESSION_TYPE=x11
    XMODIFIERS=@im=ibus
    _=/home/russell/github/beeware/briefcase/venv-3.11-briefcase/bin/briefcase
    _CE_CONDA=
    _CE_M=

Briefcase Log:
[12:56:10]                                                                                                                                                             gradle.py:219
           [testfs] Updating app metadata...                                                                                                                           gradle.py:219
           Setting main module... done                                                                                                                                 gradle.py:201
                                                                                                                                                                       gradle.py:222
           [testfs] Building Android APK...                                                                                                                            gradle.py:222
           Downloading the Android emulator...                                                                                                                    android_sdk.py:429
                                                                                                                                                                   subprocess.py:659
           >>> Running Command:                                                                                                                                    subprocess.py:660
           >>>     /home/russell/.cache/briefcase/tools/android_sdk/cmdline-tools/latest/bin/sdkmanager platform-tools emulator                                    subprocess.py:661
           >>> Working Directory:                                                                                                                                  subprocess.py:668
           >>>     /home/russell/tmp/beeware/testfs                                                                                                                subprocess.py:669
           >>> Environment Overrides:                                                                                                                              subprocess.py:678
           >>>     ANDROID_SDK_ROOT=/home/russell/.cache/briefcase/tools/android_sdk                                                                               subprocess.py:680
           >>>     JAVA_HOME=/home/russell/.cache/briefcase/tools/java                                                                                             subprocess.py:680
[12:56:11] Loading package information...                                                                                                                          subprocess.py:633
           Loading local repository...                                                                                                                             subprocess.py:633
           [                                       ] 3% Loading local repository...                                                                                subprocess.py:633
           [                                       ] 3% Fetch remote repository...                                                                                 subprocess.py:633
           [=                                      ] 3% Fetch remote repository...                                                                                 subprocess.py:633
           [=                                      ] 4% Fetch remote repository...                                                                                 subprocess.py:633
           [=                                      ] 5% Fetch remote repository...                                                                                 subprocess.py:633
           [==                                     ] 5% Fetch remote repository...                                                                                 subprocess.py:633
           [==                                     ] 6% Fetch remote repository...                                                                                 subprocess.py:633
           [==                                     ] 7% Fetch remote repository...                                                                                 subprocess.py:633
           [==                                     ] 7% Computing updates...                                                                                       subprocess.py:633
           [===                                    ] 8% Computing updates...                                                                                       subprocess.py:633
           [===                                    ] 10% Computing updates...                                                                                      subprocess.py:633
           [===                                    ] 10% Installing Android Emulator                                                                               subprocess.py:633
           [===                                    ] 10% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [====                                   ] 10% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
[12:56:12] [====                                   ] 11% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [====                                   ] 12% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [=====                                  ] 13% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [=====                                  ] 14% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [=====                                  ] 15% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [======                                 ] 15% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [======                                 ] 16% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [======                                 ] 17% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
[12:56:13] [=======                                ] 18% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [=======                                ] 19% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [=======                                ] 20% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [========                               ] 20% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [========                               ] 21% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [========                               ] 22% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [=========                              ] 23% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
[12:56:14] [=========                              ] 24% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [=========                              ] 25% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [==========                             ] 25% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [==========                             ] 26% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [==========                             ] 27% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [===========                            ] 28% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [===========                            ] 29% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [===========                            ] 30% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [============                           ] 30% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
[12:56:15] [============                           ] 31% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [============                           ] 32% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [============                           ] 33% Downloading emulator-linux_x64-932                                                                        subprocess.py:633
           [============                           ] 33% Unzipping...                                                                                              subprocess.py:633
           [============                           ] 33% Unzipping... emulator/NOTICE.txt                                                                          subprocess.py:633
           [=============                          ] 33% Unzipping... emulator/NOTICE.txt                                                                          subprocess.py:633
           [=============                          ] 33% Unzipping... emulator/NOTICE.csv                                                                          subprocess.py:633
           [=============                          ] 33% Unzipping... emulator/qsn                                                                                 subprocess.py:633
           [=============                          ] 33% Unzipping... emulator/goldfish-web                                                                        subprocess.py:633
           [=============                          ] 34% Unzipping... emulator/goldfish-web                                                                        subprocess.py:633
           [=============                          ] 34% Unzipping... emulator/mksdcard                                                                            subprocess.py:633
           [=============                          ] 34% Unzipping... emulator/emulator64-c                                                                        subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/emulator64-c                                                                        subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/perfetto-pro                                                                        subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/source.prope                                                                        subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/qemu-img                                                                            subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/android-info                                                                        subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/LICENSE                                                                             subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/emulator-che                                                                        subprocess.py:633
           [=============                          ] 35% Unzipping... emulator/emulator                                                                            subprocess.py:633
           [==============                         ] 35% Unzipping... emulator/emulator                                                                            subprocess.py:633
           [==============                         ] 35% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
[12:56:16] [==============                         ] 36% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [==============                         ] 37% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [===============                        ] 38% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [===============                        ] 39% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [===============                        ] 40% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [================                       ] 40% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
[12:56:17] [================                       ] 41% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [================                       ] 42% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [=================                      ] 43% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [=================                      ] 44% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/qemu/linux-x                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/snapshot                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/ui_contr                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/advanced                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/emu-orig                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/snapshot                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/hostapd.                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/waterfal                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/emulator                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/hardware                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/advanced                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/rtc_serv                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/ca-bundl                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib/pc-bios/                                                                        subprocess.py:633
           [=================                      ] 45% Unzipping... emulator/lib64/libsha                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/libsha                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/libc++                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/libima                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/libc++                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/libOpe                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/libtcm                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/libemu                                                                        subprocess.py:633
           [==================                     ] 45% Unzipping... emulator/lib64/gles_s                                                                        subprocess.py:633
           [==================                     ] 46% Unzipping... emulator/lib64/gles_s                                                                        subprocess.py:633
[12:56:18] [==================                     ] 46% Unzipping... emulator/lib64/gles_m                                                                        subprocess.py:633
           [==================                     ] 47% Unzipping... emulator/lib64/gles_m                                                                        subprocess.py:633
           [==================                     ] 47% Unzipping... emulator/lib64/vulkan                                                                        subprocess.py:633
           [===================                    ] 48% Unzipping... emulator/lib64/vulkan                                                                        subprocess.py:633
           [===================                    ] 48% Unzipping... emulator/lib64/qt/plu                                                                        subprocess.py:633
           [===================                    ] 48% Unzipping... emulator/lib64/qt/lib                                                                        subprocess.py:633
           [===================                    ] 49% Unzipping... emulator/lib64/qt/lib                                                                        subprocess.py:633
           [===================                    ] 50% Unzipping... emulator/lib64/qt/lib                                                                        subprocess.py:633
           [====================                   ] 50% Unzipping... emulator/lib64/qt/lib                                                                        subprocess.py:633
           [====================                   ] 51% Unzipping... emulator/lib64/qt/lib                                                                        subprocess.py:633
[12:56:19] [====================                   ] 52% Unzipping... emulator/lib64/qt/lib                                                                        subprocess.py:633
           [=====================                  ] 53% Unzipping... emulator/lib64/qt/lib                                                                        subprocess.py:633
           [=====================                  ] 53% Unzipping... emulator/lib64/qt/tra                                                                        subprocess.py:633
           [=====================                  ] 53% Unzipping... emulator/lib64/qt/res                                                                        subprocess.py:633
           [=====================                  ] 54% Unzipping... emulator/lib64/qt/res                                                                        subprocess.py:633
           [=====================                  ] 54% Unzipping... emulator/resources/To                                                                        subprocess.py:633
           [=====================                  ] 54% Unzipping... emulator/resources/po                                                                        subprocess.py:633
           [=====================                  ] 54% Unzipping... emulator/resources/To                                                                        subprocess.py:633
           [=====================                  ] 55% Unzipping... emulator/resources/To                                                                        subprocess.py:633
           [=====================                  ] 55% Unzipping... emulator/resources/ma                                                                        subprocess.py:633
           [=====================                  ] 55% Unzipping... emulator/bin64/e2fsck                                                                        subprocess.py:633
           [=====================                  ] 55% Unzipping... emulator/bin64/mkfs.e                                                                        subprocess.py:633
           [=====================                  ] 55% Unzipping... emulator/bin64/resize                                                                        subprocess.py:633
           [=====================                  ] 55% Unzipping... emulator/bin64/fsck.e                                                                        subprocess.py:633
           [=====================                  ] 55% Unzipping... emulator/bin64/tune2f                                                                        subprocess.py:633
           [=======================================] 100% Unzipping... emulator/bin64/tune2                                                                        subprocess.py:633
           >>> Return code: 0                                                                                                                                      subprocess.py:696
                                                                                                                                                                   subprocess.py:659
           >>> Running Command:                                                                                                                                    subprocess.py:660
           >>>     '/home/russell/tmp/beeware/testfs/android/gradle/Hello World/gradlew' assembleDebug --console plain                                             subprocess.py:661
           >>> Working Directory:                                                                                                                                  subprocess.py:668
           >>>     /home/russell/tmp/beeware/testfs/android/gradle/Hello World                                                                                     subprocess.py:669
           >>> Environment Overrides:                                                                                                                              subprocess.py:678
           >>>     ANDROID_SDK_ROOT=/home/russell/.cache/briefcase/tools/android_sdk                                                                               subprocess.py:680
           >>>     JAVA_HOME=/home/russell/.cache/briefcase/tools/java                                                                                             subprocess.py:680
[12:56:20]                                                                                                                                                         subprocess.py:633
           > Configure project :app                                                                                                                                subprocess.py:633
           Warning: Python version 3.11 may have fewer packages available. If you experience problems, try switching to version 3.8.                               subprocess.py:633
                                                                                                                                                                   subprocess.py:633
           > Task :app:preBuild UP-TO-DATE                                                                                                                         subprocess.py:633
           > Task :app:preDebugBuild UP-TO-DATE                                                                                                                    subprocess.py:633
           > Task :app:compileDebugAidl NO-SOURCE                                                                                                                  subprocess.py:633
           > Task :app:compileDebugRenderscript NO-SOURCE                                                                                                          subprocess.py:633
           > Task :app:generateDebugBuildConfig UP-TO-DATE                                                                                                         subprocess.py:633
           > Task :app:extractPythonBuildPackages UP-TO-DATE                                                                                                       subprocess.py:633
           > Task :app:generateDebugPythonRequirements UP-TO-DATE                                                                                                  subprocess.py:633
           > Task :app:mergeDebugPythonSources UP-TO-DATE                                                                                                          subprocess.py:633
           > Task :app:generateDebugPythonProxies UP-TO-DATE                                                                                                       subprocess.py:633
           > Task :app:javaPreCompileDebug UP-TO-DATE                                                                                                              subprocess.py:633
           > Task :app:checkDebugAarMetadata UP-TO-DATE                                                                                                            subprocess.py:633
           > Task :app:generateDebugResValues UP-TO-DATE                                                                                                           subprocess.py:633
           > Task :app:generateDebugResources UP-TO-DATE                                                                                                           subprocess.py:633
           > Task :app:mergeDebugResources UP-TO-DATE                                                                                                              subprocess.py:633
           > Task :app:createDebugCompatibleScreenManifests UP-TO-DATE                                                                                             subprocess.py:633
           > Task :app:extractDeepLinksDebug UP-TO-DATE                                                                                                            subprocess.py:633
           > Task :app:processDebugMainManifest UP-TO-DATE                                                                                                         subprocess.py:633
           > Task :app:processDebugManifest UP-TO-DATE                                                                                                             subprocess.py:633
           > Task :app:processDebugManifestForPackage UP-TO-DATE                                                                                                   subprocess.py:633
           > Task :app:processDebugResources UP-TO-DATE                                                                                                            subprocess.py:633
           > Task :app:compileDebugJavaWithJavac UP-TO-DATE                                                                                                        subprocess.py:633
           > Task :app:generateJsonModelDebug                                                                                                                      subprocess.py:633
                                                                                                                                                                   subprocess.py:633
           > Task :app:externalNativeBuildDebug                                                                                                                    subprocess.py:633
           Build native-lib_armeabi-v7a                                                                                                                            subprocess.py:633
           ninja: Entering directory `/home/russell/tmp/beeware/testfs/android/gradle/Hello World/app/.cxx/cmake/debug/armeabi-v7a'                                subprocess.py:633
           Build native-lib_arm64-v8a                                                                                                                              subprocess.py:633
           ninja: Entering directory `/home/russell/tmp/beeware/testfs/android/gradle/Hello World/app/.cxx/cmake/debug/arm64-v8a'                                  subprocess.py:633
           Build native-lib_x86_64                                                                                                                                 subprocess.py:633
           ninja: Entering directory `/home/russell/tmp/beeware/testfs/android/gradle/Hello World/app/.cxx/cmake/debug/x86_64'                                     subprocess.py:633
                                                                                                                                                                   subprocess.py:633
           > Task :app:compileDebugSources                                                                                                                         subprocess.py:633
           > Task :app:mergeDebugNativeDebugMetadata NO-SOURCE                                                                                                     subprocess.py:633
           > Task :app:mergeDebugShaders UP-TO-DATE                                                                                                                subprocess.py:633
           > Task :app:compileDebugShaders NO-SOURCE                                                                                                               subprocess.py:633
           > Task :app:generateDebugAssets UP-TO-DATE                                                                                                              subprocess.py:633
           > Task :app:generateDebugPythonAppAssets UP-TO-DATE                                                                                                     subprocess.py:633
           > Task :app:generateDebugPythonMiscAssets UP-TO-DATE                                                                                                    subprocess.py:633
           > Task :app:generateDebugPythonRequirementsAssets UP-TO-DATE                                                                                            subprocess.py:633
           > Task :app:generateDebugPythonBuildAssets UP-TO-DATE                                                                                                   subprocess.py:633
           > Task :app:mergeDebugAssets UP-TO-DATE                                                                                                                 subprocess.py:633
           > Task :app:compressDebugAssets UP-TO-DATE                                                                                                              subprocess.py:633
           > Task :app:processDebugJavaRes NO-SOURCE                                                                                                               subprocess.py:633
           > Task :app:mergeDebugJavaResource UP-TO-DATE                                                                                                           subprocess.py:633
           > Task :app:checkDebugDuplicateClasses UP-TO-DATE                                                                                                       subprocess.py:633
           > Task :app:desugarDebugFileDependencies UP-TO-DATE                                                                                                     subprocess.py:633
           > Task :app:mergeExtDexDebug UP-TO-DATE                                                                                                                 subprocess.py:633
           > Task :app:mergeLibDexDebug UP-TO-DATE                                                                                                                 subprocess.py:633
           > Task :app:dexBuilderDebug UP-TO-DATE                                                                                                                  subprocess.py:633
           > Task :app:mergeProjectDexDebug UP-TO-DATE                                                                                                             subprocess.py:633
           > Task :app:generateDebugPythonJniLibs UP-TO-DATE                                                                                                       subprocess.py:633
           > Task :app:mergeDebugJniLibFolders UP-TO-DATE                                                                                                          subprocess.py:633
           > Task :app:mergeDebugNativeLibs UP-TO-DATE                                                                                                             subprocess.py:633
           > Task :app:stripDebugDebugSymbols UP-TO-DATE                                                                                                           subprocess.py:633
           > Task :app:validateSigningDebug UP-TO-DATE                                                                                                             subprocess.py:633
[12:56:21] > Task :app:writeDebugAppMetadata UP-TO-DATE                                                                                                            subprocess.py:633
           > Task :app:writeDebugSigningConfigVersions UP-TO-DATE                                                                                                  subprocess.py:633
           > Task :app:packageDebug UP-TO-DATE                                                                                                                     subprocess.py:633
           > Task :app:assembleDebug                                                                                                                               subprocess.py:633
                                                                                                                                                                   subprocess.py:633
           BUILD SUCCESSFUL in 614ms                                                                                                                               subprocess.py:633
           40 actionable tasks: 2 executed, 38 up-to-date                                                                                                          subprocess.py:633
           >>> Return code: 0                                                                                                                                      subprocess.py:696
           Building... done                                                                                                                                            gradle.py:223
                                                                                                                                                                         build.py:73
           [testfs] Built android/gradle/Hello World/app/build/outputs/apk/debug/app-debug.apk                                                                           build.py:73
                                                                                                                                                                      console.py:279
           >>> Extra information:                                                                                                                                     console.py:280
                                                                                                                                                                   subprocess.py:659
           >>> Running Command:                                                                                                                                    subprocess.py:660
           >>>     /home/russell/.cache/briefcase/tools/android_sdk/cmdline-tools/latest/bin/sdkmanager --list_installed                                           subprocess.py:661
           >>> Working Directory:                                                                                                                                  subprocess.py:668
           >>>     /home/russell/tmp/beeware/testfs                                                                                                                subprocess.py:669
           >>> Environment Overrides:                                                                                                                              subprocess.py:678
           >>>     ANDROID_SDK_ROOT=/home/russell/.cache/briefcase/tools/android_sdk                                                                               subprocess.py:680
           >>>     JAVA_HOME=/home/russell/.cache/briefcase/tools/java                                                                                             subprocess.py:680
           >>> Command Output:                                                                                                                                     subprocess.py:685
           >>>     Loading package information...                                                                                                                  subprocess.py:687
           >>>     Loading local repository...                                                                                                                     subprocess.py:687
           >>>     [=========                              ] 25% Loading local repository...                                                                       subprocess.py:687
           >>>     [=========                              ] 25% Fetch remote repository...                                                                        subprocess.py:687
           >>>     [=======================================] 100% Fetch remote repository...                                                                       subprocess.py:687
           >>>     Installed packages:                                                                                                                             subprocess.py:687
           >>>       Path                 | Version      | Description                     | Location                                                              subprocess.py:687
           >>>       -------              | -------      | -------                         | -------                                                               subprocess.py:687
           >>>       build-tools;30.0.2   | 30.0.2       | Android SDK Build-Tools 30.0.2  | build-tools/30.0.2                                                    subprocess.py:687
           >>>       cmake;3.10.2.4988404 | 3.10.2       | CMake 3.10.2.4988404            | cmake/3.10.2.4988404                                                  subprocess.py:687
           >>>       emulator             | 31.3.14      | Android Emulator                | emulator                                                              subprocess.py:687
           >>>       ndk;25.1.8937393     | 25.1.8937393 | NDK (Side by side) 25.1.8937393 | ndk/25.1.8937393                                                      subprocess.py:687
           >>>       patcher;v4           | 1            | SDK Patch Applier v4            | patcher/v4                                                            subprocess.py:687
           >>>       platform-tools       | 33.0.3       | Android SDK Platform-Tools      | platform-tools                                                        subprocess.py:687
           >>>       platforms;android-33 | 2            | Android SDK Platform 33         | platforms/android-33                                                  subprocess.py:687
           >>>                                                                                                                                                     subprocess.py:687
           >>> Return code: 0                                                                                                                                      subprocess.py:696

```

</details>

### Additional context

_No response_

Discussion:

Patch:
diff --git a/changes/1055.bugfix.rst b/changes/1055.bugfix.rst
new file mode 100644
index 00000000..385ab903
--- /dev/null
+++ b/changes/1055.bugfix.rst
@@ -0,0 +1,1 @@
+To prevent console corruption, dynamic console elements, such as the Wait Bar, are temporarily removed when output streaming is disabled for a command.
diff --git a/src/briefcase/integrations/subprocess.py b/src/briefcase/integrations/subprocess.py
index 23993372..637eee3f 100644
--- a/src/briefcase/integrations/subprocess.py
+++ b/src/briefcase/integrations/subprocess.py
@@ -124,7 +124,10 @@ def ensure_console_is_safe(sub_method):
         # such as the Wait Bar can hide this message from the user.
         if sub.tools.host_os == "Windows":
             executable = str(args[0]).strip() if args else ""
-            remove_dynamic_elements = executable.lower().endswith(".bat")
+            remove_dynamic_elements |= executable.lower().endswith(".bat")
+
+        # Release control for commands that cannot be streamed.
+        remove_dynamic_elements |= kwargs.get("stream_output") is False
 
         # Run subprocess command with or without console control
         if remove_dynamic_elements:
@@ -375,14 +378,11 @@ class Subprocess(Tool):
         :param kwargs: keyword args for subprocess.run()
         :return: `CompletedProcess` for invoked process
         """
-        # If `stream_output` or dynamic screen content (e.g. the Wait Bar) is
-        # active and output is not redirected, use run with output streaming.
-        is_output_redirected = kwargs.get("capture_output") or (
-            kwargs.get("stdout") and kwargs.get("stderr")
-        )
-        if stream_output or (
-            self.tools.input.is_console_controlled and not is_output_redirected
-        ):
+
+        # Stream the output unless the caller explicitly disables it. When a
+        # caller sets stream_output=False, then ensure_console_is_safe() will
+        # disable any dynamic console elements while the command runs.
+        if stream_output:
             return self._run_and_stream_output(args, **kwargs)
 
         # Otherwise, invoke run() normally.


Test patch:
diff --git a/tests/integrations/subprocess/test_Subprocess__run__controlled_console.py b/tests/integrations/subprocess/test_Subprocess__run__controlled_console.py
index e277f958..ba04afa1 100644
--- a/tests/integrations/subprocess/test_Subprocess__run__controlled_console.py
+++ b/tests/integrations/subprocess/test_Subprocess__run__controlled_console.py
@@ -5,17 +5,12 @@ from unittest.mock import ANY
 
 import pytest
 
-#####
-# These tests are run with stream_output=False to ensure it is the
-# Wait Bar that influences the control flow of Subprocess.run().
-#####
-
 
 def test_call(mock_sub, capsys):
     """A simple call will be invoked."""
 
     with mock_sub.tools.input.wait_bar():
-        mock_sub.run(["hello", "world"], stream_output=False)
+        mock_sub.run(["hello", "world"])
 
     mock_sub._subprocess.Popen.assert_called_with(
         ["hello", "world"],
@@ -40,7 +35,7 @@ def test_call_with_arg(mock_sub, capsys):
     """Any extra keyword arguments are passed through as-is."""
 
     with mock_sub.tools.input.wait_bar():
-        mock_sub.run(["hello", "world"], universal_newlines=True, stream_output=False)
+        mock_sub.run(["hello", "world"], universal_newlines=True)
 
     mock_sub._subprocess.Popen.assert_called_with(
         ["hello", "world"],
@@ -66,7 +61,7 @@ def test_debug_call(mock_sub, capsys):
     mock_sub.tools.logger.verbosity = 2
 
     with mock_sub.tools.input.wait_bar():
-        mock_sub.run(["hello", "world"], stream_output=False)
+        mock_sub.run(["hello", "world"])
 
     mock_sub._subprocess.Popen.assert_called_with(
         ["hello", "world"],
@@ -102,7 +97,6 @@ def test_debug_call_with_env(mock_sub, capsys, tmp_path):
             ["hello", "world"],
             env=env,
             cwd=tmp_path / "cwd",
-            stream_output=False,
         )
 
     merged_env = mock_sub.tools.os.environ.copy()
@@ -153,7 +147,7 @@ def test_text_eq_true_default_overriding(mock_sub, in_kwargs, kwargs):
     """if text or universal_newlines is explicitly provided, those should
     override text=true default."""
     with mock_sub.tools.input.wait_bar():
-        mock_sub.run(["hello", "world"], **in_kwargs, stream_output=False)
+        mock_sub.run(["hello", "world"], **in_kwargs)
 
     mock_sub._subprocess.Popen.assert_called_with(
         ["hello", "world"],
@@ -172,7 +166,6 @@ def test_stderr_is_redirected(mock_sub, streaming_process, capsys):
         run_result = mock_sub.run(
             ["hello", "world"],
             stderr=subprocess.PIPE,
-            stream_output=False,
         )
 
     mock_sub._subprocess.Popen.assert_called_with(
@@ -203,7 +196,6 @@ def test_stderr_dev_null(mock_sub, streaming_process, capsys):
         run_result = mock_sub.run(
             ["hello", "world"],
             stderr=subprocess.DEVNULL,
-            stream_output=False,
         )
 
     mock_sub._subprocess.Popen.assert_called_with(
@@ -238,7 +230,6 @@ def test_calledprocesserror(mock_sub, streaming_process, capsys):
                 ["hello", "world"],
                 check=True,
                 stderr=subprocess.PIPE,
-                stream_output=False,
             )
 
     # fmt: off
@@ -262,31 +253,9 @@ def test_invalid_invocations(mock_sub):
             mock_sub.run(
                 ["hello", "world"],
                 stdout=subprocess.PIPE,
-                stream_output=False,
             )
 
     for invalid_arg in ("timeout", "input"):
         with pytest.raises(AssertionError):
             with mock_sub.tools.input.wait_bar():
                 mock_sub.run(["hello", "world"], **{invalid_arg: "value"})
-
-
-@pytest.mark.parametrize(
-    "redirected_kwargs",
-    [
-        dict(capture_output=True),
-        dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE),
-        dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT),
-        dict(stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL),
-        dict(stdout=-1, stderr=-1),
-    ],
-)
-def test_redirected_output(mock_sub, redirected_kwargs, capsys):
-    """Output is not streamed if it is redirected."""
-    with mock_sub.tools.input.wait_bar():
-        mock_sub.run(["hello", "world"], stream_output=False, **redirected_kwargs)
-
-    mock_sub._subprocess.run.assert_called_with(
-        ["hello", "world"], text=True, encoding=ANY, **redirected_kwargs
-    )
-    assert capsys.readouterr().out == "\n"
diff --git a/tests/integrations/subprocess/test_ensure_console_is_safe.py b/tests/integrations/subprocess/test_ensure_console_is_safe.py
index 26c2cabd..5fde772a 100644
--- a/tests/integrations/subprocess/test_ensure_console_is_safe.py
+++ b/tests/integrations/subprocess/test_ensure_console_is_safe.py
@@ -34,7 +34,7 @@ def test_run_windows_batch_script(mock_sub, batch_script):
 def test_check_output_windows_batch_script(mock_sub, batch_script):
     """Console control is released for a Windows batch script in
     check_output."""
-    # Console control is only released on Windows
+    # Console control is only released on Windows for batch scripts
     mock_sub.tools.host_os = "Windows"
 
     with mock_sub.tools.input.wait_bar("Testing..."):
@@ -48,6 +48,30 @@ def test_check_output_windows_batch_script(mock_sub, batch_script):
     mock_sub.tools.input.release_console_control.assert_called_once()
 
 
+@pytest.mark.parametrize("sub_kwargs", [{"stream_output": True}, {}])
+def test_run_stream_output_true(mock_sub, sub_kwargs):
+    """Console control is not released when stream_output=True or is
+    unspecified."""
+    with mock_sub.tools.input.wait_bar("Testing..."):
+        mock_sub.run(["Hello", "World"], **sub_kwargs)
+
+    mock_sub._run_and_stream_output.assert_called_with(["Hello", "World"])
+    mock_sub.tools.input.release_console_control.assert_not_called()
+
+
+def test_run_stream_output_false(mock_sub):
+    """Console control is released when stream_output=False."""
+    with mock_sub.tools.input.wait_bar("Testing..."):
+        mock_sub.run(["Hello", "World"], stream_output=False)
+
+    mock_sub._subprocess.run.assert_called_with(
+        ["Hello", "World"],
+        text=True,
+        encoding=ANY,
+    )
+    mock_sub.tools.input.release_console_control.assert_called_once()
+
+
 @pytest.mark.parametrize(
     "cmdline, kwargs",
     [