Skip to content
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

Merged
merged 14 commits into from
Feb 24, 2021
Merged

Conversation

thomaszurkan-optimizely
Copy link
Contributor

@thomaszurkan-optimizely thomaszurkan-optimizely commented Feb 2, 2021

Summary

Test plan

  • Tests are all passing
  • Some tests can be removed with the deprecated APIs/classes

Issues

Copy link

@prasannarupan prasannarupan left a 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.

Copy link
Contributor

@mnoman09 mnoman09 left a 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.

Copy link
Contributor

@jaeopt jaeopt left a 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.

datafile-handler/build.gradle Outdated Show resolved Hide resolved
datafile-handler/src/main/AndroidManifest.xml Outdated Show resolved Hide resolved
@@ -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) {
Copy link
Contributor

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)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines 49 to +52
// 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))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +79 to +82
workRequestBuilder.setBackoffCriteria(
BackoffPolicy.LINEAR,
retryInterval * 1000,
TimeUnit.MILLISECONDS);
Copy link
Contributor

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?

Copy link
Contributor Author

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>
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomaszurkan-optimizely thomaszurkan-optimizely dismissed mnoman09’s stale review February 24, 2021 20:05

I updated the proper headers

@thomaszurkan-optimizely thomaszurkan-optimizely merged commit 790e1de into master Feb 24, 2021
@thomaszurkan-optimizely thomaszurkan-optimizely deleted the workManager branch February 24, 2021 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants