Listen for suspend events

This commit is contained in:
M66B 2022-04-01 09:51:40 +02:00
parent 51a1728edb
commit a96171665a
1 changed files with 18 additions and 0 deletions

View File

@ -199,6 +199,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
registerReceiver(dataSaverChanged, new IntentFilter(ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED)); registerReceiver(dataSaverChanged, new IntentFilter(ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
IntentFilter suspend = new IntentFilter();
suspend.addAction(Intent.ACTION_MY_PACKAGE_SUSPENDED);
suspend.addAction(Intent.ACTION_MY_PACKAGE_UNSUSPENDED);
registerReceiver(suspendChanged, suspend);
}
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
@ -859,6 +866,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.unregisterOnSharedPreferenceChangeListener(this); prefs.unregisterOnSharedPreferenceChangeListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
unregisterReceiver(suspendChanged);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
unregisterReceiver(dataSaverChanged); unregisterReceiver(dataSaverChanged);
@ -2634,6 +2644,14 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
}; };
private final BroadcastReceiver suspendChanged = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
EntityLog.log(context, intent.getAction() + " " +
TextUtils.join(", ", Log.getExtras(intent.getExtras())));
}
};
private void updateNetworkState(final Network network, final String reason) { private void updateNetworkState(final Network network, final String reason) {
getMainHandler().post(new Runnable() { getMainHandler().post(new Runnable() {
@Override @Override