BackgroundJobManager.kt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 android.os.Build
  22. import androidx.annotation.RequiresApi
  23. import androidx.lifecycle.LiveData
  24. import com.nextcloud.client.account.User
  25. import com.owncloud.android.datamodel.OCFile
  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. /**
  37. * Start content observer job that monitors changes in media folders
  38. * and launches synchronization when needed.
  39. *
  40. * This call is idempotent - there will be only one scheduled job
  41. * regardless of number of calls.
  42. */
  43. @RequiresApi(Build.VERSION_CODES.N)
  44. fun scheduleContentObserverJob()
  45. /**
  46. * Schedule periodic contacts backups job. Operating system will
  47. * decide when to start the job.
  48. *
  49. * This call is idempotent - there can be only one scheduled job
  50. * at any given time.
  51. *
  52. * @param user User for which job will be scheduled.
  53. */
  54. fun schedulePeriodicContactsBackup(user: User)
  55. /**
  56. * Cancel periodic contacts backup. Existing tasks might finish, but no new
  57. * invocations will occur.
  58. */
  59. fun cancelPeriodicContactsBackup(user: User)
  60. /**
  61. * Immediately start single contacts backup job.
  62. * This job will launch independently from periodic contacts backup.
  63. *
  64. * @return Job info with current status; status is null if job does not exist
  65. */
  66. fun startImmediateContactsBackup(user: User): LiveData<JobInfo?>
  67. /**
  68. * Schedule periodic calendar backups job. Operating system will
  69. * decide when to start the job.
  70. *
  71. * This call is idempotent - there can be only one scheduled job
  72. * at any given time.
  73. *
  74. * @param user User for which job will be scheduled.
  75. */
  76. fun schedulePeriodicCalendarBackup(user: User)
  77. /**
  78. * Cancel periodic calendar backup. Existing tasks might finish, but no new
  79. * invocations will occur.
  80. */
  81. fun cancelPeriodicCalendarBackup(user: User)
  82. /**
  83. * Immediately start single calendar backup job.
  84. * This job will launch independently from periodic calendar backup.
  85. *
  86. * @return Job info with current status; status is null if job does not exist
  87. */
  88. fun startImmediateCalendarBackup(user: User): LiveData<JobInfo?>
  89. /**
  90. * Immediately start contacts import job. Import job will be started only once.
  91. * If new job is started while existing job is running - request will be ignored
  92. * and currently running job will continue running.
  93. *
  94. * @param contactsAccountName Target contacts account name; null for local contacts
  95. * @param contactsAccountType Target contacts account type; null for local contacts
  96. * @param vCardFilePath Path to file containing all contact entries
  97. * @param selectedContacts List of contact indices to import from [vCardFilePath] file
  98. *
  99. * @return Job info with current status; status is null if job does not exist
  100. */
  101. fun startImmediateContactsImport(
  102. contactsAccountName: String?,
  103. contactsAccountType: String?,
  104. vCardFilePath: String,
  105. selectedContacts: IntArray
  106. ): LiveData<JobInfo?>
  107. /**
  108. * Immediately start calendar import job. Import job will be started only once.
  109. * If new job is started while existing job is running - request will be ignored
  110. * and currently running job will continue running.
  111. *
  112. * @param calendarPaths Array of paths of calendar files to import from
  113. *
  114. * @return Job info with current status; status is null if job does not exist
  115. */
  116. fun startImmediateCalendarImport(calendarPaths: Map<String, Int>): LiveData<JobInfo?>
  117. fun startImmediateFilesExportJob(files: Collection<OCFile>): LiveData<JobInfo?>
  118. fun schedulePeriodicFilesSyncJob()
  119. fun startImmediateFilesSyncJob(skipCustomFolders: Boolean = false, overridePowerSaving: Boolean = false)
  120. fun scheduleOfflineSync()
  121. fun scheduleMediaFoldersDetectionJob()
  122. fun startMediaFoldersDetectionJob()
  123. fun startNotificationJob(subject: String, signature: String)
  124. fun startAccountRemovalJob(accountName: String, remoteWipe: Boolean)
  125. fun startFilesUploadJob(user: User)
  126. fun getFileUploads(user: User): LiveData<List<JobInfo>>
  127. fun startPdfGenerateAndUploadWork(user: User, uploadFolder: String, imagePaths: List<String>, pdfPath: String)
  128. fun scheduleTestJob()
  129. fun startImmediateTestJob()
  130. fun cancelTestJob()
  131. fun pruneJobs()
  132. fun cancelAllJobs()
  133. }