use of com.evernote.android.job.util.support.PersistableBundleCompat in project android by nextcloud.
the class NCFirebaseMessagingService method onMessageReceived.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData() != null) {
PersistableBundleCompat persistableBundleCompat = new PersistableBundleCompat();
persistableBundleCompat.putString(NotificationJob.KEY_NOTIFICATION_SUBJECT, remoteMessage.getData().get(NotificationJob.KEY_NOTIFICATION_SUBJECT));
persistableBundleCompat.putString(NotificationJob.KEY_NOTIFICATION_SIGNATURE, remoteMessage.getData().get(NotificationJob.KEY_NOTIFICATION_SIGNATURE));
new JobRequest.Builder(NotificationJob.TAG).addExtras(persistableBundleCompat).setUpdateCurrent(false).startNow().build().schedule();
}
}
use of com.evernote.android.job.util.support.PersistableBundleCompat in project android-job by evernote.
the class JobRequestTest method testSimpleJob.
@Test
public void testSimpleJob() {
JobRequest request = getBuilder().setExecutionWindow(2_000L, 3_000L).setBackoffCriteria(4_000, JobRequest.BackoffPolicy.LINEAR).setExtras(new PersistableBundleCompat()).setPersisted(true).build();
assertThat(request.getJobId()).isGreaterThan(0);
assertThat(request.getTag()).isEqualTo(TestJob.TAG);
assertThat(request.getStartMs()).isEqualTo(2_000L);
assertThat(request.getEndMs()).isEqualTo(3_000L);
assertThat(request.getBackoffMs()).isEqualTo(4_000L);
assertThat(request.getBackoffPolicy()).isEqualTo(JobRequest.BackoffPolicy.LINEAR);
assertThat(request.isPersisted()).isTrue();
assertThat(request.getExtras()).isNotNull();
assertThat(request.getIntervalMs()).isZero();
assertThat(request.isExact()).isFalse();
assertThat(request.isPeriodic()).isFalse();
assertThat(request.requiredNetworkType()).isEqualTo(JobRequest.DEFAULT_NETWORK_TYPE);
assertThat(request.requirementsEnforced()).isFalse();
assertThat(request.requiresCharging()).isFalse();
assertThat(request.requiresDeviceIdle()).isFalse();
}
use of com.evernote.android.job.util.support.PersistableBundleCompat in project android-job by evernote.
the class JobRequestTest method testPeriodic.
@Test
public void testPeriodic() {
long interval = JobRequest.MIN_INTERVAL * 5;
JobRequest request = getBuilder().setPeriodic(interval).setExtras(new PersistableBundleCompat()).setPersisted(true).build();
assertThat(request.getJobId()).isGreaterThan(0);
assertThat(request.getTag()).isEqualTo(TestJob.TAG);
assertThat(request.isPersisted()).isTrue();
assertThat(request.getIntervalMs()).isEqualTo(interval);
assertThat(request.getFlexMs()).isEqualTo(interval);
assertThat(request.isPeriodic()).isTrue();
assertThat(request.isFlexSupport()).isFalse();
assertThat(request.getStartMs()).isNegative();
assertThat(request.getEndMs()).isNegative();
assertThat(request.getBackoffMs()).isEqualTo(JobRequest.DEFAULT_BACKOFF_MS);
assertThat(request.getBackoffPolicy()).isEqualTo(JobRequest.DEFAULT_BACKOFF_POLICY);
assertThat(request.getExtras()).isNotNull();
assertThat(request.isExact()).isFalse();
assertThat(request.requiredNetworkType()).isEqualTo(JobRequest.DEFAULT_NETWORK_TYPE);
assertThat(request.requirementsEnforced()).isFalse();
assertThat(request.requiresCharging()).isFalse();
assertThat(request.requiresDeviceIdle()).isFalse();
}
use of com.evernote.android.job.util.support.PersistableBundleCompat in project android-job by evernote.
the class PersistableBundleCompatTest method testBundle.
@SuppressWarnings("ConstantConditions")
@Test
public void testBundle() {
PersistableBundleCompat bundle = new PersistableBundleCompat();
bundle.putBoolean("bool1", true);
bundle.putInt("int1", 1);
bundle.putLong("long1", 1L);
bundle.putDouble("double1", 1.0);
bundle.putString("string1", "hello");
bundle.putIntArray("intArr", new int[] { 1, 2, 3 });
bundle.putLongArray("longArr", new long[] { 4L, 5L, 6L });
bundle.putDoubleArray("doubleArr", new double[] { 7.0, 8.0, 9.0 });
bundle.putStringArray("stringArr", new String[] { "Hello", "world" });
PersistableBundleCompat other = new PersistableBundleCompat();
other.putString("string2", "world");
bundle.putPersistableBundleCompat("bundle1", other);
String xml = bundle.saveToXml();
PersistableBundleCompat inflated = PersistableBundleCompat.fromXml(xml);
assertThat(xml).isNotEmpty();
assertThat(inflated).isNotNull();
assertThat(inflated.getBoolean("bool1", false)).isTrue();
assertThat(inflated.getInt("int1", 0)).isEqualTo(1);
assertThat(inflated.getLong("long1", 0L)).isEqualTo(1L);
assertThat(inflated.getDouble("double1", 0.0)).isEqualTo(1.0);
assertThat(inflated.getString("string1", null)).isEqualTo("hello");
assertThat(inflated.getIntArray("intArr")).isNotEmpty().containsExactly(1, 2, 3);
assertThat(inflated.getLongArray("longArr")).isNotEmpty().containsExactly(4L, 5L, 6L);
assertThat(inflated.getDoubleArray("doubleArr")).isNotEmpty().containsExactly(7.0, 8.0, 9.0);
assertThat(inflated.getStringArray("stringArr")).isNotEmpty().containsExactly("Hello", "world");
PersistableBundleCompat inflatedInner = inflated.getPersistableBundleCompat("bundle1");
assertThat(inflatedInner).isNotNull();
assertThat(inflatedInner.getString("string2", null)).isEqualTo("world");
}
use of com.evernote.android.job.util.support.PersistableBundleCompat in project android-job by evernote.
the class PersistableBundleCompatTest method testNullInStringArray.
@Test
public void testNullInStringArray() {
PersistableBundleCompat bundle = new PersistableBundleCompat();
String[] array = { "111", null, "333" };
bundle.putStringArray("array", array);
bundle = PersistableBundleCompat.fromXml(bundle.saveToXml());
String[] inflated = bundle.getStringArray("array");
assertThat(inflated).isNotNull().hasSize(3).containsExactly("111", null, "333");
}
Aggregations