Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content

Use WorkManager API to schedule periodic sync

Vincent Bourgmayer requested to merge 7-issue-workmanagerAPI into 1-epic-refactoring-p1

Description

Include Jetpack's workManager API and replace JobScheduler by WorkRequest to schedule periodic sync. Also removes useless stuff like ScreenOffReceiver, etc.

Notes every commit until f79e5bb6 have already been reviewed and validated in previous MR (!74 (merged), !75 (merged), !76 (merged) and !77 (merged)) .

Issue(s)

closes https://gitlab.e.foundation/e/os/backlog/-/issues/1

Test environment

  • Root your device (App is now persistent, so it's Required) (adb root)
  • Download artifact from latest pipeline
  • Extract the release-unsigned APK
  • Sign the APK accordingly to your test devices (apksigner sign --key xxx.pk8 --cert xxx.x509.pem --out eDrive.apk xxxx.apk)
  • Manually push the signed APK on the device (adb remount then adb push eDrive.apk /system/app/eDrive/eDrive.apk)
  • Reboot the device. (adb reboot)
  • Register an /e/ account if no one is already registered.

example/help here

Test procedures

The validation of this MR is only about full scan triggering not file transfer success, or any other topics.

  • Turning off the screen doesn't trigger a full scan (remote files + local files) anymore
  • Full scan is still run every 31 minutes but from another component. Below is the list of conditions:
    • when battery is not low
    • Even after device reboot
    • when any kind of network is available
    • At least, one synchronization option (media or settings), in /e/ account settings, must be enabled. Test case
    • Device must be Idle to be able to start full scan

You can use:

  • adb logcat | grep 'ObserverService*' to see if full scan is started
Logcat example:
03-09 09:49:48.401  1861  1861 I ObserverService: onStartCommand(1)
03-09 09:49:48.401  1861  1861 D ObserverService: ServiceExceptionHandler already set!
03-09 09:49:48.413  1861  1861 I ObserverService: begin()
03-09 09:49:48.414  1861  1861 I ObserverService: clearCachedFile()
03-09 09:49:48.422  1861  1861 I ObserverService: deleteOldestCrashLogs()
03-09 09:49:48.428  1861  1861 D ObserverService: 0 old crashlogs file.s deleted
03-09 09:49:48.428  1861  1861 I ObserverService: startScan(true)
03-09 09:49:48.443  1861  1861 D ObserverService: SyncedFolder: libelle, localFolder, lastmodified, scanLocal, id :
03-09 09:49:48.443  1861  1861 D ObserverService: Images, /storage/emulated/0/DCIM/, 0, true, 1
03-09 09:49:48.443  1861  1861 D ObserverService: Images, /storage/emulated/0/Pictures/, 0, true, 2
03-09 09:49:48.443  1861  1861 D ObserverService: Movies, /storage/emulated/0/Movies/, 0, true, 3
03-09 09:49:48.443  1861  1861 D ObserverService: Music, /storage/emulated/0/Music/, 0, true, 4
03-09 09:49:48.443  1861  1861 D ObserverService: Ringtones, /storage/emulated/0/Ringtones/, 0, true, 5
03-09 09:49:48.443  1861  1861 D ObserverService: Documents, /storage/emulated/0/Documents/, 0, true, 6
03-09 09:49:48.443  1861  1861 D ObserverService: Podcasts, /storage/emulated/0/Podcasts/, 0, true, 7
03-09 09:49:48.443  1861  1861 D ObserverService: Rom settings, /data/system/users/0/, 0, true, 8
03-09 09:49:48.443  1861  1861 D ObserverService: Rom settings, /data/data/foundation.e.drive/files/, 0, true, 9
03-09 09:49:48.451  1861  1861 D ObserverService: Going to scan remote files
03-09 09:50:03.550  1861  1861 I ObserverService: onRemoteOperationFinish()
03-09 09:50:03.563  1861  1861 I ObserverService: handleRemoteFiles()
03-09 09:50:03.563  1861  1861 D ObserverService: start to loop through remoteFiles
03-09 09:50:03.563  1861  1861 D ObserverService: start to loop through syncedFileList for: /Documents/foundation.e.drive.beta-1-build-o-22-03-07T1452-debug.apk
03-09 09:50:03.563  1861  1861 V ObserverService: SyncedFileState corresponding to remoteFile not found.
03-09 09:50:03.581  1861  1861 I ObserverService: Add download operation for new file 1
03-09 09:50:03.585  1861  1861 V ObserverService: Start to handle remotly missing file
03-09 09:50:03.586  1861  1861 I ObserverService: handleRemoteRemainingSyncedFileState()
03-09 09:50:03.586  1861  1861 I ObserverService: startScan(false)
03-09 09:50:03.597  1861  1861 D ObserverService: SyncedFolder: libelle, localFolder, lastmodified, scanLocal, id :
03-09 09:50:03.597  1861  1861 D ObserverService: Images, /storage/emulated/0/DCIM/, 0, true, 1
03-09 09:50:03.597  1861  1861 D ObserverService: Images, /storage/emulated/0/Pictures/, 0, true, 2
03-09 09:50:03.597  1861  1861 D ObserverService: Movies, /storage/emulated/0/Movies/, 0, true, 3
03-09 09:50:03.597  1861  1861 D ObserverService: Music, /storage/emulated/0/Music/, 0, true, 4
03-09 09:50:03.597  1861  1861 D ObserverService: Ringtones, /storage/emulated/0/Ringtones/, 0, true, 5
03-09 09:50:03.597  1861  1861 D ObserverService: Documents, /storage/emulated/0/Documents/, 0, true, 6
03-09 09:50:03.597  1861  1861 D ObserverService: Podcasts, /storage/emulated/0/Podcasts/, 0, true, 7
03-09 09:50:03.597  1861  1861 D ObserverService: Rom settings, /data/system/users/0/, 0, true, 8
03-09 09:50:03.597  1861  1861 D ObserverService: Rom settings, /data/data/foundation.e.drive/files/, 0, true, 9
03-09 09:50:03.597  1861  1861 I ObserverService: scanLocalFiles()
03-09 09:50:03.598  1861  1861 I ObserverService: generateAppListFile()
03-09 09:50:03.671  1861  1861 D ObserverService: SyncedFolder :Images, /storage/emulated/0/DCIM/, 0, true, 1
03-09 09:50:03.672  1861  1861 D ObserverService: Local Folder (last modified / exists): 1646674190000, true
03-09 09:50:03.672  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.675  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.675  1861  1861 V ObserverService: subfile /storage/emulated/0/DCIM/OpenCamera is a directory.
03-09 09:50:03.676  1861  1861 D ObserverService: SyncedFolder :Images, /storage/emulated/0/DCIM/OpenCamera/, 0, true, -1
03-09 09:50:03.676  1861  1861 V ObserverService: This is a new folder, we must register it
03-09 09:50:03.696  1861  1861 V ObserverService: Folder has been registered in DB
03-09 09:50:03.697  1861  1861 D ObserverService: Local Folder (last modified / exists): 1646674180000, true
03-09 09:50:03.697  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.697  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.698  1861  1861 D ObserverService: SyncedFolder :Images, /storage/emulated/0/Pictures/, 0, true, 2
03-09 09:50:03.698  1861  1861 D ObserverService: Local Folder (last modified / exists): 1641220579000, true
03-09 09:50:03.698  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.699  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.699  1861  1861 V ObserverService: subfile /storage/emulated/0/Pictures/Screenshots is a directory.
03-09 09:50:03.699  1861  1861 D ObserverService: SyncedFolder :Images, /storage/emulated/0/Pictures/Screenshots/, 0, true, -1
03-09 09:50:03.699  1861  1861 V ObserverService: This is a new folder, we must register it
03-09 09:50:03.712  1861  1861 V ObserverService: Folder has been registered in DB
03-09 09:50:03.712  1861  1861 D ObserverService: Local Folder (last modified / exists): 1646760927000, true
03-09 09:50:03.713  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.713  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.714  1861  1861 V ObserverService: subfile /storage/emulated/0/Pictures/Screenshots/Screenshot_20220308-183527_Gallery.png is a file added to list of file to sync
03-09 09:50:03.714  1861  1861 D ObserverService: SyncedFolder :Movies, /storage/emulated/0/Movies/, 0, true, 3
03-09 09:50:03.714  1861  1861 D ObserverService: Local Folder (last modified / exists): 1641230457000, true
03-09 09:50:03.714  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.715  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.715  1861  1861 D ObserverService: SyncedFolder :Music, /storage/emulated/0/Music/, 0, true, 4
03-09 09:50:03.715  1861  1861 D ObserverService: Local Folder (last modified / exists): 1640004113000, true
03-09 09:50:03.716  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.716  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.716  1861  1861 D ObserverService: SyncedFolder :Ringtones, /storage/emulated/0/Ringtones/, 0, true, 5
03-09 09:50:03.716  1861  1861 D ObserverService: Local Folder (last modified / exists): 1640004113000, true
03-09 09:50:03.716  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.717  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.717  1861  1861 D ObserverService: SyncedFolder :Documents, /storage/emulated/0/Documents/, 0, true, 6
03-09 09:50:03.717  1861  1861 D ObserverService: Local Folder (last modified / exists): 1646665763000, true
03-09 09:50:03.717  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.718  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.719  1861  1861 V ObserverService: subfile /storage/emulated/0/Documents/foundation.e.drive.beta-1-build-o-22-03-07T1452-debug.apk is a file added to list of file to sync
03-09 09:50:03.719  1861  1861 D ObserverService: SyncedFolder :Podcasts, /storage/emulated/0/Podcasts/, 0, true, 7
03-09 09:50:03.719  1861  1861 D ObserverService: Local Folder (last modified / exists): 1640004113000, true
03-09 09:50:03.719  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.720  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.720  1861  1861 D ObserverService: SyncedFolder :Rom settings, /data/system/users/0/, 0, true, 8
03-09 09:50:03.720  1861  1861 D ObserverService: Local Folder (last modified / exists): 1646815760000, true
03-09 09:50:03.720  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.721  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.721  1861  1861 D ObserverService: SyncedFolder :Rom settings, /data/data/foundation.e.drive/files/, 0, true, 9
03-09 09:50:03.721  1861  1861 D ObserverService: Local Folder (last modified / exists): 1646815803000, true
03-09 09:50:03.721  1861  1861 V ObserverService: local folder has changed
03-09 09:50:03.722  1861  1861 V ObserverService: loop through subfiles
03-09 09:50:03.722  1861  1861 V ObserverService: subfile /data/data/foundation.e.drive/files/packages_list.csv is a file added to list of file to sync
03-09 09:50:03.832  1861  1861 I ObserverService: handleLocalFiles()
03-09 09:50:03.832  1861  1861 D ObserverService: Loop through local file list
03-09 09:50:03.832  1861  1861 V ObserverService: format: filePath, exist, lastModified) :
03-09 09:50:03.833  1861  1861 V ObserverService: Current file is /storage/emulated/0/Pictures/Screenshots/Screenshot_20220308-183527_Gallery.png, true, 1646760927000
03-09 09:50:03.833  1861  1861 D ObserverService: Loop through syncedFileStates 
03-09 09:50:03.833  1861  1861 V ObserverService: format: (Path, Id, last Modified)
03-09 09:50:03.833  1861  1861 V ObserverService: /storage/emulated/0/Documents/foundation.e.drive.beta-1-build-o-22-03-07T1452-debug.apk, 1, 0
03-09 09:50:03.833  1861  1861 V ObserverService: this is a new file to sync
03-09 09:50:03.850  1861  1861 I ObserverService: Add upload operation for new file 2
03-09 09:50:03.854  1861  1861 V ObserverService: Current file is /storage/emulated/0/Documents/foundation.e.drive.beta-1-build-o-22-03-07T1452-debug.apk, true, 1646664723000
03-09 09:50:03.854  1861  1861 D ObserverService: Loop through syncedFileStates 
03-09 09:50:03.854  1861  1861 V ObserverService: format: (Path, Id, last Modified)
03-09 09:50:03.854  1861  1861 V ObserverService: /storage/emulated/0/Documents/foundation.e.drive.beta-1-build-o-22-03-07T1452-debug.apk, 1, 0
03-09 09:50:03.854  1861  1861 D ObserverService_handleLocalFiles(): foundation.e.drive.beta-1-build-o-22-03-07T1452-debug.apk file has been modified or never sync
03-09 09:50:03.855  1861  1861 I ObserverService: Add upload operation for file 1
03-09 09:50:03.855  1861  1861 V ObserverService: Current file is /data/data/foundation.e.drive/files/packages_list.csv, true, 1646673887000
03-09 09:50:03.855  1861  1861 D ObserverService: Loop through syncedFileStates 
03-09 09:50:03.855  1861  1861 V ObserverService: format: (Path, Id, last Modified)
03-09 09:50:03.855  1861  1861 V ObserverService: this is a new file to sync
03-09 09:50:03.871  1861  1861 I ObserverService: Add upload operation for new file 3
03-09 09:50:03.871  1861  1861 I ObserverService: handleLocalRemainingSyncedFileState(...)
03-09 09:50:03.871  1861  1861 V ObserverService: operationsForIntent contains 3
03-09 09:50:03.887  1861  1861 D ObserverService: ServiceExceptionHandler already set!
03-09 09:50:03.918  1861  1861 I ObserverService: onDestroy()
  • adb logcat | grep 'FullScanWorker*' and looked for doWork(): going to send intent to ObserverService input
  • Use adb shell dumpsys deviceidle force-idle to force device to be idle even if connected through USB

Check list

  • Self review
  • Test procedure explained
  • Tested on fresh install
  • Tested applied as an update
  • License
Edited by Vincent Bourgmayer

Merge request reports

Loading