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
// return null. Let m_jniThreadRef stay null in that case; doResume()
// 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 ) {
// see http://stackoverflow.com/questions/680180/where-to-stop- \
// destroy-threads-in-android-service-class
@ -2787,7 +2787,7 @@ public class BoardDelegate extends DelegateBase
GamePtr gamePtr = null;
GameSummary summary = null;
CurGameInfo gi = null;
JNIThread thread = JNIThread.getRetained( rowID );
JNIThread thread = JNIThread.getRetained( activity, rowID );
if ( null != thread ) {
gamePtr = thread.getGamePtr().retain();
summary = thread.getSummary();
@ -2798,6 +2798,9 @@ public class BoardDelegate extends DelegateBase
summary = DBUtils.getSummary( activity, lock );
gi = new CurGameInfo( activity );
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()
{
super.onResume();
m_jniThreadRef = JNIThread.getRetained( m_rowid );
m_jniThreadRef = JNIThread.getRetained( m_activity, m_rowid );
if ( null == m_jniThreadRef ) {
Log.w( TAG, "onResume(): m_jniThreadRef null; exiting" );
finish();

View file

@ -99,6 +99,16 @@ public class DbgUtils {
showf( context, LocUtils.getString( context, formatid ), args );
} // 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()
{
assertOnUIThread( true );

View file

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

View file

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

View file

@ -75,7 +75,7 @@ abstract class XWServiceHelper {
{
boolean allConsumed = true;
boolean[] isLocalP = new boolean[1];
JNIThread jniThread = JNIThread.getRetained( rowid );
JNIThread jniThread = JNIThread.getRetained( context, rowid );
boolean consumed = false;
if ( null != jniThread ) {
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;
synchronized( s_instances ) {
@ -839,6 +839,8 @@ public class JNIThread extends Thread {
if ( lock != null ) {
result = new JNIThread( lock );
s_instances.put( rowid, result );
} else {
DbgUtils.toastNoLock( TAG, context, "getRetained(%d)", rowid );
}
}
}