diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java index 731c6faa8..952c9fc84 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -2592,7 +2592,7 @@ public class BoardDelegate extends DelegateBase public static boolean rematchSupported( Context context, long rowID ) { - GameSummary summary = DBUtils.getSummary( context, rowID, 1 ); + GameSummary summary = GameUtils.getSummary( context, rowID, 1 ); return null != summary && rematchSupported( null, summary ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index ae3fdd690..a31d43335 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -116,27 +116,6 @@ public class DBUtils { public int[] m_counts; } - public static GameSummary getSummary( Context context, long rowid, - long maxMillis ) - { - GameSummary result = null; - try { - GameLock lock = new GameLock( rowid, false ).lock( maxMillis ); - if ( null != lock ) { - result = getSummary( context, lock ); - lock.unlock(); - } - } catch ( GameLock.GameLockedException gle ) { - DbgUtils.loge( gle ); - } - return result; - } - - public static GameSummary getSummary( Context context, long rowid ) - { - return getSummary( context, rowid, 0L ); - } - public static GameSummary getSummary( Context context, GameLock lock ) { @@ -1125,6 +1104,9 @@ public class DBUtils { lock.unlock(); } else { DbgUtils.logf( "deleteGame: unable to lock rowid %d", rowid ); + if ( BuildConfig.DEBUG ) { + Assert.fail(); + } } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListItem.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListItem.java index ec3b3aefb..a581da510 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListItem.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameListItem.java @@ -351,21 +351,7 @@ public class GameListItem extends LinearLayout @Override protected GameSummary doInBackground( Void... unused ) { - GameSummary result = null; - - JNIThread thread = JNIThread.getRetained( m_rowid ); - if ( null != thread ) { - GameLock lock = thread.getLock(); - if ( null != lock ) { - result = DBUtils.getSummary( m_context, lock ); - } - thread.release( false ); - } - - if ( null == result ) { - result = DBUtils.getSummary( m_context, m_rowid, SUMMARY_WAIT_MSECS ); - } - return result; + return GameUtils.getSummary( m_context, m_rowid, SUMMARY_WAIT_MSECS ); } // doInBackground @Override diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index d24f5b145..ac43ce43e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -213,6 +213,38 @@ public class GameUtils { return result; } + public static GameSummary getSummary( Context context, long rowid, + long maxMillis ) + { + GameSummary result = null; + JNIThread thread = JNIThread.getRetained( rowid ); + GameLock lock = null; + if ( null != thread ) { + lock = thread.getLock(); + } else { + try { + lock = new GameLock( rowid, false ).lock( maxMillis ); + } catch ( GameLock.GameLockedException gle ) { + DbgUtils.loge( gle ); + } + } + + if ( null != lock ) { + result = DBUtils.getSummary( context, lock ); + if ( null == thread ) { + lock.unlock(); + } else { + thread.release(); + } + } + return result; + } + + public static GameSummary getSummary( Context context, long rowid ) + { + return getSummary( context, rowid, 0L ); + } + public static long dupeGame( Context context, long rowidIn ) { long rowid = DBUtils.ROWID_NOTFOUND; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index d4bab59ea..964a92dc8 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -711,7 +711,7 @@ public class GamesListDelegate extends ListDelegateBase self.m_adapter.invalName( self.m_rowid ); } }; - GameSummary summary = DBUtils.getSummary( m_activity, m_rowid ); + GameSummary summary = GameUtils.getSummary( m_activity, m_rowid ); int labelID = (summary.isMultiGame() && !summary.anyMissing()) ? R.string.rename_label_caveat : R.string.rename_label; dialog = buildNamerDlg( GameUtils.getName( m_activity, m_rowid ), @@ -1748,7 +1748,8 @@ public class GamesListDelegate extends ListDelegateBase Action.NEW_FROM, selRowIDs[0] ); break; case R.id.games_game_copy: - final GameSummary smry = DBUtils.getSummary( m_activity, selRowIDs[0] ); + final GameSummary smry = GameUtils.getSummary( m_activity, + selRowIDs[0] ); if ( smry.inRelayGame() ) { showOKOnlyDialog( R.string.no_copy_network ); } else { @@ -1782,7 +1783,7 @@ public class GamesListDelegate extends ListDelegateBase // DEBUG only case R.id.games_game_invites: - msg = DBUtils.getSummary( m_activity, selRowIDs[0] ) + msg = GameUtils.getSummary( m_activity, selRowIDs[0] ) .conTypes.toString( m_activity ); msg = getString( R.string.invites_net_fmt, msg ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NagTurnReceiver.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NagTurnReceiver.java index 85c7e65c8..9372e5829 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NagTurnReceiver.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NagTurnReceiver.java @@ -81,8 +81,8 @@ public class NagTurnReceiver extends BroadcastReceiver { boolean lastWarning = 0 == info.m_nextNag; long rowid = info.m_rowid; - GameSummary summary = DBUtils.getSummary( context, rowid, - 10 ); + GameSummary summary = GameUtils.getSummary( context, rowid, + 10 ); String prevPlayer = null == summary ? LocUtils.getString(context, R.string.prev_player) : summary.getPrevPlayer(); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index 42d50f3ff..2f3976a5e 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -233,7 +233,7 @@ public class JNIThread extends Thread { public GamePtr getGamePtr() { return m_jniGamePtr; } public CurGameInfo getGI() { return m_gi; } public GameSummary getSummary() { return m_summary; } - public GameLock getLock() { return m_lock; } + public GameLock getLock() { Assert.assertNotNull(m_lock); return m_lock; } private void waitToStop( boolean save ) { @@ -787,6 +787,7 @@ public class JNIThread extends Thread { result = s_instances.get( rowid ); if ( null == result && makeNew ) { result = new JNIThread( new GameLock( rowid, true ).lock() ); + Assert.assertNotNull( result ); s_instances.put( rowid, result ); } if ( null != result ) {