mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-31 03:21:36 +00:00
Listen for data saver events
This commit is contained in:
parent
b6cb1673f0
commit
1313005e2f
1 changed files with 21 additions and 0 deletions
|
@ -181,6 +181,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
registerReceiver(idleModeChangedReceiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
|
registerReceiver(idleModeChangedReceiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||||
|
registerReceiver(dataSaverChanged, new IntentFilter(ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED));
|
||||||
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
DB db = DB.getInstance(this);
|
DB db = DB.getInstance(this);
|
||||||
|
@ -745,6 +748,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.N)
|
||||||
|
unregisterReceiver(dataSaverChanged);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
unregisterReceiver(idleModeChangedReceiver);
|
unregisterReceiver(idleModeChangedReceiver);
|
||||||
|
|
||||||
|
@ -2145,6 +2151,21 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private BroadcastReceiver dataSaverChanged = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Log.i("Received intent=" + intent +
|
||||||
|
" " + TextUtils.join(" ", Log.getExtras(intent.getExtras())));
|
||||||
|
|
||||||
|
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
Integer status = (cm == null ? null : cm.getRestrictBackgroundStatus());
|
||||||
|
EntityLog.log(context, "Data saver=" + status);
|
||||||
|
|
||||||
|
updateNetworkState(null, "datasaver");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private class MediatorState extends MediatorLiveData<List<TupleAccountNetworkState>> {
|
private class MediatorState extends MediatorLiveData<List<TupleAccountNetworkState>> {
|
||||||
private boolean running = true;
|
private boolean running = true;
|
||||||
private ConnectionHelper.NetworkState lastNetworkState = null;
|
private ConnectionHelper.NetworkState lastNetworkState = null;
|
||||||
|
|
Loading…
Reference in a new issue