Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

java.lang.IllegalStateException: RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request. #46

Closed
tarasantoshchuk opened this issue May 10, 2016 · 21 comments
Labels

Comments

@tarasantoshchuk
Copy link
Contributor

One of my activities asks for camera permission on trigger (button click)
After following steps, exception is thrown:

  1. user presses button and shadow activity with dialog that asks for permission is shown
  2. user goes to settings and revoke some other permission
  3. user reopens app - shadow activity with dialog is still there
  4. user allows/denies permission and app crashes with exception

from what I saw in code:
RxPermissions.request_() where mSubjects is filled is called before permission is revoked by user

After user revoked permission app is recreated in new process and mSubjects is empty - therefore exception is thrown in RxPermissions.onRequestPermissionsResult()

Can you please fix this or suggest a workaround?

@tbruyelle
Copy link
Owner

tbruyelle commented May 10, 2016

Do you answer to the permission dialog on 1. ?

@tarasantoshchuk
Copy link
Contributor Author

no, I leave app while dialog is shown

@tbruyelle
Copy link
Owner

Ok there's probably a bug but the case you described is kindy weird... Why the user would go to the settings before answering the permission dialog ?

@tarasantoshchuk
Copy link
Contributor Author

Yes, it is weird.
But our crash reporter shows that this crash happens in production

@tbruyelle
Copy link
Owner

Can you provide a detailled stack trace please?

@tarasantoshchuk
Copy link
Contributor Author

java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=42, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {.../com.tbruyelle.rxpermissions.ShadowActivity}: java.lang.IllegalStateException: RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.
at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: RxPermissions.onRequestPermissionsResult invoked but didn't find the corresponding permission request.
at com.tbruyelle.rxpermissions.RxPermissions.onRequestPermissionsResult(RxPermissions.java:286)
at com.tbruyelle.rxpermissions.ShadowActivity.onRequestPermissionsResult(ShadowActivity.java:32)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6582)
at android.app.Activity.dispatchActivityResult(Activity.java:6460)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) 
at android.app.ActivityThread.-wrap16(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

@tbruyelle
Copy link
Owner

Ok I think I understand.
When you update the app's permissions in the settings, your app is killed, and in that case RxPermissions doesn't save the current state, but the framework save the permission request and so restore it when the user is back.

RxPermissions should probably save the state when the app is killed, and restore it after. If you have some time to develop a fix, I could merge it. I don't have the time for the moment sorry.

tarasantoshchuk pushed a commit to tarasantoshchuk/RxPermissions that referenced this issue May 13, 2016
@tarasantoshchuk
Copy link
Contributor Author

@tbruyelle
please, review my pull request

@tarasantoshchuk
Copy link
Contributor Author

@tbruyelle
I added new pull request that fixes crash, please review

@tushar-nallan
Copy link

+1 Got the same issue in production.

@Dwite
Copy link

Dwite commented Aug 4, 2016

@tbruyelle so what do you think about PR?

@AAverin
Copy link

AAverin commented Sep 18, 2016

I have just started open beta for my app, have some 500 users, maybe half of them active at best.
Got 1 instance of this exception already. The only permission I ask for is Location.
That means that STR are wrong – my users can't "go to settings and revoke some other permission", because I have only one available, and revoking or granting it while dialog shows on the screen doesn't break the app

@tbruyelle
Copy link
Owner

@AAverin Note that the bug affects only devices with sdk >= 23

@AAverin
Copy link

AAverin commented Sep 18, 2016

@tbruyelle yes, you're right, my bug is on 6.0.1.
Well, that's a bit more reassuring, but probably should be resolved nevertheless

@tbruyelle
Copy link
Owner

@AAverin Agree I want to resolve it but until now nobody found an acceptable fix.

@SjAndy88
Copy link

I don't think the issue can be resolved.

@gotev
Copy link

gotev commented Sep 29, 2016

@flztsj if you request permissions without rx, even if you try the described steps, your app will not crash. I request permissions with this helper I wrote and it works: https://gist.github.com/gotev/67c300c563bdf68a502c

Maybe it can be useful to figure out what is going wrong with RxPermissions

@tbruyelle
Copy link
Owner

Fixed in 0.8.0

@AAverin
Copy link

AAverin commented Nov 5, 2016

@tbruyelle 0.8.0 is tag on github, but not marked as latest release. Is it safe to grab it and use?

@YellFunGit
Copy link

I found that app will crash while mutil RxPermission request at one time. @tbruyelle caused by the same issue.

@epool
Copy link
Collaborator

epool commented Nov 29, 2016

@YellFunGit what version are you using?

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

No branches or pull requests

9 participants