Commit 9cd96b27 authored by dougarnett's avatar dougarnett Committed by Commit bot

Uses TriggerConditions in the BackgroundScheduler.

BUG=619686

Review-Url: https://codereview.chromium.org/2094013003
Cr-Commit-Position: refs/heads/master@{#402613}
parent 188d4f93
...@@ -39,10 +39,20 @@ public class BackgroundOfflinerTask { ...@@ -39,10 +39,20 @@ public class BackgroundOfflinerTask {
ChromeBackgroundServiceWaiter waiter) { ChromeBackgroundServiceWaiter waiter) {
// Set up backup scheduled task in case processing is killed before RequestCoordinator // Set up backup scheduled task in case processing is killed before RequestCoordinator
// has a chance to reschedule base on remaining work. // has a chance to reschedule base on remaining work.
BackgroundScheduler.schedule(context, DEFER_START_SECONDS); TriggerConditions previousTriggerConditions =
TaskExtrasPacker.unpackTriggerConditionsFromBundle(bundle);
BackgroundScheduler.backupSchedule(context, previousTriggerConditions, DEFER_START_SECONDS);
DeviceConditions currentConditions = OfflinePageUtils.getDeviceConditions(context);
if (!currentConditions.isPowerConnected()
&& currentConditions.getBatteryPercentage()
< previousTriggerConditions.getMinimumBatteryPercentage()) {
Log.d(TAG, "Battery percentage is lower than minimum to start processing");
return false;
}
// Now initiate processing. // Now initiate processing.
processBackgroundRequests(bundle, OfflinePageUtils.getDeviceConditions(context), waiter); processBackgroundRequests(bundle, currentConditions, waiter);
// Gather UMA data to measure how often the user's machine is amenable to background // Gather UMA data to measure how often the user's machine is amenable to background
// loading when we wake to do a task. // loading when we wake to do a task.
......
...@@ -18,48 +18,62 @@ import org.chromium.chrome.browser.ChromeBackgroundService; ...@@ -18,48 +18,62 @@ import org.chromium.chrome.browser.ChromeBackgroundService;
*/ */
public class BackgroundScheduler { public class BackgroundScheduler {
private static final long ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7; private static final long ONE_WEEK_IN_SECONDS = 60 * 60 * 24 * 7;
private static final long NO_DELAY = 0;
private static final boolean OVERWRITE = true;
/** /**
* For the given Triggering conditions, start a new GCM Network Manager request. * For the given Triggering conditions, start a new GCM Network Manager request.
*/ */
public static void schedule(Context context, TriggerConditions triggerConditions) { public static void schedule(Context context, TriggerConditions triggerConditions) {
// TODO(dougarnett): Use trigger conditions in task builder config. schedule(context, triggerConditions, NO_DELAY, OVERWRITE);
schedule(context, 0 /* delayStartSecs */); }
/**
* If there is no currently scheduled task, then start a GCM Network Manager request
* for the given Triggering conditions but delayed to run after {@code delayStartSecs}.
* Typically, the Request Coordinator will overwrite this task after task processing
* and/or queue updates. This is a backup task in case processing is killed by the
* system.
*/
public static void backupSchedule(
Context context, TriggerConditions triggerConditions, long delayStartSecs) {
schedule(context, triggerConditions, delayStartSecs, !OVERWRITE);
}
/**
* Cancel any outstanding GCM Network Manager requests.
*/
public static void unschedule(Context context) {
// Get the GCM Network Scheduler.
GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);
gcmNetworkManager.cancelTask(OfflinePageUtils.TASK_TAG, ChromeBackgroundService.class);
} }
/** /**
* For the given Triggering conditions, start a new GCM Network Manager request allowed * For the given Triggering conditions, start a new GCM Network Manager request allowed
* to run after {@code delayStartSecs} seconds. * to run after {@code delayStartSecs} seconds.
*/ */
public static void schedule(Context context, long delayStartSecs) { private static void schedule(Context context, TriggerConditions triggerConditions,
long delayStartSecs, boolean overwrite) {
// Get the GCM Network Scheduler. // Get the GCM Network Scheduler.
GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context); GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);
// TODO(petewil): Add the triggering conditions into the argument bundle.
// Triggering conditions will include network state and charging requirements, maybe
// also battery percentage.
Bundle taskExtras = new Bundle(); Bundle taskExtras = new Bundle();
TaskExtrasPacker.packTimeInBundle(taskExtras); TaskExtrasPacker.packTimeInBundle(taskExtras);
TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerConditions);
Task task = new OneoffTask.Builder() Task task = new OneoffTask.Builder()
.setService(ChromeBackgroundService.class) .setService(ChromeBackgroundService.class)
.setExecutionWindow(delayStartSecs, ONE_WEEK_IN_SECONDS) .setExecutionWindow(delayStartSecs, ONE_WEEK_IN_SECONDS)
.setTag(OfflinePageUtils.TASK_TAG) .setTag(OfflinePageUtils.TASK_TAG)
.setUpdateCurrent(true) .setUpdateCurrent(overwrite)
.setRequiredNetwork(Task.NETWORK_STATE_CONNECTED) .setRequiredNetwork(triggerConditions.requireUnmeteredNetwork()
.setRequiresCharging(false) ? Task.NETWORK_STATE_UNMETERED
.setExtras(taskExtras) : Task.NETWORK_STATE_CONNECTED)
.build(); .setRequiresCharging(triggerConditions.requirePowerConnected())
.setExtras(taskExtras)
.build();
gcmNetworkManager.schedule(task); gcmNetworkManager.schedule(task);
} }
/**
* Cancel any outstanding GCM Network Manager requests.
*/
public static void unschedule(Context context) {
// Get the GCM Network Scheduler.
GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);
gcmNetworkManager.cancelTask(OfflinePageUtils.TASK_TAG, ChromeBackgroundService.class);
}
} }
...@@ -213,15 +213,7 @@ public class OfflinePageUtils { ...@@ -213,15 +213,7 @@ public class OfflinePageUtils {
} }
public static DeviceConditions getDeviceConditions(Context context) { public static DeviceConditions getDeviceConditions(Context context) {
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); return getInstance().getDeviceConditionsImpl(context);
// 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());
} }
/** /**
...@@ -280,6 +272,19 @@ public class OfflinePageUtils { ...@@ -280,6 +272,19 @@ public class OfflinePageUtils {
return OfflinePageBridge.getForProfile(profile); 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 @VisibleForTesting
static void setInstanceForTesting(OfflinePageUtils instance) { static void setInstanceForTesting(OfflinePageUtils instance) {
sInstance = instance; sInstance = instance;
......
...@@ -15,6 +15,11 @@ public class TaskExtrasPacker { ...@@ -15,6 +15,11 @@ public class TaskExtrasPacker {
/** Bundle key for the timestamp in milliseconds when the request started. */ /** Bundle key for the timestamp in milliseconds when the request started. */
public static final String SCHEDULED_TIME_TAG = "ScheduleTime"; public static final String SCHEDULED_TIME_TAG = "ScheduleTime";
// Trigger condition tags.
private static final String POWER_CONNECTED_TAG = "PowerConnected";
private static final String BATTERY_PERCENTAGE_TAG = "BatteryPercentage";
private static final String UNMETERED_NETWORK_TAG = "UnmeteredNetwork";
/** Puts current time into the input bundle. */ /** Puts current time into the input bundle. */
public static void packTimeInBundle(Bundle bundle) { public static void packTimeInBundle(Bundle bundle) {
bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis()); bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis());
...@@ -25,4 +30,20 @@ public class TaskExtrasPacker { ...@@ -25,4 +30,20 @@ public class TaskExtrasPacker {
public static long unpackTimeFromBundle(Bundle bundle) { public static long unpackTimeFromBundle(Bundle bundle) {
return bundle.getLong(SCHEDULED_TIME_TAG); return bundle.getLong(SCHEDULED_TIME_TAG);
} }
/** Puts trigger conditions into the input bundle. */
public static void packTriggerConditionsInBundle(Bundle bundle, TriggerConditions conditions) {
bundle.putBoolean(POWER_CONNECTED_TAG, conditions.requirePowerConnected());
bundle.putInt(BATTERY_PERCENTAGE_TAG, conditions.getMinimumBatteryPercentage());
bundle.putBoolean(UNMETERED_NETWORK_TAG, conditions.requireUnmeteredNetwork());
}
/** Extracts the trigger conditions we put into the bundle. */
public static TriggerConditions unpackTriggerConditionsFromBundle(Bundle bundle) {
boolean requirePowerConnected = bundle.getBoolean(POWER_CONNECTED_TAG, true);
int minimumBatteryPercentage = bundle.getInt(BATTERY_PERCENTAGE_TAG, 100);
boolean requireUnmeteredNetwork = bundle.getBoolean(UNMETERED_NETWORK_TAG, true);
return new TriggerConditions(
requirePowerConnected, minimumBatteryPercentage, requireUnmeteredNetwork);
}
} }
...@@ -37,4 +37,22 @@ public class TriggerConditions { ...@@ -37,4 +37,22 @@ public class TriggerConditions {
public boolean requireUnmeteredNetwork() { public boolean requireUnmeteredNetwork() {
return mRequireUnmeteredNetwork; return mRequireUnmeteredNetwork;
} }
@Override
public int hashCode() {
int hash = 13;
hash = hash * 31 + (mRequirePowerConnected ? 1 : 0);
hash = hash * 31 + mMinimumBatteryPercentage;
hash = hash * 31 + (mRequireUnmeteredNetwork ? 1 : 0);
return hash;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof TriggerConditions)) return false;
TriggerConditions otherTriggerConditions = (TriggerConditions) other;
return mRequirePowerConnected == otherTriggerConditions.mRequirePowerConnected
&& mMinimumBatteryPercentage == otherTriggerConditions.mMinimumBatteryPercentage
&& mRequireUnmeteredNetwork == otherTriggerConditions.mRequireUnmeteredNetwork;
}
} }
...@@ -1277,6 +1277,7 @@ chrome_junit_test_java_sources = [ ...@@ -1277,6 +1277,7 @@ chrome_junit_test_java_sources = [
"junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java", "junit/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtilsTest.java",
"junit/src/org/chromium/chrome/browser/offlinepages/ShadowGcmNetworkManager.java", "junit/src/org/chromium/chrome/browser/offlinepages/ShadowGcmNetworkManager.java",
"junit/src/org/chromium/chrome/browser/offlinepages/StubBackgroundSchedulerProcessor.java", "junit/src/org/chromium/chrome/browser/offlinepages/StubBackgroundSchedulerProcessor.java",
"junit/src/org/chromium/chrome/browser/offlinepages/TaskExtrasPackerTest.java",
"junit/src/org/chromium/chrome/browser/omaha/ResponseParserTest.java", "junit/src/org/chromium/chrome/browser/omaha/ResponseParserTest.java",
"junit/src/org/chromium/chrome/browser/omaha/VersionNumberTest.java", "junit/src/org/chromium/chrome/browser/omaha/VersionNumberTest.java",
"junit/src/org/chromium/chrome/browser/payments/AutofillContactTest.java", "junit/src/org/chromium/chrome/browser/payments/AutofillContactTest.java",
......
...@@ -4,14 +4,22 @@ ...@@ -4,14 +4,22 @@
package org.chromium.chrome.browser.offlinepages; package org.chromium.chrome.browser.offlinepages;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import com.google.android.gms.gcm.Task;
import org.chromium.base.BaseChromiumApplication; import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter; import org.chromium.chrome.browser.ChromeBackgroundServiceWaiter;
import org.chromium.net.ConnectionType; import org.chromium.net.ConnectionType;
...@@ -19,6 +27,8 @@ import org.chromium.testing.local.LocalRobolectricTestRunner; ...@@ -19,6 +27,8 @@ import org.chromium.testing.local.LocalRobolectricTestRunner;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
...@@ -30,16 +40,37 @@ import org.robolectric.annotation.Config; ...@@ -30,16 +40,37 @@ import org.robolectric.annotation.Config;
application = BaseChromiumApplication.class, application = BaseChromiumApplication.class,
shadows = { ShadowGcmNetworkManager.class }) shadows = { ShadowGcmNetworkManager.class })
public class BackgroundOfflinerTaskTest { public class BackgroundOfflinerTaskTest {
private static final boolean REQUIRE_POWER = true;
private static final boolean REQUIRE_UNMETERED = true;
private static final boolean POWER_CONNECTED = true;
private static final int MINIMUM_BATTERY_LEVEL = 33;
@Mock
private OfflinePageUtils mOfflinePageUtils;
private Bundle mTaskExtras; private Bundle mTaskExtras;
private long mTestTime; private long mTestTime;
private StubBackgroundSchedulerProcessor mStubBackgroundSchedulerProcessor; private StubBackgroundSchedulerProcessor mStubBackgroundSchedulerProcessor;
private TriggerConditions mTriggerConditions =
new TriggerConditions(!REQUIRE_POWER, MINIMUM_BATTERY_LEVEL, REQUIRE_UNMETERED);
private DeviceConditions mDeviceConditions = new DeviceConditions(
!POWER_CONNECTED, MINIMUM_BATTERY_LEVEL + 5, ConnectionType.CONNECTION_3G);
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// Build a bundle MockitoAnnotations.initMocks(this);
when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
.thenReturn(mDeviceConditions);
// Build a bundle with trigger conditions.
mTaskExtras = new Bundle(); mTaskExtras = new Bundle();
TaskExtrasPacker.packTimeInBundle(mTaskExtras); TaskExtrasPacker.packTimeInBundle(mTaskExtras);
TaskExtrasPacker.packTriggerConditionsInBundle(mTaskExtras, mTriggerConditions);
OfflinePageUtils.setInstanceForTesting(mOfflinePageUtils);
mStubBackgroundSchedulerProcessor = new StubBackgroundSchedulerProcessor(); mStubBackgroundSchedulerProcessor = new StubBackgroundSchedulerProcessor();
RecordHistogram.disableForTests();
ShadowGcmNetworkManager.clear();
} }
@Test @Test
...@@ -48,13 +79,11 @@ public class BackgroundOfflinerTaskTest { ...@@ -48,13 +79,11 @@ public class BackgroundOfflinerTaskTest {
BackgroundOfflinerTask task = BackgroundOfflinerTask task =
new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor); new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1); ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1);
DeviceConditions deviceConditions = task.processBackgroundRequests(mTaskExtras, mDeviceConditions, waiter);
new DeviceConditions(false, 51, ConnectionType.CONNECTION_WIFI);
task.processBackgroundRequests(mTaskExtras, deviceConditions, waiter);
// Check with ShadowBackgroundBackgroundSchedulerProcessor that startProcessing got called. // Check with ShadowBackgroundBackgroundSchedulerProcessor that startProcessing got called.
assertTrue(mStubBackgroundSchedulerProcessor.getStartProcessingCalled()); assertTrue(mStubBackgroundSchedulerProcessor.getStartProcessingCalled());
assertSame(deviceConditions, mStubBackgroundSchedulerProcessor.getDeviceConditions()); assertSame(mDeviceConditions, mStubBackgroundSchedulerProcessor.getDeviceConditions());
// TODO(dougarnett): Call processor callback and verify waiter signaled. // TODO(dougarnett): Call processor callback and verify waiter signaled.
} }
...@@ -68,15 +97,45 @@ public class BackgroundOfflinerTaskTest { ...@@ -68,15 +97,45 @@ public class BackgroundOfflinerTaskTest {
assertTrue(task.startBackgroundRequests(Robolectric.application, mTaskExtras, waiter)); assertTrue(task.startBackgroundRequests(Robolectric.application, mTaskExtras, waiter));
// Check that the backup task was scheduled. // Check that the backup task was scheduled.
assertNotNull("Backup task scheduled", ShadowGcmNetworkManager.getScheduledTask()); Task gcmTask = ShadowGcmNetworkManager.getScheduledTask();
assertNotNull("Backup task scheduled", gcmTask);
assertEquals(mTriggerConditions,
TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));
// Check with ShadowBackgroundBackgroundSchedulerProcessor that startProcessing got called. // Check with ShadowBackgroundBackgroundSchedulerProcessor that startProcessing got called.
assertTrue(mStubBackgroundSchedulerProcessor.getStartProcessingCalled()); assertTrue(mStubBackgroundSchedulerProcessor.getStartProcessingCalled());
assertSame(mDeviceConditions, mStubBackgroundSchedulerProcessor.getDeviceConditions());
} }
@Test @Test
@Feature({"OfflinePages"}) @Feature({"OfflinePages"})
public void testCallback() { public void testStartBackgroundRequestsForLowBatteryLevel() {
// TODO(petewil): Implement the test DeviceConditions deviceConditionsLowBattery = new DeviceConditions(
!POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI);
when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
.thenReturn(deviceConditionsLowBattery);
BackgroundOfflinerTask task = new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
ChromeBackgroundServiceWaiter waiter = new ChromeBackgroundServiceWaiter(1);
assertNull("Nothing scheduled", ShadowGcmNetworkManager.getScheduledTask());
assertFalse(task.startBackgroundRequests(Robolectric.application, mTaskExtras, waiter));
// Check that the backup task was scheduled.
Task gcmTask = ShadowGcmNetworkManager.getScheduledTask();
assertNotNull("Backup task scheduled", gcmTask);
assertEquals(mTriggerConditions,
TaskExtrasPacker.unpackTriggerConditionsFromBundle(gcmTask.getExtras()));
// Check that startProcessing was NOT called.
assertFalse(mStubBackgroundSchedulerProcessor.getStartProcessingCalled());
// Now verify low battery level but with power connected will start processing.
DeviceConditions deviceConditionsPowerConnected = new DeviceConditions(
POWER_CONNECTED, MINIMUM_BATTERY_LEVEL - 1, ConnectionType.CONNECTION_WIFI);
when(mOfflinePageUtils.getDeviceConditionsImpl(any(Context.class)))
.thenReturn(deviceConditionsPowerConnected);
BackgroundOfflinerTask task2 =
new BackgroundOfflinerTask(mStubBackgroundSchedulerProcessor);
ChromeBackgroundServiceWaiter waiter2 = new ChromeBackgroundServiceWaiter(1);
assertTrue(task2.startBackgroundRequests(Robolectric.application, mTaskExtras, waiter2));
} }
} }
...@@ -54,6 +54,8 @@ public class BackgroundSchedulerTest { ...@@ -54,6 +54,8 @@ public class BackgroundSchedulerTest {
assertEquals(OfflinePageUtils.TASK_TAG, task.getTag()); assertEquals(OfflinePageUtils.TASK_TAG, task.getTag());
long scheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(task.getExtras()); long scheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(task.getExtras());
assertTrue(scheduledTimeMillis > 0L); assertTrue(scheduledTimeMillis > 0L);
assertEquals(
mConditions1, TaskExtrasPacker.unpackTriggerConditionsFromBundle(task.getExtras()));
} }
@Test @Test
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.offlinepages;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import android.os.Bundle;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeBackgroundService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link TaskExtrasPacker}. */
@RunWith(JUnit4.class)
public class TaskExtrasPackerTest {
@Test
@Feature({"OfflinePages"})
public void testScheduledTimeExtra() {
Bundle taskExtras = new Bundle();
long beforeMillis = System.currentTimeMillis();
TaskExtrasPacker.packTimeInBundle(taskExtras);
long afterMillis = System.currentTimeMillis();
long scheduledTimeMillis = TaskExtrasPacker.unpackTimeFromBundle(taskExtras);
assertTrue(scheduledTimeMillis >= beforeMillis);
assertTrue(scheduledTimeMillis <= afterMillis);
assertTrue(taskExtras.getBoolean(ChromeBackgroundService.HOLD_WAKELOCK, false));
}
@Test
@Feature({"OfflinePages"})
public void testTriggerConditionsExtra() {
Bundle taskExtras = new Bundle();
TriggerConditions conditions1 = new TriggerConditions(true, 25, false);
TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, conditions1);
TriggerConditions unpackedConditions1 =
TaskExtrasPacker.unpackTriggerConditionsFromBundle(taskExtras);
assertEquals(conditions1, unpackedConditions1);
assertNotSame(conditions1, unpackedConditions1);
// Now verify overwriting bundle with different values.
TriggerConditions conditions2 = new TriggerConditions(false, 50, true);
TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, conditions2);
assertEquals(conditions2, TaskExtrasPacker.unpackTriggerConditionsFromBundle(taskExtras));
}
@Test
@Feature({"OfflinePages"})
public void testTriggerConditionsExtraDefaults() {
TriggerConditions unpackedConditionsFromEmptyBundle =
TaskExtrasPacker.unpackTriggerConditionsFromBundle(new Bundle());
// Verify conservative defaults:
assertTrue(unpackedConditionsFromEmptyBundle.requirePowerConnected());
assertEquals(100, unpackedConditionsFromEmptyBundle.getMinimumBatteryPercentage());
assertTrue(unpackedConditionsFromEmptyBundle.requireUnmeteredNetwork());
}
}
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