mirror of
https://github.com/nextcloud/android.git
synced 2024-12-20 07:52:18 +03:00
Merge remote-tracking branch 'origin/master' into dev
This commit is contained in:
commit
c31b3297a0
7 changed files with 67 additions and 20 deletions
4
.github/workflows/reuse.yml
vendored
4
.github/workflows/reuse.yml
vendored
|
@ -9,10 +9,10 @@
|
|||
|
||||
name: REUSE Compliance Check
|
||||
|
||||
on: [pull_request]
|
||||
on: pull_request
|
||||
|
||||
jobs:
|
||||
test:
|
||||
reuse-compliance-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
|
||||
|
|
|
@ -163,4 +163,5 @@ interface BackgroundJobManager {
|
|||
fun cancelAllJobs()
|
||||
fun schedulePeriodicHealthStatus()
|
||||
fun startHealthStatus()
|
||||
fun bothFilesSyncJobsRunning(): Boolean
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
|
|||
import com.nextcloud.client.jobs.download.FileDownloadWorker
|
||||
import com.nextcloud.client.jobs.upload.FileUploadWorker
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.nextcloud.utils.extensions.isWorkRunning
|
||||
import com.nextcloud.utils.extensions.isWorkScheduled
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.operations.DownloadType
|
||||
|
@ -403,6 +404,11 @@ internal class BackgroundJobManagerImpl(
|
|||
workManager.cancelJob(JOB_PERIODIC_CALENDAR_BACKUP, user)
|
||||
}
|
||||
|
||||
override fun bothFilesSyncJobsRunning(): Boolean {
|
||||
return workManager.isWorkRunning(JOB_PERIODIC_FILES_SYNC) &&
|
||||
workManager.isWorkRunning(JOB_IMMEDIATE_FILES_SYNC)
|
||||
}
|
||||
|
||||
override fun schedulePeriodicFilesSyncJob() {
|
||||
val request = periodicRequestBuilder(
|
||||
jobClass = FilesSyncWork::class,
|
||||
|
|
|
@ -91,18 +91,50 @@ class FilesSyncWork(
|
|||
setForegroundAsync(foregroundInfo)
|
||||
}
|
||||
|
||||
private fun canExitEarly(changedFiles: Array<String>?): Boolean {
|
||||
var canExitEarly = false
|
||||
// If we are in power save mode better to postpone scan and upload
|
||||
val overridePowerSaving = inputData.getBoolean(OVERRIDE_POWER_SAVING, false)
|
||||
if ((powerManagementService.isPowerSavingEnabled && !overridePowerSaving)) {
|
||||
canExitEarly = true
|
||||
}
|
||||
|
||||
// or sync worker already running and no changed files to be processed
|
||||
val alreadyRunning = backgroundJobManager.bothFilesSyncJobsRunning()
|
||||
if (alreadyRunning && changedFiles.isNullOrEmpty()) {
|
||||
Log_OC.d(TAG, "File-sync kill worker since another instance of the worker seems to be running already!")
|
||||
canExitEarly = true
|
||||
}
|
||||
|
||||
if (!syncedFolderProvider.syncedFolders.any { it.isEnabled }) {
|
||||
Log_OC.d(TAG, "File-sync kill worker since no sync folder is enabled!")
|
||||
canExitEarly = true
|
||||
}
|
||||
|
||||
if (syncedFolderProvider.syncedFolders.all { it.isChargingOnly } &&
|
||||
!powerManagementService.battery.isCharging &&
|
||||
!powerManagementService.battery.isFull
|
||||
) {
|
||||
Log_OC.d(TAG, "File-sync kill worker since phone is not charging!")
|
||||
canExitEarly = true
|
||||
}
|
||||
|
||||
return canExitEarly
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
override fun doWork(): Result {
|
||||
backgroundJobManager.logStartOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class))
|
||||
Log_OC.d(TAG, "File-sync worker started")
|
||||
|
||||
val overridePowerSaving = inputData.getBoolean(OVERRIDE_POWER_SAVING, false)
|
||||
// If we are in power save mode, better to postpone upload
|
||||
if (powerManagementService.isPowerSavingEnabled && !overridePowerSaving) {
|
||||
val changedFiles = inputData.getStringArray(CHANGED_FILES)
|
||||
|
||||
if (canExitEarly(changedFiles)) {
|
||||
val result = Result.success()
|
||||
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
|
||||
return result
|
||||
}
|
||||
|
||||
val resources = context.resources
|
||||
val lightVersion = resources.getBoolean(R.bool.syncedFolder_light)
|
||||
FilesSyncHelper.restartJobsIfNeeded(
|
||||
|
@ -113,7 +145,6 @@ class FilesSyncWork(
|
|||
)
|
||||
|
||||
// Get changed files from ContentObserverWork (only images and videos) or by scanning filesystem
|
||||
val changedFiles = inputData.getStringArray(CHANGED_FILES)
|
||||
Log_OC.d(TAG, "File-sync worker changed files from observer: " + changedFiles.contentToString())
|
||||
collectChangedFiles(changedFiles)
|
||||
Log_OC.d(TAG, "File-sync worker finished checking files.")
|
||||
|
@ -157,7 +188,7 @@ class FilesSyncWork(
|
|||
// Check every file in every synced folder for changes and update
|
||||
// filesystemDataProvider database (potentially needs a long time so use foreground worker)
|
||||
updateForegroundWorker(5, true)
|
||||
FilesSyncHelper.insertAllDBEntries(syncedFolderProvider)
|
||||
FilesSyncHelper.insertAllDBEntries(syncedFolderProvider, powerManagementService)
|
||||
updateForegroundWorker(50, true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,23 +13,24 @@ import com.google.common.util.concurrent.ListenableFuture
|
|||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
fun WorkManager.isWorkScheduled(tag: String): Boolean {
|
||||
val statuses: ListenableFuture<List<WorkInfo>> = this.getWorkInfosByTag(tag)
|
||||
var running = false
|
||||
private const val TAG = "WorkManager"
|
||||
|
||||
fun WorkManager.isWorkRunning(tag: String): Boolean = checkWork(tag, listOf(WorkInfo.State.RUNNING))
|
||||
|
||||
fun WorkManager.isWorkScheduled(tag: String): Boolean =
|
||||
checkWork(tag, listOf(WorkInfo.State.RUNNING, WorkInfo.State.ENQUEUED))
|
||||
|
||||
private fun WorkManager.checkWork(tag: String, stateConditions: List<WorkInfo.State>): Boolean {
|
||||
val statuses: ListenableFuture<List<WorkInfo>> = getWorkInfosByTag(tag)
|
||||
var workInfoList: List<WorkInfo> = emptyList()
|
||||
|
||||
try {
|
||||
workInfoList = statuses.get()
|
||||
} catch (e: ExecutionException) {
|
||||
Log_OC.d("Worker", "ExecutionException in isWorkScheduled: $e")
|
||||
Log_OC.d(TAG, "ExecutionException in checkWork: $e")
|
||||
} catch (e: InterruptedException) {
|
||||
Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e")
|
||||
Log_OC.d(TAG, "InterruptedException in checkWork: $e")
|
||||
}
|
||||
|
||||
for (workInfo in workInfoList) {
|
||||
val state = workInfo.state
|
||||
running = running || (state == WorkInfo.State.RUNNING || state == WorkInfo.State.ENQUEUED)
|
||||
}
|
||||
|
||||
return running
|
||||
return workInfoList.any { workInfo -> stateConditions.contains(workInfo.state) }
|
||||
}
|
||||
|
|
|
@ -145,9 +145,15 @@ public final class FilesSyncHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void insertAllDBEntries(SyncedFolderProvider syncedFolderProvider) {
|
||||
public static void insertAllDBEntries(SyncedFolderProvider syncedFolderProvider,
|
||||
PowerManagementService powerManagementService) {
|
||||
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
|
||||
if (syncedFolder.isEnabled()) {
|
||||
if (syncedFolder.isEnabled() &&
|
||||
!(syncedFolder.isChargingOnly() &&
|
||||
!powerManagementService.getBattery().isCharging() &&
|
||||
!powerManagementService.getBattery().isFull()
|
||||
)
|
||||
) {
|
||||
insertAllDBEntriesForSyncedFolder(syncedFolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,8 @@
|
|||
<string name="auth_unknown_host_title">Sunucu adı bulunamadı</string>
|
||||
<string name="auth_unsupported_multiaccount">%1$s birden çok hesabı desteklemiyor</string>
|
||||
<string name="auth_wrong_connection_title">Bağlantı kurulamadı</string>
|
||||
<string name="authenticator_activity_cancel_login">Oturum açmaktan vazgeç</string>
|
||||
<string name="authenticator_activity_please_complete_login_process">Lütfen oturum açma işlemini tarayıcınızdan tamamlayın</string>
|
||||
<string name="auto_upload_file_behaviour_kept_in_folder">salt okunur olduğundan özgün klasörde kaldı</string>
|
||||
<string name="auto_upload_on_wifi">Yalnızca kullanıma göre ücretlendirilmeyen kablosuz ağ üzerinden yüklensin</string>
|
||||
<string name="auto_upload_path">/OtomatikYükleme</string>
|
||||
|
|
Loading…
Reference in a new issue