@@ -456,12 +456,12 @@ private SyncConditionResult checkConditionSyncOnWifi(String prefNameSyncOnWifi)
456456 private SyncConditionResult checkConditionSyncOnPowerSource (String prefNameSyncOnPowerSource ) {
457457 switch (mPreferences .getString (prefNameSyncOnPowerSource , Constants .PowerSource .CHARGER_BATTERY )) {
458458 case Constants .PowerSource .CHARGER :
459- if (!isCharging_API17 ()) {
459+ if (!isCharging ()) {
460460 return new SyncConditionResult (false , res .getString (R .string .reason_not_charging ));
461461 }
462462 break ;
463463 case Constants .PowerSource .BATTERY :
464- if (isCharging_API17 ()) {
464+ if (isCharging ()) {
465465 return new SyncConditionResult (false , res .getString (R .string .reason_not_on_battery_power ));
466466 }
467467 break ;
@@ -727,12 +727,23 @@ private boolean wifiWhitelistConditionMet (boolean prefWifiWhitelistEnabled,
727727 /**
728728 * Functions for run condition information retrieval.
729729 */
730- private boolean isCharging_API17 () {
730+ private boolean isCharging () {
731731 Intent intent = mContext .registerReceiver (null , new IntentFilter (Intent .ACTION_BATTERY_CHANGED ));
732+ if (intent == null ) {
733+ LogV ("isCharging: Checking battery status intent returned null" );
734+ return false ;
735+ }
732736 int plugged = intent .getIntExtra (BatteryManager .EXTRA_PLUGGED , -1 );
737+ LogV ("isCharging: Battery status intent extras: " + (intent .getExtras () != null ? intent .getExtras ().toString () : "null" ));
738+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .TIRAMISU ) {
739+ return plugged == BatteryManager .BATTERY_PLUGGED_AC ||
740+ plugged == BatteryManager .BATTERY_PLUGGED_USB ||
741+ plugged == BatteryManager .BATTERY_PLUGGED_WIRELESS ;
742+ }
733743 return plugged == BatteryManager .BATTERY_PLUGGED_AC ||
734744 plugged == BatteryManager .BATTERY_PLUGGED_USB ||
735- plugged == BatteryManager .BATTERY_PLUGGED_WIRELESS ;
745+ plugged == BatteryManager .BATTERY_PLUGGED_WIRELESS ||
746+ plugged == BatteryManager .BATTERY_PLUGGED_DOCK ;
736747 }
737748
738749 private boolean isPowerSaving () {
0 commit comments