Search in sources :

Example 6 with PersistableBundleCompat

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();
    }
}
Also used : PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) JobRequest(com.evernote.android.job.JobRequest)

Example 7 with PersistableBundleCompat

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();
}
Also used : PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 8 with PersistableBundleCompat

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();
}
Also used : PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 9 with PersistableBundleCompat

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");
}
Also used : PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) SmallTest(android.support.test.filters.SmallTest) Test(org.junit.Test)

Example 10 with PersistableBundleCompat

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");
}
Also used : PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) SmallTest(android.support.test.filters.SmallTest) Test(org.junit.Test)

Aggregations

PersistableBundleCompat (com.evernote.android.job.util.support.PersistableBundleCompat)25 JobRequest (com.evernote.android.job.JobRequest)11 NonNull (android.support.annotation.NonNull)7 Context (android.content.Context)5 Account (android.accounts.Account)4 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)4 Test (org.junit.Test)4 Intent (android.content.Intent)3 File (java.io.File)3 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 LargeTest (android.support.test.filters.LargeTest)2 SmallTest (android.support.test.filters.SmallTest)2 FilesystemDataProvider (com.owncloud.android.datamodel.FilesystemDataProvider)2 SyncedFolder (com.owncloud.android.datamodel.SyncedFolder)2 SyncedFolderProvider (com.owncloud.android.datamodel.SyncedFolderProvider)2 FileUploader (com.owncloud.android.files.services.FileUploader)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 PrivateKey (java.security.PrivateKey)2