set check-relay timer when saving a game with a relay connection

This commit is contained in:
Eric House 2015-05-13 06:26:46 -07:00
parent 38b958751c
commit 60509f7c8b
2 changed files with 12 additions and 4 deletions

View file

@ -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 );

View file

@ -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 {