OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.offlinepages; | 5 package org.chromium.chrome.browser.offlinepages; |
6 | 6 |
7 import android.annotation.TargetApi; | |
8 import android.os.Build; | |
7 import android.os.Bundle; | 9 import android.os.Bundle; |
10 import android.os.PersistableBundle; | |
8 | 11 |
9 import org.chromium.chrome.browser.ChromeBackgroundService; | 12 import org.chromium.chrome.browser.ChromeBackgroundService; |
10 | 13 |
11 /** | 14 /** |
12 * Class to put our custom task information into the task bundle. | 15 * Class to put our custom task information into the task bundle. |
13 */ | 16 */ |
14 public class TaskExtrasPacker { | 17 public class TaskExtrasPacker { |
15 /** Bundle key for the timestamp in milliseconds when the request started. * / | 18 /** Bundle key for the timestamp in milliseconds when the request started. * / |
16 public static final String SCHEDULED_TIME_TAG = "ScheduleTime"; | 19 public static final String SCHEDULED_TIME_TAG = "ScheduleTime"; |
17 | 20 |
18 // Trigger condition tags. | 21 // Trigger condition tags. |
19 private static final String POWER_CONNECTED_TAG = "PowerConnected"; | 22 private static final String POWER_CONNECTED_TAG = "PowerConnected"; |
20 private static final String BATTERY_PERCENTAGE_TAG = "BatteryPercentage"; | 23 private static final String BATTERY_PERCENTAGE_TAG = "BatteryPercentage"; |
21 private static final String UNMETERED_NETWORK_TAG = "UnmeteredNetwork"; | 24 private static final String UNMETERED_NETWORK_TAG = "UnmeteredNetwork"; |
22 | 25 |
26 /** Puts requirement to hold a wakelock in the bundle. */ | |
27 public static void packHoldWakelock(Bundle bundle) { | |
28 bundle.putBoolean(ChromeBackgroundService.HOLD_WAKELOCK, true); | |
29 } | |
30 | |
23 /** Puts current time into the input bundle. */ | 31 /** Puts current time into the input bundle. */ |
24 public static void packTimeInBundle(Bundle bundle) { | 32 public static void packTimeInBundle(Bundle bundle) { |
25 bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis()); | 33 bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis()); |
26 bundle.putBoolean(ChromeBackgroundService.HOLD_WAKELOCK, true); | 34 } |
35 | |
36 /** Puts current time into the input bundle. */ | |
37 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) | |
Pete Williamson
2017/02/10 02:10:43
On the day this change lands, we might have some t
fgorski
2017/02/10 19:26:00
Corresponding methods for Bundle still work. GCMNe
| |
38 public static void packTimeInBundle(PersistableBundle bundle) { | |
39 bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis()); | |
27 } | 40 } |
28 | 41 |
29 /** Extracts the time we put into the bundle. */ | 42 /** Extracts the time we put into the bundle. */ |
30 public static long unpackTimeFromBundle(Bundle bundle) { | 43 public static long unpackTimeFromBundle(Bundle bundle) { |
31 return bundle.getLong(SCHEDULED_TIME_TAG); | 44 return bundle.getLong(SCHEDULED_TIME_TAG); |
32 } | 45 } |
33 | 46 |
47 /** Extracts the time we put into the bundle. */ | |
48 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) | |
49 public static long unpackTimeFromBundle(PersistableBundle bundle) { | |
50 return bundle.getLong(SCHEDULED_TIME_TAG); | |
51 } | |
52 | |
34 /** Puts trigger conditions into the input bundle. */ | 53 /** Puts trigger conditions into the input bundle. */ |
35 public static void packTriggerConditionsInBundle(Bundle bundle, TriggerCondi tions conditions) { | 54 public static void packTriggerConditionsInBundle(Bundle bundle, TriggerCondi tions conditions) { |
36 bundle.putBoolean(POWER_CONNECTED_TAG, conditions.requirePowerConnected( )); | 55 bundle.putBoolean(POWER_CONNECTED_TAG, conditions.requirePowerConnected( )); |
37 bundle.putInt(BATTERY_PERCENTAGE_TAG, conditions.getMinimumBatteryPercen tage()); | 56 bundle.putInt(BATTERY_PERCENTAGE_TAG, conditions.getMinimumBatteryPercen tage()); |
38 bundle.putBoolean(UNMETERED_NETWORK_TAG, conditions.requireUnmeteredNetw ork()); | 57 bundle.putBoolean(UNMETERED_NETWORK_TAG, conditions.requireUnmeteredNetw ork()); |
39 } | 58 } |
40 | 59 |
60 /** Puts trigger conditions into the input bundle. */ | |
61 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) | |
62 public static void packTriggerConditionsInBundle( | |
63 PersistableBundle bundle, TriggerConditions conditions) { | |
64 bundle.putBoolean(POWER_CONNECTED_TAG, conditions.requirePowerConnected( )); | |
65 bundle.putInt(BATTERY_PERCENTAGE_TAG, conditions.getMinimumBatteryPercen tage()); | |
66 bundle.putBoolean(UNMETERED_NETWORK_TAG, conditions.requireUnmeteredNetw ork()); | |
67 } | |
68 | |
41 /** Extracts the trigger conditions we put into the bundle. */ | 69 /** Extracts the trigger conditions we put into the bundle. */ |
42 public static TriggerConditions unpackTriggerConditionsFromBundle(Bundle bun dle) { | 70 public static TriggerConditions unpackTriggerConditionsFromBundle(Bundle bun dle) { |
43 boolean requirePowerConnected = bundle.getBoolean(POWER_CONNECTED_TAG, t rue); | 71 boolean requirePowerConnected = bundle.getBoolean(POWER_CONNECTED_TAG, t rue); |
44 int minimumBatteryPercentage = bundle.getInt(BATTERY_PERCENTAGE_TAG, 100 ); | 72 int minimumBatteryPercentage = bundle.getInt(BATTERY_PERCENTAGE_TAG, 100 ); |
45 boolean requireUnmeteredNetwork = bundle.getBoolean(UNMETERED_NETWORK_TA G, true); | 73 boolean requireUnmeteredNetwork = bundle.getBoolean(UNMETERED_NETWORK_TA G, true); |
46 return new TriggerConditions( | 74 return new TriggerConditions( |
47 requirePowerConnected, minimumBatteryPercentage, requireUnmetere dNetwork); | 75 requirePowerConnected, minimumBatteryPercentage, requireUnmetere dNetwork); |
48 } | 76 } |
77 | |
78 /** Extracts the trigger conditions we put into the bundle. */ | |
79 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) | |
80 public static TriggerConditions unpackTriggerConditionsFromBundle(Persistabl eBundle bundle) { | |
81 boolean requirePowerConnected = bundle.getBoolean(POWER_CONNECTED_TAG, t rue); | |
82 int minimumBatteryPercentage = bundle.getInt(BATTERY_PERCENTAGE_TAG, 100 ); | |
83 boolean requireUnmeteredNetwork = bundle.getBoolean(UNMETERED_NETWORK_TA G, true); | |
84 return new TriggerConditions( | |
85 requirePowerConnected, minimumBatteryPercentage, requireUnmetere dNetwork); | |
86 } | |
49 } | 87 } |
OLD | NEW |