plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Bug]: share_plus does file I/O on the main thread

Open dowski opened this issue 1 year ago • 5 comments

Platform

Android 12

Plugin

share_plus

Version

7.2.1

Flutter SDK

Any

Steps to reproduce

  1. Enable Android's StrictMode to catch main thread disk read violations
  2. Use this plugin and trigger a share of a file

StrictMode catches that the plugin does I/O on the main thread. This leads to ANR bugs.

11-30 12:08:07.706 D/StrictMode(10062): StrictMode policy violation: 
11-30 12:08:07.706 D/StrictMode(10062): android.os.strictmode.DiskReadViolation
11-30 12:08:07.706 D/StrictMode(10062): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1659)
11-30 12:08:07.706 D/StrictMode(10062): 	at libcore.io.BlockGuardOs.access(BlockGuardOs.java:74)
11-30 12:08:07.706 D/StrictMode(10062): 	at libcore.io.ForwardingOs.access(ForwardingOs.java:131)
11-30 12:08:07.706 D/StrictMode(10062): 	at android.app.ActivityThread$AndroidOs.access(ActivityThread.java:7716)
11-30 12:08:07.706 D/StrictMode(10062): 	at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:281)
11-30 12:08:07.706 D/StrictMode(10062): 	at java.io.File.exists(File.java:813)
11-30 12:08:07.706 D/StrictMode(10062): 	at kotlin.io.FilesKt__UtilsKt.copyTo(Utils.kt:218)
11-30 12:08:07.706 D/StrictMode(10062): 	at kotlin.io.FilesKt__UtilsKt.copyTo$default(Utils.kt:217)
11-30 12:08:07.706 D/StrictMode(10062): 	at dev.fluttercommunity.plus.share.Share.copyToShareCacheFolder(Share.kt:248)
11-30 12:08:07.706 D/StrictMode(10062): 	at dev.fluttercommunity.plus.share.Share.getUrisForPaths(Share.kt:184)
11-30 12:08:07.706 D/StrictMode(10062): 	at dev.fluttercommunity.plus.share.Share.shareFiles(Share.kt:96)
11-30 12:08:07.706 D/StrictMode(10062): 	at dev.fluttercommunity.plus.share.MethodCallHandler.onMethodCall(MethodCallHandler.kt:46)
11-30 12:08:07.706 D/StrictMode(10062): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
11-30 12:08:07.706 D/StrictMode(10062): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
11-30 12:08:07.706 D/StrictMode(10062): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
11-30 12:08:07.706 D/StrictMode(10062): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
11-30 12:08:07.706 D/StrictMode(10062): 	at android.os.Handler.handleCallback(Handler.java:938)
11-30 12:08:07.706 D/StrictMode(10062): 	at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 12:08:07.706 D/StrictMode(10062): 	at android.os.Looper.loopOnce(Looper.java:201)
11-30 12:08:07.706 D/StrictMode(10062): 	at android.os.Looper.loop(Looper.java:288)
11-30 12:08:07.706 D/StrictMode(10062): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
11-30 12:08:07.706 D/StrictMode(10062): 	at java.lang.reflect.Method.invoke(Native Method)
11-30 12:08:07.706 D/StrictMode(10062): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
11-30 12:08:07.706 D/StrictMode(10062): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Code Sample

No response

Logs

N/A

Flutter Doctor

N/A

Checklist before submitting a bug

  • [X] I searched issues in this repository and couldn't find such bug/problem
  • [X] I Google'd a solution and I couldn't find it
  • [X] I searched on StackOverflow for a solution and I couldn't find it
  • [X] I read the README.md file of the plugin
  • [X] I'm using the latest version of the plugin
  • [X] All dependencies are up to date with flutter pub upgrade
  • [X] I did a flutter clean
  • [X] I tried running the example project

dowski avatar Nov 30 '23 20:11 dowski

More details about how to enable/use StrictMode here:

https://developer.android.com/reference/android/os/StrictMode

dowski avatar Nov 30 '23 20:11 dowski

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Feb 29 '24 00:02 github-actions[bot]

Good catch, indeed the Android shareFiles function should run asynchronously

miquelbeltran avatar Feb 29 '24 07:02 miquelbeltran

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar May 30 '24 00:05 github-actions[bot]