Browse Source

Update Android job

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
d12af2a342

+ 3 - 3
build.gradle

@@ -30,7 +30,7 @@ configurations.all {
 }
 
 ext {
-    supportLibraryVersion = '25.4.0'
+    supportLibraryVersion = '26.0.1'
     googleLibraryVersion = '11.2.2'
 
     travisBuild = System.getenv("TRAVIS") == "true"
@@ -64,7 +64,7 @@ android {
         javaMaxHeapSize "4g"
     }
 
-    compileSdkVersion 25
+    compileSdkVersion 26
     buildToolsVersion '26.0.2'
 
     defaultConfig {
@@ -205,7 +205,7 @@ dependencies {
     implementation 'com.github.albfernandez:juniversalchardet:v2.0.0'
     implementation 'com.google.code.findbugs:annotations:2.0.1'
     implementation 'commons-io:commons-io:2.5'
-    implementation 'com.github.evernote:android-job:v1.1.11'
+    implementation 'com.github.evernote:android-job:v1.2.0'
     implementation 'com.jakewharton:butterknife:8.5.1'
     annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
     implementation 'org.greenrobot:eventbus:3.0.0'

+ 18 - 0
src/main/java/com/owncloud/android/MainApp.java

@@ -20,6 +20,7 @@
 package com.owncloud.android;
 
 import android.Manifest;
+import android.accounts.Account;
 import android.app.Activity;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -38,7 +39,9 @@ import android.support.v7.app.AlertDialog;
 import android.view.WindowManager;
 
 import com.evernote.android.job.JobManager;
+import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.PassCodeManager;
+import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.MediaFolder;
 import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.MediaProvider;
@@ -50,6 +53,7 @@ import com.owncloud.android.jobs.NCJobCreator;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
 import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.ui.activity.ContactsPreferenceActivity;
 import com.owncloud.android.ui.activity.Preferences;
 import com.owncloud.android.ui.activity.SyncedFoldersActivity;
 import com.owncloud.android.ui.activity.WhatsNewActivity;
@@ -66,6 +70,8 @@ import java.util.Map;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
+import static com.owncloud.android.ui.activity.ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP;
+
 
 /**
  * Main Application of the project
@@ -139,6 +145,7 @@ public class MainApp extends MultiDexApplication {
         }
 
         initAutoUpload();
+        initContactsBackup();
 
         // register global protection with pass code
         registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@@ -184,6 +191,17 @@ public class MainApp extends MultiDexApplication {
         });
     }
 
+    public static void initContactsBackup() {
+        ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver());
+        Account[] accounts = AccountUtils.getAccounts(mContext);
+
+        for (Account account : accounts) {
+            if (arbitraryDataProvider.getBooleanValue(account, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)) {
+                ContactsPreferenceActivity.startContactBackupJob(account);
+            }
+        }
+
+    }
     public static void initAutoUpload() {
         updateToAutoUpload();
         cleanOldEntries();

+ 1 - 0
src/main/java/com/owncloud/android/files/BootupBroadcastReceiver.java

@@ -53,6 +53,7 @@ public class BootupBroadcastReceiver extends BroadcastReceiver {
         context.startService(initObservers);
 
         MainApp.initAutoUpload();
+        MainApp.initContactsBackup();
     }
 
 }

+ 2 - 4
src/main/java/com/owncloud/android/jobs/NContentObserverJob.java

@@ -31,8 +31,6 @@ import com.evernote.android.job.util.support.PersistableBundleCompat;
 import com.owncloud.android.utils.FilesSyncHelper;
 import com.owncloud.android.utils.UploadUtils;
 
-import java.util.concurrent.TimeUnit;
-
 /*
     Job that triggers new FilesSyncJob in case new photo or video were detected
  */
@@ -51,8 +49,8 @@ public class NContentObserverJob extends JobService {
                 persistableBundleCompat.putBoolean(FilesSyncJob.SKIP_CUSTOM, true);
 
                 new JobRequest.Builder(FilesSyncJob.TAG)
-                        .setExecutionWindow(1, TimeUnit.SECONDS.toMillis(2))
-                        .setBackoffCriteria(TimeUnit.SECONDS.toMillis(5), JobRequest.BackoffPolicy.LINEAR)
+                        .addExtras(persistableBundleCompat)
+                        .startNow()
                         .setExtras(persistableBundleCompat)
                         .setUpdateCurrent(false)
                         .build()

+ 0 - 1
src/main/java/com/owncloud/android/ui/activity/ContactsPreferenceActivity.java

@@ -116,7 +116,6 @@ public class ContactsPreferenceActivity extends FileActivity implements FileFrag
         new JobRequest.Builder(ContactsBackupJob.TAG)
                 .setExtras(bundle)
                 .setRequiresCharging(false)
-                .setPersisted(true)
                 .setUpdateCurrent(true)
                 .setPeriodic(24 * 60 * 60 * 1000)
                 .build()

+ 1 - 2
src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java

@@ -420,9 +420,8 @@ public class ManageAccountsActivity extends FileActivity
         bundle.putString(AccountRemovalJob.ACCOUNT, account.name);
 
         new JobRequest.Builder(AccountRemovalJob.TAG)
-                .setExecutionWindow(1_000L, 10_000L)
+                .startNow()
                 .setExtras(bundle)
-                .setPersisted(false)
                 .setUpdateCurrent(false)
                 .build()
                 .schedule();

+ 1 - 2
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactListFragment.java

@@ -357,9 +357,8 @@ public class ContactListFragment extends FileFragment {
 
         new JobRequest.Builder(ContactsImportJob.TAG)
                 .setExtras(bundle)
-                .setExecutionWindow(3_000L, 10_000L)
+                .startNow()
                 .setRequiresCharging(false)
-                .setPersisted(false)
                 .setUpdateCurrent(false)
                 .build()
                 .schedule();

+ 1 - 2
src/main/java/com/owncloud/android/ui/fragment/contactsbackup/ContactsBackupFragment.java

@@ -315,9 +315,8 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
 
         new JobRequest.Builder(ContactsBackupJob.TAG)
                 .setExtras(bundle)
-                .setExecutionWindow(3_000L, 10_000L)
+                .startNow()
                 .setRequiresCharging(false)
-                .setPersisted(false)
                 .setUpdateCurrent(false)
                 .build()
                 .schedule();