diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java index 7b87a59dd..a13914d12 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnViaViewLayout.java @@ -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 diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java index 90b2bf84c..d6cc77cfc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java @@ -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 ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index 9514555e5..c3fc76163 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -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 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 ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java index 87e39c04f..a030d819e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommsAddrRec.java @@ -77,7 +77,6 @@ public class CommsAddrRec { public static class CommsConnTypeSet extends HashSet { 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,