mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-24 07:58:34 +01:00
use new DevID class instead of methods in XWPrefs, which are removed.
This commit is contained in:
parent
23f803bb98
commit
440e85f3a5
8 changed files with 35 additions and 96 deletions
|
@ -44,7 +44,7 @@ public class GCMIntentService extends GCMBaseIntentService {
|
||||||
protected void onRegistered( Context context, String regId )
|
protected void onRegistered( Context context, String regId )
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "GCMIntentService.onRegistered(%s)", regId );
|
DbgUtils.logf( "GCMIntentService.onRegistered(%s)", regId );
|
||||||
XWPrefs.setGCMDevID( context, regId );
|
DevID.setGCMDevID( context, regId );
|
||||||
notifyRelayService( context, true );
|
notifyRelayService( context, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class GCMIntentService extends GCMBaseIntentService {
|
||||||
protected void onUnregistered( Context context, String regId )
|
protected void onUnregistered( Context context, String regId )
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "GCMIntentService.onUnregistered(%s)", regId );
|
DbgUtils.logf( "GCMIntentService.onUnregistered(%s)", regId );
|
||||||
XWPrefs.clearGCMDevID( context );
|
DevID.clearGCMDevID( context );
|
||||||
RelayService.devIDChanged();
|
RelayService.devIDChanged();
|
||||||
notifyRelayService( context, false );
|
notifyRelayService( context, false );
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class GCMIntentService extends GCMBaseIntentService {
|
||||||
try {
|
try {
|
||||||
GCMRegistrar.checkDevice( app );
|
GCMRegistrar.checkDevice( app );
|
||||||
// GCMRegistrar.checkManifest( app );
|
// GCMRegistrar.checkManifest( app );
|
||||||
String regId = XWPrefs.getGCMDevID( app );
|
String regId = DevID.getGCMDevID( app );
|
||||||
if (regId.equals("")) {
|
if (regId.equals("")) {
|
||||||
GCMRegistrar.register( app, GCMConsts.SENDER_ID );
|
GCMRegistrar.register( app, GCMConsts.SENDER_ID );
|
||||||
}
|
}
|
||||||
|
|
|
@ -581,7 +581,7 @@ public class GameConfigDelegate extends DelegateBase
|
||||||
} else if ( !localOnlyGame() ) {
|
} else if ( !localOnlyGame() ) {
|
||||||
String relayName = XWPrefs.getDefaultRelayHost( m_activity );
|
String relayName = XWPrefs.getDefaultRelayHost( m_activity );
|
||||||
int relayPort = XWPrefs.getDefaultRelayPort( 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,
|
XwJNI.comms_getInitialAddr( m_carOrig, relayName,
|
||||||
relayPort, devID );
|
relayPort, devID );
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class GameUtils {
|
||||||
if ( 0 == addr.conTypes.size() ) {
|
if ( 0 == addr.conTypes.size() ) {
|
||||||
String relayName = XWPrefs.getDefaultRelayHost( context );
|
String relayName = XWPrefs.getDefaultRelayHost( context );
|
||||||
int relayPort = XWPrefs.getDefaultRelayPort( context );
|
int relayPort = XWPrefs.getDefaultRelayPort( context );
|
||||||
int devID = XWPrefs.getRelayDevIDInt( context );
|
int devID = DevID.getRelayDevIDInt( context );
|
||||||
XwJNI.comms_getInitialAddr( addr, relayName, relayPort, devID );
|
XwJNI.comms_getInitialAddr( addr, relayName, relayPort, devID );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class RelayInviteDelegate extends InviteDelegate {
|
||||||
addMe.setVisibility( View.VISIBLE );
|
addMe.setVisibility( View.VISIBLE );
|
||||||
addMe.setOnClickListener( new View.OnClickListener() {
|
addMe.setOnClickListener( new View.OnClickListener() {
|
||||||
public void onClick( View view ) {
|
public void onClick( View view ) {
|
||||||
int devIDInt = XWPrefs.getRelayDevIDInt( m_activity );
|
int devIDInt = DevID.getRelayDevIDInt( m_activity );
|
||||||
String devID = String.format( "%d", devIDInt );
|
String devID = String.format( "%d", devIDInt );
|
||||||
DevIDRec rec = new DevIDRec( "self", devID );
|
DevIDRec rec = new DevIDRec( "self", devID );
|
||||||
addChecked( rec );
|
addChecked( rec );
|
||||||
|
|
|
@ -45,15 +45,16 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
|
||||||
import org.eehouse.android.xw4.MultiService.DictFetchOwner;
|
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.CommsConnType;
|
||||||
|
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||||
import org.eehouse.android.xw4.jni.GameSummary;
|
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.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;
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
|
|
||||||
public class RelayService extends XWService
|
public class RelayService extends XWService
|
||||||
|
@ -163,7 +164,7 @@ public class RelayService extends XWService
|
||||||
public static void inviteRemote( Context context, int destDevID,
|
public static void inviteRemote( Context context, int destDevID,
|
||||||
String relayID, NetLaunchInfo nli )
|
String relayID, NetLaunchInfo nli )
|
||||||
{
|
{
|
||||||
int myDevID = XWPrefs.getRelayDevIDInt( context );
|
int myDevID = DevID.getRelayDevIDInt( context );
|
||||||
if ( 0 != myDevID ) {
|
if ( 0 != myDevID ) {
|
||||||
context.startService( getIntentTo( context, MsgCmds.INVITE )
|
context.startService( getIntentTo( context, MsgCmds.INVITE )
|
||||||
.putExtra( DEV_ID_SRC, myDevID )
|
.putExtra( DEV_ID_SRC, myDevID )
|
||||||
|
@ -538,6 +539,8 @@ public class RelayService extends XWService
|
||||||
|
|
||||||
InetAddress addr = InetAddress.getByName( host );
|
InetAddress addr = InetAddress.getByName( host );
|
||||||
m_UDPSocket.connect( addr, port ); // remember this address
|
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 ) {
|
} catch( java.net.SocketException se ) {
|
||||||
DbgUtils.loge( se );
|
DbgUtils.loge( se );
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
|
@ -574,12 +577,13 @@ public class RelayService extends XWService
|
||||||
try {
|
try {
|
||||||
DatagramPacket outPacket = outData.assemble();
|
DatagramPacket outPacket = outData.assemble();
|
||||||
m_UDPSocket.send( outPacket );
|
m_UDPSocket.send( outPacket );
|
||||||
int packetID = outData.m_packetID;
|
int pid = outData.m_packetID;
|
||||||
DbgUtils.logdf( "Sent udp packet, id=%d, of "
|
DbgUtils.logdf( "Sent udp packet, cmd=%s, id=%d,"
|
||||||
+ "length %d",
|
+ " of length %d",
|
||||||
packetID, outPacket.getLength() );
|
outData.m_cmd.toString(),
|
||||||
|
pid, outPacket.getLength());
|
||||||
synchronized( s_packetsSent ) {
|
synchronized( s_packetsSent ) {
|
||||||
s_packetsSent.add( packetID );
|
s_packetsSent.add( pid );
|
||||||
}
|
}
|
||||||
resetExitTimer();
|
resetExitTimer();
|
||||||
ConnStatusHandler.showSuccessOut();
|
ConnStatusHandler.showSuccessOut();
|
||||||
|
@ -665,7 +669,7 @@ public class RelayService extends XWService
|
||||||
case XWPDEV_BADREG:
|
case XWPDEV_BADREG:
|
||||||
str = getVLIString( dis );
|
str = getVLIString( dis );
|
||||||
DbgUtils.logf( "bad relayID \"%s\" reported", str );
|
DbgUtils.logf( "bad relayID \"%s\" reported", str );
|
||||||
XWPrefs.clearRelayDevID( this );
|
DevID.clearRelayDevID( this );
|
||||||
s_registered = false;
|
s_registered = false;
|
||||||
registerWithRelay();
|
registerWithRelay();
|
||||||
break;
|
break;
|
||||||
|
@ -676,7 +680,7 @@ public class RelayService extends XWService
|
||||||
Integer.parseInt( str, 16 ),
|
Integer.parseInt( str, 16 ),
|
||||||
maxIntervalSeconds );
|
maxIntervalSeconds );
|
||||||
setMaxIntervalSeconds( maxIntervalSeconds );
|
setMaxIntervalSeconds( maxIntervalSeconds );
|
||||||
XWPrefs.setRelayDevID( this, str );
|
DevID.setRelayDevID( this, str );
|
||||||
s_registered = true;
|
s_registered = true;
|
||||||
break;
|
break;
|
||||||
case XWPDEV_HAVEMSGS:
|
case XWPDEV_HAVEMSGS:
|
||||||
|
@ -744,13 +748,9 @@ public class RelayService extends XWService
|
||||||
|
|
||||||
private boolean shouldRegister()
|
private boolean shouldRegister()
|
||||||
{
|
{
|
||||||
String relayID = XWPrefs.getRelayDevID( this );
|
String relayID = DevID.getRelayDevID( this, true );
|
||||||
boolean registered = null != relayID;
|
boolean registered = null != relayID;
|
||||||
if ( registered ) {
|
DbgUtils.logdf( "shouldRegister()=>%b", !registered );
|
||||||
registered = XWPrefs
|
|
||||||
.getPrefsBoolean( this, R.string.key_relay_regid_ackd, false );
|
|
||||||
}
|
|
||||||
// DbgUtils.logf( "shouldRegister()=>%b", !registered );
|
|
||||||
return !registered;
|
return !registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,7 +770,7 @@ public class RelayService extends XWService
|
||||||
DbgUtils.logf( "registerWithRelay: skipping because only %d "
|
DbgUtils.logf( "registerWithRelay: skipping because only %d "
|
||||||
+ "seconds since last start", interval );
|
+ "seconds since last start", interval );
|
||||||
} else {
|
} else {
|
||||||
String relayID = XWPrefs.getRelayDevID( this );
|
String relayID = DevID.getRelayDevID( this );
|
||||||
DevIDType[] typa = new DevIDType[1];
|
DevIDType[] typa = new DevIDType[1];
|
||||||
String devid = getDevID( typa );
|
String devid = getDevID( typa );
|
||||||
DevIDType typ = typa[0];
|
DevIDType typ = typa[0];
|
||||||
|
@ -954,17 +954,13 @@ public class RelayService extends XWService
|
||||||
|
|
||||||
private String getDevID( DevIDType[] typp )
|
private String getDevID( DevIDType[] typp )
|
||||||
{
|
{
|
||||||
String devid = null;
|
|
||||||
DevIDType typ;
|
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() ) {
|
if ( null != devid && 0 < devid.length() ) {
|
||||||
typ = DevIDType.ID_TYPE_RELAY;
|
typ = DevIDType.ID_TYPE_RELAY;
|
||||||
} else {
|
} else {
|
||||||
devid = XWPrefs.getGCMDevID( this );
|
devid = DevID.getGCMDevID( this );
|
||||||
if ( null != devid && 0 < devid.length() ) {
|
if ( null != devid && 0 < devid.length() ) {
|
||||||
typ = DevIDType.ID_TYPE_ANDROID_GCM;
|
typ = DevIDType.ID_TYPE_ANDROID_GCM;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1411,5 +1407,4 @@ public class RelayService extends XWService
|
||||||
public byte[] m_header;
|
public byte[] m_header;
|
||||||
public int m_packetID;
|
public int m_packetID;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class XWDevIDPreference extends EditTextPreference {
|
||||||
protected void onAttachedToActivity()
|
protected void onAttachedToActivity()
|
||||||
{
|
{
|
||||||
super.onAttachedToActivity();
|
super.onAttachedToActivity();
|
||||||
int devID = XWPrefs.getRelayDevIDInt( m_context );
|
int devID = DevID.getRelayDevIDInt( m_context );
|
||||||
setSummary( String.format( "%d", devID ) );
|
setSummary( String.format( "%d", devID ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.google.android.gcm.GCMRegistrar;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
@ -252,6 +251,7 @@ public class XWPrefs {
|
||||||
return getPrefsStringArray( context, R.string.key_sms_phones );
|
return getPrefsStringArray( context, R.string.key_sms_phones );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used by RelayInviteDelegate.java
|
||||||
public static void setRelayIDs( Context context, String[] names )
|
public static void setRelayIDs( Context context, String[] names )
|
||||||
{
|
{
|
||||||
setPrefsStringArray( context, R.string.key_relay_ids, names );
|
setPrefsStringArray( context, R.string.key_relay_ids, names );
|
||||||
|
@ -283,62 +283,6 @@ public class XWPrefs {
|
||||||
return id;
|
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 )
|
public static DictUtils.DictLoc getDefaultLoc( Context context )
|
||||||
{
|
{
|
||||||
boolean internal = getDefaultLocInternal( context );
|
boolean internal = getDefaultLocInternal( context );
|
||||||
|
|
|
@ -28,7 +28,7 @@ import junit.framework.Assert;
|
||||||
import org.eehouse.android.xw4.DbgUtils;
|
import org.eehouse.android.xw4.DbgUtils;
|
||||||
import org.eehouse.android.xw4.R;
|
import org.eehouse.android.xw4.R;
|
||||||
import org.eehouse.android.xw4.XWApp;
|
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.jni.CommsAddrRec.CommsConnTypeSet;
|
||||||
import org.eehouse.android.xw4.loc.LocUtils;
|
import org.eehouse.android.xw4.loc.LocUtils;
|
||||||
|
|
||||||
|
@ -100,11 +100,11 @@ public class UtilCtxtImpl implements UtilCtxt {
|
||||||
public String getDevID( /*out*/ byte[] typa )
|
public String getDevID( /*out*/ byte[] typa )
|
||||||
{
|
{
|
||||||
UtilCtxt.DevIDType typ = UtilCtxt.DevIDType.ID_TYPE_NONE;
|
UtilCtxt.DevIDType typ = UtilCtxt.DevIDType.ID_TYPE_NONE;
|
||||||
String result = XWPrefs.getRelayDevID( m_context );
|
String result = DevID.getRelayDevID( m_context );
|
||||||
if ( null != result ) {
|
if ( null != result ) {
|
||||||
typ = UtilCtxt.DevIDType.ID_TYPE_RELAY;
|
typ = UtilCtxt.DevIDType.ID_TYPE_RELAY;
|
||||||
} else {
|
} else {
|
||||||
result = XWPrefs.getGCMDevID( m_context );
|
result = DevID.getGCMDevID( m_context );
|
||||||
if ( result.equals("") ) {
|
if ( result.equals("") ) {
|
||||||
result = null;
|
result = null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,10 +119,10 @@ public class UtilCtxtImpl implements UtilCtxt {
|
||||||
{
|
{
|
||||||
switch ( devIDType ) {
|
switch ( devIDType ) {
|
||||||
case ID_TYPE_RELAY:
|
case ID_TYPE_RELAY:
|
||||||
XWPrefs.setRelayDevID( m_context, idRelay );
|
DevID.setRelayDevID( m_context, idRelay );
|
||||||
break;
|
break;
|
||||||
case ID_TYPE_NONE:
|
case ID_TYPE_NONE:
|
||||||
XWPrefs.clearRelayDevID( m_context );
|
DevID.clearRelayDevID( m_context );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
|
|
Loading…
Add table
Reference in a new issue