BackgroundJobManager.kt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Chris Narkiewicz
  5. * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package com.nextcloud.client.jobs
  21. import androidx.lifecycle.LiveData
  22. import androidx.work.ListenableWorker
  23. import com.nextcloud.client.account.User
  24. import com.owncloud.android.datamodel.OCFile
  25. import com.owncloud.android.operations.DownloadType
  26. /**
  27. * This interface allows to control, schedule and monitor all application
  28. * long-running background tasks, such as periodic checks or synchronization.
  29. */
  30. @Suppress("TooManyFunctions") // we expect this implementation to have rich API
  31. interface BackgroundJobManager {
  32. /**
  33. * Information about all application background jobs.
  34. */
  35. val jobs: LiveData<List<JobInfo>>
  36. fun logStartOfWorker(workerName: String?)
  37. fun logEndOfWorker(workerName: String?, result: ListenableWorker.Result)
  38. /**
  39. * Start content observer job that monitors changes in media folders
  40. * and launches synchronization when needed.
  41. *
  42. * This call is idempotent - there will be only one scheduled job
  43. * regardless of number of calls.
  44. */
  45. fun scheduleContentObserverJob()
  46. /**
  47. * Schedule periodic contacts backups job. Operating system will
  48. * decide when to start the job.
  49. *
  50. * This call is idempotent - there can be only one scheduled job
  51. * at any given time.
  52. *
  53. * @param user User for which job will be scheduled.
  54. */
  55. fun schedulePeriodicContactsBackup(user: User)
  56. /**
  57. * Cancel periodic contacts backup. Existing tasks might finish, but no new
  58. * invocations will occur.
  59. */
  60. fun cancelPeriodicContactsBackup(user: User)
  61. /**
  62. * Immediately start single contacts backup job.
  63. * This job will launch independently from periodic contacts backup.
  64. *
  65. * @return Job info with current status; status is null if job does not exist
  66. */
  67. fun startImmediateContactsBackup(user: User): LiveData<JobInfo?>
  68. /**
  69. * Schedule periodic calendar backups job. Operating system will
  70. * decide when to start the job.
  71. *
  72. * This call is idempotent - there can be only one scheduled job
  73. * at any given time.
  74. *
  75. * @param user User for which job will be scheduled.
  76. */
  77. fun schedulePeriodicCalendarBackup(user: User)
  78. /**
  79. * Cancel periodic calendar backup. Existing tasks might finish, but no new
  80. * invocations will occur.
  81. */
  82. fun cancelPeriodicCalendarBackup(user: User)
  83. /**
  84. * Immediately start single calendar backup job.
  85. * This job will launch independently from periodic calendar backup.
  86. *
  87. * @return Job info with current status; status is null if job does not exist
  88. */
  89. fun startImmediateCalendarBackup(user: User): LiveData<JobInfo?>
  90. /**
  91. * Immediately start contacts import job. Import job will be started only once.
  92. * If new job is started while existing job is running - request will be ignored
  93. * and currently running job will continue running.
  94. *
  95. * @param contactsAccountName Target contacts account name; null for local contacts
  96. * @param contactsAccountType Target contacts account type; null for local contacts
  97. * @param vCardFilePath Path to file containing all contact entries
  98. * @param selectedContacts List of contact indices to import from [vCardFilePath] file
  99. *
  100. * @return Job info with current status; status is null if job does not exist
  101. */
  102. fun startImmediateContactsImport(
  103. contactsAccountName: String?,
  104. contactsAccountType: String?,
  105. vCardFilePath: String,
  106. selectedContacts: IntArray
  107. ): LiveData<JobInfo?>
  108. /**
  109. * Immediately start calendar import job. Import job will be started only once.
  110. * If new job is started while existing job is running - request will be ignored
  111. * and currently running job will continue running.
  112. *
  113. * @param calendarPaths Array of paths of calendar files to import from
  114. *
  115. * @return Job info with current status; status is null if job does not exist
  116. */
  117. fun startImmediateCalendarImport(calendarPaths: Map<String, Int>): LiveData<JobInfo?>
  118. fun startImmediateFilesExportJob(files: Collection<OCFile>): LiveData<JobInfo?>
  119. fun schedulePeriodicFilesSyncJob()
  120. fun startImmediateFilesSyncJob(skipCustomFolders: Boolean = false, overridePowerSaving: Boolean = false)
  121. fun scheduleOfflineSync()
  122. fun scheduleMediaFoldersDetectionJob()
  123. fun startMediaFoldersDetectionJob()
  124. fun startNotificationJob(subject: String, signature: String)
  125. fun startAccountRemovalJob(accountName: String, remoteWipe: Boolean)
  126. fun startFilesUploadJob(user: User)
  127. fun getFileUploads(user: User): LiveData<List<JobInfo>>
  128. fun cancelFilesUploadJob(user: User)
  129. fun cancelFilesDownloadJob(user: User, fileId: Long)
  130. fun isStartFileDownloadJobScheduled(user: User, fileId: Long): Boolean
  131. @Suppress("LongParameterList")
  132. fun startFileDownloadJob(
  133. user: User,
  134. file: OCFile,
  135. behaviour: String,
  136. downloadType: DownloadType?,
  137. activityName: String,
  138. packageName: String,
  139. conflictUploadId: Long?
  140. )
  141. fun startPdfGenerateAndUploadWork(user: User, uploadFolder: String, imagePaths: List<String>, pdfPath: String)
  142. fun scheduleTestJob()
  143. fun startImmediateTestJob()
  144. fun cancelTestJob()
  145. fun pruneJobs()
  146. fun cancelAllJobs()
  147. fun schedulePeriodicHealthStatus()
  148. fun startHealthStatus()
  149. }