Search in sources :

Example 6 with JobManager

use of com.evernote.android.job.JobManager in project PhoneProfilesPlus by henrichg.

the class WifiScanJob method _scheduleJob.

private static void _scheduleJob(final Context context, final boolean shortInterval, final boolean forScreenOn, final boolean afterEnableWifi) {
    JobManager jobManager = null;
    try {
        jobManager = JobManager.instance();
    } catch (Exception ignored) {
    }
    if (jobManager != null) {
        final JobRequest.Builder jobBuilder;
        if (!shortInterval) {
            jobManager.cancelAllForTag(JOB_TAG_SHORT);
            int interval = ApplicationPreferences.applicationEventWifiScanInterval(context);
            // boolean isPowerSaveMode = PPApplication.isPowerSaveMode;
            boolean isPowerSaveMode = DataWrapper.isPowerSaveMode(context);
            if (isPowerSaveMode && ApplicationPreferences.applicationEventWifiScanInPowerSaveMode(context).equals("1"))
                interval = 2 * interval;
            jobBuilder = new JobRequest.Builder(JOB_TAG);
            if (TimeUnit.MINUTES.toMillis(interval) < JobRequest.MIN_INTERVAL) {
                jobManager.cancelAllForTag(JOB_TAG);
                jobBuilder.setExact(TimeUnit.MINUTES.toMillis(interval));
            } else {
                int requestsForTagSize = jobManager.getAllJobRequestsForTag(JOB_TAG).size();
                PPApplication.logE("WifiScanJob.scheduleJob", "requestsForTagSize=" + requestsForTagSize);
                if (requestsForTagSize == 0) {
                    if (TimeUnit.MINUTES.toMillis(interval) < JobRequest.MIN_INTERVAL)
                        // must be set min interval because:
                        // java.lang.IllegalArgumentException: intervalMs is out of range of [900000, 9223372036854775807] (too low)
                        jobBuilder.setPeriodic(JobRequest.MIN_INTERVAL);
                    else
                        jobBuilder.setPeriodic(TimeUnit.MINUTES.toMillis(interval));
                } else
                    return;
            }
        } else {
            _cancelJob(context);
            jobBuilder = new JobRequest.Builder(JOB_TAG_SHORT);
            if (afterEnableWifi)
                jobBuilder.setExact(TimeUnit.SECONDS.toMillis(2));
            else if (forScreenOn)
                jobBuilder.setExact(TimeUnit.SECONDS.toMillis(5));
            else
                jobBuilder.setExact(TimeUnit.SECONDS.toMillis(5));
        }
        PPApplication.logE("WifiScanJob.scheduleJob", "build and schedule");
        try {
            jobBuilder.setUpdateCurrent(// don't update current, it would cancel this currently running job
            false).build().scheduleAsync();
        } catch (Exception e) {
            PPApplication.logE("WifiScanJob.scheduleJob", e.toString());
        }
    }
}
Also used : JobRequest(com.evernote.android.job.JobRequest) JobManager(com.evernote.android.job.JobManager)

Example 7 with JobManager

use of com.evernote.android.job.JobManager in project PhoneProfilesPlus by henrichg.

the class SearchCalendarEventsJob method _cancelJob.

private static void _cancelJob() /*final Context context*/
{
    try {
        JobManager jobManager = JobManager.instance();
        jobManager.cancelAllForTag(JOB_TAG_SHORT);
        jobManager.cancelAllForTag(JOB_TAG);
    } catch (Exception ignored) {
    }
}
Also used : JobManager(com.evernote.android.job.JobManager)

Example 8 with JobManager

use of com.evernote.android.job.JobManager in project PhoneProfilesPlus by henrichg.

the class SearchCalendarEventsJob method _scheduleJob.

private static void _scheduleJob(/*final Context context, */
final boolean shortInterval) {
    JobManager jobManager = null;
    try {
        jobManager = JobManager.instance();
    } catch (Exception ignored) {
    }
    if (jobManager != null) {
        final JobRequest.Builder jobBuilder;
        if (!shortInterval) {
            jobManager.cancelAllForTag(JOB_TAG_SHORT);
            int requestsForTagSize = jobManager.getAllJobRequestsForTag(JOB_TAG).size();
            PPApplication.logE("SearchCalendarEventsJob.scheduleJob", "requestsForTagSize=" + requestsForTagSize);
            if (requestsForTagSize == 0) {
                jobBuilder = new JobRequest.Builder(JOB_TAG);
                // each 24 hours
                jobBuilder.setPeriodic(TimeUnit.HOURS.toMillis(24));
            } else
                return;
        } else {
            _cancelJob();
            jobBuilder = new JobRequest.Builder(JOB_TAG_SHORT);
            jobBuilder.setExact(TimeUnit.SECONDS.toMillis(5));
        }
        PPApplication.logE("SearchCalendarEventsJob.scheduleJob", "build and schedule");
        try {
            jobBuilder.setUpdateCurrent(// don't update current, it would cancel this currently running job
            false).build().scheduleAsync();
        } catch (Exception ignored) {
        }
    }
}
Also used : JobRequest(com.evernote.android.job.JobRequest) JobManager(com.evernote.android.job.JobManager)

Example 9 with JobManager

use of com.evernote.android.job.JobManager in project PhoneProfilesPlus by henrichg.

the class GeofenceScannerJob method _scheduleJob.

private static void _scheduleJob(final Context context, final boolean startScanning, final boolean forScreenOn) {
    /*if (startScanning) {
            synchronized (PPApplication.geofenceScannerMutex) {
                if ((PhoneProfilesService.instance != null) && PhoneProfilesService.isGeofenceScannerStarted())
                    PhoneProfilesService.getGeofencesScanner().mUpdatesStarted = false;
            }
        }*/
    JobManager jobManager = null;
    try {
        jobManager = JobManager.instance();
    } catch (Exception ignored) {
    }
    if (jobManager != null) {
        final JobRequest.Builder jobBuilder;
        if (!startScanning) {
            jobManager.cancelAllForTag(JOB_TAG_START);
            int interval;
            synchronized (PPApplication.geofenceScannerMutex) {
                if ((PhoneProfilesService.instance != null) && PhoneProfilesService.isGeofenceScannerStarted())
                    PPApplication.logE("GeofenceScannerJob.scheduleJob", "mUpdatesStarted=" + PhoneProfilesService.getGeofencesScanner().mUpdatesStarted);
                else
                    PPApplication.logE("GeofenceScannerJob.scheduleJob", "mUpdatesStarted=false");
                if ((PhoneProfilesService.instance != null) && PhoneProfilesService.isGeofenceScannerStarted() && PhoneProfilesService.getGeofencesScanner().mUpdatesStarted) {
                    interval = ApplicationPreferences.applicationEventLocationUpdateInterval(context) * 60;
                    PPApplication.logE("GeofenceScannerJob.scheduleJob", "interval=" + interval);
                    // boolean isPowerSaveMode = PPApplication.isPowerSaveMode;
                    boolean isPowerSaveMode = DataWrapper.isPowerSaveMode(context);
                    if (isPowerSaveMode && ApplicationPreferences.applicationEventLocationUpdateInPowerSaveMode(context).equals("1"))
                        interval = 2 * interval;
                // interval = interval - updateDuration;
                } else {
                    interval = 5;
                }
            }
            jobBuilder = new JobRequest.Builder(JOB_TAG);
            if (TimeUnit.SECONDS.toMillis(interval) < JobRequest.MIN_INTERVAL) {
                jobManager.cancelAllForTag(JOB_TAG);
                jobBuilder.setExact(TimeUnit.SECONDS.toMillis(interval));
            } else {
                int requestsForTagSize = jobManager.getAllJobRequestsForTag(JOB_TAG).size();
                PPApplication.logE("GeofenceScannerJob.scheduleJob", "requestsForTagSize=" + requestsForTagSize);
                if (requestsForTagSize == 0) {
                    if (TimeUnit.SECONDS.toMillis(interval) < JobRequest.MIN_INTERVAL)
                        // must be set min interval because:
                        // java.lang.IllegalArgumentException: intervalMs is out of range of [900000, 9223372036854775807] (too low)
                        jobBuilder.setPeriodic(JobRequest.MIN_INTERVAL);
                    else
                        jobBuilder.setPeriodic(TimeUnit.SECONDS.toMillis(interval));
                } else
                    return;
            }
        } else {
            _cancelJob();
            jobBuilder = new JobRequest.Builder(JOB_TAG_START);
            if (forScreenOn)
                jobBuilder.setExact(5);
            else
                jobBuilder.setExact(5);
        }
        PPApplication.logE("GeofenceScannerJob.scheduleJob", "build and schedule");
        try {
            jobBuilder.setUpdateCurrent(// don't update current, it would cancel this currently running job
            false).build().scheduleAsync();
        } catch (Exception ignored) {
        }
    }
}
Also used : JobRequest(com.evernote.android.job.JobRequest) JobManager(com.evernote.android.job.JobManager)

Example 10 with JobManager

use of com.evernote.android.job.JobManager in project PhoneProfilesPlus by henrichg.

the class BluetoothScanJob method _scheduleJob.

private static void _scheduleJob(final Context context, final boolean shortInterval, final boolean forScreenOn) {
    JobManager jobManager = null;
    try {
        jobManager = JobManager.instance();
    } catch (Exception ignored) {
    }
    if (jobManager != null) {
        final JobRequest.Builder jobBuilder;
        if (!shortInterval) {
            jobManager.cancelAllForTag(JOB_TAG_SHORT);
            int interval = ApplicationPreferences.applicationEventBluetoothScanInterval(context);
            // boolean isPowerSaveMode = PPApplication.isPowerSaveMode;
            boolean isPowerSaveMode = DataWrapper.isPowerSaveMode(context);
            if (isPowerSaveMode && ApplicationPreferences.applicationEventBluetoothScanInPowerSaveMode(context).equals("1"))
                interval = 2 * interval;
            jobBuilder = new JobRequest.Builder(JOB_TAG);
            if (TimeUnit.MINUTES.toMillis(interval) < JobRequest.MIN_INTERVAL) {
                jobManager.cancelAllForTag(JOB_TAG);
                jobBuilder.setExact(TimeUnit.MINUTES.toMillis(interval));
            } else {
                int requestsForTagSize = jobManager.getAllJobRequestsForTag(JOB_TAG).size();
                PPApplication.logE("BluetoothScanJob.scheduleJob", "requestsForTagSize=" + requestsForTagSize);
                if (requestsForTagSize == 0) {
                    if (TimeUnit.MINUTES.toMillis(interval) < JobRequest.MIN_INTERVAL)
                        // must be set min interval because:
                        // java.lang.IllegalArgumentException: intervalMs is out of range of [900000, 9223372036854775807] (too low)
                        jobBuilder.setPeriodic(JobRequest.MIN_INTERVAL);
                    else
                        jobBuilder.setPeriodic(TimeUnit.MINUTES.toMillis(interval));
                } else
                    return;
            }
        } else {
            _cancelJob(context);
            jobBuilder = new JobRequest.Builder(JOB_TAG_SHORT);
            if (forScreenOn)
                jobBuilder.setExact(TimeUnit.SECONDS.toMillis(5));
            else
                jobBuilder.setExact(TimeUnit.SECONDS.toMillis(5));
        }
        PPApplication.logE("BluetoothScanJob.scheduleJob", "build and schedule");
        try {
            jobBuilder.setUpdateCurrent(// don't update current, it would cancel this currently running job
            false).build().scheduleAsync();
        } catch (Exception ignored) {
        }
    }
}
Also used : JobRequest(com.evernote.android.job.JobRequest) JobManager(com.evernote.android.job.JobManager) SuppressLint(android.annotation.SuppressLint)

Aggregations

JobManager (com.evernote.android.job.JobManager)12 JobRequest (com.evernote.android.job.JobRequest)8 PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)2 SuppressLint (android.annotation.SuppressLint)1