Repository: flutter
Issue: [Android] Keyboard input failure on physical Android devices after screen lock/unlock
Labels: a: text input,e: device-specific,platform-android,engine,has reproducible steps,P2,workaround available,team-android,triaged-android,found in release: 3.13,found in release: 3.16

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. Execute flutter run.
2. Focus TextField. Keyboard appears. Type something.
3. Lock android screen by pressing Power button.
4. Unlock android screen.
5. Type something again.

### Expected results

Keyboard input occurs in TextField

### Actual results

Keyboard input is not performed and is restored only after re-focusing on the TextField

This problem occurs only on physical devices.
List of devices on which this was noticed:
1) Readme 9A (Android 10, MIUI Global 12.0.17)
2) Nokia 5.3 (Android 11)
3) ZTE Smart 20 blade

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(child: TextField()),
    );
  }
}
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/49119428/6524f527-2c93-4b68-bcf0-fa146dd55e51

</details>



### Logs

<details><summary>Logs</summary>

```console
[+2216 ms] I/e.test_keyboar( 9779): ProcessProfilingInfo new_methods=15 is saved saved_to_disk=1 resolve_classes_delay=8000
[+122037 ms] V/PhoneWindow( 9779): DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@6f70371, this = DecorView@49f1556[MainActivity]
[  +44 ms] D/libMEOW ( 9779): applied 0 plugin for [com.example.test_keyboard].
[   +9 ms] D/SurfaceView( 9779): UPDATE null, mIsCastMode = false
[  +16 ms] D/libMEOW ( 9779): applied 0 plugin for [com.example.test_keyboard].
[        ] D/Surface ( 9779): Surface::connect(this=0xd868b000,api=1)
[  +18 ms] W/Gralloc3( 9779): mapper 3.x is not supported
[   +1 ms] D/Surface ( 9779): Surface::connect(this=0xd865f000,api=1)
[  +14 ms] E/ion     ( 9779): ioctl c0044901 failed with code -1: Invalid argument
[   +5 ms] D/Surface ( 9779): Surface::setBufferCount(this=0xd865f000,bufferCount=3)
[  +23 ms] D/ViewRootImpl( 9779): setSurfaceViewCreated, created:true
[+2011 ms] I/AssistStructure( 9779): Flattened final assist data: 460 bytes, containing 1 windows, 3 views
[ +127 ms] E/SpannableStringBuilder( 9779): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
[        ] E/SpannableStringBuilder( 9779): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
[   +5 ms] E/SpannableStringBuilder( 9779): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
[   +7 ms] E/SpannableStringBuilder( 9779): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
[   +9 ms] E/SpannableStringBuilder( 9779): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
[        ] E/SpannableStringBuilder( 9779): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
[+2612 ms] W/IInputConnectionWrapper( 9779): getExtractedText on inactive InputConnection
[   +2 ms] W/IInputConnectionWrapper( 9779): getTextBeforeCursor on inactive InputConnection
[   +1 ms] W/IInputConnectionWrapper( 9779): getExtractedText on inactive InputConnection
[   +2 ms] W/IInputConnectionWrapper( 9779): getTextBeforeCursor on inactive InputConnection
[ +423 ms] D/Surface ( 9779): Surface::disconnect(this=0xd868b000,api=1)
[   +7 ms] D/ViewRootImpl( 9779): setSurfaceViewCreated, created:false
[        ] D/Surface ( 9779): Surface::disconnect(this=0xd868b000,api=-1)
[  +20 ms] I/GED     ( 9779): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 2, oppidx_max 2, oppidx_min 0
[ +199 ms] D/Surface ( 9779): Surface::disconnect(this=0xd865f000,api=1)
[  +24 ms] D/Surface ( 9779): Surface::connect(this=0xd865f800,api=1)
[   +1 ms] D/Surface ( 9779): Surface::setBufferCount(this=0xd865f800,bufferCount=3)
[   +8 ms] D/Surface ( 9779): Surface::connect(this=0xd868b800,api=1)
[   +6 ms] D/ViewRootImpl( 9779): setSurfaceViewCreated, created:true
[  +45 ms] V/PhoneWindow( 9779): DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@6f70371, this = DecorView@49f1556[MainActivity]
[ +326 ms] D/Surface ( 9779): Surface::disconnect(this=0xd868b800,api=1)
[   +5 ms] D/ViewRootImpl( 9779): setSurfaceViewCreated, created:false
[        ] D/Surface ( 9779): Surface::disconnect(this=0xd868b800,api=-1)
[   +3 ms] D/Surface ( 9779): Surface::disconnect(this=0xd865f800,api=1)
[  +23 ms] I/GED     ( 9779): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 2, oppidx_max 2, oppidx_min 0
[  +12 ms] V/PhoneWindow( 9779): DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@6f70371, this = DecorView@49f1556[MainActivity]
[ +618 ms] V/PhoneWindow( 9779): DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@6f70371, this = DecorView@49f1556[MainActivity]
[  +18 ms] D/Surface ( 9779): Surface::connect(this=0xd865f800,api=1)
[   +1 ms] D/Surface ( 9779): Surface::setBufferCount(this=0xd865f800,bufferCount=3)
[  +13 ms] D/Surface ( 9779): Surface::connect(this=0xe8a4f000,api=1)
[   +4 ms] D/ViewRootImpl( 9779): setSurfaceViewCreated, created:true
[ +987 ms] V/ViewRootImpl[MainActivity]( 9779): [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 07:00:00.000, this =
com.mediatek.view.impl.ViewDebugManagerImpl@28241d8
[   +1 ms] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@d73f6b6 at 2023-11-01 14:13:40.121
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@601c324 at 2023-11-01 14:13:40.122
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@c370e51 at 2023-11-01 14:13:40.118
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@64fafb7 at 2023-11-01 14:13:40.121
[ +103 ms] V/ViewRootImpl[MainActivity]( 9779): [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 07:00:00.000, this =
com.mediatek.view.impl.ViewDebugManagerImpl@28241d8
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@d73f6b6 at 2023-11-01 14:13:40.283
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@601c324 at 2023-11-01 14:13:40.283
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@c370e51 at 2023-11-01 14:13:40.282
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@64fafb7 at 2023-11-01 14:13:40.283
[ +155 ms] V/ViewRootImpl[MainActivity]( 9779): [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 07:00:00.000, this =
com.mediatek.view.impl.ViewDebugManagerImpl@28241d8
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@d73f6b6 at 2023-11-01 14:13:40.434
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@601c324 at 2023-11-01 14:13:40.434
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@c370e51 at 2023-11-01 14:13:40.434
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@64fafb7 at 2023-11-01 14:13:40.434
[ +139 ms] V/ViewRootImpl[MainActivity]( 9779): [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 07:00:00.000, this =
com.mediatek.view.impl.ViewDebugManagerImpl@28241d8
[   +4 ms] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@d73f6b6 at 2023-11-01 14:13:40.580
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@601c324 at 2023-11-01 14:13:40.580
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@c370e51 at 2023-11-01 14:13:40.579
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@64fafb7 at 2023-11-01 14:13:40.580
[ +139 ms] V/ViewRootImpl[MainActivity]( 9779): [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 07:00:00.000, this =
com.mediatek.view.impl.ViewDebugManagerImpl@28241d8
[   +1 ms] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@d73f6b6 at 2023-11-01 14:13:40.723
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@601c324 at 2023-11-01 14:13:40.723
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@c370e51 at 2023-11-01 14:13:40.723
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@64fafb7 at 2023-11-01 14:13:40.723
[ +181 ms] V/ViewRootImpl[MainActivity]( 9779): [ANR Warning]Input routeing takes more than 6000ms since 1970-01-01 07:00:00.000, this =
com.mediatek.view.impl.ViewDebugManagerImpl@28241d8
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$NativePostImeInputStage@d73f6b6 at 2023-11-01 14:13:40.909
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$SyntheticInputStage@601c324 at 2023-11-01 14:13:40.910
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$EarlyPostImeInputStage@c370e51 at 2023-11-01 14:13:40.909
[        ] V/ViewRootImpl[MainActivity]( 9779): Input event delivered to android.view.ViewRootImpl$ViewPostImeInputStage@64fafb7 at 2023-11-01 14:13:40.909
[+1991 ms] W/IInputConnectionWrapper( 9779): getExtractedText on inactive InputConnection
[        ] W/IInputConnectionWrapper( 9779): getTextBeforeCursor on inactive InputConnection
[   +2 ms] W/IInputConnectionWrapper( 9779): getExtractedText on inactive InputConnection
[   +3 ms] W/IInputConnectionWrapper( 9779): getTextBeforeCursor on inactive InputConnection
[ +455 ms] D/Surface ( 9779): Surface::disconnect(this=0xe8a4f000,api=1)
[        ] D/ViewRootImpl( 9779): setSurfaceViewCreated, created:false
[        ] D/Surface ( 9779): Surface::disconnect(this=0xe8a4f000,api=-1)
[  +50 ms] I/GED     ( 9779): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 2, oppidx_max 2, oppidx_min 0
[ +279 ms] V/PhoneWindow( 9779): DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@6f70371, this = DecorView@49f1556[MainActivity]
[  +21 ms] D/Surface ( 9779): Surface::disconnect(this=0xd865f800,api=1)

```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[!] Flutter (Channel stable, 3.13.9, on macOS 14.0 23A344 darwin-arm64, locale ru-RU)
    • Flutter version 3.13.9 on channel stable at /Users/andrejkurakov/fvm/versions/3.13.9
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.1.4/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/andrejkurakov/fvm/versions/3.13.9. Consider adding /Users/andrejkurakov/fvm/versions/3.13.9/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (6 days ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/andrejkurakov/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Users/andrejkurakov/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10406996/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/andrejkurakov/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10406996/Android Studio.app/Contents
    • 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.6+0-17.0.6b829.9-10027231)

[✓] Android Studio (version 2022.3)
    • Android Studio at /Users/andrejkurakov/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/223.8836.35.2231.10811636/Android Studio.app/Contents
    • 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.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Community Edition (version 2022.2.3)
    • IntelliJ at /Users/andrejkurakov/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/222.4345.14/IntelliJ IDEA CE.app
    • 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

[✓] IntelliJ IDEA Community Edition (version 2022.3.2)
    • IntelliJ at /Users/andrejkurakov/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/223.8617.56/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.83.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • iPhone (Андрей) (2) (mobile) • 00008101-000E64693E46001E • ios            • iOS 17.0.3 21A360
    • macOS (desktop)              • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)                 • chrome                    • web-javascript • Google Chrome 118.0.5993.117

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>