icerockdev / moko-permissions

Runtime permissions controls for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
396 stars 41 forks source link

Exception: RequestCanceledException is thrown on App launch (Andorid). #92

Open farhazulmullick-pw opened 1 year ago

farhazulmullick-pw commented 1 year ago

Trying to show notification permission as soon as app starts. My device throw dev.icerock.moko.permissions.RequestCanceledException Activity says Can request only one set of permissions at a time

I have attached sample code and error logs. Please check this and tell me if anything from my end is not well.

code

@Composable
fun App() {

    val factory = rememberPermissionsControllerFactory()
    val controller = remember(factory) { factory.createPermissionsController() }
    val scope = rememberCoroutineScope()

    BindEffect(controller)
    LaunchedEffect(key1 = true) {
        try {
            controller.providePermission(Permission.REMOTE_NOTIFICATION)
        } catch (e: Exception) {
            println("Line 54, e: ${e.getScopeName()}")
            e.printStackTrace()
        }
    }

    Text("Hello Student $name")
}

error Logs:

2023-11-15 14:16:24.887 23794-23794 Activity                com.penpencil.parent.android         W  Can request only one set of permissions at a time
2023-11-15 14:16:24.889 23794-23794 System.out              com.penpencil.parent.android         I  Line 54, e: q:'dev.icerock.moko.permissions.RequestCanceledException'
2023-11-15 14:16:24.890 23794-23794 System.err              com.penpencil.parent.android         W  dev.icerock.moko.permissions.RequestCanceledException
2023-11-15 14:16:24.890 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment.requestPermissionLauncher$lambda$1(ResolverFragment.kt:32)
2023-11-15 14:16:24.891 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment.$r8$lambda$xVWh1OMY-jV8sGm90Z_Lnoc0rAA(Unknown Source:0)
2023-11-15 14:16:24.891 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment$$ExternalSyntheticLambda0.onActivityResult(Unknown Source:4)
2023-11-15 14:16:24.891 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:418)
2023-11-15 14:16:24.892 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:375)
2023-11-15 14:16:24.892 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.activity.ComponentActivity.onRequestPermissionsResult(ComponentActivity.java:844)
2023-11-15 14:16:24.892 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.fragment.app.FragmentActivity.onRequestPermissionsResult(FragmentActivity.java:490)
2023-11-15 14:16:24.892 23794-23794 System.err              com.penpencil.parent.android         W      at android.app.Activity.requestPermissions(Activity.java:5486)
2023-11-15 14:16:24.893 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.core.app.ActivityCompat$Api23Impl.requestPermissions(ActivityCompat.java:944)
2023-11-15 14:16:24.893 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.core.app.ActivityCompat.requestPermissions(ActivityCompat.java:560)
2023-11-15 14:16:24.893 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.activity.ComponentActivity$2.onLaunch(ComponentActivity.java:237)
2023-11-15 14:16:24.893 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.activity.result.ActivityResultRegistry$2.launch(ActivityResultRegistry.java:175)
2023-11-15 14:16:24.894 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.fragment.app.Fragment$10.launch(Fragment.java:3621)
2023-11-15 14:16:24.894 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.activity.result.ActivityResultLauncher.launch(ActivityResultLauncher.java:47)
2023-11-15 14:16:24.894 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment$requestPermission$1$1.invokeSuspend(ResolverFragment.kt:79)
2023-11-15 14:16:24.894 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment$requestPermission$1$1.invoke(Unknown Source:8)
2023-11-15 14:16:24.895 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment$requestPermission$1$1.invoke(Unknown Source:4)
2023-11-15 14:16:24.895 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invokeSuspend(RepeatOnLifecycle.kt:111)
2023-11-15 14:16:24.895 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invoke(Unknown Source:8)
2023-11-15 14:16:24.896 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invoke(Unknown Source:4)
2023-11-15 14:16:24.896 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
2023-11-15 14:16:24.896 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
2023-11-15 14:16:24.896 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1.invokeSuspend(RepeatOnLifecycle.kt:110)
2023-11-15 14:16:24.897 23794-23794 System.err              com.penpencil.parent.android         W      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2023-11-15 14:16:24.897 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
2023-11-15 14:16:24.897 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:68)
2023-11-15 14:16:24.897 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:375)
2023-11-15 14:16:24.898 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
2023-11-15 14:16:24.898 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
2023-11-15 14:16:24.898 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
2023-11-15 14:16:24.899 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
2023-11-15 14:16:24.899 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
2023-11-15 14:16:24.899 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
2023-11-15 14:16:24.900 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
2023-11-15 14:16:24.900 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
2023-11-15 14:16:24.900 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment.requestPermission(ResolverFragment.kt:58)
2023-11-15 14:16:24.900 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.PermissionsControllerImpl.providePermission(PermissionsControllerImpl.kt:57)
2023-11-15 14:16:24.901 23794-23794 System.err              com.penpencil.parent.android         W      at com.penpencil.parent.AppKt$App$2.invokeSuspend(App.kt:54)
2023-11-15 14:16:24.901 23794-23794 System.err              com.penpencil.parent.android         W      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2023-11-15 14:16:24.902 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
2023-11-15 14:16:24.902 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Handler.handleCallback(Handler.java:942)
2023-11-15 14:16:24.903 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Handler.dispatchMessage(Handler.java:99)
2023-11-15 14:16:24.903 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Looper.loopOnce(Looper.java:226)
2023-11-15 14:16:24.903 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Looper.loop(Looper.java:313)
2023-11-15 14:16:24.903 23794-23794 System.err              com.penpencil.parent.android         W      at android.app.ActivityThread.main(ActivityThread.java:8762)
2023-11-15 14:16:24.903 23794-23794 System.err              com.penpencil.parent.android         W      at java.lang.reflect.Method.invoke(Native Method)
2023-11-15 14:16:24.904 23794-23794 System.err              com.penpencil.parent.android         W      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
2023-11-15 14:16:24.904 23794-23794 System.err              com.penpencil.parent.android         W      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
2023-11-15 14:16:24.910 23794-23794 System.out              com.penpencil.parent.android         I  Line 54, e: q:'dev.icerock.moko.permissions.RequestCanceledException'
2023-11-15 14:16:24.910 23794-23794 System.err              com.penpencil.parent.android         W  dev.icerock.moko.permissions.RequestCanceledException
2023-11-15 14:16:24.911 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment$requestPermission$1$1.invokeSuspend(ResolverFragment.kt:73)
2023-11-15 14:16:24.911 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment$requestPermission$1$1.invoke(Unknown Source:8)
2023-11-15 14:16:24.911 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment$requestPermission$1$1.invoke(Unknown Source:4)
2023-11-15 14:16:24.912 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invokeSuspend(RepeatOnLifecycle.kt:111)
2023-11-15 14:16:24.912 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invoke(Unknown Source:8)
2023-11-15 14:16:24.912 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1.invoke(Unknown Source:4)
2023-11-15 14:16:24.912 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
2023-11-15 14:16:24.913 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
2023-11-15 14:16:24.913 23794-23794 System.err              com.penpencil.parent.android         W      at androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1.invokeSuspend(RepeatOnLifecycle.kt:110)
2023-11-15 14:16:24.913 23794-23794 System.err              com.penpencil.parent.android         W      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2023-11-15 14:16:24.914 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
2023-11-15 14:16:24.914 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:68)
2023-11-15 14:16:24.914 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:375)
2023-11-15 14:16:24.914 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
2023-11-15 14:16:24.915 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
2023-11-15 14:16:24.915 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
2023-11-15 14:16:24.915 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
2023-11-15 14:16:24.915 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
2023-11-15 14:16:24.916 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
2023-11-15 14:16:24.916 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
2023-11-15 14:16:24.916 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
2023-11-15 14:16:24.917 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.ResolverFragment.requestPermission(ResolverFragment.kt:58)
2023-11-15 14:16:24.917 23794-23794 System.err              com.penpencil.parent.android         W      at dev.icerock.moko.permissions.PermissionsControllerImpl.providePermission(PermissionsControllerImpl.kt:57)
2023-11-15 14:16:24.917 23794-23794 System.err              com.penpencil.parent.android         W      at com.penpencil.parent.AppKt$App$2.invokeSuspend(App.kt:54)
2023-11-15 14:16:24.917 23794-23794 System.err              com.penpencil.parent.android         W      at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2023-11-15 14:16:24.918 23794-23794 System.err              com.penpencil.parent.android         W      at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
2023-11-15 14:16:24.918 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Handler.handleCallback(Handler.java:942)
2023-11-15 14:16:24.918 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Handler.dispatchMessage(Handler.java:99)
2023-11-15 14:16:24.918 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Looper.loopOnce(Looper.java:226)
2023-11-15 14:16:24.919 23794-23794 System.err              com.penpencil.parent.android         W      at android.os.Looper.loop(Looper.java:313)
2023-11-15 14:16:24.919 23794-23794 System.err              com.penpencil.parent.android         W      at android.app.ActivityThread.main(ActivityThread.java:8762)
2023-11-15 14:16:24.919 23794-23794 System.err              com.penpencil.parent.android         W      at java.lang.reflect.Method.invoke(Native Method)
2023-11-15 14:16:24.919 23794-23794 System.err              com.penpencil.parent.android         W      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
2023-11-15 14:16:24.920 23794-23794 System.err              com.penpencil.parent.android         W      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Kronos0041 commented 8 months ago

Hello, try this:

LaunchedEffect(Unit) {
 // code for just once permission to provide...
}
brucemax commented 3 months ago

I have the same crash, and it occurs only on one of 4 my phones, crap

raheemadamboev commented 1 month ago

Same issue, it looks like it doesn't throw the exception in controller.providePermission()throws it somewhere else.

 dev.icerock.moko.permissions.RequestCanceledException
2024-10-14 18:48:09.343 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at dev.icerock.moko.permissions.PermissionsControllerImpl.bind$lambda$1(PermissionsControllerImpl.kt:62)
2024-10-14 18:48:09.343 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at dev.icerock.moko.permissions.PermissionsControllerImpl.$r8$lambda$ssanpq_AuAXa1Gs9w4o6Ga8mzFs(Unknown Source:0)
2024-10-14 18:48:09.343 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at dev.icerock.moko.permissions.PermissionsControllerImpl$$ExternalSyntheticLambda0.onActivityResult(D8$$SyntheticClass:0)
2024-10-14 18:48:09.343 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.kt:371)
2024-10-14 18:48:09.344 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.kt:331)
2024-10-14 18:48:09.344 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at androidx.activity.ComponentActivity.onRequestPermissionsResult(ComponentActivity.kt:811)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.Activity.onRequestPermissionsResult(Activity.java:5780)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:9532)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.Activity.internalDispatchActivityResult(Activity.java:9387)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.Activity.dispatchActivityResult(Activity.java:9356)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.ActivityThread.deliverResults(ActivityThread.java:5867)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.ActivityThread.handleSendResult(ActivityThread.java:5917)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:69)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2636)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.os.Handler.dispatchMessage(Handler.java:107)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.os.Looper.loopOnce(Looper.java:232)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.os.Looper.loop(Looper.java:317)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at android.app.ActivityThread.main(ActivityThread.java:8705)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at java.lang.reflect.Method.invoke(Native Method)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
2024-10-14 18:48:09.346 22652-22652 System.err              xyz.teamgravity.mokopermissionsdemo  W      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
MohammadRezaei92 commented 3 weeks ago

This is my code to request permission. but every time I get RequestCanceledException


fun RequestPermission(
    factory: PermissionsControllerFactory = rememberPermissionsControllerFactory(),
    controller: PermissionsController = remember(factory) { factory.createPermissionsController() },
    permission: Permission,
    onResult: (PermissionState) -> Unit
) {
    BindEffect(controller)
    LaunchedEffect(Unit) {
        runCatching {
            controller.providePermission(permission)
            onResult(PermissionState.Granted)
        }.onFailure { exception ->
            when (exception) {
                is DeniedAlwaysException -> onResult(PermissionState.DeniedAlways)
                is DeniedException -> onResult(PermissionState.Denied)
                is RequestCanceledException -> onResult(PermissionState.NotGranted)
            }
        }
    }
}