com.google.android.gms.gcm.Task Java Examples

The following examples show how to use com.google.android.gms.gcm.Task. 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: MainActivity.java    From android-gcmnetworkmanager with Apache License 2.0 6 votes vote down vote up
public void startWifiTask() {
    Log.d(TAG, "startWiFiTask");

    // Disable WiFi so the task does not start immediately
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    wifi.setWifiEnabled(false);

    // [START start_one_off_task]
    OneoffTask task = new OneoffTask.Builder()
            .setService(MyTaskService.class)
            .setTag(TASK_TAG_WIFI)
            .setExecutionWindow(0L, 3600L)
            .setRequiredNetwork(Task.NETWORK_STATE_UNMETERED)
            .build();

    mGcmNetworkManager.schedule(task);
    // [END start_one_off_task]
}
 
Example #2
Source File: NetworkGCMTaskService.java    From q-municate-android with Apache License 2.0 6 votes vote down vote up
public static void scheduleOneOff(Context context, String what) {
        Bundle extras = new Bundle();
        extras.putString(EXTRA_KEY, what);
        OneoffTask task = new OneoffTask.Builder()
                .setService(NetworkGCMTaskService.class)
                .setTag(TASK_NETWORK_TAG)
                .setExtras(extras)
//                Execution window: The time period in which the task will execute.
//                First param is the lower bound and the second is the upper bound (both are in seconds).
                .setExecutionWindow(0L, 30L)
                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
                .setUpdateCurrent(true)
                .build();

        GcmNetworkManager.getInstance(context).schedule(task);
    }
 
Example #3
Source File: BackgroundTaskSchedulerGcmNetworkManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean schedule(Context context, @NonNull TaskInfo taskInfo) {
    ThreadUtils.assertOnUiThread();
    if (!BackgroundTaskScheduler.hasParameterlessPublicConstructor(
                taskInfo.getBackgroundTaskClass())) {
        Log.e(TAG,
                "BackgroundTask " + taskInfo.getBackgroundTaskClass()
                        + " has no parameterless public constructor.");
        return false;
    }

    GcmNetworkManager gcmNetworkManager = getGcmNetworkManager(context);
    if (gcmNetworkManager == null) {
        Log.e(TAG, "GcmNetworkManager is not available.");
        return false;
    }

    Task task = createTaskFromTaskInfo(taskInfo);

    gcmNetworkManager.schedule(task);
    return true;
}
 
Example #4
Source File: BackgroundTaskSchedulerGcmNetworkManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static Task createTaskFromTaskInfo(@NonNull TaskInfo taskInfo) {
    Bundle taskExtras = new Bundle();
    taskExtras.putString(
            BACKGROUND_TASK_CLASS_KEY, taskInfo.getBackgroundTaskClass().getName());
    taskExtras.putBundle(BACKGROUND_TASK_EXTRAS_KEY, taskInfo.getExtras());

    Task.Builder builder;
    if (taskInfo.isPeriodic()) {
        builder = getPeriodicTaskBuilder(taskInfo.getPeriodicInfo());
    } else {
        builder = getOneOffTaskBuilder(taskInfo.getOneOffInfo());
    }

    builder.setExtras(taskExtras)
            .setPersisted(taskInfo.isPersisted())
            .setRequiredNetwork(getGcmNetworkManagerNetworkTypeFromTypeFromTaskNetworkType(
                    taskInfo.getRequiredNetworkType()))
            .setRequiresCharging(taskInfo.requiresCharging())
            .setService(BackgroundTaskGcmTaskService.class)
            .setTag(taskIdToTaskTag(taskInfo.getTaskId()))
            .setUpdateCurrent(taskInfo.shouldUpdateCurrent());

    return builder.build();
}
 
Example #5
Source File: BackgroundSyncLauncher.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static boolean scheduleLaunchTask(GcmNetworkManager scheduler, long minDelayMs) {
    // 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.
    final long minDelaySecs = minDelayMs / 1000;
    OneoffTask oneoff = new OneoffTask.Builder()
                                .setService(ChromeBackgroundService.class)
                                .setTag(TASK_TAG)
                                // We have to set a non-zero execution window here
                                .setExecutionWindow(minDelaySecs, minDelaySecs + 1)
                                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
                                .setPersisted(true)
                                .setUpdateCurrent(true)
                                .build();
    try {
        scheduler.schedule(oneoff);
    } catch (IllegalArgumentException e) {
        // Disable GCM for the remainder of this session.
        setGCMEnabled(false);
        // Return false so that the failure will be logged.
        return false;
    }
    return true;
}
 
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: 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 #8
Source File: BackgroundSyncLauncher.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static boolean scheduleLaunchTask(
        Context context, GcmNetworkManager scheduler, long minDelayMs) {
    // 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.
    final long minDelaySecs = minDelayMs / 1000;
    OneoffTask oneoff = new OneoffTask.Builder()
                                .setService(ChromeBackgroundService.class)
                                .setTag(TASK_TAG)
                                // We have to set a non-zero execution window here
                                .setExecutionWindow(minDelaySecs, minDelaySecs + 1)
                                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
                                .setPersisted(true)
                                .setUpdateCurrent(true)
                                .build();
    try {
        scheduler.schedule(oneoff);
    } catch (IllegalArgumentException e) {
        // Disable GCM for the remainder of this session.
        setGCMEnabled(false);
        // Return false so that the failure will be logged.
        return false;
    }
    return true;
}
 
Example #9
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 #10
Source File: BackgroundSyncLauncher.java    From delion with Apache License 2.0 6 votes vote down vote up
private static boolean scheduleLaunchTask(
        Context context, GcmNetworkManager scheduler, long minDelayMs) {
    // 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.
    final long minDelaySecs = minDelayMs / 1000;
    OneoffTask oneoff = new OneoffTask.Builder()
                                .setService(ChromeBackgroundService.class)
                                .setTag(TASK_TAG)
                                // We have to set a non-zero execution window here
                                .setExecutionWindow(minDelaySecs, minDelaySecs + 1)
                                .setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
                                .setPersisted(true)
                                .setUpdateCurrent(true)
                                .build();
    try {
        scheduler.schedule(oneoff);
    } catch (IllegalArgumentException e) {
        // Disable GCM for the remainder of this session.
        setGCMEnabled(false);
        // Return false so that the failure will be logged.
        return false;
    }
    return true;
}
 
Example #11
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 #12
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 #13
Source File: RegistrationIntentService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void sendRegistrationToServer(String token) {
    try {
        Log.d(TAG, "Scheduling tasks");
        PeriodicTask task = new PeriodicTask.Builder()
                .setService(TaskService.class)
                .setTag(GcmActivity.TASK_TAG_UNMETERED)
                .setRequiredNetwork(Task.NETWORK_STATE_UNMETERED)
                .setPeriod(7200L)
                .build();

        GcmNetworkManager.getInstance(this).cancelAllTasks(TaskService.class);
        GcmNetworkManager.getInstance(this).schedule(task);
        PlusSyncService.startSyncService(getApplicationContext(), "RegistrationToServer");
        GcmActivity.queueCheckOld(getApplicationContext());
    } catch (Exception e) {
        Log.e(TAG, "Exception in sendRegistration: " + e.toString());
    }
}
 
Example #14
Source File: RegistrationIntentService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void sendRegistrationToServer(String token) {
    try {
        Log.d(TAG, "Scheduling tasks");
        PeriodicTask task = new PeriodicTask.Builder()
                .setService(TaskService.class)
                .setTag(GcmActivity.TASK_TAG_UNMETERED)
                .setRequiredNetwork(Task.NETWORK_STATE_UNMETERED)
                .setPeriod(7200L)
                .build();

        GcmNetworkManager.getInstance(this).cancelAllTasks(TaskService.class);
        GcmNetworkManager.getInstance(this).schedule(task);
        PlusSyncService.startSyncService(getApplicationContext(), "RegistrationToServer");
        GcmActivity.queueCheckOld(getApplicationContext());
    } catch (Exception e) {
        Log.e(TAG, "Exception in sendRegistration: " + e.toString());
    }
}
 
Example #15
Source File: JobProxyGcm.java    From android-job with Apache License 2.0 5 votes vote down vote up
private void scheduleTask(Task task) {
    try {
        mGcmNetworkManager.schedule(task);
    } catch (IllegalArgumentException e) {
        if (e.getMessage() != null && e.getMessage().startsWith("The GcmTaskService class you provided")) {
            throw new JobProxyIllegalStateException(e);
        } else {
            throw e;
        }
    }
}
 
Example #16
Source File: JobProxyGcm.java    From android-job with Apache License 2.0 5 votes vote down vote up
protected <T extends Task.Builder> T prepareBuilder(T builder, JobRequest request) {
    builder.setTag(createTag(request))
            .setService(PlatformGcmService.class)
            .setUpdateCurrent(true)
            .setRequiredNetwork(convertNetworkType(request.requiredNetworkType()))
            .setPersisted(JobUtil.hasBootPermission(mContext))
            .setRequiresCharging(request.requiresCharging())
            .setExtras(request.getTransientExtras());
    return builder;
}
 
Example #17
Source File: JobProxyGcm.java    From android-job with Apache License 2.0 5 votes vote down vote up
protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) {
    switch (networkType) {
        case ANY:
            return Task.NETWORK_STATE_ANY;
        case CONNECTED:
            return Task.NETWORK_STATE_CONNECTED;
        case UNMETERED:
            return Task.NETWORK_STATE_UNMETERED;
        case NOT_ROAMING:
            return Task.NETWORK_STATE_UNMETERED; // use as fallback, NOT_ROAMING not supported
        default:
            throw new IllegalStateException("not implemented");
    }
}
 
Example #18
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 #19
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 #20
Source File: PrecacheTaskScheduler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
boolean scheduleTask(Context context, Task task) {
    if (!canScheduleTasks(context)) {
        return false;
    }
    try {
        GcmNetworkManager.getInstance(context).schedule(task);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}
 
Example #21
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 #22
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 #23
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 #24
Source File: BackgroundTaskSchedulerGcmNetworkManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static Task.Builder getPeriodicTaskBuilder(TaskInfo.PeriodicInfo periodicInfo) {
    PeriodicTask.Builder builder = new PeriodicTask.Builder();
    builder.setPeriod(TimeUnit.MILLISECONDS.toSeconds(periodicInfo.getIntervalMs()));
    if (periodicInfo.hasFlex()) {
        builder.setFlex(TimeUnit.MILLISECONDS.toSeconds(periodicInfo.getFlexMs()));
    }
    return builder;
}
 
Example #25
Source File: BackgroundTaskSchedulerGcmNetworkManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static Task.Builder getOneOffTaskBuilder(TaskInfo.OneOffInfo oneOffInfo) {
    OneoffTask.Builder builder = new OneoffTask.Builder();
    long windowStartSeconds = oneOffInfo.hasWindowStartTimeConstraint()
            ? TimeUnit.MILLISECONDS.toSeconds(oneOffInfo.getWindowStartTimeMs())
            : 0;
    builder.setExecutionWindow(windowStartSeconds,
            TimeUnit.MILLISECONDS.toSeconds(oneOffInfo.getWindowEndTimeMs()));
    return builder;
}
 
Example #26
Source File: PrecacheTaskScheduler.java    From delion with Apache License 2.0 5 votes vote down vote up
boolean scheduleTask(Context context, Task task) {
    if (!canScheduleTasks(context)) {
        return false;
    }
    try {
        GcmNetworkManager.getInstance(context).schedule(task);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}
 
Example #27
Source File: PrecacheTaskScheduler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
boolean scheduleTask(Context context, Task task) {
    if (!canScheduleTasks(context)) {
        return false;
    }
    try {
        GcmNetworkManager.getInstance(context).schedule(task);
    } catch (IllegalArgumentException e) {
        return false;
    }
    return true;
}