Skip to content

[Android]Avoid clipboard reading permissions on XiaoMi MIUI 13 #101196

Open

Description

@Linloir

I'm developing an app that doesn't really need the clipboard permission, but I can't get rid of the system alert of clipboard reading.

Ways I have tried to fix the problem

  • switch to master channel
  • run flutter upgrade
  • set enableInteractiveSelection flag to false in TextField widget

Nothing has yet worked on my device nor my friend's

Steps to Reproduce

  1. Connect a XiaoMi device with MIUI 13 installed
  2. Execute flutter debug on the code sample
  3. Copy any text from another place
  4. Open the debug app just built and the alert pops up

Expected results:
Textfield without reading clipboard

Actual results:
Textfield still reading clipboard everytime it inits

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: TextField()
      ),
    );
  }
}
Flutter doctor
[✓] Flutter (Channel master, 2.13.0-0.0.pre.358, on Ubuntu 20.04.4 LTS
    5.11.0-27-generic, locale en_US.UTF-8)
    • Flutter version 2.13.0-0.0.pre.358 at /home/linloir/SDK/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff08bc4e85 (87 minutes ago), 2022-04-01 10:31:09 -0400
    • Engine revision 276261e5d8
    • Dart version 2.17.0 (build 2.17.0-263.0.dev)
    • DevTools version 2.12.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
    • Android SDK at /home/linloir/Android/Sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /snap/android-studio/119/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /snap/android-studio/119/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 11.0.11+0-b60-7590822)

[✓] VS Code (version 1.64.2)
    • VS Code at /usr/share/code
    • Flutter extension version 3.36.0

[✓] Connected device (2 available)
    • M2007J1SC (mobile) • c0063973 • android-arm64  • Android 12 (API 31)
    • Chrome (web)       • chrome   • web-javascript • Google Chrome
      98.0.4758.102

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Activity

  1. changed the title [-]Flutter reads clipboard on XiaoMi MIUI 13[/-] [+]Avoid reading clipboard on XiaoMi MIUI 13[/+] on Apr 1, 2022
  2. Linloir commented on Apr 1, 2022

    @Linloir
    Author

    I'm really sorry to post a similar issue to #74139, #85610 and #91591

    But after checking the solutions commented in those issues which appears to be the same: change to master channel and upgrade, nothing has worked for me

  3. maheshj01 commented on Apr 4, 2022

    @maheshj01
    Member

    Hi @Linloir, Thanks for filing the issue. Unfortunately none of us on the triage team have a miui 13 to reproduce this issue. We verified on Xiaomi k20 pro (Android 11) miui 12.5 on the latest stable/master channel and the issue was not reproducible. I did try restarting and minimizing the app but it was not reproducible. Labeling this issue for further investigation from the team.

    Screen.Recording.2022-04-04.at.12.39.17.PM.mov
    flutter doctor -v (mac)
    [✓] Flutter (Channel stable, 2.10.4, on macOS 12.3 21E230 darwin-arm, locale en-GB)
        • Flutter version 2.10.4 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision c860cba910 (3 days ago), 2022-03-25 00:23:12 -0500
        • Engine revision 57d3bac3dd
        • Dart version 2.16.2
        • DevTools version 2.9.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.2)
        • Android Studio at /Applications/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 11.0.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.65.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.37.20220301
    
    [✓] Connected device (4 available)
        • Redmi K20 Pro (mobile) • 192.168.1.2:55555                    • android-arm64  • Android 11 (API 30)
        • iPhone 12 Pro (mobile) • 535317A4-921C-488F-B234-C2CC6D4AE5A1 • ios            •
          com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.3 21E230 darwin-arm
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 99.0.4844.83
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel master, 2.13.0-0.0.pre.277, on macOS 12.3 21E230 darwin-arm, locale en-GB)
        • Flutter version 2.13.0-0.0.pre.277 at /Users/mahesh/Documents/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 13d2381109 (6 hours ago), 2022-03-27 21:00:08 -0400
        • Engine revision 559e259c54
        • Dart version 2.17.0 (build 2.17.0-246.0.dev)
        • DevTools version 2.11.4
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [!] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! CocoaPods 1.10.2 out of date (1.11.0 is recommended).
            CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin
            usage on the Dart side.
            Without CocoaPods, plugins will not work on iOS or macOS.
            For more info, see https://flutter.dev/platform-plugins
          To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.2)
        • Android Studio at /Applications/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 11.0.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.65.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.37.20220301
    
    [✓] Connected device (4 available)
        • Redmi K20 Pro (mobile) • 192.168.1.2:55555                    • android-arm64  • Android 11 (API 30)
        • iPhone 12 Pro (mobile) • 535317A4-921C-488F-B234-C2CC6D4AE5A1 • ios            •
          com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.3 21E230 darwin-arm
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 99.0.4844.83
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
  4. added
    a: text inputEntering text in a text field or keyboard related problems
    platform-androidAndroid applications specifically
    engineflutter/engine related. See also e: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Apr 4, 2022
  5. changed the title [-]Avoid reading clipboard on XiaoMi MIUI 13[/-] [+][Android]Avoid clipboard reading permissions on XiaoMi MIUI 13[/+] on Apr 4, 2022
  6. Linloir commented on Apr 4, 2022

    @Linloir
    Author

    @maheshmnj Thanks for testing!

    It's weird that I also tried this on my friend's RedMiK30P with MIUI 12.5 but it's reproducible.

    Therefore I've done some research on this feature (clipboard monitoring) and found out it seems to be available only on Chinese version of MIUI, maybe this causes the problem not reproducible.

  7. NorthSecond commented on Apr 4, 2022

    @NorthSecond

    The divice I use is Xiaomi Redmi K30 pro with miui 12.5 public development version 21.11.3 (Android 11). I succeed in reproducing the problem. When I open this app from the Home screen, the MIUI's security application claims that this app has accessed the clipboard 8 times. (You can find the app behavior record in the app info interface).

    2dec6529aa74fd4e86445fc477b66ca

  8. added
    P2Important issues not at the top of the work list
    on Apr 4, 2022
  9. chinmaygarde commented on Apr 4, 2022

    @chinmaygarde
    Contributor

    cc @blasten for guidance on whether the out of the box key input interface needs clipboard access by default.

  10. blasten commented on Apr 4, 2022

    @blasten

    maybe related to #85610, and #87678.
    cc @justinmc

  11. fzyzcjy commented on Jul 4, 2023

    @fzyzcjy
    Contributor

    I can reproduce it in latest Flutter stable: #129931 I am willing to PR to fix it.

  12. 4 remaining items

  13. fzyzcjy commented on Jul 7, 2023

    @fzyzcjy
    Contributor

    @justinmc Thank you. By the way, if the paste button disappears like that, I (personally) may even think it is a bug not a feature - hey where is my button? ;)

    You're right that not many people probably care about that, though. Always showing the Paste button is a pretty attractive easy solution.

    So, shall I (am I allowed to) make a PR to make it "always show the paste button"? As you said, that will be much easier to PR

  14. justinmc commented on Jan 8, 2024

    @justinmc
    Contributor

    If this is affecting many people then it makes sense to always show Paste on Android for now. Otherwise we should look at hasPrimaryClip.

  15. ratiger commented on Feb 6, 2024

    @ratiger

    the same problem. seemed like invokeMethod 'Clipboard.hasStrings' in xiaomi would show the warning dialog.

  16. LYFhub commented on Feb 8, 2024

    @LYFhub

    May I know any updates for this topic? Thanks.

  17. alicelifengmei commented on Aug 19, 2024

    @alicelifengmei

    I’m dealing with the same issue, I’ve been told that we can’t keep reading clipboard content too often, or the app might get taken down

  18. bleroux commented on Aug 21, 2024

    @bleroux
    Contributor

    @justinmc
    In #101196 (comment), you gave direction to address this issue:

    If this is affecting many people then it makes sense to always show Paste on Android for now. Otherwise we should look at hasPrimaryClip.

    Looking at the engine code it seems that hasPrimaryClip support was implemented some years ago in flutter-team-archive/engine#27215 on the engine side and in #87678 for the framework side.
    It does not help to fix the issue because hasPrimaryClip will usually return true (having an empty clipboard is probably rare).

    Do you think we should proceed with "always show Paste on Android for now"?

  19. Morris-Mao commented on Sep 24, 2024

    @Morris-Mao

    Flutter 3.16.6 same issue . dozens of time per second。

    java.lang.Exception at android.content.ClipboardManager.getPrimaryClipDescription(Native Method) at io.flutter.plugin.platform.PlatformPlugin.clipboardHasStrings(PlatformPlugin.java:555) at io.flutter.plugin.platform.PlatformPlugin.access$1200(PlatformPlugin.java:31) at io.flutter.plugin.platform.PlatformPlugin$1.clipboardHasStrings(PlatformPlugin.java:144) at io.flutter.embedding.engine.systemchannels.PlatformChannel$1.onMethodCall(PlatformChannel.java:184) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322) at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:257) at android.app.ActivityThread.main(ActivityThread.java:8246) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1031)

  20. justinmc commented on Sep 25, 2024

    @justinmc
    Contributor

    @bleroux Why exactly is this still a problem if we are using hasPrimaryClip now? Do XiaoMi devices still show the dialog even when hasPrimaryClip is called? If that's true then I'm on board with just always showing Paste on Android.

    I would think it should work and not show the dialog now though. On the framework side hasStrings is used to decide to show Paste or not, and in the engine with flutter-team-archive/engine#27215 it looks like that should only call hasPrimaryClip now.

  21. bleroux commented on Sep 25, 2024

    @bleroux
    Contributor

    @bleroux Why exactly is this still a problem if we are using hasPrimaryClip now? Do XiaoMi devices still show the dialog even when hasPrimaryClip is called? If that's true then I'm on board with just always showing Paste on Android.

    @justinmc Unfortunately I don't have such a device to look more closely.
    I came to this issue because of some recent reports (#153750 and #153749), and I saw that some comments above are somewhat recent (2024).

    I would think it should work and not show the dialog now though. On the framework side hasStrings is used to decide to show Paste or not, and in the engine with flutter/engine#27215 it looks like that should only call hasPrimaryClip now.

    Yes you're right. I looked more closely at the code. At first I thought that hasStrings was just returning true when there is something in the clipboard and then that a call to getClipboardData was made to see if the content is a text. But I was wrong, getPrimaryClipDescription is called to get this information and it is not supposed to trigger any security concerns (based on https://developer.android.com/develop/ui/views/touch-and-input/copy-paste#PastingSystemNotifications).

    It looks like, on some devices, there is another layer of security which flags those calls to hasPrimaryClip and/or getPrimaryClipDescription.
    Ideally, it would be great to see what happens if a we create a native Android app that calls hasPrimaryClip and getPrimaryClipDescription many times. My bet is that the warning would be the same of those devices.

    Not sure how to proceed. Would it make sense to always show 'Paste' to accomodate those devices security check? This will apply to all devices, not sure about the impact for end users seeing a paste button when there no valid content to paste.

    For reference:

  22. ThinkMars commented on Dec 13, 2025

    @ThinkMars

    Can we remove the loop call 'getPrimaryClipDescription' from didUpdateWidget, as it may cause permission misjudgment and compliance issues on certain platforms.
    For this i create a PR: #179840

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions