test for null back from refusal to load quarantined game

This commit is contained in:
Eric House 2020-04-20 12:19:04 -07:00
parent 54efffa635
commit fe9eb9ae7c
3 changed files with 58 additions and 36 deletions

View file

@ -32,7 +32,8 @@ public class Assert {
assertTrue(! val); assertTrue(! val);
} }
public static void assertTrue(boolean val) { public static void assertTrue( boolean val )
{
if (! val) { if (! val) {
Log.e( TAG, "firing assert!" ); Log.e( TAG, "firing assert!" );
DbgUtils.printStack( TAG ); DbgUtils.printStack( TAG );

View file

@ -386,6 +386,16 @@ public class GameUtils {
return loadMakeGame( context, gi, util, tp, stream, lock.getRowid() ); return loadMakeGame( context, gi, util, tp, stream, lock.getRowid() );
} }
private static CurGameInfo giFromStream( Context context, byte[] stream )
{
CurGameInfo gi = null;
if ( null != stream ) {
gi = new CurGameInfo( context );
XwJNI.gi_from_stream( gi, stream );
}
return gi;
}
private static GamePtr loadMakeGame( Context context, CurGameInfo gi, private static GamePtr loadMakeGame( Context context, CurGameInfo gi,
UtilCtxt util, TransportProcs tp, UtilCtxt util, TransportProcs tp,
byte[] stream, long rowid ) byte[] stream, long rowid )
@ -832,22 +842,28 @@ public class GameUtils {
public static String[] dictNames( Context context, GameLock lock ) public static String[] dictNames( Context context, GameLock lock )
{ {
String[] result = null;
byte[] stream = savedGame( context, lock ); byte[] stream = savedGame( context, lock );
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = giFromStream( context, stream );
XwJNI.gi_from_stream( gi, stream ); if ( null != gi ) {
return gi.dictNames(); result = gi.dictNames();
}
return result;
} }
public static String[] dictNames( Context context, long rowid, public static String[] dictNames( Context context, long rowid,
int[] missingLang ) int[] missingLang )
{ {
String[] result = null;
byte[] stream = savedGame( context, rowid ); byte[] stream = savedGame( context, rowid );
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = giFromStream( context, stream );
XwJNI.gi_from_stream( gi, stream ); if ( null != gi ) {
if ( null != missingLang ) { if ( null != missingLang ) {
missingLang[0] = gi.dictLang; missingLang[0] = gi.dictLang;
} }
return gi.dictNames(); result = gi.dictNames();
}
return result;
} }
public static String[] dictNames( Context context, long rowid ) public static String[] dictNames( Context context, long rowid )
@ -863,7 +879,7 @@ public class GameUtils {
public static boolean gameDictsHere( Context context, GameLock lock ) public static boolean gameDictsHere( Context context, GameLock lock )
{ {
String[] gameDicts = dictNames( context, lock ); String[] gameDicts = dictNames( context, lock );
return gameDictsHere( context, null, gameDicts ); return null != gameDicts && gameDictsHere( context, null, gameDicts );
} }
// Return true if all dicts present. Return list of those that // Return true if all dicts present. Return list of those that
@ -873,7 +889,8 @@ public class GameUtils {
int[] missingLang ) int[] missingLang )
{ {
String[] gameDicts = dictNames( context, rowid, missingLang ); String[] gameDicts = dictNames( context, rowid, missingLang );
return gameDictsHere( context, missingNames, gameDicts ); return null != gameDicts
&& gameDictsHere( context, missingNames, gameDicts );
} }
public static boolean gameDictsHere( Context context, public static boolean gameDictsHere( Context context,
@ -1089,11 +1106,17 @@ public class GameUtils {
boolean success; boolean success;
try ( GameLock lock = GameLock.lock( rowid, 300 ) ) { try ( GameLock lock = GameLock.lock( rowid, 300 ) ) {
success = null != lock; success = null != lock;
if ( success ) { if ( !success ) {
DbgUtils.toastNoLock( TAG, context, rowid,
"replaceDicts(): rowid %d",
rowid );
} else {
byte[] stream = savedGame( context, lock ); byte[] stream = savedGame( context, lock );
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = giFromStream( context, stream );
XwJNI.gi_from_stream( gi, stream ); success = null != gi;
if ( !success ) {
Log.e( TAG, "replaceDicts(): unable to load rowid %d", rowid );
} else {
// first time required so dictNames() will work // first time required so dictNames() will work
gi.replaceDicts( context, newDict ); gi.replaceDicts( context, newDict );
@ -1113,10 +1136,7 @@ public class GameUtils {
summarize( context, lock, gamePtr, gi ); summarize( context, lock, gamePtr, gi );
} }
} else { }
DbgUtils.toastNoLock( TAG, context, rowid,
"replaceDicts(): rowid %d",
rowid );
} }
} }
return success; return success;

View file

@ -168,6 +168,7 @@ public class XwJNI {
public static void gi_from_stream( CurGameInfo gi, byte[] stream ) public static void gi_from_stream( CurGameInfo gi, byte[] stream )
{ {
Assert.assertNotNull( stream );
gi_from_stream( getJNI().m_ptrGlobals, gi, stream ); // called here gi_from_stream( getJNI().m_ptrGlobals, gi, stream ); // called here
} }