From 51badfa721294f7a8a9917e9755cafe15a619336 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 2 Jun 2017 13:00:20 +0200 Subject: [PATCH] enable forground service for sony smartphones by default --- .../persistance/DatabaseBackend.java | 31 ------------------- .../services/XmppConnectionService.java | 17 ++-------- .../conversations/ui/SettingsActivity.java | 4 --- 3 files changed, 2 insertions(+), 50 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index e6d0e2905..45e4eb170 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -1394,37 +1394,6 @@ public class DatabaseBackend extends SQLiteOpenHelper { deleteArgs); } - public boolean startTimeCountExceedsThreshold() { - SQLiteDatabase db = this.getWritableDatabase(); - long cleanBeforeTimestamp = System.currentTimeMillis() - Config.FREQUENT_RESTARTS_DETECTION_WINDOW; - db.execSQL("delete from "+START_TIMES_TABLE+" where timestamp < "+cleanBeforeTimestamp); - ContentValues values = new ContentValues(); - values.put("timestamp",System.currentTimeMillis()); - db.insert(START_TIMES_TABLE,null,values); - String[] columns = new String[]{"count(timestamp)"}; - Cursor cursor = db.query(START_TIMES_TABLE,columns,null,null,null,null,null); - int count; - if (cursor.moveToFirst()) { - count = cursor.getInt(0); - } else { - count = 0; - } - cursor.close(); - Log.d(Config.LOGTAG,"start time counter reached "+count); - return count >= Config.FREQUENT_RESTARTS_THRESHOLD; - } - - public void clearStartTimeCounter(boolean justOne) { - SQLiteDatabase db = this.getWritableDatabase(); - if (justOne) { - db.execSQL("delete from "+START_TIMES_TABLE+" where timestamp in (select timestamp from "+START_TIMES_TABLE+" order by timestamp desc limit 1)"); - Log.d(Config.LOGTAG,"do not count start up after being swiped away"); - } else { - Log.d(Config.LOGTAG,"resetting start time counter"); - db.execSQL("delete from " + START_TIMES_TABLE); - } - } - public List getFrequentContacts(int days) { SQLiteDatabase db = this.getReadableDatabase(); final String SQL = "select "+Conversation.TABLENAME+"."+Conversation.ACCOUNT+","+Conversation.TABLENAME+"."+Conversation.CONTACTJID+" from "+Conversation.TABLENAME+" join "+Message.TABLENAME+" on conversations.uuid=messages.conversationUuid where messages.status!=0 and carbon==0 and conversations.mode=0 and messages.timeSent>=? group by conversations.uuid order by count(body) desc limit 4;"; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index c4048a3bd..b780c9c67 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -999,12 +999,9 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG,"restoring accounts..."); this.accounts = databaseBackend.getAccounts(); - if (Config.FREQUENT_RESTARTS_THRESHOLD != 0 - && Config.FREQUENT_RESTARTS_DETECTION_WINDOW != 0 - && !keepForegroundService() - && databaseBackend.startTimeCountExceedsThreshold()) { + if (this.accounts.size() == 0 && Arrays.asList("Sony","Sony Ericsson").contains(Build.MANUFACTURER)) { getPreferences().edit().putBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE,true).commit(); - Log.d(Config.LOGTAG,"number of restarts exceeds threshold. enabling foreground service"); + Log.d(Config.LOGTAG,Build.MANUFACTURER+" is on blacklist. enabling foreground service"); } restoreFromDatabase(); @@ -1107,7 +1104,6 @@ public class XmppConnectionService extends Service { private void logoutAndSave(boolean stop) { int activeAccounts = 0; - databaseBackend.clearStartTimeCounter(true); // regular swipes don't count towards restart counter for (final Account account : accounts) { if (account.getStatus() != Account.State.DISABLED) { activeAccounts++; @@ -3907,15 +3903,6 @@ public class XmppConnectionService extends Service { conversation.setBookmark(bookmark); } - public void clearStartTimeCounter() { - mDatabaseExecutor.execute(new Runnable() { - @Override - public void run() { - databaseBackend.clearStartTimeCounter(false); - } - }); - } - public boolean verifyFingerprints(Contact contact, List fingerprints) { boolean needsRosterWrite = false; boolean performedVerification = false; diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index d48839cdd..ad24b7b0b 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -353,10 +353,6 @@ 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) {