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
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
385
383
24 changes: 12 additions & 12 deletions src/androidTest/java/com/owncloud/android/UploadIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public RemoteOperationResult testUpload(OCUpload ocUpload) {
account,
null,
ocUpload,
false,
FileUploader.NameCollisionPolicy.DEFAULT,
FileUploader.LOCAL_BEHAVIOUR_COPY,
targetContext,
false,
Expand All @@ -140,17 +140,17 @@ public void testUploadInNonExistingFolder() {
OCUpload ocUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/empty.txt",
"/testUpload/2/3/4/1.txt", account.name);
UploadFileOperation newUpload = new UploadFileOperation(
storageManager,
connectivityServiceMock,
powerManagementServiceMock,
account,
null,
ocUpload,
false,
FileUploader.LOCAL_BEHAVIOUR_COPY,
targetContext,
false,
false
storageManager,
connectivityServiceMock,
powerManagementServiceMock,
account,
null,
ocUpload,
FileUploader.NameCollisionPolicy.DEFAULT,
FileUploader.LOCAL_BEHAVIOUR_COPY,
targetContext,
false,
false
);
newUpload.addRenameUploadListener(() -> {
// dummy
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ private static void initiateExistingAutoUploadEntries(Clock clock) {

for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
if (syncedFolder.isEnabled()) {
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolder);
FilesSyncHelper.insertAllDBEntriesForSyncedFolder(syncedFolder, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SyncedFolder implements Serializable, Cloneable {
@Getter @Setter private String remotePath;
@Getter @Setter private boolean wifiOnly;
@Getter @Setter private boolean chargingOnly;
@Getter @Setter private boolean existing;
@Getter @Setter private boolean subfolderByDate;
@Getter @Setter private String account;
@Getter @Setter private int uploadAction;
Expand All @@ -54,6 +55,7 @@ public class SyncedFolder implements Serializable, Cloneable {
* @param remotePath remote path
* @param wifiOnly upload on wifi only flag
* @param chargingOnly upload on charging only
* @param existing upload existing files
* @param subfolderByDate create sub-folders by date (month)
* @param account the account owning the synced folder
* @param uploadAction the action to be done after the upload
Expand All @@ -66,15 +68,16 @@ public SyncedFolder(String localPath,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
MediaFolderType type,
boolean hidden) {
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account,
uploadAction, enabled, timestampMs, type, hidden);
}

/**
Expand All @@ -87,6 +90,7 @@ protected SyncedFolder(long id,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
Expand All @@ -99,6 +103,7 @@ protected SyncedFolder(long id,
this.remotePath = remotePath;
this.wifiOnly = wifiOnly;
this.chargingOnly = chargingOnly;
this.existing = existing;
this.subfolderByDate = subfolderByDate;
this.account = account;
this.uploadAction = uploadAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
* @param remotePath remote path
* @param wifiOnly upload on wifi only flag
* @param chargingOnly upload on charging only
* @param existing also upload existing
* @param subfolderByDate create sub-folders by date (month)
* @param account the account owning the synced folder
* @param uploadAction the action to be done after the upload
Expand All @@ -60,6 +61,7 @@ public SyncedFolderDisplayItem(long id,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
Expand All @@ -70,8 +72,8 @@ public SyncedFolderDisplayItem(long id,
long numberOfFiles,
MediaFolderType type,
boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type, hidden);
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
this.filePaths = filePaths;
this.folderName = folderName;
this.numberOfFiles = numberOfFiles;
Expand All @@ -82,14 +84,15 @@ public SyncedFolderDisplayItem(long id,
String remotePath,
boolean wifiOnly,
boolean chargingOnly,
boolean existing,
boolean subfolderByDate,
String account,
int uploadAction,
boolean enabled,
long timestampMs,
String folderName, MediaFolderType type, boolean hidden) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type, hidden);
super(id, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account, uploadAction,
enabled, timestampMs, type, hidden);
this.folderName = folderName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY)) == 1;
boolean chargingOnly = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY)) == 1;
boolean existing = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING)) == 1;
boolean subfolderByDate = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE)) == 1;
String accountName = cursor.getString(cursor.getColumnIndex(
Expand All @@ -357,8 +359,9 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
boolean hidden = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN)) == 1;

syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate,
accountName, uploadAction, enabled, enabledTimestampMs, type, hidden);
syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, existing,
subfolderByDate, accountName, uploadAction, enabled, enabledTimestampMs,
type, hidden);
}
return syncedFolder;
}
Expand All @@ -376,6 +379,7 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH, syncedFolder.getRemotePath());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY, syncedFolder.isWifiOnly());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY, syncedFolder.isChargingOnly());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING, syncedFolder.isExisting());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED, syncedFolder.isEnabled());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS, syncedFolder.getEnabledTimestampMs());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE, syncedFolder.isSubfolderByDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public long storeUpload(OCUpload ocUpload) {
cv.put(ProviderTableMeta.UPLOADS_FILE_SIZE, ocUpload.getFileSize());
cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value);
cv.put(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR, ocUpload.getLocalAction());
cv.put(ProviderTableMeta.UPLOADS_FORCE_OVERWRITE, ocUpload.isForceOverwrite() ? 1 : 0);
cv.put(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY, ocUpload.getNameCollisionPolicy().serialize());
cv.put(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER, ocUpload.isCreateRemoteFolder() ? 1 : 0);
cv.put(ProviderTableMeta.UPLOADS_LAST_RESULT, ocUpload.getLastResult().getValue());
cv.put(ProviderTableMeta.UPLOADS_CREATED_BY, ocUpload.getCreatedBy());
Expand Down Expand Up @@ -329,8 +329,8 @@ private OCUpload createOCUploadFromCursor(Cursor c) {
UploadStatus.fromValue(c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_STATUS)))
);
upload.setLocalAction(c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR)));
upload.setForceOverwrite(c.getInt(
c.getColumnIndex(ProviderTableMeta.UPLOADS_FORCE_OVERWRITE)) == 1);
upload.setNameCollisionPolicy(FileUploader.NameCollisionPolicy.deserialize(c.getInt(
c.getColumnIndex(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY))));
upload.setCreateRemoteFolder(c.getInt(
c.getColumnIndex(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER)) == 1);
upload.setUploadEndTimestamp(c.getLong(c.getColumnIndex(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP)));
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/owncloud/android/db/OCUpload.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public class OCUpload implements Parcelable {
@Getter @Setter private int localAction;

/**
* Overwrite destination file?
* What to do in case of name collision.
*/
@Getter @Setter private boolean forceOverwrite;
@Getter @Setter private FileUploader.NameCollisionPolicy nameCollisionPolicy;

/**
* Create destination folder?
Expand Down Expand Up @@ -172,7 +172,7 @@ private void resetData() {
fileSize = -1;
uploadId = -1;
localAction = FileUploader.LOCAL_BEHAVIOUR_COPY;
forceOverwrite = false;
nameCollisionPolicy = FileUploader.NameCollisionPolicy.DEFAULT;
createRemoteFolder = false;
uploadStatus = UploadStatus.UPLOAD_IN_PROGRESS;
lastResult = UploadResult.UNKNOWN;
Expand Down Expand Up @@ -281,7 +281,7 @@ private void readFromParcel(Parcel source) {
remotePath = source.readString();
accountName = source.readString();
localAction = source.readInt();
forceOverwrite = source.readInt() == 1;
nameCollisionPolicy = FileUploader.NameCollisionPolicy.deserialize(source.readInt());
createRemoteFolder = source.readInt() == 1;
try {
uploadStatus = UploadStatus.valueOf(source.readString());
Expand Down Expand Up @@ -312,7 +312,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(remotePath);
dest.writeString(accountName);
dest.writeInt(localAction);
dest.writeInt(forceOverwrite ? 1 : 0);
dest.writeInt(nameCollisionPolicy.serialize());
dest.writeInt(createRemoteFolder ? 1 : 0);
dest.writeString(uploadStatus.name());
dest.writeLong(uploadEndTimestamp);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 53;
public static final int DB_VERSION = 54;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -208,7 +208,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String UPLOADS_STATUS = "status";
public static final String UPLOADS_LOCAL_BEHAVIOUR = "local_behaviour";
public static final String UPLOADS_UPLOAD_TIME = "upload_time";
public static final String UPLOADS_FORCE_OVERWRITE = "force_overwrite";
public static final String UPLOADS_NAME_COLLISION_POLICY = "name_collision_policy";
public static final String UPLOADS_IS_CREATE_REMOTE_FOLDER = "is_create_remote_folder";
public static final String UPLOADS_UPLOAD_END_TIMESTAMP = "upload_end_timestamp";
public static final String UPLOADS_LAST_RESULT = "last_result";
Expand All @@ -223,6 +223,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String SYNCED_FOLDER_REMOTE_PATH = "remote_path";
public static final String SYNCED_FOLDER_WIFI_ONLY = "wifi_only";
public static final String SYNCED_FOLDER_CHARGING_ONLY = "charging_only";
public static final String SYNCED_FOLDER_EXISTING = "existing";
public static final String SYNCED_FOLDER_ENABLED = "enabled";
public static final String SYNCED_FOLDER_ENABLED_TIMESTAMP_MS = "enabled_timestamp_ms";
public static final String SYNCED_FOLDER_TYPE = "type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.db.OCUpload;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
Expand Down Expand Up @@ -87,6 +89,7 @@ public class FileDownloader extends Service
public static final String EXTRA_FILE_PATH = "FILE_PATH";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_LINKED_TO_PATH = "LINKED_TO";
public static final String EXTRA_CONFLICT_UPLOAD = "CONFLICT_UPLOAD";
public static final String ACCOUNT_NAME = "ACCOUNT_NAME";

private static final int FOREGROUND_SERVICE_ID = 412;
Expand All @@ -110,7 +113,10 @@ public class FileDownloader extends Service

private Notification mNotification;

private OCUpload conflictUpload;

@Inject UserAccountManager accountManager;
@Inject UploadsStorageManager uploadsStorageManager;

public static String getDownloadAddedMessage() {
return FileDownloader.class.getName() + DOWNLOAD_ADDED_MESSAGE;
Expand Down Expand Up @@ -195,6 +201,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
final String behaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
String activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME);
String packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME);
this.conflictUpload = intent.getParcelableExtra(FileDownloader.EXTRA_CONFLICT_UPLOAD);
AbstractList<String> requestedDownloads = new Vector<String>();
try {
DownloadFileOperation newDownload = new DownloadFileOperation(account, file, behaviour, activityName,
Expand Down Expand Up @@ -634,6 +641,10 @@ private void notifyDownloadResult(DownloadFileOperation download,

// Remove success notification
if (downloadResult.isSuccess()) {
if (this.conflictUpload != null) {
uploadsStorageManager.removeUpload(this.conflictUpload);
}

// Sleep 2 seconds, so show the notification before remove it
NotificationUtils.cancelWithDelay(mNotificationManager,
R.string.downloader_download_succeeded_ticker, 2000);
Expand Down
Loading