aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-11-08 21:37:44 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-11-08 21:37:44 +0100
commit698ddadbee462c3e48a8635fdc7f01eb2ddbfbf1 (patch)
treed1d6ca7bbbc9ce72ce794c45dc63bfaf027b4425 /src/main
parent1ef8d0a74633e9236f4d6868650b1af254897284 (diff)
brought restart threshold down to 8 times in 8h
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/Config.java4
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java22
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java9
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SettingsActivity.java4
4 files changed, 31 insertions, 8 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java
index 1ebb4d13..9f956fa4 100644
--- a/src/main/java/eu/siacs/conversations/Config.java
+++ b/src/main/java/eu/siacs/conversations/Config.java
@@ -101,8 +101,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; // 10 hours
+ public static final long FREQUENT_RESTARTS_THRESHOLD = 8;
public static final ChatState DEFAULT_CHATSTATE = ChatState.ACTIVE;
public static final int TYPING_TIMEOUT = 8;
diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
index ad8dc62c..6181451f 100644
--- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java
@@ -139,7 +139,9 @@ 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);
@@ -1232,16 +1234,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/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 044a518a..c1bd59e9 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -3605,6 +3605,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();
diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
index c2bf20ac..7fcb1e3c 100644
--- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
@@ -249,6 +249,10 @@ public class SettingsActivity extends XmppActivity implements
}
}
} else if (name.equals("keep_foreground_service")) {
+ boolean foreground_service = preferences.getBoolean("keep_foreground_service",false);
+ if (!foreground_service) {
+ xmppConnectionService.clearStartTimeCounter();
+ }
xmppConnectionService.toggleForegroundService();
} else if (resendPresence.contains(name)) {
if (xmppConnectionServiceBound) {