show toast when GameLock fails to lock (some cases)

This commit is contained in:
Eric House 2019-01-08 10:09:43 -08:00
parent 4fcc5fd99b
commit e9e03a06a3
7 changed files with 34 additions and 15 deletions

View file

@ -590,7 +590,7 @@ public class BoardDelegate extends DelegateBase
// getRetained() can in threory fail to get the lock and so will // getRetained() can in threory fail to get the lock and so will
// return null. Let m_jniThreadRef stay null in that case; doResume() // return null. Let m_jniThreadRef stay null in that case; doResume()
// will finish() in that case. // will finish() in that case.
m_jniThreadRef = JNIThread.getRetained( m_rowid, true ); m_jniThreadRef = JNIThread.getRetained( m_activity, m_rowid, true );
if ( null != m_jniThreadRef ) { if ( null != m_jniThreadRef ) {
// see http://stackoverflow.com/questions/680180/where-to-stop- \ // see http://stackoverflow.com/questions/680180/where-to-stop- \
// destroy-threads-in-android-service-class // destroy-threads-in-android-service-class
@ -2787,7 +2787,7 @@ public class BoardDelegate extends DelegateBase
GamePtr gamePtr = null; GamePtr gamePtr = null;
GameSummary summary = null; GameSummary summary = null;
CurGameInfo gi = null; CurGameInfo gi = null;
JNIThread thread = JNIThread.getRetained( rowID ); JNIThread thread = JNIThread.getRetained( activity, rowID );
if ( null != thread ) { if ( null != thread ) {
gamePtr = thread.getGamePtr().retain(); gamePtr = thread.getGamePtr().retain();
summary = thread.getSummary(); summary = thread.getSummary();
@ -2798,6 +2798,9 @@ public class BoardDelegate extends DelegateBase
summary = DBUtils.getSummary( activity, lock ); summary = DBUtils.getSummary( activity, lock );
gi = new CurGameInfo( activity ); gi = new CurGameInfo( activity );
gamePtr = GameUtils.loadMakeGame( activity, gi, lock ); gamePtr = GameUtils.loadMakeGame( activity, gi, lock );
} else {
DbgUtils.toastNoLock( TAG, activity,
"setupRematchFor(%d)", rowID );
} }
} }
} }

View file

@ -130,7 +130,7 @@ public class ChatDelegate extends DelegateBase {
protected void onResume() protected void onResume()
{ {
super.onResume(); super.onResume();
m_jniThreadRef = JNIThread.getRetained( m_rowid ); m_jniThreadRef = JNIThread.getRetained( m_activity, m_rowid );
if ( null == m_jniThreadRef ) { if ( null == m_jniThreadRef ) {
Log.w( TAG, "onResume(): m_jniThreadRef null; exiting" ); Log.w( TAG, "onResume(): m_jniThreadRef null; exiting" );
finish(); finish();

View file

@ -99,6 +99,16 @@ public class DbgUtils {
showf( context, LocUtils.getString( context, formatid ), args ); showf( context, LocUtils.getString( context, formatid ), args );
} // showf } // showf
public static void toastNoLock( String tag, Context context, String format,
Object... args )
{
format = "Unable to lock game; " + format;
if ( BuildConfig.DEBUG ) {
showf( context, format, args );
}
Log.w( tag, format, args );
}
public static void assertOnUIThread() public static void assertOnUIThread()
{ {
assertOnUIThread( true ); assertOnUIThread( true );

View file

@ -483,7 +483,7 @@ public class GameConfigDelegate extends DelegateBase
@Override @Override
protected void onResume() protected void onResume()
{ {
m_jniThread = JNIThread.getRetained( m_rowid ); m_jniThread = JNIThread.getRetained( m_activity, m_rowid );
super.onResume(); super.onResume();
loadGame(); loadGame();
} }

View file

@ -168,7 +168,8 @@ public class GameUtils {
Utils.cancelNotification( context, (int)rowidIn ); Utils.cancelNotification( context, (int)rowidIn );
success = true; success = true;
} else { } else {
Log.w( TAG, "resetGame: unable to open rowid %d", rowidIn ); DbgUtils.toastNoLock( TAG, context, "resetGame(): rowid %d",
rowidIn );
} }
} }
return success; return success;
@ -218,7 +219,7 @@ public class GameUtils {
long maxMillis ) long maxMillis )
{ {
GameSummary result = null; GameSummary result = null;
JNIThread thread = JNIThread.getRetained( rowid ); JNIThread thread = JNIThread.getRetained( context, rowid );
GameLock lock = null; GameLock lock = null;
if ( null != thread ) { if ( null != thread ) {
lock = thread.getLock(); lock = thread.getLock();
@ -251,7 +252,7 @@ public class GameUtils {
long rowid = DBUtils.ROWID_NOTFOUND; long rowid = DBUtils.ROWID_NOTFOUND;
GameLock lockSrc = null; GameLock lockSrc = null;
JNIThread thread = JNIThread.getRetained( rowidIn ); JNIThread thread = JNIThread.getRetained( context, rowidIn );
if ( null != thread ) { if ( null != thread ) {
lockSrc = thread.getLock(); lockSrc = thread.getLock();
} else { } else {
@ -296,7 +297,8 @@ public class GameUtils {
deleteGame( context, lock, informNow ); deleteGame( context, lock, informNow );
success = true; success = true;
} else { } else {
Log.w( TAG, "deleteGame: unable to delete rowid %d", rowid ); DbgUtils.toastNoLock( TAG, context, "deleteGame(): rowid %d",
rowid );
success = false; success = false;
} }
} }
@ -1008,7 +1010,8 @@ public class GameUtils {
} }
} }
} catch ( GameLock.GameLockedException gle ) { } catch ( GameLock.GameLockedException gle ) {
Log.e( TAG, "feedMessage(): game locked; dropping message" ); DbgUtils.toastNoLock( TAG, context, "feedMessage(): dropping message "
+ " for %d", rowid );
} }
} }
return draw; return draw;
@ -1048,7 +1051,8 @@ public class GameUtils {
summarizeAndRelease( context, lock, gamePtr, gi ); summarizeAndRelease( context, lock, gamePtr, gi );
} else { } else {
Log.w( TAG, "replaceDicts: unable to open rowid %d", rowid ); DbgUtils.toastNoLock( TAG, context, "replaceDicts(): rowid %d",
rowid );
} }
} }
return success; return success;
@ -1322,7 +1326,7 @@ public class GameUtils {
+ " failed for rowid %d", rowid ); + " failed for rowid %d", rowid );
} }
} else { } else {
JNIThread jniThread = JNIThread.getRetained( rowid ); JNIThread jniThread = JNIThread.getRetained( m_context, rowid );
if ( null != jniThread ) { if ( null != jniThread ) {
jniThread.handle( JNIThread.JNICmd.CMD_RESEND, false, jniThread.handle( JNIThread.JNICmd.CMD_RESEND, false,
false, false ); false, false );

View file

@ -75,7 +75,7 @@ abstract class XWServiceHelper {
{ {
boolean allConsumed = true; boolean allConsumed = true;
boolean[] isLocalP = new boolean[1]; boolean[] isLocalP = new boolean[1];
JNIThread jniThread = JNIThread.getRetained( rowid ); JNIThread jniThread = JNIThread.getRetained( context, rowid );
boolean consumed = false; boolean consumed = false;
if ( null != jniThread ) { if ( null != jniThread ) {
consumed = true; consumed = true;

View file

@ -822,12 +822,12 @@ public class JNIThread extends Thread {
} }
} }
public static JNIThread getRetained( long rowid ) public static JNIThread getRetained( Context context, long rowid )
{ {
return getRetained( rowid, false ); return getRetained( context, rowid, false );
} }
public static JNIThread getRetained( long rowid, boolean makeNew ) public static JNIThread getRetained( Context context, long rowid, boolean makeNew )
{ {
JNIThread result = null; JNIThread result = null;
synchronized( s_instances ) { synchronized( s_instances ) {
@ -839,6 +839,8 @@ public class JNIThread extends Thread {
if ( lock != null ) { if ( lock != null ) {
result = new JNIThread( lock ); result = new JNIThread( lock );
s_instances.put( rowid, result ); s_instances.put( rowid, result );
} else {
DbgUtils.toastNoLock( TAG, context, "getRetained(%d)", rowid );
} }
} }
} }