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 #450

Open
korzonkiee opened this issue Feb 27, 2024 · 1 comment · May be fixed by #451
Open

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

korzonkiee opened this issue Feb 27, 2024 · 1 comment · May be fixed by #451

Comments

@korzonkiee
Copy link

korzonkiee commented Feb 27, 2024

Problem

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.

@g-apparence
Copy link
Collaborator

Yes I ended using permission package that does this way better.
I am thinking about removing this from the plugin and encourage using it.

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