From 60509f7c8b255b9298a25c6559545f82829bd3d8 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 13 May 2015 06:26:46 -0700 Subject: [PATCH] set check-relay timer when saving a game with a relay connection --- .../XWords4/src/org/eehouse/android/xw4/DBUtils.java | 11 +++++++++-- .../src/org/eehouse/android/xw4/RelayReceiver.java | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index daa93e8f1..d0c85587f 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -280,6 +280,7 @@ public class DBUtils { public static void saveSummary( Context context, GameLock lock, GameSummary summary, String inviteID ) { + boolean needsTimer = false; Assert.assertTrue( lock.canWrite() ); long rowid = lock.getRowid(); String selection = String.format( ROW_ID_FMT, rowid ); @@ -328,7 +329,9 @@ public class DBUtils { switch ( iter.next() ) { case COMMS_CONN_RELAY: values.put( DBHelper.ROOMNAME, summary.roomName ); - values.put( DBHelper.RELAYID, summary.relayID ); + String relayID = summary.relayID; + values.put( DBHelper.RELAYID, relayID ); + needsTimer = null != relayID && 0 < relayID.length(); break; case COMMS_CONN_BT: case COMMS_CONN_SMS: @@ -361,6 +364,10 @@ public class DBUtils { if ( null != summary ) { // nag time may have changed NagTurnReceiver.setNagTimer( context ); } + + if ( needsTimer ) { + RelayReceiver.setTimer( context ); + } } // saveSummary public static void addRematchInfo( Context context, long rowid, String btAddr, @@ -751,7 +758,7 @@ public class DBUtils { return result; } - public static boolean haveRelayGames( Context context ) + public static boolean haveRelayIDs( Context context ) { long[][] rowIDss = new long[1][]; String[] relayIDs = getRelayIDs( context, rowIDss ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java index 1906bb9c8..bfd84f88d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java @@ -50,8 +50,9 @@ public class RelayReceiver extends BroadcastReceiver { Intent intent = new Intent( context, RelayReceiver.class ); PendingIntent pi = PendingIntent.getBroadcast( context, 0, intent, 0 ); - // Check if we have any relay games - if ( interval_millis > 0 && DBUtils.haveRelayGames( context ) ) { + // Check if we have any relay IDs, since we'll be using them to + // identify connected games for which we can fetch messages + if ( interval_millis > 0 && DBUtils.haveRelayIDs( context ) ) { long fire_millis = SystemClock.elapsedRealtime() + interval_millis; am.set( AlarmManager.ELAPSED_REALTIME_WAKEUP, fire_millis, pi ); } else {