com.evernote.android.job.JobRequest Java Examples

The following examples show how to use com.evernote.android.job.JobRequest. 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: JobProxy21.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isPlatformJobScheduled(JobRequest request) {
    List<JobInfo> pendingJobs;
    try {
        pendingJobs = getJobScheduler().getAllPendingJobs();
    } catch (Exception e) {
        // it's possible that this throws an exception, see https://gist.github.com/vRallev/a59947dd3932d2642641
        mCat.e(e);
        return false;
    }

    //noinspection ConstantConditions
    if (pendingJobs == null || pendingJobs.isEmpty()) {
        return false;
    }

    for (JobInfo info : pendingJobs) {
        if (isJobInfoScheduled(info, request)) {
            return true;
        }
    }

    return false;
}
 
Example #2
Source File: DeviceTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
public void testNetworkStateWifiAndRoaming() {
    NetworkInfo networkInfo = mock(NetworkInfo.class);
    when(networkInfo.isConnected()).thenReturn(true);
    when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
    when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI);
    when(networkInfo.isRoaming()).thenReturn(true);

    ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);

    Context context = mock(MockContext.class);
    when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);

    assertThat(Device.getNetworkType(context)).isEqualTo(JobRequest.NetworkType.UNMETERED);
}
 
Example #3
Source File: JobProxy26.java    From android-job with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) {
    switch (networkType) {
        case METERED:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                return JobInfo.NETWORK_TYPE_CELLULAR;
            } else {
                return JobInfo.NETWORK_TYPE_METERED;
            }

        default:
            return super.convertNetworkType(networkType);
    }

}
 
Example #4
Source File: DeviceTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
public void testNetworkStateWifiAndMobile() {
    NetworkInfo networkInfo = mock(NetworkInfo.class);
    when(networkInfo.isConnected()).thenReturn(true);
    when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
    when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI);
    when(networkInfo.isRoaming()).thenReturn(false);

    ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);

    Context context = mock(MockContext.class);
    when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);

    assertThat(Device.getNetworkType(context)).isEqualTo(JobRequest.NetworkType.UNMETERED);
}
 
Example #5
Source File: JobProxyWorkManager.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public void plantOneOff(JobRequest request) {
    if (request.isTransient()) {
        TransientBundleHolder.putBundle(request.getJobId(), request.getTransientExtras());
    }

    OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(PlatformWorker.class)
            .setInitialDelay(request.getStartMs(), TimeUnit.MILLISECONDS) // don't use the average here, WorkManager will do the right thing
            .setConstraints(buildConstraints(request))
            .addTag(createTag(request.getJobId()))
            .build();

    // don't set the back-off criteria, android-job is handling this

    WorkManager workManager = getWorkManager();
    if (workManager == null) {
        throw new JobProxyIllegalStateException("WorkManager is null");
    }

    workManager.enqueue(workRequest);
}
 
Example #6
Source File: JobProxyWorkManager.java    From android-job with Apache License 2.0 6 votes vote down vote up
@NonNull
private static NetworkType mapNetworkType(@NonNull JobRequest.NetworkType networkType) {
    switch (networkType) {
        case ANY:
            return NetworkType.NOT_REQUIRED;
        case METERED:
            return NetworkType.METERED;
        case CONNECTED:
            return NetworkType.CONNECTED;
        case UNMETERED:
            return NetworkType.UNMETERED;
        case NOT_ROAMING:
            return NetworkType.NOT_ROAMING;
        default:
            throw new IllegalStateException("Not implemented");
    }
}
 
Example #7
Source File: PlatformAlarmService.java    From android-job with Apache License 2.0 6 votes vote down vote up
static void runJob(@Nullable Intent intent, @NonNull Service service, @NonNull JobCat cat) {
    if (intent == null) {
        cat.i("Delivered intent is null");
        return;
    }

    int jobId = intent.getIntExtra(PlatformAlarmReceiver.EXTRA_JOB_ID, -1);
    Bundle transientExtras = intent.getBundleExtra(PlatformAlarmReceiver.EXTRA_TRANSIENT_EXTRAS);
    final JobProxy.Common common = new JobProxy.Common(service, cat, jobId);

    // create the JobManager. Seeing sometimes exceptions, that it wasn't created, yet.
    final JobRequest request = common.getPendingRequest(true, true);
    if (request != null) {
        common.executeJobRequest(request, transientExtras);
    }
}
 
Example #8
Source File: JobProxyGcm.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public void plantPeriodicFlexSupport(JobRequest request) {
    CAT.w("plantPeriodicFlexSupport called although flex is supported");

    long startMs = Common.getStartMsSupportFlex(request);
    long endMs = Common.getEndMsSupportFlex(request);

    OneoffTask task = prepareBuilder(new OneoffTask.Builder(), request)
            .setExecutionWindow(startMs / 1_000, endMs / 1_000)
            .build();

    scheduleTask(task);

    CAT.d("Scheduled periodic (flex support), %s, start %s, end %s, flex %s", request, JobUtil.timeToString(startMs),
            JobUtil.timeToString(endMs), JobUtil.timeToString(request.getFlexMs()));
}
 
Example #9
Source File: PlatformWorkManagerTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
private void testConstraints(JobRequest.Builder builder) {
    int jobId = builder
            .setRequiredNetworkType(JobRequest.NetworkType.METERED)
            .setRequiresBatteryNotLow(true)
            .setRequiresCharging(true)
            .setRequiresDeviceIdle(true)
            .setRequiresStorageNotLow(true)
            .build()
            .schedule();

    String tag = JobProxyWorkManager.createTag(jobId);
    List<WorkInfo> statuses = mWorkManagerRule.getWorkStatus(tag);

    assertThat(statuses).isNotNull().hasSize(1);
    assertThat(statuses.get(0).getState()).isEqualTo(WorkInfo.State.ENQUEUED);

    mWorkManagerRule.getManager().cancelAllForTag(TAG);
    assertThat(mWorkManagerRule.getWorkStatus(tag).get(0).getState()).isEqualTo(WorkInfo.State.CANCELLED);
}
 
Example #10
Source File: JobProxy14.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public void plantOneOff(JobRequest request) {
    PendingIntent pendingIntent = getPendingIntent(request, false);

    AlarmManager alarmManager = getAlarmManager();
    if (alarmManager == null) {
        return;
    }

    try {
        if (request.isExact()) {
            if (request.getStartMs() == 1 && request.getFailureCount() <= 0) {
                // this job should start immediately
                PlatformAlarmService.start(mContext, request.getJobId(), request.getTransientExtras());
            } else {
                plantOneOffExact(request, alarmManager, pendingIntent);
            }
        } else {
            plantOneOffInexact(request, alarmManager, pendingIntent);
        }
    } catch (Exception e) {
        // https://gist.github.com/vRallev/621b0b76a14ddde8691c
        mCat.e(e);
    }
}
 
Example #11
Source File: BackgroundTaskModule.java    From react-native-background-task with MIT License 6 votes vote down vote up
@Override
public void initialize() {
    Log.d(TAG, "Initializing");
    super.initialize();

    // Read in an existing scheduled job if there is one
    Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequests();
    if (jobRequests.size() > 1) {
        Log.w(TAG, "Found " + jobRequests.size() + " scheduled jobs, expecting 0 or 1");
    }
    if (!jobRequests.isEmpty()) {
        mJobRequest = jobRequests.iterator().next();
    }

    // Hook into lifecycle events so we can tell when the application is foregrounded
    ReactApplicationContext context = getReactApplicationContext();
    context.addLifecycleEventListener(this);
}
 
Example #12
Source File: AndroidJobStrategy.java    From cloudinary_android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void executeRequestsNow(int howMany) {
    int started = 0;
    for (JobRequest jobRequest : JobManager.instance().getAllJobRequests()) {
        if (isSoonButNotImmediate(jobRequest)) {
            JobRequest.Builder builder = jobRequest.cancelAndEdit();
            long endMillis = Math.max(jobRequest.getEndMs(), RUN_NOW_TIME_WINDOW_END);
            builder.setExecutionWindow(RUN_NOW_TIME_WINDOW_START, endMillis).build().schedule();
            started++;
        }

        if (started == howMany) {
            break;
        }
    }

    Logger.d(TAG, String.format("Job scheduled started %d requests.", started));
}
 
Example #13
Source File: TransientBundleCompat.java    From android-job with Apache License 2.0 6 votes vote down vote up
public static boolean startWithTransientBundle(@NonNull Context context, @NonNull JobRequest request) {
    // transientExtras are not necessary in this case
    Intent intent = PlatformAlarmServiceExact.createIntent(context, request.getJobId(), null);
    PendingIntent pendingIntent = PendingIntent.getService(context, request.getJobId(), intent, PendingIntent.FLAG_NO_CREATE);

    if (pendingIntent == null) {
        return false;
    }

    try {
        CAT.i("Delegating transient job %s to API 14", request);
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        CAT.e(e);
        return false;
    }

    if (!request.isPeriodic()) {
        cancel(context, request.getJobId(), pendingIntent);
    }

    return true;
}
 
Example #14
Source File: JobProxy21.java    From android-job with Apache License 2.0 6 votes vote down vote up
protected int convertNetworkType(@NonNull JobRequest.NetworkType networkType) {
    switch (networkType) {
        case ANY:
            return JobInfo.NETWORK_TYPE_NONE;
        case CONNECTED:
            return JobInfo.NETWORK_TYPE_ANY;
        case UNMETERED:
            return JobInfo.NETWORK_TYPE_UNMETERED;
        case NOT_ROAMING:
            return JobInfo.NETWORK_TYPE_UNMETERED; // use unmetered here, is overwritten in v24
        case METERED:
            return JobInfo.NETWORK_TYPE_ANY; // use any here as fallback
        default:
            throw new IllegalStateException("not implemented");
    }
}
 
Example #15
Source File: DeviceTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
public void testNetworkStateRoaming() {
    NetworkInfo networkInfo = mock(NetworkInfo.class);
    when(networkInfo.isConnected()).thenReturn(true);
    when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
    when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_MOBILE);
    when(networkInfo.isRoaming()).thenReturn(true);

    ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);

    Context context = mock(MockContext.class);
    when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);

    assertThat(Device.getNetworkType(context)).isEqualTo(JobRequest.NetworkType.CONNECTED);
}
 
Example #16
Source File: UnitTestDatabaseCreator.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public void createPeriodic() {
    for (int i = 0; i < 10; i++) {
        JobRequest.Builder builder = new JobRequest.Builder("tag")
                .setRequiresCharging(random())
                .setRequiresDeviceIdle(random())
                .setRequiredNetworkType(random() ? JobRequest.NetworkType.ANY : JobRequest.NetworkType.CONNECTED)
                .setRequirementsEnforced(random());

        if (random()) {
            PersistableBundleCompat extras = new PersistableBundleCompat();
            extras.putString("key", "Hello world");
            builder.setExtras(extras);
        }
        if (random()) {
            builder.setPeriodic(JobRequest.MIN_INTERVAL);
        } else {
            builder.setPeriodic(JobRequest.MIN_INTERVAL, JobRequest.MIN_FLEX);
        }

        builder.build().schedule();
    }
}
 
Example #17
Source File: PlatformWorkManagerTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransientExtras() {
    Bundle extras = new Bundle();
    extras.putInt("key", 5);

    JobRequest.Builder builder = new JobRequest.Builder(TAG)
            .setExecutionWindow(TimeUnit.HOURS.toMillis(4), TimeUnit.HOURS.toMillis(5))
            .setTransientExtras(extras);

    int jobId = builder.build().schedule();

    Bundle bundle = TransientBundleHolder.getBundle(jobId);
    assertThat(bundle).isNotNull();
    assertThat(bundle.getInt("key")).isEqualTo(5);

    mWorkManagerRule.getManager().cancel(jobId);
    assertThat(TransientBundleHolder.getBundle(jobId)).isNull();

    jobId = builder.build().schedule();
    mWorkManagerRule.runJob(JobProxyWorkManager.createTag(jobId));

    assertThat(TransientBundleHolder.getBundle(jobId)).isNull();
}
 
Example #18
Source File: DeviceTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
public void testNetworkStateMeteredNotRoaming() {
    NetworkInfo networkInfo = mock(NetworkInfo.class);
    when(networkInfo.isConnected()).thenReturn(true);
    when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
    when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_MOBILE);
    when(networkInfo.isRoaming()).thenReturn(false);

    ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);

    Context context = mock(MockContext.class);
    when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);

    assertThat(Device.getNetworkType(context)).isEqualTo(JobRequest.NetworkType.NOT_ROAMING);
}
 
Example #19
Source File: JobProxy21.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public void plantOneOff(JobRequest request) {
    long startMs = Common.getStartMs(request);
    long endMs = Common.getEndMs(request, true);

    JobInfo jobInfo = createBuilderOneOff(createBaseBuilder(request, true), startMs, endMs).build();
    int scheduleResult = schedule(jobInfo);

    if (scheduleResult == ERROR_BOOT_PERMISSION) {
        jobInfo = createBuilderOneOff(createBaseBuilder(request, false), startMs, endMs).build();
        scheduleResult = schedule(jobInfo);
    }

    mCat.d("Schedule one-off jobInfo %s, %s, start %s, end %s (from now), reschedule count %d", scheduleResultToString(scheduleResult),
            request, JobUtil.timeToString(startMs), JobUtil.timeToString(Common.getEndMs(request, false)), Common.getRescheduleCount(request));
}
 
Example #20
Source File: JobProxy21.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public void plantPeriodic(JobRequest request) {
    long intervalMs = request.getIntervalMs();
    long flexMs = request.getFlexMs();

    JobInfo jobInfo = createBuilderPeriodic(createBaseBuilder(request, true), intervalMs, flexMs).build();
    int scheduleResult = schedule(jobInfo);

    if (scheduleResult == ERROR_BOOT_PERMISSION) {
        jobInfo = createBuilderPeriodic(createBaseBuilder(request, false), intervalMs, flexMs).build();
        scheduleResult = schedule(jobInfo);
    }

    mCat.d("Schedule periodic jobInfo %s, %s, interval %s, flex %s", scheduleResultToString(scheduleResult),
            request, JobUtil.timeToString(intervalMs), JobUtil.timeToString(flexMs));
}
 
Example #21
Source File: JobProxy21.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Override
public void plantPeriodicFlexSupport(JobRequest request) {
    long startMs = Common.getStartMsSupportFlex(request);
    long endMs = Common.getEndMsSupportFlex(request);

    JobInfo jobInfo = createBuilderOneOff(createBaseBuilder(request, true), startMs, endMs).build();
    int scheduleResult = schedule(jobInfo);

    if (scheduleResult == ERROR_BOOT_PERMISSION) {
        jobInfo = createBuilderOneOff(createBaseBuilder(request, false), startMs, endMs).build();
        scheduleResult = schedule(jobInfo);
    }

    mCat.d("Schedule periodic (flex support) jobInfo %s, %s, start %s, end %s, flex %s", scheduleResultToString(scheduleResult),
            request, JobUtil.timeToString(startMs), JobUtil.timeToString(endMs), JobUtil.timeToString(request.getFlexMs()));
}
 
Example #22
Source File: JobProxy19.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Override
protected void plantOneOffFlexSupport(JobRequest request, AlarmManager alarmManager, PendingIntent pendingIntent) {
    long currentTime = System.currentTimeMillis();
    long startMs = currentTime + Common.getStartMsSupportFlex(request);
    long lengthMs = Common.getEndMsSupportFlex(request) - Common.getStartMsSupportFlex(request);

    alarmManager.setWindow(AlarmManager.RTC, startMs, lengthMs, pendingIntent);

    mCat.d("Scheduled repeating alarm (flex support), %s, start %s, end %s, flex %s", request,
            JobUtil.timeToString(Common.getStartMsSupportFlex(request)), JobUtil.timeToString(Common.getEndMsSupportFlex(request)),
            JobUtil.timeToString(request.getFlexMs()));
}
 
Example #23
Source File: TransientBundleCompat.java    From android-job with Apache License 2.0 5 votes vote down vote up
public static void persistBundle(@NonNull Context context, @NonNull JobRequest request) {
    Intent intent = PlatformAlarmServiceExact.createIntent(context, request.getJobId(), request.getTransientExtras());
    PendingIntent pendingIntent = PendingIntent.getService(context, request.getJobId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

    long when = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1000);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.setExact(AlarmManager.RTC, when, pendingIntent);
}
 
Example #24
Source File: Device.java    From android-job with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the network condition of the device and returns the best type. If the device
 * is connected to a WiFi and mobile network at the same time, then it would assume
 * that the connection is unmetered because of the WiFi connection.
 *
 * @param context Any context, e.g. the application context.
 * @return The current network type of the device.
 */
@NonNull
@SuppressWarnings("deprecation")
public static JobRequest.NetworkType getNetworkType(@NonNull Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo;
    try {
        networkInfo = connectivityManager.getActiveNetworkInfo();
    } catch (Throwable t) {
        return JobRequest.NetworkType.ANY;
    }

    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        return JobRequest.NetworkType.ANY;
    }

    boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager);
    if (!metered) {
        return JobRequest.NetworkType.UNMETERED;
    }

    if (isRoaming(connectivityManager, networkInfo)) {
        return JobRequest.NetworkType.CONNECTED;
    } else {
        return JobRequest.NetworkType.NOT_ROAMING;
    }
}
 
Example #25
Source File: JobProxyGcm.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Override
public void plantPeriodic(JobRequest request) {
    PeriodicTask task = prepareBuilder(new PeriodicTask.Builder(), request)
            .setPeriod(request.getIntervalMs() / 1_000)
            .setFlex(request.getFlexMs() / 1_000)
            .build();

    scheduleTask(task);

    CAT.d("Scheduled PeriodicTask, %s, interval %s, flex %s", request, JobUtil.timeToString(request.getIntervalMs()),
            JobUtil.timeToString(request.getFlexMs()));
}
 
Example #26
Source File: JobProxy21.java    From android-job with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #27
Source File: DeviceTest.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Test
public void testNetworkStateVpn() {
    NetworkInfo networkInfo = mock(NetworkInfo.class);
    when(networkInfo.isConnected()).thenReturn(true);
    when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
    when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_VPN);

    ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
    when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);

    Context context = mock(MockContext.class);
    when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);

    assertThat(Device.getNetworkType(context)).isEqualTo(JobRequest.NetworkType.NOT_ROAMING);
}
 
Example #28
Source File: JobProxyWorkManager.java    From android-job with Apache License 2.0 5 votes vote down vote up
private static Constraints buildConstraints(JobRequest request) {
    Constraints.Builder constraintsBuilder = new Constraints.Builder()
            .setRequiresBatteryNotLow(request.requiresBatteryNotLow())
            .setRequiresCharging(request.requiresCharging())
            .setRequiresStorageNotLow(request.requiresStorageNotLow())
            .setRequiredNetworkType(mapNetworkType(request.requiredNetworkType()));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        constraintsBuilder.setRequiresDeviceIdle(request.requiresDeviceIdle());
    }

    return constraintsBuilder.build();
}
 
Example #29
Source File: JobProxy21.java    From android-job with Apache License 2.0 5 votes vote down vote up
protected JobInfo.Builder createBaseBuilder(JobRequest request, boolean allowPersisting) {
    JobInfo.Builder builder = new JobInfo.Builder(request.getJobId(), new ComponentName(mContext, PlatformJobService.class))
            .setRequiresCharging(request.requiresCharging())
            .setRequiresDeviceIdle(request.requiresDeviceIdle())
            .setRequiredNetworkType(convertNetworkType(request.requiredNetworkType()))
            .setPersisted(allowPersisting && !request.isTransient() && JobUtil.hasBootPermission(mContext));

    return setTransientBundle(request, builder);
}
 
Example #30
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");
    }
}