|
@@ -45,6 +45,7 @@ import com.owncloud.android.lib.common.network.WebdavEntry;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
|
|
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
|
|
|
|
+import com.owncloud.android.lib.resources.files.model.FileLockType;
|
|
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
|
import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
|
import com.owncloud.android.lib.resources.shares.OCShare;
|
|
import com.owncloud.android.lib.resources.shares.OCShare;
|
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
|
@@ -70,6 +71,7 @@ import java.util.Set;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
|
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
|
|
|
|
|
|
|
|
public class FileDataStorageManager {
|
|
public class FileDataStorageManager {
|
|
@@ -83,9 +85,9 @@ public class FileDataStorageManager {
|
|
public static final int ROOT_PARENT_ID = 0;
|
|
public static final int ROOT_PARENT_ID = 0;
|
|
public static final String NULL_STRING = "null";
|
|
public static final String NULL_STRING = "null";
|
|
|
|
|
|
- private ContentResolver contentResolver;
|
|
|
|
- private ContentProviderClient contentProviderClient;
|
|
|
|
- private User user;
|
|
|
|
|
|
+ private final ContentResolver contentResolver;
|
|
|
|
+ private final ContentProviderClient contentProviderClient;
|
|
|
|
+ private final User user;
|
|
|
|
|
|
public FileDataStorageManager(User user, ContentResolver contentResolver) {
|
|
public FileDataStorageManager(User user, ContentResolver contentResolver) {
|
|
this.contentProviderClient = null;
|
|
this.contentProviderClient = null;
|
|
@@ -208,44 +210,10 @@ public class FileDataStorageManager {
|
|
|
|
|
|
public boolean saveFile(OCFile ocFile) {
|
|
public boolean saveFile(OCFile ocFile) {
|
|
boolean overridden = false;
|
|
boolean overridden = false;
|
|
- ContentValues cv = new ContentValues();
|
|
|
|
- cv.put(ProviderTableMeta.FILE_MODIFIED, ocFile.getModificationTimestamp());
|
|
|
|
- cv.put(
|
|
|
|
- ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
|
|
|
- ocFile.getModificationTimestampAtLastSyncForData()
|
|
|
|
- );
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CREATION, ocFile.getCreationTimestamp());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, ocFile.getFileLength());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, ocFile.getMimeType());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_NAME, ocFile.getFileName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ENCRYPTED_NAME, ocFile.getEncryptedFileName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PARENT, ocFile.getParentId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PATH, ocFile.getRemotePath());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, ocFile.getDecryptedRemotePath());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_IS_ENCRYPTED, ocFile.isEncrypted());
|
|
|
|
- if (!ocFile.isFolder()) {
|
|
|
|
- cv.put(ProviderTableMeta.FILE_STORAGE_PATH, ocFile.getStoragePath());
|
|
|
|
|
|
+ final ContentValues cv = createContentValuesForFile(ocFile);
|
|
|
|
+ if (ocFile.isFolder()) {
|
|
|
|
+ cv.remove(ProviderTableMeta.FILE_STORAGE_PATH);
|
|
}
|
|
}
|
|
- cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, ocFile.getLastSyncDateForProperties());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, ocFile.getLastSyncDateForData());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG, ocFile.getEtag());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, ocFile.getEtagOnServer());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, ocFile.isSharedViaLink() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, ocFile.isSharedWithSharee() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PERMISSIONS, ocFile.getPermissions());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_REMOTE_ID, ocFile.getRemoteId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, ocFile.isUpdateThumbnailNeeded());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, ocFile.isDownloading());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, ocFile.getEtagInConflict());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT, ocFile.getUnreadCommentsCount());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_OWNER_ID, ocFile.getOwnerId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, ocFile.getOwnerDisplayName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_NOTE, ocFile.getNote());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(ocFile.getSharees()));
|
|
|
|
- cv.put(ProviderTableMeta.FILE_RICH_WORKSPACE, ocFile.getRichWorkspace());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_HAS_PREVIEW, ocFile.isPreviewAvailable() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_FAVORITE, ocFile.isFavorite());
|
|
|
|
|
|
|
|
boolean sameRemotePath = fileExists(ocFile.getRemotePath());
|
|
boolean sameRemotePath = fileExists(ocFile.getRemotePath());
|
|
if (sameRemotePath ||
|
|
if (sameRemotePath ||
|
|
@@ -369,7 +337,8 @@ public class FileDataStorageManager {
|
|
|
|
|
|
// prepare operations to insert or update files to save in the given folder
|
|
// prepare operations to insert or update files to save in the given folder
|
|
for (OCFile ocFile : updatedFiles) {
|
|
for (OCFile ocFile : updatedFiles) {
|
|
- ContentValues contentValues = createContentValueForFile(ocFile, folder);
|
|
|
|
|
|
+ ContentValues contentValues = createContentValuesForFile(ocFile);
|
|
|
|
+ contentValues.put(ProviderTableMeta.FILE_PARENT, folder.getFileId());
|
|
|
|
|
|
if (fileExists(ocFile.getFileId()) || fileExists(ocFile.getRemotePath())) {
|
|
if (fileExists(ocFile.getFileId()) || fileExists(ocFile.getRemotePath())) {
|
|
long fileId;
|
|
long fileId;
|
|
@@ -423,7 +392,7 @@ public class FileDataStorageManager {
|
|
}
|
|
}
|
|
|
|
|
|
// update metadata of folder
|
|
// update metadata of folder
|
|
- ContentValues contentValues = createContentValueForFile(folder);
|
|
|
|
|
|
+ ContentValues contentValues = createContentValuesForFolder(folder);
|
|
|
|
|
|
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI)
|
|
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI)
|
|
.withValues(contentValues)
|
|
.withValues(contentValues)
|
|
@@ -467,76 +436,76 @@ public class FileDataStorageManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private ContentValues createContentValueForFile(OCFile folder) {
|
|
|
|
- ContentValues cv = new ContentValues();
|
|
|
|
- cv.put(ProviderTableMeta.FILE_MODIFIED, folder.getModificationTimestamp());
|
|
|
|
- cv.put(
|
|
|
|
- ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
|
|
|
- folder.getModificationTimestampAtLastSyncForData()
|
|
|
|
- );
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CREATION, folder.getCreationTimestamp());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, folder.getMimeType());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_NAME, folder.getFileName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PATH, folder.getRemotePath());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, folder.getDecryptedRemotePath());
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns a {@link ContentValues} filled with values that are common to both files and folders
|
|
|
|
+ * @see #createContentValuesForFile(OCFile)
|
|
|
|
+ * @see #createContentValuesForFolder(OCFile)
|
|
|
|
+ */
|
|
|
|
+ private ContentValues createContentValuesBase(OCFile fileOrFolder) {
|
|
|
|
+ final ContentValues cv = new ContentValues();
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_MODIFIED, fileOrFolder.getModificationTimestamp());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, fileOrFolder.getModificationTimestampAtLastSyncForData());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_PARENT, fileOrFolder.getParentId());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_CREATION, fileOrFolder.getCreationTimestamp());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, fileOrFolder.getMimeType());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_NAME, fileOrFolder.getFileName());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_PATH, fileOrFolder.getRemotePath());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, fileOrFolder.getDecryptedRemotePath());
|
|
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
|
|
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
|
|
- cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, folder.getLastSyncDateForProperties());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, folder.getLastSyncDateForData());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, folder.getEtagOnServer());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_FAVORITE, folder.isFavorite());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_IS_ENCRYPTED, folder.isEncrypted());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT, folder.getUnreadCommentsCount());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_OWNER_ID, folder.getOwnerId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, folder.getOwnerDisplayName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_NOTE, folder.getNote());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(folder.getSharees()));
|
|
|
|
- cv.put(ProviderTableMeta.FILE_RICH_WORKSPACE, folder.getRichWorkspace());
|
|
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_IS_ENCRYPTED, fileOrFolder.isEncrypted());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, fileOrFolder.getLastSyncDateForProperties());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, fileOrFolder.getLastSyncDateForData());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_ETAG, fileOrFolder.getEtag());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, fileOrFolder.getEtagOnServer());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, fileOrFolder.isSharedViaLink() ? 1 : 0);
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, fileOrFolder.isSharedWithSharee() ? 1 : 0);
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_PERMISSIONS, fileOrFolder.getPermissions());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_REMOTE_ID, fileOrFolder.getRemoteId());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_FAVORITE, fileOrFolder.isFavorite());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT, fileOrFolder.getUnreadCommentsCount());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_OWNER_ID, fileOrFolder.getOwnerId());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, fileOrFolder.getOwnerDisplayName());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_NOTE, fileOrFolder.getNote());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(fileOrFolder.getSharees()));
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_RICH_WORKSPACE, fileOrFolder.getRichWorkspace());
|
|
|
|
+ return cv;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns a {@link ContentValues} filled with values for a folder
|
|
|
|
+ * @see #createContentValuesForFile(OCFile)
|
|
|
|
+ * @see #createContentValuesBase(OCFile)
|
|
|
|
+ */
|
|
|
|
+ private ContentValues createContentValuesForFolder(OCFile folder) {
|
|
|
|
+ final ContentValues cv = createContentValuesBase(folder);
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, 0);
|
|
return cv;
|
|
return cv;
|
|
}
|
|
}
|
|
|
|
|
|
- private ContentValues createContentValueForFile(OCFile file, OCFile folder) {
|
|
|
|
- ContentValues cv = new ContentValues();
|
|
|
|
- cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Returns a {@link ContentValues} filled with values for a file
|
|
|
|
+ * @see #createContentValuesForFolder(OCFile)
|
|
|
|
+ * @see #createContentValuesBase(OCFile)
|
|
|
|
+ */
|
|
|
|
+ @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
|
|
|
|
+ private ContentValues createContentValuesForFile(OCFile file) {
|
|
|
|
+ final ContentValues cv = createContentValuesBase(file);
|
|
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
|
|
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
|
|
- cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimeType());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
|
|
|
|
cv.put(ProviderTableMeta.FILE_ENCRYPTED_NAME, file.getEncryptedFileName());
|
|
cv.put(ProviderTableMeta.FILE_ENCRYPTED_NAME, file.getEncryptedFileName());
|
|
- cv.put(ProviderTableMeta.FILE_PARENT, folder.getFileId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PATH_DECRYPTED, file.getDecryptedRemotePath());
|
|
|
|
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
|
|
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
|
|
- cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, file.getEtagOnServer());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
|
|
|
|
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.isUpdateThumbnailNeeded());
|
|
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.isUpdateThumbnailNeeded());
|
|
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
|
|
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
|
|
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
|
|
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
|
|
- cv.put(ProviderTableMeta.FILE_FAVORITE, file.isFavorite());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_IS_ENCRYPTED, file.isEncrypted());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_MOUNT_TYPE, file.getMountType().ordinal());
|
|
|
|
cv.put(ProviderTableMeta.FILE_HAS_PREVIEW, file.isPreviewAvailable() ? 1 : 0);
|
|
cv.put(ProviderTableMeta.FILE_HAS_PREVIEW, file.isPreviewAvailable() ? 1 : 0);
|
|
- cv.put(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT, file.getUnreadCommentsCount());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_OWNER_ID, file.getOwnerId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME, file.getOwnerDisplayName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_NOTE, file.getNote());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHAREES, new Gson().toJson(file.getSharees()));
|
|
|
|
- cv.put(ProviderTableMeta.FILE_RICH_WORKSPACE, file.getRichWorkspace());
|
|
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCKED, file.isLocked());
|
|
|
|
+ final FileLockType lockType = file.getLockType();
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCK_TYPE, lockType != null ? lockType.getValue() : -1);
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCK_OWNER, file.getLockOwnerId());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCK_OWNER_DISPLAY_NAME, file.getLockOwnerDisplayName());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCK_OWNER_EDITOR, file.getLockOwnerEditor());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCK_TIMESTAMP, file.getLockTimestamp());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCK_TIMEOUT, file.getLockTimeout());
|
|
|
|
+ cv.put(ProviderTableMeta.FILE_LOCK_TOKEN, file.getLockToken());
|
|
|
|
|
|
return cv;
|
|
return cv;
|
|
}
|
|
}
|
|
@@ -1030,6 +999,16 @@ public class FileDataStorageManager {
|
|
ocFile.setOwnerDisplayName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)));
|
|
ocFile.setOwnerDisplayName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)));
|
|
ocFile.setNote(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NOTE)));
|
|
ocFile.setNote(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NOTE)));
|
|
ocFile.setRichWorkspace(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_RICH_WORKSPACE)));
|
|
ocFile.setRichWorkspace(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_RICH_WORKSPACE)));
|
|
|
|
+ ocFile.setLocked(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCKED)) == 1);
|
|
|
|
+ final int lockTypeInt = cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCK_TYPE));
|
|
|
|
+ ocFile.setLockType(lockTypeInt != -1 ? FileLockType.fromValue(lockTypeInt) : null);
|
|
|
|
+ ocFile.setLockOwnerId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCK_OWNER)));
|
|
|
|
+ ocFile.setLockOwnerDisplayName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCK_OWNER_DISPLAY_NAME)));
|
|
|
|
+ ocFile.setLockOwnerEditor(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCK_OWNER_EDITOR)));
|
|
|
|
+ ocFile.setLockTimestamp(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCK_TIMESTAMP)));
|
|
|
|
+ ocFile.setLockTimeout(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCK_TIMEOUT)));
|
|
|
|
+ ocFile.setLockToken(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LOCK_TOKEN)));
|
|
|
|
+
|
|
|
|
|
|
String sharees = cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHAREES));
|
|
String sharees = cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHAREES));
|
|
|
|
|
|
@@ -1424,86 +1403,6 @@ public class FileDataStorageManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void updateSharedFiles(Collection<OCFile> sharedFiles) {
|
|
|
|
- resetShareFlagsInAllFiles();
|
|
|
|
-
|
|
|
|
- if (sharedFiles != null) {
|
|
|
|
- ArrayList<ContentProviderOperation> operations = new ArrayList<>(sharedFiles.size());
|
|
|
|
-
|
|
|
|
- // prepare operations to insert or update files to save in the given folder
|
|
|
|
- for (OCFile file : sharedFiles) {
|
|
|
|
- ContentValues cv = new ContentValues();
|
|
|
|
- cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
|
|
|
|
- cv.put(
|
|
|
|
- ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
|
|
|
- file.getModificationTimestampAtLastSyncForData()
|
|
|
|
- );
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimeType());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
|
|
|
|
- if (!file.isFolder()) {
|
|
|
|
- cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
|
|
|
|
- }
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
|
|
|
|
- cv.put(
|
|
|
|
- ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA,
|
|
|
|
- file.getLastSyncDateForData()
|
|
|
|
- );
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, file.getEtagOnServer());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_FAVORITE, file.isFavorite());
|
|
|
|
- cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.isUpdateThumbnailNeeded() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading() ? 1 : 0);
|
|
|
|
- cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
|
|
|
|
-
|
|
|
|
- boolean existsByPath = fileExists(file.getRemotePath());
|
|
|
|
- if (existsByPath || fileExists(file.getFileId())) {
|
|
|
|
- // updating an existing file
|
|
|
|
- operations.add(
|
|
|
|
- ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
|
|
|
|
- withValues(cv).
|
|
|
|
- withSelection(ProviderTableMeta._ID + "=?",
|
|
|
|
- new String[]{String.valueOf(file.getFileId())})
|
|
|
|
- .build());
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- // adding a new file
|
|
|
|
- operations.add(
|
|
|
|
- ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).
|
|
|
|
- withValues(cv).
|
|
|
|
- build()
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // apply operations in batch
|
|
|
|
- if (operations.size() > 0) {
|
|
|
|
- @SuppressWarnings("unused")
|
|
|
|
- ContentProviderResult[] results = null;
|
|
|
|
- Log_OC.d(TAG, String.format(Locale.ENGLISH, SENDING_TO_FILECONTENTPROVIDER_MSG, operations.size()));
|
|
|
|
- try {
|
|
|
|
- if (getContentResolver() != null) {
|
|
|
|
- results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
|
|
|
|
- } else {
|
|
|
|
- results = getContentProviderClient().applyBatch(operations);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (OperationApplicationException | RemoteException e) {
|
|
|
|
- Log_OC.e(TAG, EXCEPTION_MSG + e.getMessage(), e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void removeShare(OCShare share) {
|
|
public void removeShare(OCShare share) {
|
|
Uri contentUriShare = ProviderTableMeta.CONTENT_URI_SHARE;
|
|
Uri contentUriShare = ProviderTableMeta.CONTENT_URI_SHARE;
|
|
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND +
|
|
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND +
|
|
@@ -2075,6 +1974,8 @@ public class FileDataStorageManager {
|
|
contentValues.put(ProviderTableMeta.CAPABILITIES_USER_STATUS, capability.getUserStatus().getValue());
|
|
contentValues.put(ProviderTableMeta.CAPABILITIES_USER_STATUS, capability.getUserStatus().getValue());
|
|
contentValues.put(ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI,
|
|
contentValues.put(ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI,
|
|
capability.getUserStatusSupportsEmoji().getValue());
|
|
capability.getUserStatusSupportsEmoji().getValue());
|
|
|
|
+ contentValues.put(ProviderTableMeta.CAPABILITIES_FILES_LOCKING_VERSION,
|
|
|
|
+ capability.getFilesLockingVersion());
|
|
|
|
|
|
return contentValues;
|
|
return contentValues;
|
|
}
|
|
}
|
|
@@ -2224,6 +2125,8 @@ public class FileDataStorageManager {
|
|
capability.setUserStatus(getBoolean(cursor, ProviderTableMeta.CAPABILITIES_USER_STATUS));
|
|
capability.setUserStatus(getBoolean(cursor, ProviderTableMeta.CAPABILITIES_USER_STATUS));
|
|
capability.setUserStatusSupportsEmoji(
|
|
capability.setUserStatusSupportsEmoji(
|
|
getBoolean(cursor, ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI));
|
|
getBoolean(cursor, ProviderTableMeta.CAPABILITIES_USER_STATUS_SUPPORTS_EMOJI));
|
|
|
|
+ capability.setFilesLockingVersion(
|
|
|
|
+ getString(cursor, ProviderTableMeta.CAPABILITIES_FILES_LOCKING_VERSION));
|
|
}
|
|
}
|
|
return capability;
|
|
return capability;
|
|
}
|
|
}
|
|
@@ -2258,22 +2161,6 @@ public class FileDataStorageManager {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void saveVirtual(VirtualFolderType type, OCFile file) {
|
|
|
|
- ContentValues cv = new ContentValues();
|
|
|
|
- cv.put(ProviderTableMeta.VIRTUAL_TYPE, type.toString());
|
|
|
|
- cv.put(ProviderTableMeta.VIRTUAL_OCFILE_ID, file.getFileId());
|
|
|
|
-
|
|
|
|
- if (getContentResolver() != null) {
|
|
|
|
- getContentResolver().insert(ProviderTableMeta.CONTENT_URI_VIRTUAL, cv);
|
|
|
|
- } else {
|
|
|
|
- try {
|
|
|
|
- getContentProviderClient().insert(ProviderTableMeta.CONTENT_URI_VIRTUAL, cv);
|
|
|
|
- } catch (RemoteException e) {
|
|
|
|
- Log_OC.e(TAG, FAILED_TO_INSERT_MSG + e.getMessage(), e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public List<OCFile> getAllGalleryItems() {
|
|
public List<OCFile> getAllGalleryItems() {
|
|
return getGalleryItems(0, Long.MAX_VALUE);
|
|
return getGalleryItems(0, Long.MAX_VALUE);
|
|
}
|
|
}
|