Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,24 +272,6 @@ internal class BackgroundJobManagerImpl(
return workInfo.map { it -> it.map { fromWorkInfo(it) ?: JobInfo() }.sortedBy { it.started }.reversed() }
}

@Suppress("MagicNumber")
override fun scheduleContentObserverJob() {
val constrains = Constraints.Builder()
.addContentUriTrigger(MediaStore.Images.Media.INTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Video.Media.INTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true)
.setTriggerContentUpdateDelay(Duration.ofSeconds(5))
.setTriggerContentMaxDelay(Duration.ofSeconds(10))
.build()

val request = oneTimeRequestBuilder(ContentObserverWork::class, JOB_CONTENT_OBSERVER)
.setConstraints(constrains)
.build()

workManager.enqueueUniqueWork(JOB_CONTENT_OBSERVER, ExistingWorkPolicy.REPLACE, request)
}

override fun schedulePeriodicContactsBackup(user: User) {
val data = Data.Builder()
.putString(ContactsBackupWork.KEY_ACCOUNT, user.accountName)
Expand Down Expand Up @@ -481,6 +463,25 @@ internal class BackgroundJobManagerImpl(
)
}

@Suppress("MagicNumber")
override fun scheduleContentObserverJob() {
val constrains = Constraints.Builder()
.addContentUriTrigger(MediaStore.Images.Media.INTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Video.Media.INTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, true)
.addContentUriTrigger(MediaStore.Files.getContentUri("external"), true)
.setTriggerContentUpdateDelay(Duration.ofSeconds(5))
.setTriggerContentMaxDelay(Duration.ofSeconds(10))
.build()

val request = oneTimeRequestBuilder(ContentObserverWork::class, JOB_CONTENT_OBSERVER)
.setConstraints(constrains)
.build()

workManager.enqueueUniqueWork(JOB_CONTENT_OBSERVER, ExistingWorkPolicy.REPLACE, request)
}

override fun startAutoUpload(syncedFolder: SyncedFolder, overridePowerSaving: Boolean) {
val syncedFolderID = syncedFolder.id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class FileSystemRepository(
return
}

if (checkFileType && !syncedFolder.containsTypedFile(file, localPath)) {
if (checkFileType && !syncedFolder.isFileInFolderWithCorrectMediaType(file, localPath)) {
Log_OC.w(TAG, "synced folder not contains typed file: $localPath")
return
}
Expand Down
31 changes: 27 additions & 4 deletions app/src/main/java/com/owncloud/android/datamodel/SyncedFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,35 @@ public void setExcludeHidden(boolean excludeHidden) {
this.excludeHidden = excludeHidden;
}

public boolean containsTypedFile(File file,String filePath){
/**
* Determines whether the given file:
* <ul>
* <li>Exists under the configured {@code localPath}</li>
* <li>Matches the expected media type of this folder</li>
* </ul>
*
* @param file the file to validate
* @param filePath the absolute path of the file e.g. /storage/emulated/0/DCIM/Camera/document.pdf
* @return {@code true} if the file is located under {@code localPath}
* and matches the folder's media type; {@code false} otherwise
*/
public boolean isFileInFolderWithCorrectMediaType(File file, String filePath) {
if (filePath == null || filePath.isEmpty() || localPath == null || localPath.isEmpty()) {
return false;
}

String normalizedLocal = localPath.endsWith(File.separator)
? localPath
: localPath + File.separator;

boolean isInLocalDirectory = filePath.startsWith(normalizedLocal);

boolean isCorrectMediaType =
(getType() == MediaFolderType.IMAGE && MimeTypeUtil.isImage(file)) ||
(getType() == MediaFolderType.IMAGE && MimeTypeUtil.isImage(file)) ||
(getType() == MediaFolderType.VIDEO && MimeTypeUtil.isVideo(file)) ||
getType() == MediaFolderType.CUSTOM;
return filePath.contains(localPath) && isCorrectMediaType;
getType() == MediaFolderType.CUSTOM;

return isInLocalDirectory && isCorrectMediaType;
}

public long getLastScanTimestampMs() { return lastScanTimestampMs; }
Expand Down
Loading
Loading