Commit a08775af authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Add ScreenOnAndUnlocked info to DeviceConditions.

Some features need to know if the screen is on and unlocked (e.g. the
ClickToCall feature will use this to open the dialer immediately instead
of displaying a notification). This adds this information to
DeviceConditions and updates all dependencies.

Bug: None
Change-Id: If67dc2d736b20284c0e79a0244753f594bfdba74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1751730Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686482}
parent 291b96e7
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser; package org.chromium.chrome.browser;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.KeyguardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
...@@ -14,6 +15,7 @@ import android.os.BatteryManager; ...@@ -14,6 +15,7 @@ import android.os.BatteryManager;
import android.os.Build; import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.net.ConnectionType; import org.chromium.net.ConnectionType;
import org.chromium.net.NetworkChangeNotifier; import org.chromium.net.NetworkChangeNotifier;
...@@ -27,6 +29,7 @@ public class DeviceConditions { ...@@ -27,6 +29,7 @@ public class DeviceConditions {
private boolean mPowerConnected; private boolean mPowerConnected;
private int mBatteryPercentage; private int mBatteryPercentage;
private boolean mPowerSaveOn; private boolean mPowerSaveOn;
private boolean mScreenOnAndUnlocked;
// Network related variables. // Network related variables.
private @ConnectionType int mNetConnectionType = ConnectionType.CONNECTION_UNKNOWN; private @ConnectionType int mNetConnectionType = ConnectionType.CONNECTION_UNKNOWN;
...@@ -42,12 +45,13 @@ public class DeviceConditions { ...@@ -42,12 +45,13 @@ public class DeviceConditions {
*/ */
@VisibleForTesting @VisibleForTesting
public DeviceConditions(boolean powerConnected, int batteryPercentage, int netConnectionType, public DeviceConditions(boolean powerConnected, int batteryPercentage, int netConnectionType,
boolean powerSaveOn, boolean activeNetworkMetered) { boolean powerSaveOn, boolean activeNetworkMetered, boolean screenOnAndUnlocked) {
mPowerConnected = powerConnected; mPowerConnected = powerConnected;
mBatteryPercentage = batteryPercentage; mBatteryPercentage = batteryPercentage;
mPowerSaveOn = powerSaveOn; mPowerSaveOn = powerSaveOn;
mNetConnectionType = netConnectionType; mNetConnectionType = netConnectionType;
mActiveNetworkMetered = activeNetworkMetered; mActiveNetworkMetered = activeNetworkMetered;
mScreenOnAndUnlocked = screenOnAndUnlocked;
} }
@VisibleForTesting @VisibleForTesting
...@@ -64,7 +68,7 @@ public class DeviceConditions { ...@@ -64,7 +68,7 @@ public class DeviceConditions {
return new DeviceConditions(isCurrentlyPowerConnected(context, batteryStatus), return new DeviceConditions(isCurrentlyPowerConnected(context, batteryStatus),
getCurrentBatteryPercentage(context, batteryStatus), getCurrentBatteryPercentage(context, batteryStatus),
getCurrentNetConnectionType(context), isCurrentlyInPowerSaveMode(context), getCurrentNetConnectionType(context), isCurrentlyInPowerSaveMode(context),
isCurrentActiveNetworkMetered(context)); isCurrentActiveNetworkMetered(context), isCurrentlyScreenOnAndUnlocked(context));
} }
/** @return Whether the device is connected to a power source. */ /** @return Whether the device is connected to a power source. */
...@@ -173,6 +177,16 @@ public class DeviceConditions { ...@@ -173,6 +177,16 @@ public class DeviceConditions {
return cm.isActiveNetworkMetered(); return cm.isActiveNetworkMetered();
} }
/**
* @return Whether the screen is currently on and unlocked.
*/
public static boolean isCurrentlyScreenOnAndUnlocked(Context context) {
KeyguardManager keyguardManager =
(KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
return keyguardManager != null && !keyguardManager.isKeyguardLocked()
&& ApiCompatibilityUtils.isInteractive(context);
}
private static Intent getBatteryStatus(Context context) { private static Intent getBatteryStatus(Context context) {
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
// Note this is a sticky intent, so we aren't really registering a receiver, just getting // Note this is a sticky intent, so we aren't really registering a receiver, just getting
...@@ -232,4 +246,9 @@ public class DeviceConditions { ...@@ -232,4 +246,9 @@ public class DeviceConditions {
public boolean isActiveNetworkMetered() { public boolean isActiveNetworkMetered() {
return mActiveNetworkMetered; return mActiveNetworkMetered;
} }
/** Returns whether the screen is on and unlocked. */
public boolean isScreenOnAndUnlocked() {
return mScreenOnAndUnlocked;
}
} }
...@@ -59,4 +59,9 @@ public class ShadowDeviceConditions { ...@@ -59,4 +59,9 @@ public class ShadowDeviceConditions {
public static boolean isCurrentActiveNetworkMetered(Context context) { public static boolean isCurrentActiveNetworkMetered(Context context) {
return sDeviceConditions.isActiveNetworkMetered(); return sDeviceConditions.isActiveNetworkMetered();
} }
@Implementation
public static boolean isCurrentlyScreenOnAndUnlocked(Context context) {
return sDeviceConditions.isScreenOnAndUnlocked();
}
} }
...@@ -114,9 +114,10 @@ public class ExploreSitesBackgroundTaskUnitTest { ...@@ -114,9 +114,10 @@ public class ExploreSitesBackgroundTaskUnitTest {
boolean powerSaveModeOn = true; boolean powerSaveModeOn = true;
int highBatteryLevel = 75; int highBatteryLevel = 75;
boolean metered = true; boolean metered = true;
boolean screenOnAndUnlocked = true;
DeviceConditions deviceConditions = new DeviceConditions( DeviceConditions deviceConditions = new DeviceConditions(!powerConnected, highBatteryLevel,
!powerConnected, highBatteryLevel, connectionType, !powerSaveModeOn, !metered); connectionType, !powerSaveModeOn, !metered, screenOnAndUnlocked);
ShadowDeviceConditions.setCurrentConditions(deviceConditions); ShadowDeviceConditions.setCurrentConditions(deviceConditions);
} }
......
...@@ -62,6 +62,7 @@ public class OfflineBackgroundTaskTest { ...@@ -62,6 +62,7 @@ public class OfflineBackgroundTaskTest {
private static final boolean POWER_CONNECTED = true; private static final boolean POWER_CONNECTED = true;
private static final boolean POWER_SAVE_MODE_ON = true; private static final boolean POWER_SAVE_MODE_ON = true;
private static final boolean METERED = true; private static final boolean METERED = true;
private static final boolean SCREEN_ON_AND_UNLOCKED = true;
private static final int MINIMUM_BATTERY_LEVEL = 33; private static final int MINIMUM_BATTERY_LEVEL = 33;
private static final String IS_LOW_END_DEVICE_SWITCH = private static final String IS_LOW_END_DEVICE_SWITCH =
"--" + BaseSwitches.ENABLE_LOW_END_DEVICE_MODE; "--" + BaseSwitches.ENABLE_LOW_END_DEVICE_MODE;
...@@ -74,7 +75,8 @@ public class OfflineBackgroundTaskTest { ...@@ -74,7 +75,8 @@ public class OfflineBackgroundTaskTest {
private TriggerConditions mTriggerConditions = private TriggerConditions mTriggerConditions =
new TriggerConditions(!REQUIRE_POWER, MINIMUM_BATTERY_LEVEL, REQUIRE_UNMETERED); new TriggerConditions(!REQUIRE_POWER, MINIMUM_BATTERY_LEVEL, REQUIRE_UNMETERED);
private DeviceConditions mDeviceConditions = new DeviceConditions(!POWER_CONNECTED, private DeviceConditions mDeviceConditions = new DeviceConditions(!POWER_CONNECTED,
MINIMUM_BATTERY_LEVEL + 5, ConnectionType.CONNECTION_3G, !POWER_SAVE_MODE_ON, !METERED); MINIMUM_BATTERY_LEVEL + 5, ConnectionType.CONNECTION_3G, !POWER_SAVE_MODE_ON, !METERED,
SCREEN_ON_AND_UNLOCKED);
private Activity mTestActivity; private Activity mTestActivity;
@Mock @Mock
...@@ -134,9 +136,9 @@ public class OfflineBackgroundTaskTest { ...@@ -134,9 +136,9 @@ public class OfflineBackgroundTaskTest {
@Feature({"OfflinePages"}) @Feature({"OfflinePages"})
public void testCheckConditions_BatteryConditions_LowBattery_NoPower() { public void testCheckConditions_BatteryConditions_LowBattery_NoPower() {
// Setup low battery conditions with no power connected. // Setup low battery conditions with no power connected.
DeviceConditions deviceConditionsLowBattery = DeviceConditions deviceConditionsLowBattery = new DeviceConditions(!POWER_CONNECTED,
new DeviceConditions(!POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON,
ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED); !METERED, SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsLowBattery); ShadowDeviceConditions.setCurrentConditions(deviceConditionsLowBattery);
// Verify that conditions for processing are not met. // Verify that conditions for processing are not met.
...@@ -159,9 +161,9 @@ public class OfflineBackgroundTaskTest { ...@@ -159,9 +161,9 @@ public class OfflineBackgroundTaskTest {
@Feature({"OfflinePages"}) @Feature({"OfflinePages"})
public void testCheckConditions_BatteryConditions_LowBattery_WithPower() { public void testCheckConditions_BatteryConditions_LowBattery_WithPower() {
// Set battery percentage below minimum level, but connect power. // Set battery percentage below minimum level, but connect power.
DeviceConditions deviceConditionsPowerConnected = DeviceConditions deviceConditionsPowerConnected = new DeviceConditions(POWER_CONNECTED,
new DeviceConditions(POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON,
ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED); !METERED, SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsPowerConnected); ShadowDeviceConditions.setCurrentConditions(deviceConditionsPowerConnected);
// Now verify that same battery level, with power connected, will pass the conditions. // Now verify that same battery level, with power connected, will pass the conditions.
......
...@@ -195,10 +195,10 @@ public class OfflineNotificationBackgroundTaskUnitTest { ...@@ -195,10 +195,10 @@ public class OfflineNotificationBackgroundTaskUnitTest {
} }
private void setupDeviceOnlineStatus(boolean online) { private void setupDeviceOnlineStatus(boolean online) {
DeviceConditions deviceConditions = DeviceConditions deviceConditions = new DeviceConditions(false /* POWER_CONNECTED */,
new DeviceConditions(false /* POWER_CONNECTED */, 75 /* BATTERY_LEVEL */, 75 /* BATTERY_LEVEL */,
online ? ConnectionType.CONNECTION_WIFI : ConnectionType.CONNECTION_NONE, online ? ConnectionType.CONNECTION_WIFI : ConnectionType.CONNECTION_NONE,
false /* POWER_SAVE */, false /* metered */); false /* POWER_SAVE */, false /* metered */, true /* screenOnAndUnlocked */);
ShadowDeviceConditions.setCurrentConditions(deviceConditions); ShadowDeviceConditions.setCurrentConditions(deviceConditions);
} }
......
...@@ -90,6 +90,7 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -90,6 +90,7 @@ public class PrefetchBackgroundTaskUnitTest {
public static final int HIGH_BATTERY_LEVEL = 75; public static final int HIGH_BATTERY_LEVEL = 75;
public static final int LOW_BATTERY_LEVEL = 25; public static final int LOW_BATTERY_LEVEL = 25;
public static final boolean METERED = true; public static final boolean METERED = true;
public static final boolean SCREEN_ON_AND_UNLOCKED = true;
@Spy @Spy
private PrefetchBackgroundTask mPrefetchBackgroundTask = new PrefetchBackgroundTask(); private PrefetchBackgroundTask mPrefetchBackgroundTask = new PrefetchBackgroundTask();
...@@ -193,9 +194,9 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -193,9 +194,9 @@ public class PrefetchBackgroundTaskUnitTest {
TaskParameters.create(TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID).build(); TaskParameters.create(TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID).build();
// Setup battery conditions with no power connected. // Setup battery conditions with no power connected.
DeviceConditions deviceConditions = DeviceConditions deviceConditions = new DeviceConditions(!POWER_CONNECTED,
new DeviceConditions(!POWER_CONNECTED, HIGH_BATTERY_LEVEL - 1, HIGH_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON,
ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED); !METERED, SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditions); ShadowDeviceConditions.setCurrentConditions(deviceConditions);
mPrefetchBackgroundTask.onStartTask(null, params, new TaskFinishedCallback() { mPrefetchBackgroundTask.onStartTask(null, params, new TaskFinishedCallback() {
...@@ -225,7 +226,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -225,7 +226,8 @@ public class PrefetchBackgroundTaskUnitTest {
// Setup battery conditions with no power connected. // Setup battery conditions with no power connected.
DeviceConditions deviceConditions = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditions = new DeviceConditions(!POWER_CONNECTED,
0 /* battery level */, ConnectionType.CONNECTION_2G, !POWER_SAVE_MODE_ON, METERED); 0 /* battery level */, ConnectionType.CONNECTION_2G, !POWER_SAVE_MODE_ON, METERED,
SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditions); ShadowDeviceConditions.setCurrentConditions(deviceConditions);
mPrefetchBackgroundTask.onStartTask(null, params, new TaskFinishedCallback() { mPrefetchBackgroundTask.onStartTask(null, params, new TaskFinishedCallback() {
...@@ -244,7 +246,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -244,7 +246,8 @@ public class PrefetchBackgroundTaskUnitTest {
public void testBatteryLow() throws Exception { public void testBatteryLow() throws Exception {
// Setup low battery conditions with no power connected. // Setup low battery conditions with no power connected.
DeviceConditions deviceConditionsLowBattery = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditionsLowBattery = new DeviceConditions(!POWER_CONNECTED,
LOW_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, METERED); LOW_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, METERED,
SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsLowBattery); ShadowDeviceConditions.setCurrentConditions(deviceConditionsLowBattery);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
...@@ -265,7 +268,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -265,7 +268,8 @@ public class PrefetchBackgroundTaskUnitTest {
public void testBatteryHigh() throws Exception { public void testBatteryHigh() throws Exception {
// Setup high battery conditions with no power connected. // Setup high battery conditions with no power connected.
DeviceConditions deviceConditionsHighBattery = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditionsHighBattery = new DeviceConditions(!POWER_CONNECTED,
HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED); HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED,
SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsHighBattery); ShadowDeviceConditions.setCurrentConditions(deviceConditionsHighBattery);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
...@@ -286,7 +290,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -286,7 +290,8 @@ public class PrefetchBackgroundTaskUnitTest {
public void testNoNetwork() throws Exception { public void testNoNetwork() throws Exception {
// Setup no network conditions. // Setup no network conditions.
DeviceConditions deviceConditionsNoNetwork = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditionsNoNetwork = new DeviceConditions(!POWER_CONNECTED,
HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_NONE, !POWER_SAVE_MODE_ON, !METERED); HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_NONE, !POWER_SAVE_MODE_ON, !METERED,
SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsNoNetwork); ShadowDeviceConditions.setCurrentConditions(deviceConditionsNoNetwork);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
...@@ -310,9 +315,9 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -310,9 +315,9 @@ public class PrefetchBackgroundTaskUnitTest {
@Test @Test
public void testNoNetworkLimitless() throws Exception { public void testNoNetworkLimitless() throws Exception {
// Setup no network conditions. // Setup no network conditions.
DeviceConditions deviceConditionsNoNetwork = DeviceConditions deviceConditionsNoNetwork = new DeviceConditions(!POWER_CONNECTED,
new DeviceConditions(!POWER_CONNECTED, 0 /* battery level */, 0 /* battery level */, ConnectionType.CONNECTION_NONE, !POWER_SAVE_MODE_ON,
ConnectionType.CONNECTION_NONE, !POWER_SAVE_MODE_ON, !METERED); !METERED, SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsNoNetwork); ShadowDeviceConditions.setCurrentConditions(deviceConditionsNoNetwork);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
...@@ -336,7 +341,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -336,7 +341,8 @@ public class PrefetchBackgroundTaskUnitTest {
public void testUnmeteredWifiNetwork() throws Exception { public void testUnmeteredWifiNetwork() throws Exception {
// Setup unmetered wifi conditions. // Setup unmetered wifi conditions.
DeviceConditions deviceConditionsUnmeteredWifi = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditionsUnmeteredWifi = new DeviceConditions(!POWER_CONNECTED,
HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED); HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED,
SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsUnmeteredWifi); ShadowDeviceConditions.setCurrentConditions(deviceConditionsUnmeteredWifi);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
...@@ -357,7 +363,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -357,7 +363,8 @@ public class PrefetchBackgroundTaskUnitTest {
public void testMeteredWifiNetwork() throws Exception { public void testMeteredWifiNetwork() throws Exception {
// Setup metered wifi conditions. // Setup metered wifi conditions.
DeviceConditions deviceConditionsMeteredWifi = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditionsMeteredWifi = new DeviceConditions(!POWER_CONNECTED,
HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, METERED); HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, METERED,
SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsMeteredWifi); ShadowDeviceConditions.setCurrentConditions(deviceConditionsMeteredWifi);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
...@@ -378,7 +385,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -378,7 +385,8 @@ public class PrefetchBackgroundTaskUnitTest {
public void test2GNetwork() throws Exception { public void test2GNetwork() throws Exception {
// Setup metered 2g connection conditions. // Setup metered 2g connection conditions.
DeviceConditions deviceConditions2G = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditions2G = new DeviceConditions(!POWER_CONNECTED,
HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_2G, !POWER_SAVE_MODE_ON, METERED); HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_2G, !POWER_SAVE_MODE_ON, METERED,
SCREEN_ON_AND_UNLOCKED);
// TODO(petewil): this test name and the condition below do not match. // TODO(petewil): this test name and the condition below do not match.
ShadowDeviceConditions.setCurrentConditions(deviceConditions2G); ShadowDeviceConditions.setCurrentConditions(deviceConditions2G);
...@@ -399,9 +407,9 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -399,9 +407,9 @@ public class PrefetchBackgroundTaskUnitTest {
@Test @Test
public void testBluetoothNetwork() throws Exception { public void testBluetoothNetwork() throws Exception {
// Setup bluetooth connection conditions. // Setup bluetooth connection conditions.
DeviceConditions deviceConditionsBluetooth = DeviceConditions deviceConditionsBluetooth = new DeviceConditions(!POWER_CONNECTED,
new DeviceConditions(!POWER_CONNECTED, HIGH_BATTERY_LEVEL, HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_BLUETOOTH, !POWER_SAVE_MODE_ON,
ConnectionType.CONNECTION_BLUETOOTH, !POWER_SAVE_MODE_ON, !METERED); !METERED, SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsBluetooth); ShadowDeviceConditions.setCurrentConditions(deviceConditionsBluetooth);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
...@@ -425,9 +433,9 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -425,9 +433,9 @@ public class PrefetchBackgroundTaskUnitTest {
TaskParameters.create(TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID).build(); TaskParameters.create(TaskIds.OFFLINE_PAGES_PREFETCH_JOB_ID).build();
// Conditions should be appropriate for running the task. // Conditions should be appropriate for running the task.
DeviceConditions deviceConditions = DeviceConditions deviceConditions = new DeviceConditions(POWER_CONNECTED,
new DeviceConditions(POWER_CONNECTED, HIGH_BATTERY_LEVEL - 1, HIGH_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON,
ConnectionType.CONNECTION_WIFI, !POWER_SAVE_MODE_ON, !METERED); !METERED, SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditions); ShadowDeviceConditions.setCurrentConditions(deviceConditions);
mPrefetchBackgroundTask.onStartTask(null, params, new TaskFinishedCallback() { mPrefetchBackgroundTask.onStartTask(null, params, new TaskFinishedCallback() {
...@@ -447,7 +455,8 @@ public class PrefetchBackgroundTaskUnitTest { ...@@ -447,7 +455,8 @@ public class PrefetchBackgroundTaskUnitTest {
public void testPowerSaverOn() throws Exception { public void testPowerSaverOn() throws Exception {
// Setup power save mode, battery is high, wifi, not plugged in. // Setup power save mode, battery is high, wifi, not plugged in.
DeviceConditions deviceConditionsPowerSave = new DeviceConditions(!POWER_CONNECTED, DeviceConditions deviceConditionsPowerSave = new DeviceConditions(!POWER_CONNECTED,
HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, POWER_SAVE_MODE_ON, !METERED); HIGH_BATTERY_LEVEL, ConnectionType.CONNECTION_WIFI, POWER_SAVE_MODE_ON, !METERED,
SCREEN_ON_AND_UNLOCKED);
ShadowDeviceConditions.setCurrentConditions(deviceConditionsPowerSave); ShadowDeviceConditions.setCurrentConditions(deviceConditionsPowerSave);
// Check impact on starting before native loaded. // Check impact on starting before native loaded.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment