BackgroundJobManager.kt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /**
  26. * This interface allows to control, schedule and monitor all application
  27. * long-running background tasks, such as periodic checks or synchronization.
  28. */
  29. @Suppress("TooManyFunctions") // we expect this implementation to have rich API
  30. interface BackgroundJobManager {
  31. /**
  32. * Information about all application background jobs.
  33. */
  34. val jobs: LiveData<List<JobInfo>>
  35. /**
  36. * Start content observer job that monitors changes in media folders
  37. * and launches synchronization when needed.
  38. *
  39. * This call is idempotent - there will be only one scheduled job
  40. * regardless of number of calls.
  41. */
  42. @RequiresApi(Build.VERSION_CODES.N)
  43. fun scheduleContentObserverJob()
  44. /**
  45. * Schedule periodic contacts backups job. Operating system will
  46. * decide when to start the job.
  47. *
  48. * This call is idempotent - there can be only one scheduled job
  49. * at any given time.
  50. *
  51. * @param user User for which job will be scheduled.
  52. */
  53. fun schedulePeriodicContactsBackup(user: User)
  54. /**
  55. * Cancel periodic contacts backup. Existing tasks might finish, but no new
  56. * invocations will occur.
  57. */
  58. fun cancelPeriodicContactsBackup(user: User)
  59. /**
  60. * Immediately start single contacts backup job.
  61. * This job will launch independently from periodic contacts backup.
  62. *
  63. * @return Job info with current status; status is null if job does not exist
  64. */
  65. fun startImmediateContactsBackup(user: User): LiveData<JobInfo?>
  66. /**
  67. * Immediately start contacts import job. Import job will be started only once.
  68. * If new job is started while existing job is running - request will be ignored
  69. * and currently running job will continue running.
  70. *
  71. * @param contactsAccountName Target contacts account name; null for local contacts
  72. * @param contactsAccountType Target contacts account type; null for local contacts
  73. * @param vCardFilePath Path to file containing all contact entries
  74. * @param selectedContacts List of contact indices to import from [vCardFilePath] file
  75. *
  76. * @return Job info with current status; status is null if job does not exist
  77. */
  78. fun startImmediateContactsImport(
  79. contactsAccountName: String?,
  80. contactsAccountType: String?,
  81. vCardFilePath: String,
  82. selectedContacts: IntArray
  83. ): LiveData<JobInfo?>
  84. fun schedulePeriodicFilesSyncJob()
  85. fun startImmediateFilesSyncJob(skipCustomFolders: Boolean = false, overridePowerSaving: Boolean = false)
  86. fun scheduleOfflineSync()
  87. fun scheduleMediaFoldersDetectionJob()
  88. fun startMediaFoldersDetectionJob()
  89. fun scheduleTestJob()
  90. fun startImmediateTestJob()
  91. fun cancelTestJob()
  92. fun pruneJobs()
  93. fun cancelAllJobs()
  94. }