Repository: flutter
Issue: Better error message for not connecting to Android debug device - WIFI debugging
Labels: c: crash,platform-android,tool,a: debugging,c: proposal,P2,team-android,triaged-android

### Steps to reproduce

1. Connect a physical Android device to debug
2. Leave it there unattended for some time until it shows on `flutter doctor -v` that it is offline (maybe only happens on wifi debugging?)
3. Try to debug a project with `flutter run -v`
4. See the output below (logs).

About point _two_ here, not sure this is exactly when you can see this output. Look https://github.com/Dart-Code/Dart-Code/issues/5245 for more info. It happens to me whenever I have left my phone lock the screen by itself and have not used it for some time. If I lock it manually or recently this does not happen.

### Expected results

`Device is offline` message. Or some better message handling when not in verbose mode.

### Actual results

`Connection closed before full header was received` message _only in verbose mode_.

### Code sample

Not important.

### Screenshots or Video

Not important.

### Logs

<details open><summary>Logs</summary>

```console
[   +1 ms] Latest build already installed.
[        ] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:42307 shell -x logcat -v time -t 1
[ +355 ms] --------- beginning of system
                    09-02 17:13:23.818 I/wpa_supplicant( 1637): Heartbeat 62
[  +13 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:42307 shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x20000000 --ez enable-dart-profiling true   
--ez enable-checked-mode true --ez verify-entry-points true br.inf.sunsoft.produtores/br.inf.sunsoft.produtores.MainActivity
[ +157 ms] Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x20000000 cmp=br.inf.sunsoft.produtores/.MainActivity (has extras) }
[        ] Waiting for VM Service port to be available...
[+1327 ms] VM Service URL on device: http://127.0.0.1:45599/PSAwNkkAsUk=/
[   +1 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:42307 forward tcp:0 tcp:45599
[  +61 ms] 50529
[   +1 ms] Forwarded host port 50529 to device port 45599 for VM Service
[   +3 ms] Caching compiled dill
[  +78 ms] Connecting to service protocol: http://127.0.0.1:50529/PSAwNkkAsUk=/
[+31591 ms] Fail to connect to service protocol: http://127.0.0.1:50529/PSAwNkkAsUk=/: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:50529/PSAwNkkAsUk=/ws
[   +2 ms] Error connecting to the service protocol: failed to connect to http://127.0.0.1:50529/PSAwNkkAsUk=/
[  +21 ms] "flutter run" took 66.603ms.
[ +176 ms] 
                    #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
                    #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:874:9)
                    <asynchronous suspension>
                    #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1408:27)
                    <asynchronous suspension>
                    #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
                    <asynchronous suspension>
                    #4      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
                    <asynchronous suspension>
                    #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:420:9)
                    <asynchronous suspension>
                    #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
                    <asynchronous suspension>
                    #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:364:5)
                    <asynchronous suspension>
                    #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
                    <asynchronous suspension>
                    #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
                    <asynchronous suspension>
                    #10     main (package:flutter_tools/executable.dart:93:3)
                    <asynchronous suspension>


[  +46 ms] I/flutter (16413): Drift: Sent SELECT * FROM sqlite_master; with args []
[   +2 ms] I/flutter (16413): Drift: Sent select 1 with args []
[ +211 ms] ensureAnalyticsSent: 253ms
[   +1 ms] Running 2 shutdown hooks
[   +5 ms] Shutdown hooks complete
[  +26 ms] exiting with code 2
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.24.1, on Microsoft Windows [Version 10.0.22631.4037], locale pt-BR)
    • Flutter version 3.24.1 on channel stable at C:\Users\felip_0vh5fa6\.puro\envs\stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (2 weeks ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Users\felip_0vh5fa6\AppData\Local\Programs\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.6)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.35201.131
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)

[√] VS Code (version 1.92.2)
    • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.92.0

[√] VS Code (version 1.88.0-insider)
    • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code Insiders
    • Flutter extension version 3.64.0

[√] Connected device (4 available)
    • SM G780F (mobile) • 192.168.200.50:41835 • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows              • windows-x64    • Microsoft Windows [Version 10.0.22631.4037]
    • Chrome (web)      • chrome               • web-javascript • Google Chrome 128.0.6613.114
    • Edge (web)        • edge                 • web-javascript • Microsoft Edge 128.0.2739.42
    ! Device 192.168.200.50:39975 is offline.

[√] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>