Prevent multiple inits

pull/178/head
M66B 5 years ago
parent c27c1e6b8e
commit 62675805da

@ -36,6 +36,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import android.text.TextUtils; import android.text.TextUtils;
@ -149,6 +150,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
iif.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); iif.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(connectionChangedReceiver, iif); registerReceiver(connectionChangedReceiver, iif);
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
db.account().liveAccountState().observe(this, new Observer<List<TupleAccountState>>() { db.account().liveAccountState().observe(this, new Observer<List<TupleAccountState>>() {
@ -173,7 +176,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}); });
liveAccountNetworkState.observeForever(new Observer<List<TupleAccountNetworkState>>() { liveAccountNetworkState.observeForever(new Observer<List<TupleAccountNetworkState>>() {
private boolean init = false;
private boolean fts = false; private boolean fts = false;
private Integer lastQuitId = null; private Integer lastQuitId = null;
private List<TupleAccountNetworkState> accountStates = new ArrayList<>(); private List<TupleAccountNetworkState> accountStates = new ArrayList<>();
@ -192,8 +194,14 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
coreStates.clear(); coreStates.clear();
liveAccountNetworkState.removeObserver(this); liveAccountNetworkState.removeObserver(this);
} else { } else {
if (!init) { // Check init
init = true; long now = new Date().getTime();
long init = prefs.getLong("last_init", 0);
long boot = now - SystemClock.elapsedRealtime();
if (init < boot) {
EntityLog.log(ServiceSynchronize.this, "Boot=" + new Date(boot));
EntityLog.log(ServiceSynchronize.this, "Last init=" + new Date(init));
prefs.edit().putLong("last_init", now).apply();
init(); init();
} }
@ -468,7 +476,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
}); });
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
final TwoStateOwner cowner = new TwoStateOwner(this, "liveUnseenNotify"); final TwoStateOwner cowner = new TwoStateOwner(this, "liveUnseenNotify");

Loading…
Cancel
Save