Moved screen off handling to application

This commit is contained in:
M66B 2020-04-01 22:08:54 +02:00
parent 8de80b1755
commit 05e89a0dce
2 changed files with 14 additions and 11 deletions

View File

@ -24,7 +24,10 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.webkit.CookieManager;
@ -107,6 +110,8 @@ public class ApplicationEx extends Application {
WorkerWatchdog.init(this);
WorkerCleanup.queue(this);
registerReceiver(onScreenOff, new IntentFilter(Intent.ACTION_SCREEN_OFF));
long end = new Date().getTime();
Log.i("App created " + (end - start) + " ms");
}
@ -412,4 +417,13 @@ public class ApplicationEx extends Application {
}
});
}
private BroadcastReceiver onScreenOff = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("Received " + intent);
Log.logExtras(intent);
Helper.clearAuthentication(ApplicationEx.this);
}
};
}

View File

@ -148,7 +148,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
iif.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
iif.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(connectionChangedReceiver, iif);
registerReceiver(onScreenOff, new IntentFilter(Intent.ACTION_SCREEN_OFF));
DB db = DB.getInstance(this);
@ -582,7 +581,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.unregisterOnSharedPreferenceChangeListener(this);
unregisterReceiver(onScreenOff);
unregisterReceiver(connectionChangedReceiver);
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
@ -1683,15 +1681,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
};
private BroadcastReceiver onScreenOff = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("Received " + intent);
Log.logExtras(intent);
Helper.clearAuthentication(ServiceSynchronize.this);
}
};
private class MediatorState extends MediatorLiveData<List<TupleAccountNetworkState>> {
boolean running = true;
private ConnectionHelper.NetworkState lastNetworkState = null;