@@ -52,42 +52,46 @@ public class BackupJobs {
5252 private static final int BOOT_BACKUP_DELAY = 60 ;
5353 private static final String CONTENT_TRIGGER_TAG = "contentTrigger" ;
5454
55- private final Preferences mPreferences ;
55+ private final Preferences preferences ;
5656 private FirebaseJobDispatcher firebaseJobDispatcher ;
5757
5858 public BackupJobs (Context context ) {
5959 this (context , new Preferences (context ));
6060 }
6161
6262 BackupJobs (Context context , Preferences preferences ) {
63- mPreferences = preferences ;
63+ this . preferences = preferences ;
6464 firebaseJobDispatcher = new FirebaseJobDispatcher (
65- mPreferences .isUseOldScheduler () ?
65+ this . preferences .isUseOldScheduler () ?
6666 new AlarmManagerDriver (context ) :
6767 new GooglePlayDriver (context ));
6868 }
6969
7070 public Job scheduleIncoming () {
71- return schedule (mPreferences .getIncomingTimeoutSecs (), INCOMING , false );
71+ return schedule (preferences .getIncomingTimeoutSecs (), INCOMING , false );
7272 }
7373
7474 public Job scheduleRegular () {
75- return schedule (mPreferences .getRegularTimeoutSecs (), REGULAR , false );
75+ return schedule (preferences .getRegularTimeoutSecs (), REGULAR , false );
7676 }
7777
7878 public Job scheduleContentTriggerJob () {
7979 return schedule (createContentUriTriggerJob ());
8080 }
8181
8282 public Job scheduleBootup () {
83- if (mPreferences .isUseOldScheduler ()) {
83+ if (!preferences .isEnableAutoSync ()) {
84+ Log .d (TAG , "auto backup no longer enabled, canceling all jobs" );
85+ cancelAll ();
86+ return null ;
87+ } else if (preferences .isUseOldScheduler ()) {
8488 return schedule (BOOT_BACKUP_DELAY , REGULAR , false );
8589 } else {
8690 if (LOCAL_LOGV ) {
8791 Log .v (TAG , "not scheduling bootup backup (using new scheduler)" );
8892 }
89- // assume jobs are persistent
90- return null ;
93+ // assume regular jobs are persistent
94+ return scheduleContentTriggerJob () ;
9195 }
9296 }
9397
@@ -124,7 +128,7 @@ private void cancel(String tag) {
124128 Log .v (TAG , "scheduleBackup(" + inSeconds + ", " + backupType + ", " + force + ")" );
125129 }
126130
127- if (force || (mPreferences .isEnableAutoSync () && inSeconds > 0 )) {
131+ if (force || (preferences .isEnableAutoSync () && inSeconds > 0 )) {
128132 final Job job = createJob (inSeconds , backupType );
129133 if (schedule (job ) != null ) {
130134 if (LOCAL_LOGV ) {
@@ -152,15 +156,15 @@ private Job schedule(Job job) {
152156 }
153157 }
154158
155- @ NonNull private Job createJob (int inSeconds , BackupType backupType ) {
159+ private @ NonNull Job createJob (int inSeconds , BackupType backupType ) {
156160 return createBuilder (backupType )
157161 .setTrigger (inSeconds <= 0 ? NOW : Trigger .executionWindow (inSeconds , inSeconds ))
158162 .setRecurring (backupType .isRecurring ())
159163 .setLifetime (backupType .isRecurring () ? FOREVER : UNTIL_NEXT_BOOT )
160164 .build ();
161165 }
162166
163- @ NonNull private Job createContentUriTriggerJob () {
167+ private @ NonNull Job createContentUriTriggerJob () {
164168 final ObservedUri observedUri = new ObservedUri (SMS_PROVIDER , FLAG_NOTIFY_FOR_DESCENDANTS );
165169 final JobTrigger trigger = Trigger .contentUriTrigger (Collections .singletonList (observedUri ));
166170 return createBuilder (INCOMING )
@@ -171,15 +175,15 @@ private Job schedule(Job job) {
171175 .build ();
172176 }
173177
174- private Job .Builder createBuilder (BackupType backupType ) {
178+ private @ NonNull Job .Builder createBuilder (BackupType backupType ) {
175179 final Bundle extras = new Bundle ();
176180 extras .putString (BackupType .EXTRA , backupType .name ());
177181 return firebaseJobDispatcher .newJobBuilder ()
178182 .setReplaceCurrent (true )
179183 .setService (SmsJobService .class )
180184 .setExtras (extras )
181185 .setTag (backupType .name ())
182- .setConstraints (mPreferences .isWifiOnly () ? ON_UNMETERED_NETWORK : ON_ANY_NETWORK )
186+ .setConstraints (preferences .isWifiOnly () ? ON_UNMETERED_NETWORK : ON_ANY_NETWORK )
183187 .setRetryStrategy (DEFAULT_EXPONENTIAL );
184188 }
185189}
0 commit comments