tweak permissions; stop using shouldShowRequestPermissionRationale()

It apparently returns false if I haven't asked before, and that's the
one time you want to be sure to ask.
This commit is contained in:
Eric House 2022-05-16 15:12:11 -07:00
parent 71e90eed77
commit 2148288cf1
2 changed files with 42 additions and 37 deletions

View file

@ -55,11 +55,6 @@ public class Perms23 {
public String getString() { return m_str; } public String getString() { return m_str; }
public boolean isBanned( Context context ) public boolean isBanned( Context context )
{ {
// PENDING... Once this has been here for a week or so, remove
// SMS_BANNED. That way absence of the permission from a variant's
// manifest is the only way being banned is expressed. It sucks
// keeping two things in sync.
// Assert.assertFalse( m_banned == permInManifest( context, this ) );
return !permInManifest( context, this ); return !permInManifest( context, this );
} }
public static Perm getFor( String str ) { public static Perm getFor( String str ) {
@ -159,9 +154,7 @@ public class Perms23 {
Assert.assertFalse( perm.isBanned(activity) ); Assert.assertFalse( perm.isBanned(activity) );
askStrings.add( permStr ); askStrings.add( permStr );
if ( null != m_onShow && ActivityCompat if ( null != m_onShow ) {
.shouldShowRequestPermissionRationale( activity,
permStr ) ) {
needShow.add( perm ); needShow.add( perm );
} }
} }
@ -239,7 +232,7 @@ public class Perms23 {
doItAsk( validPerms, showRationale ); doItAsk( validPerms, showRationale );
} }
if ( 0 < bannedPerms.size() ) { if ( 0 < bannedPerms.size() ) {
doItFail( bannedPerms ); postNeg();
} }
} }
@ -253,8 +246,8 @@ public class Perms23 {
m_delegate.makeConfirmThenBuilder( m_rationaleMsg, m_delegate.makeConfirmThenBuilder( m_rationaleMsg,
Action.PERMS_QUERY ) Action.PERMS_QUERY )
.setTitle( R.string.perms_rationale_title ) .setTitle( R.string.perms_rationale_title )
.setPosButton( R.string.button_ask_again ) .setPosButton( R.string.button_ask )
.setNegButton( R.string.button_skip ) .setNegButton( R.string.button_deny )
.setParams( QueryInfo.this.getParams() ) .setParams( QueryInfo.this.getParams() )
.setNAKey( mNAKey ) .setNAKey( mNAKey )
.show(); .show();
@ -276,31 +269,25 @@ public class Perms23 {
} ); } );
} }
// Cons up a call with a "no" answer, and post it.
private void doItFail( Set<Perm> bannedPerms )
{
m_delegate.post( new Runnable() {
@Override
public void run() {
Log.d( TAG, "doItFail(); passing perms to onNegButton(%s)", m_action );
m_delegate.onNegButton( m_action, m_params );
}
} );
}
// Post this in case we're called from inside dialog dismiss // Post this in case we're called from inside dialog dismiss
// code. Better to unwind the stack... // code. Better to unwind the stack...
private void handleButton( final boolean positive ) private void handleButton( final boolean positive )
{ {
m_delegate.post( new Runnable() {
public void run() {
if ( positive ) { if ( positive ) {
m_delegate.post( new Runnable() {
@Override
public void run() {
doIt( false ); doIt( false );
} else {
m_delegate.onNegButton( m_action, m_params );
}
} }
} ); } );
} else {
postNeg();
}
}
private void postNeg()
{
Perms23.postNeg( m_delegate, m_action, m_params );
} }
} }
@ -316,14 +303,32 @@ public class Perms23 {
* Request permissions, giving rationale once, then call with action and * Request permissions, giving rationale once, then call with action and
* either positive or negative, the former if permission granted. * either positive or negative, the former if permission granted.
*/ */
private static void tryGetPermsImpl( DelegateBase delegate, Perm[] perms, private static void tryGetPermsImpl( final DelegateBase delegate, Perm[] perms,
String rationaleMsg, int naKey, String rationaleMsg, int naKey,
final Action action, Object... params ) final Action action, Object... params )
{ {
// Log.d( TAG, "tryGetPerms(%s)", perm.toString() ); // Log.d( TAG, "tryGetPerms(%s)", perm.toString() );
new QueryInfo( delegate, action, perms, rationaleMsg, naKey, params )
if ( 0 != naKey &&
XWPrefs.getPrefsBoolean( delegate.getActivity(), naKey, false ) ) {
postNeg( delegate, action, params );
} else {
new QueryInfo( delegate, action, perms, rationaleMsg,
naKey, params )
.doIt( true ); .doIt( true );
} }
}
private static void postNeg( final DelegateBase delegate,
final Action action, final Object[] params )
{
delegate.post( new Runnable() {
@Override
public void run() {
delegate.onNegButton( action, params );
}
} );
}
public static void tryGetPerms( DelegateBase delegate, Perm[] perms, int rationaleId, public static void tryGetPerms( DelegateBase delegate, Perm[] perms, int rationaleId,
final Action action, Object... params ) final Action action, Object... params )

View file

@ -2404,7 +2404,7 @@
</string> </string>
<string name="dicts_storage_rationale"> <string name="dicts_storage_rationale">
CrossWords can store and read wordlists in your devices CrossWords can store and read wordlists in your devices
Downloads area but it needs permission to access them Downloads area but it needs to ask for permission to access them
there.\n\nYou can safely deny this permission if you will never there.\n\nYou can safely deny this permission if you will never
download wordlists except from inside CrossWords and have not download wordlists except from inside CrossWords and have not
previously stored any there. previously stored any there.
@ -2441,13 +2441,13 @@
<string name="remove_sms">Remove SMS</string> <string name="remove_sms">Remove SMS</string>
<!-- In the permissions rationale explanation, means go ahead and <!-- In the permissions rationale explanation, means go ahead and
have the OS ask for permission --> have the OS ask for permission -->
<string name="button_ask_again">Ask again</string> <string name="button_ask">Ask</string>
<!-- Displayed as a toast --> <!-- Displayed as a toast -->
<string name="sms_send_failed">SMS send failed</string> <string name="sms_send_failed">SMS send failed</string>
<!-- In the permissions rationale explanation, means don't have the <!-- In the permissions rationale explanation, means don't have the
OS ask for permission: user is denying it implicitly --> OS ask for permission: user is denying it implicitly -->
<string name="button_skip">Skip</string> <string name="button_deny">Deny</string>
<string name="perms_rationale_title">Android Permissions</string> <string name="perms_rationale_title">Android Permission Explained</string>
<string name="toast_no_permission">Permission not granted</string> <string name="toast_no_permission">Permission not granted</string>
<!-- Explanation in settings for always-on BT notification --> <!-- Explanation in settings for always-on BT notification -->
<string name="nbsproxy_channel_expl">Alerts about NBSProxy</string> <string name="nbsproxy_channel_expl">Alerts about NBSProxy</string>