when new GCM ID is received, force re-register.

This commit is contained in:
Eric House 2013-10-11 07:51:10 -07:00
parent 9efb044c4f
commit 9a8ed72ea1
2 changed files with 14 additions and 7 deletions

View file

@ -45,7 +45,7 @@ public class GCMIntentService extends GCMBaseIntentService {
{
DbgUtils.logf( "GCMIntentService.onRegistered(%s)", regId );
XWPrefs.setGCMDevID( context, regId );
notifyRelayService( true );
notifyRelayService( context, true );
}
@Override
@ -54,14 +54,14 @@ public class GCMIntentService extends GCMBaseIntentService {
DbgUtils.logf( "GCMIntentService.onUnregistered(%s)", regId );
XWPrefs.clearGCMDevID( context );
RelayService.devIDChanged();
notifyRelayService( false );
notifyRelayService( context, false );
}
@Override
protected void onMessage( Context context, Intent intent )
{
DbgUtils.logf( "GCMIntentService.onMessage()" );
notifyRelayService( true );
notifyRelayService( context, true );
String value;
boolean ignoreIt = XWApp.GCM_IGNORED;
@ -128,12 +128,12 @@ public class GCMIntentService extends GCMBaseIntentService {
}
}
private void notifyRelayService( boolean working )
private void notifyRelayService( Context context, boolean working )
{
if ( working && XWApp.GCM_IGNORED ) {
working = false;
}
RelayService.gcmConfirmed( working );
RelayService.gcmConfirmed( context, working );
}
}

View file

@ -93,6 +93,7 @@ public class RelayService extends XWService
private Runnable m_onInactivity;
private int m_maxIntervalSeconds = 0;
private long m_lastGamePacketReceived;
private static DevIDType s_curType = DevIDType.ID_TYPE_NONE;
// These must match the enum XWPDevProto in xwrelay.h
private static enum XWPDevProto { XWPDEV_PROTO_VERSION_INVALID
@ -120,13 +121,19 @@ public class RelayService extends XWService
,XWPDEV_UPGRADE
};
public static void gcmConfirmed( boolean confirmed )
public static void gcmConfirmed( Context context, boolean confirmed )
{
if ( s_gcmWorking != confirmed ) {
DbgUtils.logf( "RelayService.gcmConfirmed(): changing "
+ "s_gcmWorking to %b", confirmed );
s_gcmWorking = confirmed;
}
// If we've gotten a GCM id and haven't registered it, do so!
if ( confirmed && !s_curType.equals( DevIDType.ID_TYPE_ANDROID_GCM ) ) {
devIDChanged();
timerFired( context );
}
}
public static void startService( Context context )
@ -143,7 +150,6 @@ public class RelayService extends XWService
}
public static void timerFired( Context context )
{
Intent intent = getIntentTo( context, MsgCmds.TIMER_FIRED );
context.startService( intent );
@ -646,6 +652,7 @@ public class RelayService extends XWService
DevIDType[] typa = new DevIDType[1];
String devid = getDevID( typa );
DevIDType typ = typa[0];
s_curType = typ;
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try {