mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 22:31:16 +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:
parent
a3deb81c72
commit
ea8621cfc3
2 changed files with 3 additions and 3 deletions
|
@ -115,7 +115,7 @@ public class DeviceStateHolder extends BroadcastReceiver {
|
|||
public boolean shouldRun() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
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) &&
|
||||
pm.isPowerSaveMode()) {
|
||||
return false;
|
||||
|
|
|
@ -312,7 +312,7 @@ public class SyncthingService extends Service implements
|
|||
|
||||
mDeviceStateHolder = new DeviceStateHolder(SyncthingService.this);
|
||||
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,
|
||||
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ public class SyncthingService extends Service implements
|
|||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
sp.unregisterOnSharedPreferenceChangeListener(this);
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
unregisterReceiver(mPowerSaveModeChangedReceiver);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
unregisterReceiver(mNetworkReceiver);
|
||||
|
|
Loading…
Reference in a new issue