Cleanup on boot/update

This commit is contained in:
M66B 2019-07-10 09:45:19 +02:00
parent 2067d89666
commit 4bfef11c2e
1 changed files with 14 additions and 8 deletions

View File

@ -22,9 +22,8 @@ package eu.faircode.email;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager; import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
public class ReceiverAutoStart extends BroadcastReceiver { public class ReceiverAutoStart extends BroadcastReceiver {
@Override @Override
@ -32,15 +31,22 @@ public class ReceiverAutoStart extends BroadcastReceiver {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) || if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) { Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
Log.i("Received " + intent); Log.i("Received " + intent);
ServiceSynchronize.boot(context); ServiceSynchronize.boot(context);
ServiceSend.boot(context); ServiceSend.boot(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Thread cleanup = new Thread(new Runnable() {
SharedPreferences.Editor editor = prefs.edit(); @Override
if (!prefs.getBoolean("unified", true)) public void run() {
editor.putString("startup", "folders"); try {
editor.remove("unified"); WorkerCleanup.cleanup(context, true);
editor.apply(); } catch (Throwable ex) {
Log.e(ex);
}
}
});
cleanup.setPriority(THREAD_PRIORITY_BACKGROUND);
cleanup.start();
} }
} }
} }