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.
This commit is contained in:
Eric House 2013-07-30 07:43:52 -07:00
parent 4ce2368e90
commit 64b89536b0
3 changed files with 28 additions and 5 deletions

View file

@ -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<String, int[]> result )
{

View file

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

View file

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