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

After requesting not granted permissions, the result should be dispatched on main thread #451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

korzonkiee
Copy link

@korzonkiee korzonkiee commented Feb 27, 2024

Description

Seeing the following crash reported multiple times in Sentry:

java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: DefaultDispatcher-worker-1
    at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:37)
    at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:1)
    at mb.c.d(DartMessenger.java:79)
    at mb.a$c.c(DartExecutor.java:4)
    at mb.a.c(DartExecutor.java:3)
    at yb.d$c$a.a(EventChannel.java:50)
    at y1.j1.e(CameraPermissions.kt:166)
    at io.flutter.embedding.engine.c$c.i(FlutterEngineConnectionRegistry.java:21)
    at io.flutter.embedding.engine.c.e(FlutterEngineConnectionRegistry.java:14)
    at io.flutter.embedding.android.f.y(FlutterActivityAndFragmentDelegate.java:60)
    at io.flutter.embedding.android.e.onRequestPermissionsResult(FlutterActivity.java:11)
    at android.app.Activity.requestPermissions(Activity.java:5633)
    at androidx.core.app.b$b.b(ActivityCompat.java:1)
    at androidx.core.app.b.r(ActivityCompat.java:140)
    at y1.j1.g(CameraPermissions.kt:100)
    at y1.j1$b.invokeSuspend(CameraPermissions.kt:48)
    at kotlin.coroutines.jvm.internal.a.resumeWith(ContinuationImpl.kt:12)
    at nd.r0.run(DispatchedTask.kt:124)
    at sd.o$a.run(LimitedDispatcher.kt:4)
    at ud.k.run(Tasks.kt:3)
    at ud.a.z(CoroutineScheduler.kt:1)
    at ud.a$c.d(CoroutineScheduler.kt:15)
    at ud.a$c.p(CoroutineScheduler.kt:29)
    at ud.a$c.run(CoroutineScheduler.kt:1)

After some investigation, it turned out that after requesting the not-granted permissions, the callback function is invoked from the IO thread, which then leads to the java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. In order to fix it, we must dispatch the callback invocation to the main thread, similarily as in the case of requesting audio permission.

Closes #450

Checklist

Before creating any Pull Request, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).

  • 📕 I read the Contributing page.
  • 🤝 I match the actual coding style.
  • ✅ I ran flutter analyze without any issues.

Breaking Change

  • 🛠 My feature contain breaking change.

If your feature break something, please detail it

@korzonkiee korzonkiee changed the title fix: after requesting not granted permissions, the result should be dispatched on main thread After requesting not granted permissions, the result should be dispatched on main thread Feb 27, 2024
@lively-bigyan
Copy link

This solution didn't work for me. It wasn't just the sentry logs that were crashing; the app was actively crashing. I have posted a fix on #511.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After requesting not granted permissions, the result should be dispatched on main thread
2 participants