From 64b89536b0c8921a58c9052cc15f61173ed15d62 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 30 Jul 2013 07:43:52 -0700 Subject: [PATCH] Test whether game is on device before starting process of opening it. Fixes problem caused by relay sending messages for games that have been deleted. --- .../src/org/eehouse/android/xw4/DBUtils.java | 18 ++++++++++++++++++ .../src/org/eehouse/android/xw4/GamesList.java | 2 +- .../org/eehouse/android/xw4/RelayService.java | 13 +++++++++---- 3 files changed, 28 insertions(+), 5 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 f038ff253..998173cf4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -481,6 +481,24 @@ public class DBUtils { return result; } + public static boolean haveGame( Context context, long rowid ) + { + boolean result = false; + initDB( context ); + synchronized( s_dbHelper ) { + SQLiteDatabase db = s_dbHelper.getReadableDatabase(); + String[] columns = { ROW_ID }; + String selection = String.format( ROW_ID + "=%d", rowid ); + Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, + selection, null, null, null, null ); + Assert.assertTrue( 1 >= cursor.getCount() ); + result = 1 == cursor.getCount(); + cursor.close(); + db.close(); + } + return result; + } + public static void listBTGames( Context context, HashMap result ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 36b274f85..cba61d08d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -953,7 +953,7 @@ public class GamesList extends XWExpandableListActivity private void startFirstHasDict( long rowid ) { - if ( -1 != rowid ) { + if ( -1 != rowid && DBUtils.haveGame( this, rowid ) ) { if ( GameUtils.gameDictsHere( this, rowid ) ) { launchGame( rowid ); } 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 16e002e22..b3e86a4cc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -128,10 +128,15 @@ public class RelayService extends XWService { { DbgUtils.logf( "RelayService::postData: packet of length %d for token %d", msg.length, rowid ); - Intent intent = getIntentTo( context, RECEIVE ) - .putExtra( ROWID, rowid ) - .putExtra( BINBUFFER, msg ); - context.startService( intent ); + if ( DBUtils.haveGame( context, rowid ) ) { + Intent intent = getIntentTo( context, RECEIVE ) + .putExtra( ROWID, rowid ) + .putExtra( BINBUFFER, msg ); + context.startService( intent ); + } else { + DbgUtils.logf( "RelayService.postData(): Dropping message for " + + "rowid %d: not on device", rowid ); + } } public static void udpChanged( Context context )