-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: convert jobscheduler to work manager #360
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes looks good. Will wait for the new build to test this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. Update headers in all the edited files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix is great. I see a lot of old messes cleaned up.
See my comments for changes suggestion.
@@ -82,23 +85,14 @@ public void onReceive(Context context, Intent intent) { | |||
void reschedule(@NonNull Context context, @NonNull Intent broadcastIntent, @NonNull Intent eventServiceIntent, @NonNull ServiceScheduler serviceScheduler) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove serviceScheduler param, not used here.
logger.info("Preemptively flushing events since wifi became available"); | ||
} | ||
} | ||
} else if (broadcastIntent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to add WIFI_STATE_CHANGED into intent-filters in AndroidManifest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I, it is registered through register service api in app (look at splash application)
@@ -90,15 +90,18 @@ public void onReceive(Context context, Intent intent) { | |||
this.logger = logger; | |||
} | |||
|
|||
void dispatch(Intent intent) { | |||
void dispatch() { | |||
List<DatafileConfig> datafileConfigs = backgroundWatchersCache.getWatchingDatafileConfigs(); | |||
|
|||
for (DatafileConfig datafileConfig : datafileConfigs) { | |||
// for scheduled jobs Android O and above, we use the JobScheduler and persistent periodic jobs | |||
// so, we don't need to do anything. | |||
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need extra support for old versions? WorkManager is supposed to take care of it even for old versions. We can completely remove this rescheduler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does handle alarm and job scheduler (old and new). No it cannot be removed, in cases of a reboot or reload the datafile rescheduler is needed because jobs are not consistent.
...handler/src/main/java/com/optimizely/ab/android/datafile_handler/DefaultDatafileHandler.java
Outdated
Show resolved
Hide resolved
...handler/src/main/java/com/optimizely/ab/android/datafile_handler/DefaultDatafileHandler.java
Outdated
Show resolved
Hide resolved
...handler/src/main/java/com/optimizely/ab/android/datafile_handler/DefaultDatafileHandler.java
Outdated
Show resolved
Hide resolved
datafile-handler/src/main/java/com/optimizely/ab/android/datafile_handler/DatafileWorker.java
Outdated
Show resolved
Hide resolved
// with the new Android O differences, you need to register the service for the intent filter you desire in code instead of | ||
// in the manifest. | ||
val eventRescheduler = EventRescheduler() | ||
applicationContext.registerReceiver(eventRescheduler, IntentFilter(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) | ||
applicationContext.registerReceiver(eventRescheduler, IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to AndroidManifest "intent-filter" of EventRescheduler like other intents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that has been deprecated. You use register receiver.
workRequestBuilder.setBackoffCriteria( | ||
BackoffPolicy.LINEAR, | ||
retryInterval * 1000, | ||
TimeUnit.MILLISECONDS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this going to retry forever? There should be a way to set the max retries like 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is up to the worker. The event worker allows for the backoff policy to continue. It should retry until sent. Otherwise, they may never get sent.
Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com>
…ile_handler/DefaultDatafileHandler.java Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com>
…ile_handler/DefaultDatafileHandler.java Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I updated the proper headers
Summary
Test plan
Issues