mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-27 19:22:15 -05:00
enable forground service for sony smartphones by default
This commit is contained in:
parent
e722ef6477
commit
51badfa721
@ -1394,37 +1394,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||||||
deleteArgs);
|
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<ShortcutService.FrequentContact> getFrequentContacts(int days) {
|
public List<ShortcutService.FrequentContact> getFrequentContacts(int days) {
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
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;";
|
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;";
|
||||||
|
@ -999,12 +999,9 @@ public class XmppConnectionService extends Service {
|
|||||||
Log.d(Config.LOGTAG,"restoring accounts...");
|
Log.d(Config.LOGTAG,"restoring accounts...");
|
||||||
this.accounts = databaseBackend.getAccounts();
|
this.accounts = databaseBackend.getAccounts();
|
||||||
|
|
||||||
if (Config.FREQUENT_RESTARTS_THRESHOLD != 0
|
if (this.accounts.size() == 0 && Arrays.asList("Sony","Sony Ericsson").contains(Build.MANUFACTURER)) {
|
||||||
&& Config.FREQUENT_RESTARTS_DETECTION_WINDOW != 0
|
|
||||||
&& !keepForegroundService()
|
|
||||||
&& databaseBackend.startTimeCountExceedsThreshold()) {
|
|
||||||
getPreferences().edit().putBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE,true).commit();
|
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();
|
restoreFromDatabase();
|
||||||
@ -1107,7 +1104,6 @@ public class XmppConnectionService extends Service {
|
|||||||
|
|
||||||
private void logoutAndSave(boolean stop) {
|
private void logoutAndSave(boolean stop) {
|
||||||
int activeAccounts = 0;
|
int activeAccounts = 0;
|
||||||
databaseBackend.clearStartTimeCounter(true); // regular swipes don't count towards restart counter
|
|
||||||
for (final Account account : accounts) {
|
for (final Account account : accounts) {
|
||||||
if (account.getStatus() != Account.State.DISABLED) {
|
if (account.getStatus() != Account.State.DISABLED) {
|
||||||
activeAccounts++;
|
activeAccounts++;
|
||||||
@ -3907,15 +3903,6 @@ public class XmppConnectionService extends Service {
|
|||||||
conversation.setBookmark(bookmark);
|
conversation.setBookmark(bookmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearStartTimeCounter() {
|
|
||||||
mDatabaseExecutor.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
databaseBackend.clearStartTimeCounter(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean verifyFingerprints(Contact contact, List<XmppUri.Fingerprint> fingerprints) {
|
public boolean verifyFingerprints(Contact contact, List<XmppUri.Fingerprint> fingerprints) {
|
||||||
boolean needsRosterWrite = false;
|
boolean needsRosterWrite = false;
|
||||||
boolean performedVerification = false;
|
boolean performedVerification = false;
|
||||||
|
@ -353,10 +353,6 @@ public class SettingsActivity extends XmppActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
|
} else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
|
||||||
boolean foreground_service = preferences.getBoolean(KEEP_FOREGROUND_SERVICE,false);
|
|
||||||
if (!foreground_service) {
|
|
||||||
xmppConnectionService.clearStartTimeCounter();
|
|
||||||
}
|
|
||||||
xmppConnectionService.toggleForegroundService();
|
xmppConnectionService.toggleForegroundService();
|
||||||
} else if (resendPresence.contains(name)) {
|
} else if (resendPresence.contains(name)) {
|
||||||
if (xmppConnectionServiceBound) {
|
if (xmppConnectionServiceBound) {
|
||||||
|
Loading…
Reference in New Issue
Block a user