Skip to content

Conversation

@ezaquarii
Copy link
Collaborator

@ezaquarii ezaquarii commented Feb 17, 2020

@tobiasKaminsky @AndyScherzinger @mario This is still WIP but a review would be handy nevertheless.

This is rather big PR containing contacts backup job migration to new androidx.work.WorkerManager. To migrate it, I had to implement some missing infrastructure, hence the scope of this PR is much larger than I intitially anticipated. To make matters more interesting, it will get bigger (see last 2 sections).

New abstraction over WorkManager

BackgroundJobManager is our application-specific abstraction, exposing business-specific API to control running jobs. It hides all job handling machinery behind a very goal-oriented, verb-based API.

Important difference between old job manager API is that all WorkManager API is asynchronous. Exposed API is based on Java Future primitive and LiveData<T>. New semantics make some operations more tricky and porting of previously synchronous code needs some thinking, but no problems has been spotted so far.

One limitation of WorkManager API is that it does not provide elegant way of storing job metadata - like the previously used com.evernote.android.job.JobRequest.getExtras() - and provides onlylimited API in form of Set<String> WorkInfo.getTags(). The missing functionality has been implemented in as JobInfo abstraction that replaces WorkInfo. JobInfo is created by parsing tags stored in WorkInfo. Type translation is handled by the BackgroundJobManagerImpl and those complexities are not visible for the end user of our API.

Observable collection of all jobs is exposed using LiveData<T> interface, so it should play nice with the UI code.

ETM Screen

Background Jobs

Viewing current background job status is quite important do debug any potential issues, so I added EtmBackgroundJobsFragment with a list of all registered jobs and handy menu where we can dump development actions. It currently allows us to cancel all tasks and toggle TestJob that demonstrates progress indicator and is used to experiment with platform API.

Migrations

This PR provies a small screen with migrations status. It lists migrations and allows to clear migrations status. This function can be very useful when creating new migrations.

BackupContactsJob

Old code has been copied almost verbatim from old job class, with some minor tweaks around dependencies and few cleanups. There is no unit test for it, but it seems to work ok.

ContentObserverWork

Yikes! We have a bug in our current manager implementation and the observer job is added to the queue each time the app starts, which means that users are accumulating those jobs in their queues. This is not a big deal, but might eat up resources. Since the ContentObserverWork only starts legacy job implementation, the damange is contained.

This issue is addressed and the observer job is started only once.

Old job is cleared.

User.nameEquals

Extended user API with account name equality check, as we need to do a log of String comparisions.

Missing things

@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii ezaquarii changed the title Migrate contacts backup job to new background job manager API [WIP] ]Migrate contacts backup job to new background job manager API Feb 17, 2020
@tobiasKaminsky
Copy link
Member

tobiasKaminsky commented Feb 17, 2020

Wow, this is big, a bit too big… ;-)

Let me first answer your post

New abstraction looks very very good!
Same goes for ETM, which is really a big win for testing/RC phase.

Lombok:
This seems to be only for modificationTimestamp needed, or? So to avoid a (for other confusing) helper class, we could write explicitly boilerplate code.
If we see that a class is getting too much boilerplate code, we should migrate it to Kotlin.
(as far as I understand, this would solve the problem, or?)

Testing:
I hesitate to add in this PR Robolectric. What about using regular androidTests here and in a later PR we can introduce/test Robolectric?
(maybe we can then also move already existing instrumentation tests, which then speeds overall test duration)

Migration:
I fail to see what account migration has to do with job management? Sorry, if I miss the obvious :-)

EDIT: I will start reviewing it after rebasing

@ezaquarii ezaquarii force-pushed the ezaquarii/migrate-contacts-backup-job-to-worker-api branch 3 times, most recently from 792ef79 to 12105e9 Compare February 17, 2020 18:35
@nextcloud-android-bot
Copy link
Collaborator

Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii ezaquarii force-pushed the ezaquarii/migrate-contacts-backup-job-to-worker-api branch 2 times, most recently from 0dbbb33 to 6ae080f Compare February 17, 2020 18:47
@codecov
Copy link

codecov bot commented Feb 17, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@48d0249). Click here to learn what that means.
The diff coverage is 9.04%.

@@            Coverage Diff            @@
##             master    #5482   +/-   ##
=========================================
  Coverage          ?   21.85%           
  Complexity        ?        3           
=========================================
  Files             ?      405           
  Lines             ?    33794           
  Branches          ?     4741           
=========================================
  Hits              ?     7386           
  Misses            ?    25217           
  Partials          ?     1191
Impacted Files Coverage Δ Complexity Δ
...ndroid/ui/activity/ContactsPreferenceActivity.java 0% <ø> (ø) 0 <0> (?)
...java/com/nextcloud/client/di/ComponentsModule.java 0% <ø> (ø) 0 <0> (?)
...va/com/nextcloud/client/jobs/ContactsBackupWork.kt 0% <0%> (ø) 0 <0> (?)
...xtcloud/client/migrations/MigrationsManagerImpl.kt 0% <0%> (ø) 0 <0> (?)
.../com/nextcloud/client/migrations/MigrationError.kt 0% <0%> (ø) 0 <0> (?)
...java/com/nextcloud/client/appinfo/AppInfoImpl.java 18.18% <0%> (ø) 0 <0> (?)
...wncloud/android/files/BootupBroadcastReceiver.java 0% <0%> (ø) 0 <0> (?)
src/main/java/com/nextcloud/client/jobs/JobInfo.kt 0% <0%> (ø) 0 <0> (?)
.../com/nextcloud/client/jobs/BackgroundJobFactory.kt 53.84% <0%> (ø) 0 <0> (?)
...ragment/contactsbackup/ContactsBackupFragment.java 0% <0%> (ø) 0 <0> (?)
... and 12 more

@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii ezaquarii force-pushed the ezaquarii/migrate-contacts-backup-job-to-worker-api branch from 6ae080f to 17b23b6 Compare February 17, 2020 19:39
@nextcloud-android-bot
Copy link
Collaborator

Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii ezaquarii force-pushed the ezaquarii/migrate-contacts-backup-job-to-worker-api branch 2 times, most recently from 04501fb to 0dc6ef2 Compare February 18, 2020 01:12
@ezaquarii
Copy link
Collaborator Author

@tobiasKaminsky I fixed lint and rebased.

Robolectric is still enabled in this branch until I finish the implementation. I'll remove it at later stage.

@ezaquarii
Copy link
Collaborator Author

ezaquarii commented Feb 19, 2020 via email

@AndyScherzinger
Copy link
Member

We should be fine with adding new strings imho.

They get pushed to transifex and for the languages that are very actively maintained the translations come in quite quickly.

@ezaquarii
Copy link
Collaborator Author

ezaquarii commented Feb 19, 2020 via email

@ezaquarii ezaquarii force-pushed the ezaquarii/migrate-contacts-backup-job-to-worker-api branch from 0dc6ef2 to 69a0ecb Compare February 24, 2020 06:08
@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/13072.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

705

Lint

TypemasterPR
Warnings9696
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/13073.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

705

Lint

TypemasterPR
Warnings9696
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/13074.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

705

Lint

TypemasterPR
Warnings9696
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

@nextcloud-android-bot
Copy link
Collaborator

Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@nextcloud-android-bot
Copy link
Collaborator

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
@ezaquarii ezaquarii force-pushed the ezaquarii/migrate-contacts-backup-job-to-worker-api branch from 7bf8b23 to 500fdb9 Compare March 11, 2020 23:17
@nextcloud-android-bot
Copy link
Collaborator

Codacy Here is an overview of what got changed by this pull request:

Complexity decreasing per file
==============================
+ src/main/java/com/owncloud/android/jobs/NCJobCreator.java  -1
         

See the complete overview on Codacy

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/13075.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

705

Lint

TypemasterPR
Warnings9696
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

@nextcloud-android-bot
Copy link
Collaborator

Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@nextcloud-android-bot
Copy link
Collaborator

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/13077.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

705

Lint

TypemasterPR
Warnings9696
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

@nextcloud-android-bot
Copy link
Collaborator

Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@nextcloud-android-bot
Copy link
Collaborator

@ezaquarii
Copy link
Collaborator Author

ezaquarii commented Mar 12, 2020

@tobiasKaminsky This is ready for final review.

Screenshot tests are failing. The trouble is that those tests are failing 100% if time and I'm pretty sure it's not my code.

I know the flakiness is a challenge. Can we revisit this solution and think about some kind of compromise that won't impect the daily development process?

@nextcloud-android-bot
Copy link
Collaborator

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/13097.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@nextcloud-android-bot
Copy link
Collaborator

Codacy

375

Lint

TypemasterPR
Warnings9696
Errors00

SpotBugs (new)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

SpotBugs (master)

Warning TypeNumber
Bad practice Warnings26
Correctness Warnings70
Internationalization Warnings13
Malicious code vulnerability Warnings5
Multithreaded correctness Warnings9
Performance Warnings77
Security Warnings44
Dodgy code Warnings141
Total385

@nextcloud-android-bot
Copy link
Collaborator

@tobiasKaminsky
Copy link
Member

Wow!
This is really really great.

@tobiasKaminsky tobiasKaminsky merged commit e1b0b52 into master Mar 12, 2020
@delete-merged-branch delete-merged-branch bot deleted the ezaquarii/migrate-contacts-backup-job-to-worker-api branch March 12, 2020 13:34
@tobiasKaminsky
Copy link
Member

2020-03-12-143406

The trash bin should be tinted, but I merged it so that I do not delay further work :-)

@AndyScherzinger AndyScherzinger added this to the Nextcloud App 3.12.0 milestone Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants