mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-30 12:42:16 -05:00
brought restart threshold down to 8 times in 8h
This commit is contained in:
parent
1ef8d0a746
commit
698ddadbee
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user