Skip to content

[Super Clipboard] - Pasting on Android crashes the app after some time. #566

@matthew-carroll

Description

@matthew-carroll

Hey @knopp can you let me know if you're familiar with this cause of this crash?

With my current use of super_clipboard I can read the OS clipboard and paste stuff, including images. That all works great when I copy an image and immediately paste it.

However, it seems that if some amount of time passes between copying the image and pasting it, the whole app crashes when I try to paste. My uneducated assumption is that there's some kind of timer in the clipboard that invalidates or otherwise alters content after some period of time, but I don't know what I'm supposed to check to avoid this crash.

Here's the stack trace:

E/AndroidRuntime(15992): java.lang.SecurityException: Permission Denial: opening provider org.chromium.chrome.browser.util.ChromeFileProvider from ProcessRecord{b345f7b 15992:my.app.name/u0a358} (pid=15992, uid=10358) that is not exported from UID 10206
E/AndroidRuntime(15992): 	at android.os.Parcel.createExceptionOrNull(Parcel.java:3355)
E/AndroidRuntime(15992): 	at android.os.Parcel.createException(Parcel.java:3339)
E/AndroidRuntime(15992): 	at android.os.Parcel.readException(Parcel.java:3322)
E/AndroidRuntime(15992): 	at android.os.Parcel.readException(Parcel.java:3264)
E/AndroidRuntime(15992): 	at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:6484)
E/AndroidRuntime(15992): 	at android.app.ActivityThread.acquireProvider(ActivityThread.java:8258)
E/AndroidRuntime(15992): 	at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:3822)
E/AndroidRuntime(15992): 	at android.content.ContentResolver.acquireProvider(ContentResolver.java:2495)
E/AndroidRuntime(15992): 	at android.content.ContentResolver.getStreamTypes(ContentResolver.java:1068)
E/AndroidRuntime(15992): 	at com.superlist.super_native_extensions.ClipDataHelper.getFormats(ClipDataHelper.java:92)
E/AndroidRuntime(15992): 	at com.superlist.super_native_extensions.ClipDataHelper.getFormats(ClipDataHelper.java:41)
E/AndroidRuntime(15992): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime(15992): 	at android.os.MessageQueue.nextLegacy(MessageQueue.java:1003)
E/AndroidRuntime(15992): 	at android.os.MessageQueue.next(MessageQueue.java:1112)
E/AndroidRuntime(15992): 	at android.os.Looper.loopOnce(Looper.java:197)
E/AndroidRuntime(15992): 	at android.os.Looper.loop(Looper.java:349)
E/AndroidRuntime(15992): 	at android.app.ActivityThread.main(ActivityThread.java:9041)
E/AndroidRuntime(15992): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(15992): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
E/AndroidRuntime(15992): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
E/AndroidRuntime(15992): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(15992): 	at com.android.server.am.ContentProviderHelper.checkAssociationAndPermissionLocked(ContentProviderHelper.java:726)
E/AndroidRuntime(15992): 	at com.android.server.am.ContentProviderHelper.getContentProviderImpl(ContentProviderHelper.java:310)
E/AndroidRuntime(15992): 	at com.android.server.am.ContentProviderHelper.getContentProvider(ContentProviderHelper.java:150)
E/AndroidRuntime(15992): 	at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:7131)
E/AndroidRuntime(15992): 	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3038)

This completely crashes the app. And at least based on the stacktrace, there aren't any Dart code paths for me to alter.

I think I've noticed a similar failure to paste after time on iOS, but I don't think iOS completely crashes like Android.

Update: After adding some print statements, it looks like the crash happens when attempting to read the clipboard, in this case between the two print statements:

  final clipboard = SystemClipboard.instance;
  if (clipboard == null) {
    return;
  }

  print("Reading clipboard");
  final reader = await clipboard.read();
  print("Done reading clipboard");

Update 2: After digging down into the read() call, I found that the crash happens after "2" and before "3" in the source code below:

Future<ClipboardReader> read() async {
    print("In read()");
    final reader = await raw.ClipboardReader.instance.newClipboardReader();
    print("1");
    final readerItems = await reader.getItems();
    print("2");
    final itemInfo = await raw.DataReaderItem.getItemInfo(readerItems); // <------
    print("3");
    final items = <ClipboardDataReader>[];
    for (final item in itemInfo) {
      items.add(ClipboardDataReader.forItemInfo(item));
    }
    print("4");
    return ClipboardReader(items);
  }

Update 3: I forked the repo and changed it locally by wrapping this line with a try/catch: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/android/src/main/java/com/superlist/super_native_extensions/ClipDataHelper.java#L92

That try/catch saved me from the crash. Obviously pasting still doesn't work in that case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions