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

@OnNeverAskAgain not being called #78

Closed
emarc-m opened this issue Jan 20, 2016 · 10 comments
Closed

@OnNeverAskAgain not being called #78

emarc-m opened this issue Jan 20, 2016 · 10 comments
Assignees
Labels
Milestone

Comments

@emarc-m
Copy link

emarc-m commented Jan 20, 2016

Annotating a method with @OnNeverAskAgain is not called. What is called is the method annotated with @OnPermissionDenied.

I think the generated code conditions checks are incorrect.

static void onRequestPermissionsResult(BaseActivity target, int requestCode, int[] grantResults) {
    switch (requestCode) {
      case REQUEST_INITIALIZESCANNING:
      // this would always be true if the permission was denied and on never ask again
      if (!PermissionUtils.hasSelfPermissions(target, PERMISSION_INITIALIZESCANNING)) {
        target.showDenied();
        return;
      }
      if (PermissionUtils.verifyPermissions(grantResults)) {
        target.initializeScanning();
      } else {
        if (!PermissionUtils.shouldShowRequestPermissionRationale(target, PERMISSION_INITIALIZESCANNING)) {
          target.showNeverAsk(); // this is NEVER called
        } else {
          target.showDenied();
        }
      }
      break;
      default:
      break;
    }
  }

Thanks. Great work BTW.

@hotchemi
Copy link
Member

@emarc-m Ah, could u use 2.0.2 for the time being? It might works well. So sorry!

@hotchemi hotchemi added the bug label Jan 21, 2016
@hotchemi hotchemi self-assigned this Jan 21, 2016
@emarc-m
Copy link
Author

emarc-m commented Jan 21, 2016

@hotchemi Thanks for that info.

@shiraji
Copy link
Member

shiraji commented Jan 21, 2016

It's time to add functional tests.

@hotchemi
Copy link
Member

Right code is as follows.

static void onRequestPermissionsResult(BaseActivity target, int requestCode, int[] grantResults) {
    switch (requestCode) {
      case REQUEST_INITIALIZESCANNING:
+     // Never ask again is never shown if Build.VERSION. SDK_INT is under 23 
+     if (Build.VERSION. SDK_INT < 23 && !PermissionUtils.hasSelfPermissions(target, PERMISSION_INITIALIZESCANNING)) {
        target.showDenied();
        return;
      }
      if (PermissionUtils.verifyPermissions(grantResults)) {
        target.initializeScanning();
      } else {
        if (!PermissionUtils.shouldShowRequestPermissionRationale(target, PERMISSION_INITIALIZESCANNING)) {
          target.showNeverAsk(); // this is NEVER called
        } else {
          target.showDenied();
        }
      }
      break;
      default:
      break;
    }
  }

@hotchemi hotchemi added this to the 2.0.4 milestone Jan 21, 2016
@hotchemi
Copy link
Member

@shiraji Might be the good idea but it takes a bunch of cost...worrisome problem.

@shiraji
Copy link
Member

shiraji commented Jan 21, 2016

Wait, I think there is one more problem. PermissionDispatcher must take care of SYSTEM_ALERT_WINDOW and WRITE_SETTINGS.

This test case is not correct. Should be following:

if (!Settings.System.canWrite(target)) 

This line should check if it is in ADD_WITH_CHECK_BODY_MAP

We need to refactor fun addHasSelfPermissionsCondition(builder: MethodSpec.Builder, activityVar: String) as well in order to take care of this one.

Do you want me to send pull request for this?

@hotchemi
Copy link
Member

@shiraji Umm, actually this line is just workaround for under M devices. See #45 (comment) .

I'm not sure the same thing happens in SYSTEM_ALERT_WINDOW and WRITE_SETTINGS.
So, we should delete this line when exceptional permissions case.

Do you want me to send pull request for this?

Sure!

@shiraji
Copy link
Member

shiraji commented Jan 21, 2016

So, we should delete this line when exceptional permissions case.

That makes life easier!

@hotchemi
Copy link
Member

@emarc-m Just released 2.0.4. Really appreciated for your report.

@emarc-m
Copy link
Author

emarc-m commented Jan 22, 2016

@hotchemi Thanks for the support.

shiraji pushed a commit to shiraji/PermissionsDispatcher that referenced this issue Jan 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants