This commit is contained in:
M66B 2019-03-03 09:54:40 +00:00
parent b3db2956d1
commit 0a28267744
1 changed files with 0 additions and 46 deletions

View File

@ -1,25 +1,15 @@
package eu.faircode.email; package eu.faircode.email;
import android.app.IntentService; import android.app.IntentService;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.PowerManager;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import java.util.HashMap;
import java.util.Map;
import javax.mail.Store;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
public class ServiceUI extends IntentService { public class ServiceUI extends IntentService {
private PowerManager.WakeLock wl;
private Map<EntityAccount, Store> accountStore = new HashMap<>();
static final int PI_WHY = 1; static final int PI_WHY = 1;
static final int PI_SUMMARY = 2; static final int PI_SUMMARY = 2;
static final int PI_CLEAR = 3; static final int PI_CLEAR = 3;
@ -40,40 +30,12 @@ public class ServiceUI extends IntentService {
@Override @Override
public void onCreate() { public void onCreate() {
Log.i("Service UI create"); Log.i("Service UI create");
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":ui");
wl.acquire();
super.onCreate(); super.onCreate();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
Log.i("Service UI destroy"); Log.i("Service UI destroy");
final DB db = DB.getInstance(this);
new Thread(new Runnable() {
@Override
public void run() {
try {
for (EntityAccount account : accountStore.keySet())
try {
Log.i(account.name + " closing");
db.account().setAccountState(account.id, "closing");
accountStore.get(account).close();
} catch (Throwable ex) {
Log.w(ex);
} finally {
Log.i(account.name + " closed");
db.account().setAccountState(account.id, null);
}
accountStore.clear();
} finally {
wl.release();
}
}
}).start();
super.onDestroy(); super.onDestroy();
} }
@ -98,31 +60,24 @@ public class ServiceUI extends IntentService {
case "why": case "why":
onWhy(); onWhy();
break; break;
case "summary": case "summary":
onSummary(); onSummary();
break; break;
case "clear": case "clear":
onClear(); onClear();
break; break;
case "seen": case "seen":
onSeen(id); onSeen(id);
break; break;
case "archive": case "archive":
onArchive(id); onArchive(id);
break; break;
case "trash": case "trash":
onTrash(id); onTrash(id);
break; break;
case "ignore": case "ignore":
onIgnore(id); onIgnore(id);
break; break;
case "snooze": case "snooze":
// AlarmManager.RTC_WAKEUP // AlarmManager.RTC_WAKEUP
// When the alarm is dispatched, the app will also be added to the system's temporary whitelist // When the alarm is dispatched, the app will also be added to the system's temporary whitelist
@ -130,7 +85,6 @@ public class ServiceUI extends IntentService {
// https://developer.android.com/reference/android/app/AlarmManager // https://developer.android.com/reference/android/app/AlarmManager
onSnooze(id); onSnooze(id);
break; break;
default: default:
Log.w("Unknown action: " + parts[0]); Log.w("Unknown action: " + parts[0]);
} }