diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index b2a8c3bf1..c671b6ebe 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -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 ); } } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java index f3239e590..b72506648 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/ChatDelegate.java @@ -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(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java index 96ab11ec7..d124f66de 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DbgUtils.java @@ -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 ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java index 8cae19c7b..847964d62 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java @@ -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(); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java index 370672797..99f887cfd 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java @@ -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 ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java index 3f076f1f8..7594e4fcd 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWServiceHelper.java @@ -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; diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java index 0dd797b00..503929cc2 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIThread.java @@ -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 ); } } }