Skip to content

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

Open
korzonkiee wants to merge 1 commit intoApparence-io:masterfrom
korzonkiee:fix/450
Open

After requesting not granted permissions, the result should be dispatched on main thread#451
korzonkiee wants to merge 1 commit intoApparence-io:masterfrom
korzonkiee:fix/450

Conversation

@korzonkiee
Copy link
Copy Markdown

@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
Copy Markdown

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.

@korzonkiee korzonkiee force-pushed the fix/450 branch 2 times, most recently from 684b840 to 0b8430c Compare September 2, 2024 11:20
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