diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java index f6fb0138b..87e172886 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java @@ -44,7 +44,7 @@ public class GCMIntentService extends GCMBaseIntentService { protected void onRegistered( Context context, String regId ) { DbgUtils.logf( "GCMIntentService.onRegistered(%s)", regId ); - XWPrefs.setGCMDevID( context, regId ); + DevID.setGCMDevID( context, regId ); notifyRelayService( context, true ); } @@ -52,7 +52,7 @@ public class GCMIntentService extends GCMBaseIntentService { protected void onUnregistered( Context context, String regId ) { DbgUtils.logf( "GCMIntentService.onUnregistered(%s)", regId ); - XWPrefs.clearGCMDevID( context ); + DevID.clearGCMDevID( context ); RelayService.devIDChanged(); notifyRelayService( context, false ); } @@ -122,7 +122,7 @@ public class GCMIntentService extends GCMBaseIntentService { try { GCMRegistrar.checkDevice( app ); // GCMRegistrar.checkManifest( app ); - String regId = XWPrefs.getGCMDevID( app ); + String regId = DevID.getGCMDevID( app ); if (regId.equals("")) { GCMRegistrar.register( app, GCMConsts.SENDER_ID ); } 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 2d2163f89..af535dbac 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfigDelegate.java @@ -581,7 +581,7 @@ public class GameConfigDelegate extends DelegateBase } else if ( !localOnlyGame() ) { String relayName = XWPrefs.getDefaultRelayHost( m_activity ); int relayPort = XWPrefs.getDefaultRelayPort( m_activity ); - int devID = XWPrefs.getRelayDevIDInt( m_activity ); + int devID = DevID.getRelayDevIDInt( m_activity ); XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort, devID ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index 08ddbeda4..f17a8a766 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -112,7 +112,7 @@ public class GameUtils { if ( 0 == addr.conTypes.size() ) { String relayName = XWPrefs.getDefaultRelayHost( context ); int relayPort = XWPrefs.getDefaultRelayPort( context ); - int devID = XWPrefs.getRelayDevIDInt( context ); + int devID = DevID.getRelayDevIDInt( context ); XwJNI.comms_getInitialAddr( addr, relayName, relayPort, devID ); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java index 2de135b08..7d984455b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayInviteDelegate.java @@ -100,7 +100,7 @@ public class RelayInviteDelegate extends InviteDelegate { addMe.setVisibility( View.VISIBLE ); addMe.setOnClickListener( new View.OnClickListener() { public void onClick( View view ) { - int devIDInt = XWPrefs.getRelayDevIDInt( m_activity ); + int devIDInt = DevID.getRelayDevIDInt( m_activity ); String devID = String.format( "%d", devIDInt ); DevIDRec rec = new DevIDRec( "self", devID ); addChecked( rec ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java index 9d8f1a714..40d78301d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -45,15 +45,16 @@ import java.util.concurrent.LinkedBlockingQueue; import junit.framework.Assert; -import org.eehouse.android.xw4.MultiService.MultiEvent; import org.eehouse.android.xw4.MultiService.DictFetchOwner; -import org.eehouse.android.xw4.jni.CommsAddrRec; +import org.eehouse.android.xw4.MultiService.MultiEvent; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; +import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.GameSummary; -import org.eehouse.android.xw4.jni.UtilCtxt; -import org.eehouse.android.xw4.jni.UtilCtxt.DevIDType; -import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.LastMoveInfo; +import org.eehouse.android.xw4.jni.UtilCtxt.DevIDType; +import org.eehouse.android.xw4.jni.UtilCtxt; +import org.eehouse.android.xw4.jni.UtilCtxtImpl; +import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.loc.LocUtils; public class RelayService extends XWService @@ -163,7 +164,7 @@ public class RelayService extends XWService public static void inviteRemote( Context context, int destDevID, String relayID, NetLaunchInfo nli ) { - int myDevID = XWPrefs.getRelayDevIDInt( context ); + int myDevID = DevID.getRelayDevIDInt( context ); if ( 0 != myDevID ) { context.startService( getIntentTo( context, MsgCmds.INVITE ) .putExtra( DEV_ID_SRC, myDevID ) @@ -538,6 +539,8 @@ public class RelayService extends XWService InetAddress addr = InetAddress.getByName( host ); m_UDPSocket.connect( addr, port ); // remember this address + DbgUtils.logdf( "RelayService.connectSocket(%s:%d): m_UDPSocket" + + " now %H", host, port, m_UDPSocket ); } catch( java.net.SocketException se ) { DbgUtils.loge( se ); Assert.fail(); @@ -574,12 +577,13 @@ public class RelayService extends XWService try { DatagramPacket outPacket = outData.assemble(); m_UDPSocket.send( outPacket ); - int packetID = outData.m_packetID; - DbgUtils.logdf( "Sent udp packet, id=%d, of " - + "length %d", - packetID, outPacket.getLength() ); + int pid = outData.m_packetID; + DbgUtils.logdf( "Sent udp packet, cmd=%s, id=%d," + + " of length %d", + outData.m_cmd.toString(), + pid, outPacket.getLength()); synchronized( s_packetsSent ) { - s_packetsSent.add( packetID ); + s_packetsSent.add( pid ); } resetExitTimer(); ConnStatusHandler.showSuccessOut(); @@ -665,7 +669,7 @@ public class RelayService extends XWService case XWPDEV_BADREG: str = getVLIString( dis ); DbgUtils.logf( "bad relayID \"%s\" reported", str ); - XWPrefs.clearRelayDevID( this ); + DevID.clearRelayDevID( this ); s_registered = false; registerWithRelay(); break; @@ -676,7 +680,7 @@ public class RelayService extends XWService Integer.parseInt( str, 16 ), maxIntervalSeconds ); setMaxIntervalSeconds( maxIntervalSeconds ); - XWPrefs.setRelayDevID( this, str ); + DevID.setRelayDevID( this, str ); s_registered = true; break; case XWPDEV_HAVEMSGS: @@ -744,13 +748,9 @@ public class RelayService extends XWService private boolean shouldRegister() { - String relayID = XWPrefs.getRelayDevID( this ); + String relayID = DevID.getRelayDevID( this, true ); boolean registered = null != relayID; - if ( registered ) { - registered = XWPrefs - .getPrefsBoolean( this, R.string.key_relay_regid_ackd, false ); - } - // DbgUtils.logf( "shouldRegister()=>%b", !registered ); + DbgUtils.logdf( "shouldRegister()=>%b", !registered ); return !registered; } @@ -770,7 +770,7 @@ public class RelayService extends XWService DbgUtils.logf( "registerWithRelay: skipping because only %d " + "seconds since last start", interval ); } else { - String relayID = XWPrefs.getRelayDevID( this ); + String relayID = DevID.getRelayDevID( this ); DevIDType[] typa = new DevIDType[1]; String devid = getDevID( typa ); DevIDType typ = typa[0]; @@ -954,17 +954,13 @@ public class RelayService extends XWService private String getDevID( DevIDType[] typp ) { - String devid = null; DevIDType typ; + String devid = DevID.getRelayDevID( this, true ); - if ( XWPrefs.getPrefsBoolean( this, R.string.key_relay_regid_ackd, - false ) ) { - devid = XWPrefs.getRelayDevID( this ); - } if ( null != devid && 0 < devid.length() ) { typ = DevIDType.ID_TYPE_RELAY; } else { - devid = XWPrefs.getGCMDevID( this ); + devid = DevID.getGCMDevID( this ); if ( null != devid && 0 < devid.length() ) { typ = DevIDType.ID_TYPE_ANDROID_GCM; } else { @@ -1411,5 +1407,4 @@ public class RelayService extends XWService public byte[] m_header; public int m_packetID; } - } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWDevIDPreference.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWDevIDPreference.java index b70b40c55..dbb638ed0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWDevIDPreference.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWDevIDPreference.java @@ -38,7 +38,7 @@ public class XWDevIDPreference extends EditTextPreference { protected void onAttachedToActivity() { super.onAttachedToActivity(); - int devID = XWPrefs.getRelayDevIDInt( m_context ); + int devID = DevID.getRelayDevIDInt( m_context ); setSummary( String.format( "%d", devID ) ); } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java index f76e21d49..e7da93f19 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java @@ -25,7 +25,6 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.preference.PreferenceManager; import android.text.TextUtils; -import com.google.android.gcm.GCMRegistrar; import java.util.ArrayList; import junit.framework.Assert; @@ -252,6 +251,7 @@ public class XWPrefs { return getPrefsStringArray( context, R.string.key_sms_phones ); } + // Used by RelayInviteDelegate.java public static void setRelayIDs( Context context, String[] names ) { setPrefsStringArray( context, R.string.key_relay_ids, names ); @@ -283,62 +283,6 @@ public class XWPrefs { return id; } - public static void setGCMDevID( Context context, String devID ) - { - int curVers = Utils.getAppVersion( context ); - setPrefsInt( context, R.string.key_gcmvers_regid, curVers ); - setPrefsBoolean( context, R.string.key_relay_regid_ackd, false ); - } - - public static String getGCMDevID( Context context ) - { - int curVers = Utils.getAppVersion( context ); - int storedVers = getPrefsInt( context, R.string.key_gcmvers_regid, 0 ); - String result; - if ( 0 != storedVers && storedVers < curVers ) { - result = ""; // Don't trust what registrar has - } else { - result = GCMRegistrar.getRegistrationId( context ); - } - return result; - } - - public static void clearGCMDevID( Context context ) - { - setPrefsBoolean( context, R.string.key_relay_regid_ackd, false ); - } - - public static String getRelayDevID( Context context ) - { - String result = getPrefsString( context, R.string.key_relay_regid ); - if ( null != result && 0 == result.length() ) { - result = null; - } - return result; - } - - public static int getRelayDevIDInt( Context context ) - { - int result = 0; - String str = getRelayDevID( context ); - if ( null != str ) { - result = Integer.valueOf( str, 16 ); - } - DbgUtils.logf( "getRelayDevIDInt(): %s => %d", str, result ); - return result; - } - - public static void setRelayDevID( Context context, String idRelay ) - { - setPrefsString( context, R.string.key_relay_regid, idRelay ); - setPrefsBoolean( context, R.string.key_relay_regid_ackd, true ); - } - - public static void clearRelayDevID( Context context ) - { - clearPrefsKey( context, R.string.key_relay_regid ); - } - public static DictUtils.DictLoc getDefaultLoc( Context context ) { boolean internal = getDefaultLocInternal( context ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java index 0152fcce2..b8d5ddfff 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java @@ -28,7 +28,7 @@ import junit.framework.Assert; import org.eehouse.android.xw4.DbgUtils; import org.eehouse.android.xw4.R; import org.eehouse.android.xw4.XWApp; -import org.eehouse.android.xw4.XWPrefs; +import org.eehouse.android.xw4.DevID; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.loc.LocUtils; @@ -100,11 +100,11 @@ public class UtilCtxtImpl implements UtilCtxt { public String getDevID( /*out*/ byte[] typa ) { UtilCtxt.DevIDType typ = UtilCtxt.DevIDType.ID_TYPE_NONE; - String result = XWPrefs.getRelayDevID( m_context ); + String result = DevID.getRelayDevID( m_context ); if ( null != result ) { typ = UtilCtxt.DevIDType.ID_TYPE_RELAY; } else { - result = XWPrefs.getGCMDevID( m_context ); + result = DevID.getGCMDevID( m_context ); if ( result.equals("") ) { result = null; } else { @@ -119,10 +119,10 @@ public class UtilCtxtImpl implements UtilCtxt { { switch ( devIDType ) { case ID_TYPE_RELAY: - XWPrefs.setRelayDevID( m_context, idRelay ); + DevID.setRelayDevID( m_context, idRelay ); break; case ID_TYPE_NONE: - XWPrefs.clearRelayDevID( m_context ); + DevID.clearRelayDevID( m_context ); break; default: Assert.fail();