From b165072bed11ae0bf0f395bdb276839984ba7667 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 29 Oct 2020 11:25:29 -0700 Subject: [PATCH] always drop quarantine count to 0 on close There are ways I can't record a close, e.g. user swiping app to kill it. To avoid that leading to a corrupt-game warning, or to failure to open in background, drop the count to 0 rather then merely decrementing it when it closes correctly. Assumption is that if it closes ok once it's ok. --- .../org/eehouse/android/xw4/Quarantine.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Quarantine.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Quarantine.java index f95a81331..9ccbc6a3f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Quarantine.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Quarantine.java @@ -63,18 +63,21 @@ public class Quarantine { public static void recordOpened( long rowid ) { synchronized ( sDataRef ) { - get().increment( rowid ); + int newCount = get().increment( rowid ); store(); - Log.d( TAG, "recordOpened(%d): %s", rowid, sDataRef[0].toString() ); + Log.d( TAG, "recordOpened(%d): %s (count now %d)", rowid, + sDataRef[0].toString(), newCount ); + // DbgUtils.printStack( TAG ); } } public static void recordClosed( long rowid ) { synchronized ( sDataRef ) { - get().decrement( rowid ); + get().clear( rowid ); store(); - Log.d( TAG, "recordClosed(%d): %s", rowid, sDataRef[0].toString() ); + Log.d( TAG, "recordClosed(%d): %s (count now 0)", rowid, + sDataRef[0].toString() ); } } @@ -92,18 +95,14 @@ public class Quarantine { private static class Data implements Serializable { private HashMap mCounts = new HashMap<>(); - synchronized void increment( long rowid ) { + synchronized int increment( long rowid ) + { if ( ! mCounts.containsKey(rowid) ) { mCounts.put(rowid, 0); } - mCounts.put( rowid, mCounts.get(rowid) + 1 ); - } - - synchronized void decrement( long rowid ) - { - Assert.assertTrue( mCounts.containsKey(rowid) ); - mCounts.put( rowid, mCounts.get(rowid) - 1 ); - Assert.assertTrueNR( mCounts.get(rowid) >= 0 ); + int result = mCounts.get(rowid) + 1; + mCounts.put( rowid, result ); + return result; } synchronized int getFor( long rowid )