Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
index 1c0759ca5e0dcebba77083f71809587568282da5..cd416e25317e5ed7cbe78df2d0041441aa946ab8 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
@@ -213,15 +213,7 @@ public class OfflinePageUtils { |
} |
public static DeviceConditions getDeviceConditions(Context context) { |
- IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); |
- // Note this is a sticky intent, so we aren't really registering a receiver, just getting |
- // the sticky intent. That means that we don't need to unregister the filter later. |
- Intent batteryStatus = context.registerReceiver(null, filter); |
- if (batteryStatus == null) return null; |
- |
- return new DeviceConditions(isPowerConnected(batteryStatus), |
- batteryPercentage(batteryStatus), |
- NetworkChangeNotifier.getInstance().getCurrentConnectionType()); |
+ return getInstance().getDeviceConditionsImpl(context); |
} |
/** |
@@ -280,6 +272,19 @@ public class OfflinePageUtils { |
return OfflinePageBridge.getForProfile(profile); |
} |
+ /** Returns the current device conditions. May be overridden for testing. */ |
+ protected DeviceConditions getDeviceConditionsImpl(Context context) { |
+ IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); |
+ // Note this is a sticky intent, so we aren't really registering a receiver, just getting |
+ // the sticky intent. That means that we don't need to unregister the filter later. |
+ Intent batteryStatus = context.registerReceiver(null, filter); |
+ if (batteryStatus == null) return null; |
+ |
+ return new DeviceConditions(isPowerConnected(batteryStatus), |
+ batteryPercentage(batteryStatus), |
+ NetworkChangeNotifier.getInstance().getCurrentConnectionType()); |
+ } |
+ |
@VisibleForTesting |
static void setInstanceForTesting(OfflinePageUtils instance) { |
sInstance = instance; |