-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Created a test for permissionPermanentlyDenied #212
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
@itsymbal thank you for sending this PR! If you sign the CLA, happy to merge. |
|
||
import android.support.v7.app.AppCompatActivity; | ||
|
||
class TestActivity extends AppCompatActivity { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add one-line JavaDoc comments to this class and to TestApplication
to specify why we need them? When reading this PR it's obvious, but it may not be obvious to future code readers.
@samtstern the test is failing though according to @itsymbal. Also, that's making a system call so do we really need to test it? (And is it even possible?) |
Oh I didn't notice that the test was failing ... well yes I would want it to pass first! It should be possible to test this system call, we test a similar system call in the other test in the same file. @itsymbal what was your main motivation for adding this test to the library? |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
Added javadoc as requested. @SUPERCILEX The test is exercising your library call @samtstern My intention was to demonstrate a problem with the library itself. The call to 'permissionPermanentlyDenied()' method calls through to So, as I mentioned, the test is correct. |
Ohhhhhhhhh, so you're just saying you'd like us to perform the permission check for you? That would have been so much clearer if you made an issue 😂. Oh well, @samtstern do you want a PR or should we stay aligned with system behavior? I think what @itsymbal is saying makes sense so I'm for the PR. |
Well, I'm happy to make an issue also. But how does one know an issue is resolved without making a failing test into a passing test, right? |
Yeah, true. Do you want to go ahead and make your test pass then if @samtstern agrees with this change? |
Ah @itsymbal I get it now, thank you for expressing the problem as a failing test. I do appreciate how thorough that is! I was aware of this issue, that's why the docs only suggest making this call after the permission has been denied: As you said the platform API does not allow any way to determine this, but I don't think EasyPermissions should start persisting permission request information (feels like it would be error-prone). I think the best thing to do would be to add a strongly-worded warning to both the README and the JavaDoc about exactly when this method is effective. What do you think about that? |
Thanks, @samtstern. I must admit I haven't considered your suggested approach - ask for permission first, and if denied, check 'shouldShowRequestPermissionRationale()' - and if But let's consider a different, entirely reasonable, scenario. So the app logic is something like: if have permission, do the thing If I use the approach you suggest, when checking for permanent denial (ask permission then check 'shouldShowRequestPermissionRationale()') - I violate the requirement to show rationale before asking for perm. So in this type of scenario, the suggested solution of asking for permission first, doesn't work well. So, I am back to suggesting that the fact of having requested a permission be persisted - error-prone though it may be. I'm also suggesting a robust test coverage to detect some of the potential errors. I do wonder though. With you being a Google insider, do you have the ear of the platform team, for the purpose of requesting a feature to check if the perm's been permanently denied? That's information the system has access to, it merely needs to be surfaced via an api call... |
@itsymbal thanks again for the detailed discussion. I think there are two kinds of "rationale" and only one of them is supported by EasyPermissions. In this library we use "rationale" to mean "a small amount of text shown in a dialog when an app requests a previously denied permission". The idea is that the first request happens without rationale, but if the user denies it and the app wants to request again it has to give rationale first. This is just following the UX recommended by the platform team and the results coming back from system calls. The second kind of rationale, which many polished apps use, is the kind shown before any request, For example you'd show a full screen prompt saying that "In order to help you share restaurants with your friends, the app will need access to your contacts" to make the prompt not-scary. In this case the prompt normally only happens after an explicit user click. Unfortunately EasyPermissions does not deal with that kind of rationale at all, as it's something that should be designed to fit within the app flow and I don't believe we'd be able to provide a suitable one-size-fits-all solution. So here's what I think we should do:
For now I don't want to get into the business of request persistence, even if we may be able to do it correctly with careful coding and testing. |
@samtstern |
Change-Id: Id60b0b3ed25d44f3e3da027427a4337dd6672e92
The method call requires an activity, so I've added that (and an Application class which it requires and test configuration which that requires)
The test is failing.
The test is correct. The underlying library method does not work correctly.