Java Code Examples for android.app.job.JobScheduler#schedule()

The following examples show how to use android.app.job.JobScheduler#schedule() . 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: TorFragmentPresenter.java    From InviZible with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void startRefreshTorUnlockIPs(Context context) {
    if (context == null || view == null || view.getFragmentActivity() == null || view.getFragmentActivity().isFinishing()) {
        return;
    }

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP || refreshPeriodHours == 0) {
        TorRefreshIPsWork torRefreshIPsWork = new TorRefreshIPsWork(context, null);
        torRefreshIPsWork.refreshIPs();
    } else {
        ComponentName jobService = new ComponentName(context, GetIPsJobService.class);
        JobInfo.Builder getIPsJobBuilder;
        getIPsJobBuilder = new JobInfo.Builder(mJobId, jobService);
        getIPsJobBuilder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
        getIPsJobBuilder.setPeriodic(refreshPeriodHours * 60 * 60 * 1000);

        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);

        if (jobScheduler != null) {
            jobScheduler.schedule(getIPsJobBuilder.build());
        }
    }
}
 
Example 2
Source File: AddWatchNextService.java    From leanback-homescreen-channels with Apache License 2.0 6 votes vote down vote up
public static void scheduleAddWatchNextRequest(Context context, ClipData clipData) {
    JobScheduler scheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);

    PersistableBundle bundle = new PersistableBundle();
    bundle.putString(ID_KEY, clipData.getClipId());
    bundle.putString(CONTENT_ID_KEY, clipData.getContentId());
    bundle.putLong(DURATION_KEY, clipData.getDuration());
    bundle.putLong(PROGRESS_KEY, clipData.getProgress());
    bundle.putString(TITLE_KEY, clipData.getTitle());
    bundle.putString(DESCRIPTION_KEY, clipData.getDescription());
    bundle.putString(CARD_IMAGE_URL_KEY, clipData.getCardImageUrl());

    scheduler.schedule(new JobInfo.Builder(1,
            new ComponentName(context, AddWatchNextService.class))
            .setExtras(bundle)
            .build());
}
 
Example 3
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * UI onclick listener to schedule a new job. 
 */
public void scheduleJob(View v) {
	JobInfo.Builder builder = new JobInfo.Builder(kJobId++,mServiceComponent);
	String delay = mDelayEditText.getText().toString();
	if (delay != null && !TextUtils.isEmpty(delay)) {
		builder.setMinimumLatency(Long.valueOf(delay) * 1000);
	}
	String deadline = mDeadlineEditText.getText().toString();
	if (deadline != null && !TextUtils.isEmpty(deadline)) {
		builder.setOverrideDeadline(Long.valueOf(deadline) * 1000);
	}
	boolean requiresUnmetered = mWiFiConnectivityRadioButton.isChecked();
	boolean requiresAnyConnectivity = mAnyConnectivityRadioButton
			.isChecked();
	if (requiresUnmetered) {
		builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
	} else if (requiresAnyConnectivity) {
		builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
	}
	builder.setRequiresDeviceIdle(mRequiresIdleCheckbox.isChecked());
	builder.setRequiresCharging(mRequiresChargingCheckBox.isChecked());
	JobScheduler jobScheduler =
	        (JobScheduler) getApplication().getSystemService(Context.JOB_SCHEDULER_SERVICE);
	
	jobScheduler.schedule(builder.build());
}
 
Example 4
Source File: LeanplumNotificationHelper.java    From Leanplum-Android-SDK with Apache License 2.0 6 votes vote down vote up
/**
 * Schedule JobService to JobScheduler.
 *
 * @param context Current application context.
 * @param clazz JobService class.
 * @param jobId JobService id.
 */
@TargetApi(21)
static void scheduleJobService(Context context, Class clazz, int jobId) {
  if (context == null) {
    return;
  }
  ComponentName serviceName = new ComponentName(context, clazz);
  JobScheduler jobScheduler =
      (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
  if (jobScheduler != null) {
    jobId = verifyJobId(jobScheduler.getAllPendingJobs(), jobId);
    JobInfo startMyServiceJobInfo = new JobInfo.Builder(jobId, serviceName)
        .setMinimumLatency(10).build();
    jobScheduler.schedule(startMyServiceJobInfo);
  }
}
 
Example 5
Source File: MobileMessagingJobService.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
private static void registerForNetworkAvailability(Context context) {
    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
    if (jobScheduler == null) {
        return;
    }

    int scheduleId = getScheduleId(context, ON_NETWORK_AVAILABLE_JOB_ID);

    jobScheduler.cancel(scheduleId);

    int r = jobScheduler.schedule(new JobInfo.Builder(scheduleId, new ComponentName(context, MobileMessagingJobService.class))
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
            .build());
    if (r == JobScheduler.RESULT_SUCCESS) {
        MobileMessagingLogger.d(TAG, "Registered job for connectivity updates");
    } else {
        MobileMessagingLogger.e(TAG, "Failed to register job for connectivity updates");
    }
}
 
Example 6
Source File: BrightnessIdleJob.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public static void scheduleJob(Context context) {
    JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);

    JobInfo pending = jobScheduler.getPendingJob(JOB_ID);
    JobInfo jobInfo =
            new JobInfo.Builder(JOB_ID, new ComponentName(context, BrightnessIdleJob.class))
                    .setRequiresDeviceIdle(true)
                    .setRequiresCharging(true)
                    .setPeriodic(TimeUnit.HOURS.toMillis(24)).build();

    if (pending != null && !pending.equals(jobInfo)) {
        jobScheduler.cancel(JOB_ID);
        pending = null;
    }

    if (pending == null) {
        jobScheduler.schedule(jobInfo);
    }
}
 
Example 7
Source File: DataEstimator.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
private static void scheduleJob(Context context) {
    ComponentName serviceComponent = new ComponentName(context, EstimatorJob.class);
    JobInfo.Builder builder = new JobInfo.Builder(mJobId++, serviceComponent);
    builder.setMinimumLatency(1); // wait at least
    builder.setOverrideDeadline(10); // maximum delay
    builder.setRequiresCharging(false);
    builder.setRequiresDeviceIdle(false);

    JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
    jobScheduler.schedule(builder.build());
}
 
Example 8
Source File: BootReceiver.java    From ml-authentication with Apache License 2.0 5 votes vote down vote up
public static void scheduleFaceRecognitionTranining(Context context){
    ComponentName componentNameFaceRecognitionTranining = new ComponentName(context, FaceRecognitionTrainingJobService.class);
    JobInfo.Builder builderFaceRecognitionTranining = new JobInfo.Builder(LiteracyApplication.FACE_RECOGNITION_TRAINING_JOB_ID, componentNameFaceRecognitionTranining);
    int faceRecognitionTrainingPeriodic = MINUTES_BETWEEN_FACE_RECOGNITION_TRAININGS * 60 * 1000;
    builderFaceRecognitionTranining.setPeriodic(faceRecognitionTrainingPeriodic); // Every 15 minutes
    JobInfo faceRecognitionTrainingJobInfo = builderFaceRecognitionTranining.build();
    JobScheduler jobSchedulerFaceRecognitionTranining = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobSchedulerFaceRecognitionTranining.schedule(faceRecognitionTrainingJobInfo);
    Log.i(context.getClass().getName(), "FACE_RECOGNITION_TRAINING_JOB with ID " + LiteracyApplication.FACE_RECOGNITION_TRAINING_JOB_ID + " has been scheduled with periodic time = " + faceRecognitionTrainingPeriodic);
}
 
Example 9
Source File: MainActivity.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
@Override
public void onPostExecute(Void dummy) {
    super.onPostExecute(dummy);
    if (!fromOnRestart && savedInstanceState == null && prefHelper.launchToOverview()) {
        currentFragment = CurrentFragment.Overview;
        showOverview(false);
    } else if (getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG) == null || newComicFound) {
        Timber.d("Creating a new Fragment...");
        switch (currentFragment) {
            case Browser:
                showBrowserFragment(false);
                break;
            case Favorites:
                showFavoritesFragment(false);
                break;
            case Overview:
                showOverview(false);
                break;
        }
    }
    updateToolbarTitle();
    unlockRotation();
    //Setup the notifications in case the device was restarted
    Timber.d("interval: %d", prefHelper.getNotificationInterval());
    if (!fromOnRestart && savedInstanceState == null && prefHelper.getNotificationInterval() != 0) {
        JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.schedule(new JobInfo.Builder(UPDATE_JOB_ID, new ComponentName(MainActivity.this, ComicNotifierJob.class))
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                .setPeriodic(prefHelper.getNotificationInterval())
                .setPersisted(true)
                .build()
        );
        Timber.d("job scheduled...");
    }
    updateTaskRunning = false;
}
 
Example 10
Source File: EpgSyncJobService.java    From androidtv-sample-inputs with Apache License 2.0 5 votes vote down vote up
/** Send the job to JobScheduler. */
private static void scheduleJob(Context context, JobInfo job) {
    JobScheduler jobScheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    int result = jobScheduler.schedule(job);
Assert.assertEquals(JobScheduler.RESULT_SUCCESS, result);
    if (DEBUG) {
        Log.d(TAG, "Scheduling result is " + result);
    }
}
 
Example 11
Source File: ReportWatchlistJobService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Schedule the {@link ReportWatchlistJobService} to run periodically.
 */
public static void schedule(Context context) {
    if (DEBUG) Slog.d(TAG, "Scheduling records aggregator task");
    final JobScheduler scheduler =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    scheduler.schedule(new JobInfo.Builder(REPORT_WATCHLIST_RECORDS_JOB_ID,
            new ComponentName(context, ReportWatchlistJobService.class))
            //.setOverrideDeadline(45 * 1000) // Schedule job soon, for testing.
            .setPeriodic(REPORT_WATCHLIST_RECORDS_PERIOD_MILLIS)
            .setRequiresDeviceIdle(true)
            .setRequiresBatteryNotLow(true)
            .setPersisted(false)
            .build());
}
 
Example 12
Source File: VideosContentJob.java    From proofmode with GNU General Public License v3.0 5 votes vote down vote up
public static void scheduleJob(Context context) {
    JobScheduler js =
            (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    JobInfo.Builder builder = new JobInfo.Builder(
            VIDEO_JOB_ID,
            new ComponentName(context, VideosContentJob.class));
    builder.addTriggerContentUri(
            new JobInfo.TriggerContentUri(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                    JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS));
    js.schedule(builder.build());
}
 
Example 13
Source File: ExtractionUtils.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/** Starts the {@link ColorExtractionService} without checking the wallpaper id */
static void startColorExtractionService(Context context) {
    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(
            Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.schedule(new JobInfo.Builder(Utilities.COLOR_EXTRACTION_JOB_ID,
            new ComponentName(context, ColorExtractionService.class))
            .setMinimumLatency(0).build());
}
 
Example 14
Source File: Util.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public static void scheduleJob(Context context) {
    ComponentName serviceComponent = new ComponentName(context, TestJobService.class);
    JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent);
    builder.setMinimumLatency(1 * 1000); // wait at least
    builder.setOverrideDeadline(3 * 1000); // maximum delay
    //builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); // require unmetered network
    //builder.setRequiresDeviceIdle(true); // device should be idle
    //builder.setRequiresCharging(false); // we don't care if the device is charging or not
    JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
    jobScheduler.schedule(builder.build());
}
 
Example 15
Source File: MainActivity.java    From android-performance with MIT License 5 votes vote down vote up
/**
 * 演示JobScheduler的使用
 */
private void startJobScheduler() {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo.Builder builder = new JobInfo.Builder(1, new ComponentName(getPackageName(), JobSchedulerService.class.getName()));
        builder.setRequiresCharging(true)
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
        jobScheduler.schedule(builder.build());
    }
}
 
Example 16
Source File: JobSchedulerScheduler.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(26)
@Override
public void schedule(long delay, @NonNull List<Constraint> constraints) {
  JobInfo.Builder jobInfoBuilder = new JobInfo.Builder(getNextId(), new ComponentName(application, SystemService.class))
                                              .setMinimumLatency(delay)
                                              .setPersisted(true);

  for (Constraint constraint : constraints) {
    constraint.applyToJobInfo(jobInfoBuilder);
  }

  Log.i(TAG, "Scheduling a run in " + delay + " ms.");
  JobScheduler jobScheduler = application.getSystemService(JobScheduler.class);
  jobScheduler.schedule(jobInfoBuilder.build());
}
 
Example 17
Source File: BGTask.java    From transistor-background-fetch with MIT License 4 votes vote down vote up
static void schedule(Context context, BackgroundFetchConfig config) {
    Log.d(BackgroundFetch.TAG, config.toString());

    long interval = (config.isFetchTask()) ? (TimeUnit.MINUTES.toMillis(config.getMinimumFetchInterval())) : config.getDelay();

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !config.getForceAlarmManager()) {
        // API 21+ uses new JobScheduler API

        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo.Builder builder = new JobInfo.Builder(config.getJobId(), new ComponentName(context, FetchJobService.class))
                .setRequiredNetworkType(config.getRequiredNetworkType())
                .setRequiresDeviceIdle(config.getRequiresDeviceIdle())
                .setRequiresCharging(config.getRequiresCharging())
                .setPersisted(config.getStartOnBoot() && !config.getStopOnTerminate());

        if (config.getPeriodic()) {
            if (android.os.Build.VERSION.SDK_INT >= 24) {
                builder.setPeriodic(interval, interval);
            } else {
                builder.setPeriodic(interval);
            }
        } else {
            builder.setMinimumLatency(interval);
        }
        PersistableBundle extras = new PersistableBundle();
        extras.putString(BackgroundFetchConfig.FIELD_TASK_ID, config.getTaskId());
        builder.setExtras(extras);

        if (android.os.Build.VERSION.SDK_INT >= 26) {
            builder.setRequiresStorageNotLow(config.getRequiresStorageNotLow());
            builder.setRequiresBatteryNotLow(config.getRequiresBatteryNotLow());
        }
        if (jobScheduler != null) {
            jobScheduler.schedule(builder.build());
        }
    } else {
        // Everyone else get AlarmManager
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        if (alarmManager != null) {
            PendingIntent pi = getAlarmPI(context, config.getTaskId());
            long delay = System.currentTimeMillis() + interval;
            if (config.getPeriodic()) {
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, delay, interval, pi);
            } else {
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, delay, pi);
                } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    alarmManager.setExact(AlarmManager.RTC_WAKEUP, delay, pi);
                } else {
                    alarmManager.set(AlarmManager.RTC_WAKEUP, delay, pi);
                }
            }
        }
    }
}
 
Example 18
Source File: UpdateService.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Schedule this service to update the app index while canceling any previously
 * scheduled updates, according to the current preferences. Should be called
 * a) at boot, b) if the preference is changed, or c) on startup, in case we get
 * upgraded. It works differently on {@code android-21} and newer, versus older,
 * due to the {@link JobScheduler} API handling it very nicely for us.
 *
 * @see <a href="https://developer.android.com/about/versions/android-5.0.html#Power">Project Volta: Scheduling jobs</a>
 */
public static void schedule(Context context) {
    Preferences prefs = Preferences.get();
    long interval = prefs.getUpdateInterval();
    int data = prefs.getOverData();
    int wifi = prefs.getOverWifi();
    boolean scheduleNewJob =
            interval != Preferences.UPDATE_INTERVAL_DISABLED
                    && !(data == Preferences.OVER_NETWORK_NEVER && wifi == Preferences.OVER_NETWORK_NEVER);

    if (Build.VERSION.SDK_INT < 21) {
        Intent intent = new Intent(context, UpdateService.class);
        PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);

        AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarm.cancel(pending);
        if (scheduleNewJob) {
            alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,
                    SystemClock.elapsedRealtime() + 5000, interval, pending);
            Utils.debugLog(TAG, "Update scheduler alarm set");
        } else {
            Utils.debugLog(TAG, "Update scheduler alarm not set");
        }
    } else {
        Utils.debugLog(TAG, "Using android-21 JobScheduler for updates");
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        ComponentName componentName = new ComponentName(context, UpdateJobService.class);
        JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, componentName)
                .setRequiresDeviceIdle(true)
                .setPeriodic(interval);
        if (Build.VERSION.SDK_INT >= 26) {
            builder.setRequiresBatteryNotLow(true)
                    .setRequiresStorageNotLow(true);
        }
        if (data == Preferences.OVER_NETWORK_ALWAYS && wifi == Preferences.OVER_NETWORK_ALWAYS) {
            builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
        } else {
            builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
        }

        jobScheduler.cancel(JOB_ID);
        if (scheduleNewJob) {
            jobScheduler.schedule(builder.build());
            Utils.debugLog(TAG, "Update scheduler alarm set");
        } else {
            Utils.debugLog(TAG, "Update scheduler alarm not set");
        }
    }
}
 
Example 19
Source File: ServiceScheduler.java    From android-sdk with Apache License 2.0 4 votes vote down vote up
private void setRepeating(long interval, PendingIntent pendingIntent, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int jobId = getJobId(intent);
        if (jobId == -1) {
            logger.error("Problem getting scheduled job id");
            return;
        }

        if (isScheduled(context, jobId)) {
            logger.info("Job already started");
            return;
        }

        JobScheduler jobScheduler = (JobScheduler)
                context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        JobInfo.Builder builder = new JobInfo.Builder(jobId,
                new ComponentName(context.getApplicationContext(),
                        ScheduledJobService.class.getName()));
        builder.setPeriodic(interval, interval);
        builder.setPersisted(true);
        // we are only doing repeating on datafile service. it is a prefetch.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            builder.setPrefetch(true);
        }
        builder.setBackoffCriteria(JobInfo.DEFAULT_INITIAL_BACKOFF_MILLIS, JobInfo.BACKOFF_POLICY_LINEAR);

        intent.putExtra(JobWorkService.INTENT_EXTRA_JWS_PERIODIC, interval);
        PersistableBundle persistableBundle = new PersistableBundle();

        for (String key : intent.getExtras().keySet()) {
            Object object = intent.getExtras().get(key);
            switch (object.getClass().getSimpleName()) {
                case "String":
                    persistableBundle.putString(key, (String) object);
                    break;
                case "long":
                case "Long":
                    persistableBundle.putLong(key, (Long) object);
                    break;
                default:
                    logger.info("No conversion for {}", object.getClass().getSimpleName());
            }
        }

        persistableBundle.putString(ScheduledJobService.INTENT_EXTRA_COMPONENT_NAME, intent.getComponent().getClassName());

        builder.setExtras(persistableBundle);

        try {
            if (jobScheduler.schedule(builder.build()) != RESULT_SUCCESS) {
                logger.error("ServiceScheduler", "Some error while scheduling the job");
            }
        }
        catch (Exception e) {
            logger.error(String.format("Problem scheduling job %s", intent.getComponent().toShortString()), e);
        }
    }
    else {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, interval, interval, pendingIntent);
    }
}
 
Example 20
Source File: JobInfoScheduler.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Schedules the JobScheduler service.
 *
 * @param transportContext Contains information about the backend and the priority.
 * @param attemptNumber Number of times the JobScheduler has tried to log for this backend.
 */
@Override
public void schedule(TransportContext transportContext, int attemptNumber) {
  ComponentName serviceComponent = new ComponentName(context, JobInfoSchedulerService.class);
  JobScheduler jobScheduler =
      (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
  int jobId = getJobId(transportContext);
  // Check if there exists a job scheduled for this backend name.
  if (isJobServiceOn(jobScheduler, jobId, attemptNumber)) {
    Logging.d(
        LOG_TAG, "Upload for context %s is already scheduled. Returning...", transportContext);
    return;
  }

  long nextCallTime = eventStore.getNextCallTime(transportContext);

  // Schedule the build.
  JobInfo.Builder builder =
      config.configureJob(
          new JobInfo.Builder(jobId, serviceComponent),
          transportContext.getPriority(),
          nextCallTime,
          attemptNumber);

  PersistableBundle bundle = new PersistableBundle();
  bundle.putInt(ATTEMPT_NUMBER, attemptNumber);
  bundle.putString(BACKEND_NAME, transportContext.getBackendName());
  bundle.putInt(EVENT_PRIORITY, PriorityMapping.toInt(transportContext.getPriority()));
  if (transportContext.getExtras() != null) {
    bundle.putString(EXTRAS, encodeToString(transportContext.getExtras(), DEFAULT));
  }
  builder.setExtras(bundle);

  Logging.d(
      LOG_TAG,
      "Scheduling upload for context %s with jobId=%d in %dms(Backend next call timestamp %d). Attempt %d",
      transportContext,
      jobId,
      config.getScheduleDelay(transportContext.getPriority(), nextCallTime, attemptNumber),
      nextCallTime,
      attemptNumber);

  jobScheduler.schedule(builder.build());
}