android.app.job.JobInfo#getId ( )源码实例Demo

下面列出了android.app.job.JobInfo#getId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: container   文件: VJobSchedulerService.java
@Override
public int schedule(JobInfo job) throws RemoteException {
    int vuid = VBinder.getCallingUid();
    int id = job.getId();
    ComponentName service = job.getService();
    JobId jobId = new JobId(vuid, service.getPackageName(), id);
    JobConfig config = mJobStore.get(jobId);
    if (config == null) {
        config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras());
        mJobStore.put(jobId, config);
    } else {
        config.serviceName = service.getClassName();
        config.extras = job.getExtras();
    }
    saveJobs();
    mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId);
    mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent);
    return mScheduler.schedule(job);
}
 
源代码2 项目: android_9.0.0_r45   文件: SyncManager.java
private boolean isJobIdInUseLockedH(int jobId, List<JobInfo> pendingJobs) {
    for (JobInfo job: pendingJobs) {
        if (job.getId() == jobId) {
            return true;
        }
    }
    for (ActiveSyncContext asc: mActiveSyncContexts) {
        if (asc.mSyncOperation.jobId == jobId) {
            return true;
        }
    }
    return false;
}
 
源代码3 项目: firebase-android-sdk   文件: JobInfoScheduler.java
private boolean isJobServiceOn(JobScheduler scheduler, int jobId, int attemptNumber) {
  for (JobInfo jobInfo : scheduler.getAllPendingJobs()) {
    int existingAttemptNumber = jobInfo.getExtras().getInt(ATTEMPT_NUMBER);
    if (jobInfo.getId() == jobId) {
      return existingAttemptNumber >= attemptNumber;
    }
  }
  return false;
}
 
源代码4 项目: your-local-weather   文件: MainActivity.java
private void startAlarms() {
    appendLog(this, TAG, "scheduleStart at boot, SDK=", Build.VERSION.SDK_INT);
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M) {
        JobScheduler jobScheduler = getSystemService(JobScheduler.class);
        boolean scheduled = false;
        for (JobInfo jobInfo: jobScheduler.getAllPendingJobs()) {
            if (jobInfo.getId() > 0) {
                appendLog(this, TAG, "scheduleStart does not start - it's scheduled already");
                scheduled = true;
                break;
            }
        }
        if (!scheduled) {
            appendLog(this, TAG, "scheduleStart at MainActivity");
            AppPreference.setLastSensorServicesCheckTimeInMs(this, 0);
            jobScheduler.cancelAll();
            ComponentName serviceComponent = new ComponentName(this, StartAutoLocationJob.class);
            JobInfo.Builder builder = new JobInfo.Builder(StartAutoLocationJob.JOB_ID, serviceComponent);
            builder.setMinimumLatency(1 * 1000); // wait at least
            builder.setOverrideDeadline(3 * 1000); // maximum delay
            jobScheduler.schedule(builder.build());
        }
    } else {
        Intent intentToStartUpdate = new Intent("org.thosp.yourlocalweather.action.START_ALARM_SERVICE");
        intentToStartUpdate.setPackage("org.thosp.yourlocalweather");
        startService(intentToStartUpdate);
    }
}
 
private void sendUpdateToLocationBackends() {
    appendLog(getBaseContext(), TAG,
            "update():nextScanningAllowedFrom:",
            nextScanningAllowedFrom);
    if(nextScanningAllowedFrom == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
            scanning = wifiManager.startScan();
        } else {
            scanning = true;
        }
        if (scanning) {
            nextScanningAllowedFrom = Calendar.getInstance();
            nextScanningAllowedFrom.add(Calendar.MINUTE, 15);
        }
    }
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M) {
        ComponentName serviceComponent = new ComponentName(this, NetworkLocationCellsOnlyJob.class);
        JobInfo.Builder builder = new JobInfo.Builder(NetworkLocationCellsOnlyJob.JOB_ID, serviceComponent);
        builder.setMinimumLatency(8000); // wait at least
        builder.setOverrideDeadline(10000); // maximum delay
        JobInfo jobInfo = builder.build();
        jobId= jobInfo.getId();
        JobScheduler jobScheduler = getSystemService(JobScheduler.class);
        jobScheduler.schedule(jobInfo);
    } else {
        intentToCancel = getIntentToGetCellsOnly();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime() + 8000,
                    intentToCancel);
        } else {
            alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime() + 8000,
                    intentToCancel);
        }
    }
    appendLog(getBaseContext(), TAG, "update():cells only task scheduled");
}
 
源代码6 项目: ClassSchedule   文件: AppUtils.java
private static boolean isJobPollServiceOn(Context context) {
    JobScheduler scheduler = (JobScheduler) context
            .getSystemService(Context.JOB_SCHEDULER_SERVICE);

    for (JobInfo jobInfo : scheduler.getAllPendingJobs()) {
        if (jobInfo.getId() == UPDATE_WIDGET_JOB_ID) {
            return true;
        }
    }
    return false;
}
 
源代码7 项目: intra42   文件: NotificationsJobService.java
public static void schedule(Context context) {
    JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    if (jobScheduler == null)
        return;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (jobScheduler.getPendingJob(JOB_ID) != null)
            return;
    } else {
        List<JobInfo> allPendingJobs = jobScheduler.getAllPendingJobs();
        if (!allPendingJobs.isEmpty()) {
            for (JobInfo j : allPendingJobs) {
                if (j.getId() == JOB_ID)
                    return;
            }
        }
    }

    SharedPreferences settings = AppSettings.getSharedPreferences(context);
    int notificationsFrequency = AppSettings.Notifications.getNotificationsFrequency(settings);

    ComponentName component = new ComponentName(context, NotificationsJobService.class);
    JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, component)
            .setPeriodic(60000 * notificationsFrequency);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NOT_ROAMING);
    else
        builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);


    jobScheduler.schedule(builder.build());
}
 
源代码8 项目: android-sdk   文件: ServiceScheduler.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static boolean isScheduled(Context context, Integer jobId) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        for (JobInfo jobInfo : jobScheduler.getAllPendingJobs()) {
            // we only don't allow rescheduling of periodic jobs.  jobs for individual
            // intents such as events are allowed and can end up queued in the job service queue.
            if (jobInfo.getId() == jobId && jobInfo.isPeriodic()) {
                return true;
            }
        }
    }
    return false;
}
 
源代码9 项目: android-job   文件: JobProxy21.java
@SuppressWarnings("SimplifiableIfStatement")
protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) {
    boolean correctInfo = info != null && info.getId() == request.getJobId();
    if (!correctInfo) {
        return false;
    }
    return !request.isTransient() || TransientBundleCompat.isScheduled(mContext, request.getJobId());
}
 
源代码10 项目: android-job   文件: JobProxy26.java
@Override
protected boolean isJobInfoScheduled(@Nullable JobInfo info, @NonNull JobRequest request) {
    return info != null && info.getId() == request.getJobId();
}