mirror of https://github.com/M66B/FairEmail.git
Android 9 Pie compatibility
This commit is contained in:
parent
f351bccb8e
commit
2cc3c07651
|
@ -122,6 +122,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
|
||||||
|
|
||||||
public class ServiceSynchronize extends LifecycleService {
|
public class ServiceSynchronize extends LifecycleService {
|
||||||
|
private TupleAccountStats stats = null;
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
private ServiceManager serviceManager = new ServiceManager();
|
private ServiceManager serviceManager = new ServiceManager();
|
||||||
|
|
||||||
|
@ -146,7 +147,6 @@ public class ServiceSynchronize extends LifecycleService {
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
Log.i(Helper.TAG, "Service create version=" + BuildConfig.VERSION_NAME);
|
Log.i(Helper.TAG, "Service create version=" + BuildConfig.VERSION_NAME);
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
startForeground(NOTIFICATION_SYNCHRONIZE, getNotificationService(0, 0, 0).build());
|
|
||||||
|
|
||||||
// Listen for network changes
|
// Listen for network changes
|
||||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
@ -155,18 +155,46 @@ public class ServiceSynchronize extends LifecycleService {
|
||||||
// Removed because of Android VPN service
|
// Removed because of Android VPN service
|
||||||
// builder.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
|
// builder.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
|
||||||
cm.registerNetworkCallback(builder.build(), serviceManager);
|
cm.registerNetworkCallback(builder.build(), serviceManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
Log.i(Helper.TAG, "Service destroy");
|
||||||
|
|
||||||
|
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
cm.unregisterNetworkCallback(serviceManager);
|
||||||
|
|
||||||
|
serviceManager.onLost(null);
|
||||||
|
|
||||||
|
stopForeground(true);
|
||||||
|
|
||||||
|
NotificationManager nm = getSystemService(NotificationManager.class);
|
||||||
|
nm.cancel(NOTIFICATION_SYNCHRONIZE);
|
||||||
|
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
Log.i(Helper.TAG, "Service command intent=" + intent);
|
||||||
|
super.onStartCommand(intent, flags, startId);
|
||||||
|
|
||||||
|
startForeground(NOTIFICATION_SYNCHRONIZE, getNotificationService(0, 0, 0).build());
|
||||||
|
|
||||||
DB db = DB.getInstance(this);
|
DB db = DB.getInstance(this);
|
||||||
|
|
||||||
|
db.account().liveStats().removeObservers(this);
|
||||||
db.account().liveStats().observe(this, new Observer<TupleAccountStats>() {
|
db.account().liveStats().observe(this, new Observer<TupleAccountStats>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(@Nullable TupleAccountStats stats) {
|
public void onChanged(@Nullable TupleAccountStats stats) {
|
||||||
|
ServiceSynchronize.this.stats = stats;
|
||||||
NotificationManager nm = getSystemService(NotificationManager.class);
|
NotificationManager nm = getSystemService(NotificationManager.class);
|
||||||
nm.notify(NOTIFICATION_SYNCHRONIZE,
|
nm.notify(NOTIFICATION_SYNCHRONIZE,
|
||||||
getNotificationService(stats.accounts, stats.operations, stats.unsent).build());
|
getNotificationService(stats.accounts, stats.operations, stats.unsent).build());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
db.message().liveUnseenUnified().removeObservers(this);
|
||||||
db.message().liveUnseenUnified().observe(this, new Observer<List<EntityMessage>>() {
|
db.message().liveUnseenUnified().observe(this, new Observer<List<EntityMessage>>() {
|
||||||
private List<Integer> notifying = new ArrayList<>();
|
private List<Integer> notifying = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -204,29 +232,6 @@ public class ServiceSynchronize extends LifecycleService {
|
||||||
notifying = all;
|
notifying = all;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
Log.i(Helper.TAG, "Service destroy");
|
|
||||||
|
|
||||||
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
cm.unregisterNetworkCallback(serviceManager);
|
|
||||||
|
|
||||||
serviceManager.onLost(null);
|
|
||||||
|
|
||||||
stopForeground(true);
|
|
||||||
|
|
||||||
NotificationManager nm = getSystemService(NotificationManager.class);
|
|
||||||
nm.cancel(NOTIFICATION_SYNCHRONIZE);
|
|
||||||
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
||||||
Log.i(Helper.TAG, "Service command intent=" + intent);
|
|
||||||
super.onStartCommand(intent, flags, startId);
|
|
||||||
|
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
Loading…
Reference in New Issue