Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
8 tasks done
dowski opened this issue Nov 30, 2023 · 6 comments
Open
8 tasks done

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

dowski opened this issue Nov 30, 2023 · 6 comments
Labels
android bug Something isn't working share_plus Feature, Enhancement, Bug Fixes for Share Plus Plugin

Comments

@dowski
Copy link

dowski commented Nov 30, 2023

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

  • I searched issues in this repository and couldn't find such bug/problem
  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@dowski dowski added bug Something isn't working triage labels Nov 30, 2023
@dowski
Copy link
Author

dowski commented Nov 30, 2023

More details about how to enable/use StrictMode here:

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

Copy link

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

@miquelbeltran
Copy link
Member

Good catch, indeed the Android shareFiles function should run asynchronously

@miquelbeltran miquelbeltran added share_plus Feature, Enhancement, Bug Fixes for Share Plus Plugin android and removed triage labels Feb 29, 2024
Copy link

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

Copy link

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

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android bug Something isn't working share_plus Feature, Enhancement, Bug Fixes for Share Plus Plugin
Projects
None yet
Development

No branches or pull requests

2 participants