org.chromium.chrome.browser.ChromeBackgroundService Java Examples

The following examples show how to use org.chromium.chrome.browser.ChromeBackgroundService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BackgroundScheduler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * For the given Triggering conditions, start a new GCM Network Manager request allowed
 * to run after {@code delayStartSecs} seconds.
 */
private static void schedule(Context context, TriggerConditions triggerConditions,
        long delayStartSecs, boolean overwrite) {
    // Get the GCM Network Scheduler.
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);

    Bundle taskExtras = new Bundle();
    TaskExtrasPacker.packTimeInBundle(taskExtras);
    TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerConditions);

    Task task = new OneoffTask.Builder()
                        .setService(ChromeBackgroundService.class)
                        .setExecutionWindow(delayStartSecs, ONE_WEEK_IN_SECONDS)
                        .setTag(OfflinePageUtils.TASK_TAG)
                        .setUpdateCurrent(overwrite)
                        .setRequiredNetwork(triggerConditions.requireUnmeteredNetwork()
                                        ? Task.NETWORK_STATE_UNMETERED
                                        : Task.NETWORK_STATE_CONNECTED)
                        .setRequiresCharging(triggerConditions.requirePowerConnected())
                        .setExtras(taskExtras)
                        .build();

    gcmNetworkManager.schedule(task);
}
 
Example #2
Source File: PrecacheController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Schedules a one-off task to finish precaching the resources that were
 * still outstanding when the last task was interrupted. Interrupting such
 * a one-off task will result in scheduling a new one.
 * @param context The application context.
 */
private static void schedulePrecacheCompletionTask(Context context) {
    Log.v(TAG, "scheduling a precache completion task");
    OneoffTask task = new OneoffTask.Builder()
                              .setExecutionWindow(COMPLETION_TASK_MIN_DELAY_SECONDS,
                                      COMPLETION_TASK_MAX_DELAY_SECONDS)
                              .setPersisted(true)
                              .setRequiredNetwork(OneoffTask.NETWORK_STATE_UNMETERED)
                              .setRequiresCharging(ChromeVersionInfo.isStableBuild())
                              .setService(ChromeBackgroundService.class)
                              .setTag(CONTINUATION_TASK_TAG)
                              .setUpdateCurrent(true)
                              .build();
    if (sTaskScheduler.scheduleTask(context, task)) {
        PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE);
    } else {
        PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE_FAIL);
    }
}
 
Example #3
Source File: DownloadResumptionScheduler.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Schedules a future task to start download resumption.
 * @param allowMeteredConnection Whether download resumption can start if connection is metered.
 */
public void schedule(boolean allowMeteredConnection) {
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext);
    int networkType = allowMeteredConnection
            ? Task.NETWORK_STATE_CONNECTED : Task.NETWORK_STATE_UNMETERED;
    OneoffTask task = new OneoffTask.Builder()
            .setService(ChromeBackgroundService.class)
            .setExecutionWindow(0, ONE_DAY_IN_SECONDS)
            .setTag(TASK_TAG)
            .setUpdateCurrent(true)
            .setRequiredNetwork(networkType)
            .setRequiresCharging(false)
            .build();
    try {
        gcmNetworkManager.schedule(task);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "unable to schedule resumption task.", e);
    }
}
 
Example #4
Source File: SnippetsLauncher.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static PeriodicTask buildFetchTask(
        String tag, long periodSeconds, int requiredNetwork) {
    // Add a bit of "flex" around the target period. This achieves the following:
    // - It makes sure the task doesn't run (significantly) before its initial period has
    //   elapsed. In practice, the scheduler seems to behave like that anyway, but it doesn't
    //   guarantee that, so we shouldn't rely on it.
    // - It gives the scheduler a bit of room to optimize for battery life.
    long effectivePeriodSeconds = (long) (periodSeconds * (1.0 + FLEX_FACTOR));
    long flexSeconds = (long) (periodSeconds * (2.0 * FLEX_FACTOR));
    return new PeriodicTask.Builder()
            .setService(ChromeBackgroundService.class)
            .setTag(tag)
            .setPeriod(effectivePeriodSeconds)
            .setFlex(flexSeconds)
            .setRequiredNetwork(requiredNetwork)
            .setPersisted(true)
            .setUpdateCurrent(true)
            .build();
}
 
Example #5
Source File: BackgroundScheduler.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * For the given Triggering conditions, start a new GCM Network Manager request allowed
 * to run after {@code delayStartSecs} seconds.
 */
private static void schedule(Context context, TriggerConditions triggerConditions,
        long delayStartSecs, boolean overwrite) {
    // Get the GCM Network Scheduler.
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(context);

    Bundle taskExtras = new Bundle();
    TaskExtrasPacker.packTimeInBundle(taskExtras);
    TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerConditions);

    Task task = new OneoffTask.Builder()
                        .setService(ChromeBackgroundService.class)
                        .setExecutionWindow(delayStartSecs, ONE_WEEK_IN_SECONDS)
                        .setTag(OfflinePageUtils.TASK_TAG)
                        .setUpdateCurrent(overwrite)
                        .setRequiredNetwork(triggerConditions.requireUnmeteredNetwork()
                                        ? Task.NETWORK_STATE_UNMETERED
                                        : Task.NETWORK_STATE_CONNECTED)
                        .setRequiresCharging(triggerConditions.requirePowerConnected())
                        .setExtras(taskExtras)
                        .build();

    gcmNetworkManager.schedule(task);
}
 
Example #6
Source File: DownloadResumptionScheduler.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Schedules a future task to start download resumption.
 * @param allowMeteredConnection Whether download resumption can start if connection is metered.
 */
public void schedule(boolean allowMeteredConnection) {
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext);
    int networkType = allowMeteredConnection
            ? Task.NETWORK_STATE_CONNECTED : Task.NETWORK_STATE_UNMETERED;
    OneoffTask task = new OneoffTask.Builder()
                              .setService(ChromeBackgroundService.class)
                              .setExecutionWindow(0, ONE_DAY_IN_SECONDS)
                              .setTag(TASK_TAG)
                              .setUpdateCurrent(true)
                              .setRequiredNetwork(networkType)
                              .setRequiresCharging(false)
                              .build();
    try {
        gcmNetworkManager.schedule(task);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "unable to schedule resumption task.", e);
    }
}
 
Example #7
Source File: PrecacheController.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Schedules a one-off task to finish precaching the resources that were
 * still outstanding when the last task was interrupted. Interrupting such
 * a one-off task will result in scheduling a new one.
 * @param context The application context.
 */
private static void schedulePrecacheCompletionTask(Context context) {
    Log.v(TAG, "scheduling a precache completion task");
    OneoffTask task = new OneoffTask.Builder()
            .setExecutionWindow(COMPLETION_TASK_MIN_DELAY_SECONDS,
                    COMPLETION_TASK_MAX_DELAY_SECONDS)
            .setPersisted(true)
            .setRequiredNetwork(OneoffTask.NETWORK_STATE_UNMETERED)
            .setRequiresCharging(true)
            .setService(ChromeBackgroundService.class)
            .setTag(CONTINUATION_TASK_TAG)
            .setUpdateCurrent(true)
            .build();
    if (sTaskScheduler.scheduleTask(context, task)) {
        PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE);
    } else {
        PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE_FAIL);
    }
}
 
Example #8
Source File: PrecacheController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Schedules a one-off task to finish precaching the resources that were
 * still outstanding when the last task was interrupted. Interrupting such
 * a one-off task will result in scheduling a new one.
 * @param context The application context.
 */
private static void schedulePrecacheCompletionTask(Context context) {
    Log.v(TAG, "scheduling a precache completion task");
    OneoffTask task = new OneoffTask.Builder()
                              .setExecutionWindow(COMPLETION_TASK_MIN_DELAY_SECONDS,
                                      COMPLETION_TASK_MAX_DELAY_SECONDS)
                              .setPersisted(true)
                              .setRequiredNetwork(OneoffTask.NETWORK_STATE_UNMETERED)
                              .setRequiresCharging(ChromeVersionInfo.isStableBuild())
                              .setService(ChromeBackgroundService.class)
                              .setTag(CONTINUATION_TASK_TAG)
                              .setUpdateCurrent(true)
                              .build();
    if (sTaskScheduler.scheduleTask(context, task)) {
        PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE);
    } else {
        PrecacheUMA.record(PrecacheUMA.Event.ONEOFF_TASK_SCHEDULE_FAIL);
    }
}
 
Example #9
Source File: SnippetsLauncher.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static PeriodicTask buildFetchTask(
        String tag, long periodSeconds, int requiredNetwork) {
    // Add a bit of "flex" around the target period. This achieves the following:
    // - It makes sure the task doesn't run (significantly) before its initial period has
    //   elapsed. In practice, the scheduler seems to behave like that anyway, but it doesn't
    //   guarantee that, so we shouldn't rely on it.
    // - It gives the scheduler a bit of room to optimize for battery life.
    long effectivePeriodSeconds = (long) (periodSeconds * (1.0 + FLEX_FACTOR));
    long flexSeconds = (long) (periodSeconds * (2.0 * FLEX_FACTOR));
    return new PeriodicTask.Builder()
            .setService(ChromeBackgroundService.class)
            .setTag(tag)
            .setPeriod(effectivePeriodSeconds)
            .setFlex(flexSeconds)
            .setRequiredNetwork(requiredNetwork)
            .setPersisted(true)
            .setUpdateCurrent(true)
            .build();
}
 
Example #10
Source File: DownloadResumptionScheduler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Schedules a future task to start download resumption.
 * @param allowMeteredConnection Whether download resumption can start if connection is metered.
 */
public void schedule(boolean allowMeteredConnection) {
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext);
    int networkType = allowMeteredConnection
            ? Task.NETWORK_STATE_CONNECTED : Task.NETWORK_STATE_UNMETERED;
    OneoffTask task = new OneoffTask.Builder()
            .setService(ChromeBackgroundService.class)
            .setExecutionWindow(0, ONE_DAY_IN_SECONDS)
            .setTag(TASK_TAG)
            .setUpdateCurrent(true)
            .setRequiredNetwork(networkType)
            .setRequiresCharging(false)
            .build();
    try {
        gcmNetworkManager.schedule(task);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "unable to schedule resumption task.", e);
    }
}
 
Example #11
Source File: PrecacheController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Schedules a periodic task to precache resources.
 * @param context The application context.
 * @return false if the task cannot be scheduled.
 */
private static boolean schedulePeriodicPrecacheTask(Context context) {
    PeriodicTask task = new PeriodicTask.Builder()
                                .setPeriod(WAIT_UNTIL_NEXT_PRECACHE_SECONDS)
                                .setPersisted(true)
                                .setRequiredNetwork(PeriodicTask.NETWORK_STATE_UNMETERED)
                                .setRequiresCharging(ChromeVersionInfo.isStableBuild())
                                .setService(ChromeBackgroundService.class)
                                .setTag(PERIODIC_TASK_TAG)
                                .build();
    return sTaskScheduler.scheduleTask(context, task);
}
 
Example #12
Source File: PrecacheTaskScheduler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
boolean cancelTask(Context context, String tag) {
    if (!canScheduleTasks(context)) {
        return false;
    }
    try {
        GcmNetworkManager.getInstance(context).cancelTask(tag, ChromeBackgroundService.class);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}
 
Example #13
Source File: BackgroundGcmScheduler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void scheduleImpl(TriggerConditions triggerConditions, long delayStartSeconds,
        long executionDeadlineSeconds, boolean overwrite) {
    GcmNetworkManager gcmNetworkManager = getGcmNetworkManager();
    if (gcmNetworkManager == null) return;

    Bundle taskExtras = new Bundle();
    TaskExtrasPacker.packTimeInBundle(taskExtras);
    TaskExtrasPacker.packHoldWakelock(taskExtras);
    TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerConditions);

    Task task = new OneoffTask.Builder()
                        .setService(ChromeBackgroundService.class)
                        .setExecutionWindow(delayStartSeconds, executionDeadlineSeconds)
                        .setTag(OfflinePageUtils.TASK_TAG)
                        .setUpdateCurrent(overwrite)
                        .setRequiredNetwork(triggerConditions.requireUnmeteredNetwork()
                                        ? Task.NETWORK_STATE_UNMETERED
                                        : Task.NETWORK_STATE_CONNECTED)
                        .setRequiresCharging(triggerConditions.requirePowerConnected())
                        .setPersisted(true)
                        .setExtras(taskExtras)
                        .build();

    // Schedule a task using GCM network manager.
    gcmNetworkManager.schedule(task);
}
 
Example #14
Source File: SnippetsLauncher.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private boolean schedule(long periodWifiSeconds, long periodFallbackSeconds) {
    if (!mGCMEnabled) return false;
    Log.i(TAG, "Scheduling: " + periodWifiSeconds + " " + periodFallbackSeconds);

    boolean isScheduled = periodWifiSeconds != 0 || periodFallbackSeconds != 0;
    ContextUtils.getAppSharedPreferences()
            .edit()
            .putBoolean(PREF_IS_SCHEDULED, isScheduled)
            .apply();

    // Google Play Services may not be up to date, if the application was not installed through
    // the Play Store. In this case, scheduling the task will fail silently.
    try {
        mScheduler.cancelTask(OBSOLETE_TASK_TAG_WIFI_CHARGING, ChromeBackgroundService.class);
        scheduleOrCancelFetchTask(
                TASK_TAG_WIFI, periodWifiSeconds, Task.NETWORK_STATE_UNMETERED);
        scheduleOrCancelFetchTask(
                TASK_TAG_FALLBACK, periodFallbackSeconds, Task.NETWORK_STATE_CONNECTED);
        mScheduler.cancelTask(OBSOLETE_TASK_TAG_RESCHEDULE, ChromeBackgroundService.class);
    } catch (IllegalArgumentException e) {
        // Disable GCM for the remainder of this session.
        mGCMEnabled = false;

        ContextUtils.getAppSharedPreferences().edit().remove(PREF_IS_SCHEDULED).apply();
        // Return false so that the failure will be logged.
        return false;
    }
    return true;
}
 
Example #15
Source File: SnippetsLauncher.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void scheduleOrCancelFetchTask(String taskTag, long period, int requiredNetwork) {
    if (period > 0) {
        mScheduler.schedule(buildFetchTask(taskTag, period, requiredNetwork));
    } else {
        mScheduler.cancelTask(taskTag, ChromeBackgroundService.class);
    }
}
 
Example #16
Source File: SnippetsLauncher.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void scheduleOrCancelFetchTask(String taskTag, long period, int requiredNetwork) {
    if (period > 0) {
        mScheduler.schedule(buildFetchTask(taskTag, period, requiredNetwork));
    } else {
        mScheduler.cancelTask(taskTag, ChromeBackgroundService.class);
    }
}
 
Example #17
Source File: SnippetsLauncher.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private boolean schedule(long periodWifiSeconds, long periodFallbackSeconds) {
    if (!mGCMEnabled) return false;
    Log.i(TAG, "Scheduling: " + periodWifiSeconds + " " + periodFallbackSeconds);

    boolean isScheduled = periodWifiSeconds != 0 || periodFallbackSeconds != 0;
    ContextUtils.getAppSharedPreferences()
            .edit()
            .putBoolean(PREF_IS_SCHEDULED, isScheduled)
            .apply();

    // Google Play Services may not be up to date, if the application was not installed through
    // the Play Store. In this case, scheduling the task will fail silently.
    try {
        mScheduler.cancelTask(OBSOLETE_TASK_TAG_WIFI_CHARGING, ChromeBackgroundService.class);
        scheduleOrCancelFetchTask(
                TASK_TAG_WIFI, periodWifiSeconds, Task.NETWORK_STATE_UNMETERED);
        scheduleOrCancelFetchTask(
                TASK_TAG_FALLBACK, periodFallbackSeconds, Task.NETWORK_STATE_CONNECTED);
        mScheduler.cancelTask(OBSOLETE_TASK_TAG_RESCHEDULE, ChromeBackgroundService.class);
    } catch (IllegalArgumentException e) {
        // Disable GCM for the remainder of this session.
        mGCMEnabled = false;

        ContextUtils.getAppSharedPreferences().edit().remove(PREF_IS_SCHEDULED).apply();
        // Return false so that the failure will be logged.
        return false;
    }
    return true;
}
 
Example #18
Source File: PrecacheController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Schedules a periodic task to precache resources.
 * @param context The application context.
 * @return false if the task cannot be scheduled.
 */
private static boolean schedulePeriodicPrecacheTask(Context context) {
    PeriodicTask task = new PeriodicTask.Builder()
                                .setPeriod(WAIT_UNTIL_NEXT_PRECACHE_SECONDS)
                                .setPersisted(true)
                                .setRequiredNetwork(PeriodicTask.NETWORK_STATE_UNMETERED)
                                .setRequiresCharging(ChromeVersionInfo.isStableBuild())
                                .setService(ChromeBackgroundService.class)
                                .setTag(PERIODIC_TASK_TAG)
                                .build();
    return sTaskScheduler.scheduleTask(context, task);
}
 
Example #19
Source File: PrecacheTaskScheduler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
boolean cancelTask(Context context, String tag) {
    if (!canScheduleTasks(context)) {
        return false;
    }
    try {
        GcmNetworkManager.getInstance(context).cancelTask(tag, ChromeBackgroundService.class);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}
 
Example #20
Source File: SnippetsLauncher.java    From delion with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private boolean schedule(long periodWifiChargingSeconds, long periodWifiSeconds,
        long periodFallbackSeconds, long rescheduleTime) {
    if (!mGCMEnabled) return false;
    Log.d(TAG, "Scheduling: " + periodWifiChargingSeconds + " " + periodWifiSeconds + " "
                    + periodFallbackSeconds);
    // Google Play Services may not be up to date, if the application was not installed through
    // the Play Store. In this case, scheduling the task will fail silently.
    try {
        scheduleOrCancelFetchTask(TASK_TAG_WIFI_CHARGING, periodWifiChargingSeconds,
                Task.NETWORK_STATE_UNMETERED, true);
        scheduleOrCancelFetchTask(
                TASK_TAG_WIFI, periodWifiSeconds, Task.NETWORK_STATE_UNMETERED, false);
        scheduleOrCancelFetchTask(
                TASK_TAG_FALLBACK, periodFallbackSeconds, Task.NETWORK_STATE_CONNECTED, false);
        if (rescheduleTime > 0) {
            mScheduler.schedule(buildRescheduleTask(new Date(rescheduleTime)));
        } else {
            mScheduler.cancelTask(TASK_TAG_RESCHEDULE, ChromeBackgroundService.class);
        }
    } catch (IllegalArgumentException e) {
        // Disable GCM for the remainder of this session.
        mGCMEnabled = false;
        // Return false so that the failure will be logged.
        return false;
    }
    return true;
}
 
Example #21
Source File: SnippetsLauncher.java    From delion with Apache License 2.0 5 votes vote down vote up
private void scheduleOrCancelFetchTask(
        String taskTag, long period, int requiredNetwork, boolean requiresCharging) {
    if (period > 0) {
        mScheduler.schedule(buildFetchTask(taskTag, period, requiredNetwork, requiresCharging));
    } else {
        mScheduler.cancelTask(taskTag, ChromeBackgroundService.class);
    }
}
 
Example #22
Source File: SnippetsLauncher.java    From delion with Apache License 2.0 5 votes vote down vote up
private static OneoffTask buildRescheduleTask(Date date) {
    Date now = new Date();
    // Convert from milliseconds to seconds, rounding up.
    long delaySeconds = (date.getTime() - now.getTime() + 999) / 1000;
    final long intervalSeconds = 15 * 60;
    return new OneoffTask.Builder()
            .setService(ChromeBackgroundService.class)
            .setTag(TASK_TAG_RESCHEDULE)
            .setExecutionWindow(delaySeconds, delaySeconds + intervalSeconds)
            .setRequiredNetwork(Task.NETWORK_STATE_ANY)
            .setRequiresCharging(false)
            .setPersisted(true)
            .setUpdateCurrent(true)
            .build();
}
 
Example #23
Source File: SnippetsLauncher.java    From delion with Apache License 2.0 5 votes vote down vote up
private static PeriodicTask buildFetchTask(
        String tag, long periodSeconds, int requiredNetwork, boolean requiresCharging) {
    return new PeriodicTask.Builder()
            .setService(ChromeBackgroundService.class)
            .setTag(tag)
            .setPeriod(periodSeconds)
            .setRequiredNetwork(requiredNetwork)
            .setRequiresCharging(requiresCharging)
            .setPersisted(true)
            .setUpdateCurrent(true)
            .build();
}
 
Example #24
Source File: PrecacheController.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Schedules a periodic task to precache resources.
 * @param context The application context.
 * @return false if the task cannot be scheduled.
 */
private static boolean schedulePeriodicPrecacheTask(Context context) {
    PeriodicTask task = new PeriodicTask.Builder()
            .setPeriod(WAIT_UNTIL_NEXT_PRECACHE_SECONDS)
            .setPersisted(true)
            .setRequiredNetwork(PeriodicTask.NETWORK_STATE_UNMETERED)
            .setRequiresCharging(true)
            .setService(ChromeBackgroundService.class)
            .setTag(PERIODIC_TASK_TAG)
            .build();
    return sTaskScheduler.scheduleTask(context, task);
}
 
Example #25
Source File: PrecacheTaskScheduler.java    From delion with Apache License 2.0 5 votes vote down vote up
boolean cancelTask(Context context, String tag) {
    if (!canScheduleTasks(context)) {
        return false;
    }
    try {
        GcmNetworkManager.getInstance(context).cancelTask(tag, ChromeBackgroundService.class);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}
 
Example #26
Source File: DownloadResumptionScheduler.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Cancels a download resumption task if it is scheduled.
 */
public void cancelTask() {
    GcmNetworkManager gcmNetworkManager = GcmNetworkManager.getInstance(mContext);
    gcmNetworkManager.cancelTask(TASK_TAG, ChromeBackgroundService.class);
}
 
Example #27
Source File: TaskExtrasPacker.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/** Puts current time into the input bundle. */
public static void packTimeInBundle(Bundle bundle) {
    bundle.putLong(SCHEDULED_TIME_TAG, System.currentTimeMillis());
    bundle.putBoolean(ChromeBackgroundService.HOLD_WAKELOCK, true);
}
 
Example #28
Source File: BackgroundScheduler.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: TaskExtrasPacker.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Puts requirement to hold a wakelock in the bundle. */
public static void packHoldWakelock(Bundle bundle) {
    bundle.putBoolean(ChromeBackgroundService.HOLD_WAKELOCK, true);
}
 
Example #30
Source File: BackgroundGcmScheduler.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void cancel() {
    GcmNetworkManager gcmNetworkManager = getGcmNetworkManager();
    if (gcmNetworkManager == null) return;
    gcmNetworkManager.cancelTask(OfflinePageUtils.TASK_TAG, ChromeBackgroundService.class);
}