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

Could not retrieve the image from the clipboard on Android as the app no longer have access due to lifecycle changes #2243

Closed
1 task done
EchoEllet opened this issue Sep 18, 2024 · 2 comments · Fixed by #2230
Labels
android Issues or feature requests specific to the Android platform. blocked This issue cannot be resolved due to an obstacle or dependency. bug Something isn't working minor Minimal impact or cosmetic issue. Can be resolved at a later time without affecting overall function unplanned This will not be worked on

Comments

@EchoEllet
Copy link
Collaborator

EchoEllet commented Sep 18, 2024

Is there an existing issue for this?

Flutter Quill version

Commit 9840745

Steps to reproduce

This issue is on Android only and is platform-specific in the Android JVM.

  1. Run the app on Android, copy an image from another app while the app is running.
  2. Paste it into the app, it should succeed without any issues.
  3. Refrain from copying anything to the clipboard after that.
  4. Close the app completely and then start it again (using flutter run), you might get a crash.
  5. If you didn't get any crashes, try to paste the same image from step 1.

The issue can happen on quill_native_bridge and super_clipboard (see super_native_extensions #435 for the related issue) implementation.

On super_clipbaord the Android app can crash, on the quill_native_bridge implementation introduced in #2230. The plugin will simply return null to getClipboardGif() or getClipboardImage and print a message only on debug mode referencing this issue.

The issue is that the app can lose access to the android.net.Uri on the clipboard and a workaround (to actually return the image instead of ignoring it) is to save it to a temporary location or somewhere where the image can be accessed on the app restart or lifecycle changes on the next time calling getClipboardImage.

I had to introduce this workaround instead of fixing it since saving images to the user's device (even if it's specific to the app document directory) is not ideal, the developer or the end user might not want this behavior on their apps/devices.

Expected results

To be able to retrieve the image without this crash/exception.

Once super_native_extensions #435 is confirmed and fixed, this will not be an issue for the SuperClipboardService implementation.

The DefaultClipboardService will return null and print a message on debug-only mode instead of crashing the app due to an unhandled exception from the Android code side (SecurityException or FileNotFoundException from java.io).

Actual results

App crashes on super_clipbaord implementation. For quill_native_bridge caused unhandled exception from the dart side (still not published #2230), updated to simply print a warning and handle it from the dart side and return null, image will not be available and will not have it pasted on the editor.

Additional Context

This is tested using quill_native_bridge.
For super_clipboard video refer to super_native_extensions #435

Screenshots / Video demonstration

For super_clipboard video refer to super_native_extensions #435

Screen.Recording.2024-09-18.at.4.53.08.PM.mov
Logs
Unhandled Exception: PlatformException(COULD_NOT_DECODE_IMAGE, Could not decode bitmap from Uri: Permission Denial: opening provider org.chromium.chrome.browser.util.ChromeFileProvider from ProcessRecord{b3d4d8e 14685:dev.flutterquill.quill_native_bridge_example/u0a191} (pid=14685, uid=10191) that is not exported from UID 10146, java.lang.SecurityException: Permission Denial: opening provider org.chromium.chrome.browser.util.ChromeFileProvider from ProcessRecord{b3d4d8e 14685:dev.flutterquill.quill_native_bridge_example/u0a191} (pid=14685, uid=10191) that is not exported from UID 10146, null)
E/flutter (14685): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
E/flutter (14685): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter (14685): <asynchronous suspension>
E/flutter (14685): #2      MethodChannelQuillNativeBridge.getClipboardImage (package:quill_native_bridge/src/quill_native_bridge_method_channel.dart:87:24)
E/flutter (14685): <asynchronous suspension>
E/flutter (14685): #3      Buttons.build.<anonymous closure> (package:quill_native_bridge_example/main.dart:150:32)
E/flutter (14685): <asynchronous suspension>
E/flutter (14685): 
java.io.FileNotFoundException: No content provider: content://com.android.chrome.FileProvider/images/screenshot/17266705501256549663602733807552.gif
W/System.err(17433): 	at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2029)
W/System.err(17433): 	at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
W/System.err(17433): 	at android.content.ContentResolver.openInputStream(ContentResolver.java:1528)
java.lang.SecurityException: Permission Denial: opening provider org.chromium.chrome.browser.util.ChromeFileProvider from ProcessRecord{d1d20d7 17742:dev.flutterquill.quill_native_bridge_example/u0a191} (pid=17742, uid=10191) that is not exported from UID 10146
W/System.err(17742): 	at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
W/System.err(17742): 	at android.os.Parcel.createException(Parcel.java:3041)
W/System.err(17742): 	at android.os.Parcel.readException(Parcel.java:3024)
W/System.err(17742): 	at android.os.Parcel.readException(Parcel.java:2966)
W/System.err(17742): 	at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5906)
W/System.err(17742): 	at android.app.ActivityThread.acquireProvider(ActivityThread.java:7310)
W/System.err(17742): 	at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:3668)
W/System.err(17742): 	at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2542)
W/System.err(17742): 	at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2027)
W/System.err(17742): 	at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
W/System.err(17742): 	at android.content.ContentResolver.openInputStream(ContentResolver.java:1528)
W/System.err(17742): 	at dev.flutterquill.quill_native_bridge.clipboard.ClipboardImageHandler.canRead(ClipboardImageHandler.kt:86)
W/System.err(17742): 	at dev.flutterquill.quill_native_bridge.clipboard.ClipboardImageHandler.getClipboardImage(ClipboardImageHandler.kt:114)
W/System.err(17742): 	at dev.flutterquill.quill_native_bridge.QuillNativeBridgePlugin.onMethodCall(QuillNativeBridgePlugin.kt:169)
W/System.err(17742): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
W/System.err(17742): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
W/System.err(17742): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
W/System.err(17742): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
W/System.err(17742): 	at android.os.Handler.handleCallback(Handler.java:958)
W/System.err(17742): 	at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(17742): 	at android.os.Looper.loopOnce(Looper.java:205)
W/System.err(17742): 	at android.os.Looper.loop(Looper.java:294)
W/System.err(17742): 	at android.app.ActivityThread.main(ActivityThread.java:8177)
W/System.err(17742): 	at java.lang.reflect.Method.invoke(Native Method)
W/System.err(17742): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
W/System.err(17742): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
W/System.err(17742): Caused by: android.os.RemoteException: Remote stack trace:
W/System.err(17742): 	at com.android.server.am.ContentProviderHelper.checkAssociationAndPermissionLocked(ContentProviderHelper.java:691)
W/System.err(17742): 	at com.android.server.am.ContentProviderHelper.getContentProviderImpl(ContentProviderHelper.java:287)
W/System.err(17742): 	at com.android.server.am.ContentProviderHelper.getContentProvider(ContentProviderHelper.java:144)
W/System.err(17742): 	at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:6713)
W/System.err(17742): 	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2761)
@EchoEllet EchoEllet added the bug Something isn't working label Sep 18, 2024
@EchoEllet
Copy link
Collaborator Author

The issue with handled exception from the dart side in quill_native_bridge is already fixed, will print a warning on debug only explaining the issue.

If anyone has suggestions for fixing the issue or already fixed it, we're open to feedback.

As for now, we don't have plans for fixing the issue by saving the image to the internal storage when the app lifecycle has access to it and then accessing the saved image once the app no longer have access to it due to lifecycle changes or app restart. Closing this issue and will be used as a reference to discussion related to the issue in the printed warning (on debug mode only, will be tree shaken in release mode).

@EchoEllet EchoEllet closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2024
@EchoEllet EchoEllet added unplanned This will not be worked on blocked This issue cannot be resolved due to an obstacle or dependency. labels Sep 18, 2024
@EchoEllet
Copy link
Collaborator Author

image

@EchoEllet EchoEllet added android Issues or feature requests specific to the Android platform. minor Minimal impact or cosmetic issue. Can be resolved at a later time without affecting overall function labels Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issues or feature requests specific to the Android platform. blocked This issue cannot be resolved due to an obstacle or dependency. bug Something isn't working minor Minimal impact or cosmetic issue. Can be resolved at a later time without affecting overall function unplanned This will not be worked on
Projects
None yet
1 participant