mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
check phone permission before putting up sms choice
First, needed to remove some state caching since though a non-SMS phone will never become one my ability to ask changes over time. Then changed population of communication options to first ask for the permission needed in order to find out what's supported, then to find out what's supported via methods that will return false without permission. Can't think of a better way right now....
This commit is contained in:
parent
3389e928cc
commit
d136dd65e6
4 changed files with 40 additions and 22 deletions
|
@ -20,11 +20,12 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
@ -37,6 +38,7 @@ public class ConnViaViewLayout extends LinearLayout {
|
|||
private static final String TAG = ConnViaViewLayout.class.getSimpleName();
|
||||
private CommsConnTypeSet m_curSet;
|
||||
private DlgDelegate.HasDlgDelegate m_dlgDlgt;
|
||||
private Activity m_activity;
|
||||
|
||||
public interface CheckEnabledWarner {
|
||||
public void warnDisabled( CommsConnType typ );
|
||||
|
@ -52,6 +54,8 @@ public class ConnViaViewLayout extends LinearLayout {
|
|||
super( context, as );
|
||||
}
|
||||
|
||||
public void setActivity( Activity activity ) { m_activity = activity; }
|
||||
|
||||
protected void configure( CommsConnTypeSet types,
|
||||
CheckEnabledWarner cew,
|
||||
SetEmptyWarner sew,
|
||||
|
@ -72,6 +76,21 @@ public class ConnViaViewLayout extends LinearLayout {
|
|||
}
|
||||
|
||||
private void addConnections()
|
||||
{
|
||||
|
||||
// We need SMS and PHONE permission to check if we can support SMS. So
|
||||
// ask for it here. When we get what we're getting, proceed to
|
||||
// actually check for what's supported. Those methods will return
|
||||
// false if they don't have the permission they need.
|
||||
Perms23.doWithPermission( m_activity, Perms23.Perm.READ_PHONE_STATE,
|
||||
new Perms23.PermCbck() {
|
||||
public void onPermissionResult( Perms23.Perm perm, boolean granted ) {
|
||||
addConnectionsPostPermCheck();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
private void addConnectionsPostPermCheck()
|
||||
{
|
||||
LinearLayout list = (LinearLayout)findViewById( R.id.conn_types );
|
||||
list.removeAllViews(); // in case being reused
|
||||
|
|
|
@ -288,6 +288,7 @@ public class GameConfigDelegate extends DelegateBase
|
|||
LinearLayout layout = (LinearLayout)inflate( R.layout.conn_types_display );
|
||||
final ConnViaViewLayout items = (ConnViaViewLayout)
|
||||
layout.findViewById( R.id.conn_types );
|
||||
items.setActivity( m_activity );
|
||||
final CheckBox cb = (CheckBox)layout
|
||||
.findViewById(R.id.default_check);
|
||||
cb.setVisibility( View.VISIBLE );
|
||||
|
|
|
@ -72,7 +72,7 @@ public class Utils {
|
|||
|
||||
private static Boolean s_isFirstBootThisVersion = null;
|
||||
private static Boolean s_firstVersion = null;
|
||||
private static Boolean s_deviceSupportSMS = null;
|
||||
// private static Boolean s_deviceSupportSMS = null;
|
||||
private static Boolean s_isFirstBootEver = null;
|
||||
private static Integer s_appVersion = null;
|
||||
private static HashMap<String,String> s_phonesHash =
|
||||
|
@ -112,6 +112,7 @@ public class Utils {
|
|||
SMSService.SMSPhoneInfo info = SMSService.getPhoneInfo( context );
|
||||
result = info.isPhone && info.isGSM;
|
||||
}
|
||||
DbgUtils.logd( TAG, "isGSMPhone() => %b", result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -122,18 +123,19 @@ public class Utils {
|
|||
// that's not allowed except on GSM phones.)
|
||||
public static boolean deviceSupportsSMS( Context context )
|
||||
{
|
||||
if ( null == s_deviceSupportSMS ) {
|
||||
boolean result = false;
|
||||
if ( Perms23.havePermission( Perms23.Perm.READ_PHONE_STATE ) ) {
|
||||
TelephonyManager tm = (TelephonyManager)
|
||||
context.getSystemService( Context.TELEPHONY_SERVICE );
|
||||
boolean doesSMS = null != tm;
|
||||
s_deviceSupportSMS = new Boolean( doesSMS );
|
||||
result = null != tm;
|
||||
}
|
||||
return s_deviceSupportSMS;
|
||||
DbgUtils.logd( TAG, "deviceSupportsSMS() => %b", result );
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void smsSupportChanged()
|
||||
{
|
||||
s_deviceSupportSMS = null; // force to check again
|
||||
// s_deviceSupportSMS = null; // force to check again
|
||||
}
|
||||
|
||||
public static void notImpl( Context context )
|
||||
|
|
|
@ -77,7 +77,6 @@ public class CommsAddrRec {
|
|||
|
||||
public static class CommsConnTypeSet extends HashSet<CommsConnType> {
|
||||
private static final int BIT_VECTOR_MASK = 0x8000;
|
||||
private static CommsConnTypeSet s_supported;
|
||||
|
||||
public CommsConnTypeSet() { this(BIT_VECTOR_MASK); }
|
||||
|
||||
|
@ -116,21 +115,18 @@ public class CommsAddrRec {
|
|||
|
||||
public static CommsConnTypeSet getSupported( Context context )
|
||||
{
|
||||
if ( null == s_supported ) {
|
||||
CommsConnTypeSet supported = new CommsConnTypeSet();
|
||||
supported.add( CommsConnType.COMMS_CONN_RELAY );
|
||||
if ( BTService.BTAvailable() ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_BT );
|
||||
}
|
||||
if ( Utils.isGSMPhone( context ) ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_SMS );
|
||||
}
|
||||
if ( WiDirService.supported() ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_P2P );
|
||||
}
|
||||
s_supported = supported;
|
||||
CommsConnTypeSet supported = new CommsConnTypeSet();
|
||||
supported.add( CommsConnType.COMMS_CONN_RELAY );
|
||||
if ( BTService.BTAvailable() ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_BT );
|
||||
}
|
||||
return s_supported;
|
||||
if ( Utils.isGSMPhone( context ) ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_SMS );
|
||||
}
|
||||
if ( WiDirService.supported() ) {
|
||||
supported.add( CommsConnType.COMMS_CONN_P2P );
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
public static void removeUnsupported( Context context,
|
||||
|
|
Loading…
Add table
Reference in a new issue