diff options
Diffstat (limited to '')
3 files changed, 26 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index fa7ccb0d0..05962a7fb 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -121,8 +121,8 @@ public final class Config { public static final long MAM_MAX_CATCHUP = MILLISECONDS_IN_DAY / 2; public static final int MAM_MAX_MESSAGES = 500; - public static final long FREQUENT_RESTARTS_DETECTION_WINDOW = 10 * 60 * 60 * 1000; // 10 hours - public static final long FREQUENT_RESTARTS_THRESHOLD = 10; + public static final long FREQUENT_RESTARTS_DETECTION_WINDOW = 8 * 60 * 60 * 1000; // 8 hours + public static final long FREQUENT_RESTARTS_THRESHOLD = 8; public static final ChatState DEFAULT_CHATSTATE = ChatState.ACTIVE; public static final int TYPING_TIMEOUT = 5; diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 693def6eb..812339a46 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -138,7 +138,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { + ") ON CONFLICT IGNORE" + ");"; - private static String CREATE_START_TIMES_TABLE = "create table start_times (timestamp NUMBER);"; + private static String START_TIMES_TABLE = "start_times"; + private static String CREATE_START_TIMES_TABLE = "create table "+START_TIMES_TABLE+" (timestamp NUMBER);"; private DatabaseBackend(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -1231,16 +1232,24 @@ public class DatabaseBackend extends SQLiteOpenHelper { public boolean startTimeCountExceedsThreshold() { SQLiteDatabase db = this.getWritableDatabase(); long cleanBeforeTimestamp = System.currentTimeMillis() - Config.FREQUENT_RESTARTS_DETECTION_WINDOW; - db.execSQL("delete from start_times where timestamp < "+cleanBeforeTimestamp); + db.execSQL("delete from "+START_TIMES_TABLE+" where timestamp < "+cleanBeforeTimestamp); ContentValues values = new ContentValues(); values.put("timestamp",System.currentTimeMillis()); - db.insert("start_times",null,values); + db.insert(START_TIMES_TABLE,null,values); String[] columns = new String[]{"count(timestamp)"}; - Cursor cursor = db.query("start_times",columns,null,null,null,null,null); + Cursor cursor = db.query(START_TIMES_TABLE,columns,null,null,null,null,null); + int count; if (cursor.moveToFirst()) { - return cursor.getInt(0) >= Config.FREQUENT_RESTARTS_THRESHOLD; + count = cursor.getInt(0); } else { - return false; + count = 0; } + cursor.close(); + return count >= Config.FREQUENT_RESTARTS_THRESHOLD; + } + + public void clearStartTimeCounter() { + SQLiteDatabase db = this.getWritableDatabase(); + db.execSQL("delete from " + START_TIMES_TABLE); } } diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index f0764b630..ca4018e71 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3741,6 +3741,15 @@ public class XmppConnectionService extends Service { conversation.setBookmark(bookmark); } + public void clearStartTimeCounter() { + mDatabaseExecutor.execute(new Runnable() { + @Override + public void run() { + databaseBackend.clearStartTimeCounter(); + } + }); + } + public interface OnMamPreferencesFetched { void onPreferencesFetched(Element prefs); void onPreferencesFetchFailed(); |