1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 08:11:17 +00:00

Check battery saving on Android 5.0 (#921)

isPowerSaveMode and ACTION_POWER_SAVE_MODE_CHANGED were added in API level 21.
This commit is contained in:
Unrud 2017-07-17 05:31:56 +02:00 committed by Felix Ableitner
parent a3deb81c72
commit ea8621cfc3
2 changed files with 3 additions and 3 deletions

View file

@ -115,7 +115,7 @@ public class DeviceStateHolder extends BroadcastReceiver {
public boolean shouldRun() { public boolean shouldRun() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
prefs.getBoolean("respect_battery_saving", true) && prefs.getBoolean("respect_battery_saving", true) &&
pm.isPowerSaveMode()) { pm.isPowerSaveMode()) {
return false; return false;

View file

@ -312,7 +312,7 @@ public class SyncthingService extends Service implements
mDeviceStateHolder = new DeviceStateHolder(SyncthingService.this); mDeviceStateHolder = new DeviceStateHolder(SyncthingService.this);
registerReceiver(mDeviceStateHolder, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); registerReceiver(mDeviceStateHolder, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
registerReceiver(mPowerSaveModeChangedReceiver, registerReceiver(mPowerSaveModeChangedReceiver,
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
} }
@ -412,7 +412,7 @@ public class SyncthingService extends Service implements
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
sp.unregisterOnSharedPreferenceChangeListener(this); sp.unregisterOnSharedPreferenceChangeListener(this);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
unregisterReceiver(mPowerSaveModeChangedReceiver); unregisterReceiver(mPowerSaveModeChangedReceiver);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
unregisterReceiver(mNetworkReceiver); unregisterReceiver(mNetworkReceiver);