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 6d18e323d..f6ec73518 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GCMIntentService.java @@ -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 ); } } 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 b78b3141e..7a41c1085 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -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 {