Skip to content
Closed
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 @@
423
422
50 changes: 36 additions & 14 deletions src/main/java/com/owncloud/android/datamodel/SyncedFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
/**
* Synced folder entity containing all information per synced folder.
*/
@Getter
@Setter
@AllArgsConstructor
public class SyncedFolder implements Serializable, Cloneable {
public static final long UNPERSISTED_ID = Long.MIN_VALUE;
public static final long EMPTY_ENABLED_TIMESTAMP_MS = -1;
private static final long serialVersionUID = -793476118299906429L;

private long id = UNPERSISTED_ID;
private String localPath;
private String remotePath;
private Boolean wifiOnly;
private Boolean chargingOnly;
private Boolean subfolderByDate;
private String account;
private Integer uploadAction;
private boolean enabled;
private MediaFolderType type;
@Getter @Setter private long id;
@Getter @Setter private String localPath;
@Getter @Setter private String remotePath;
@Getter @Setter private Boolean wifiOnly;
@Getter @Setter private Boolean chargingOnly;
@Getter @Setter private Boolean subfolderByDate;
@Getter @Setter private String account;
@Getter @Setter private Integer uploadAction;
@Getter private boolean enabled;
@Getter private long enabledTimestampMs;
@Getter @Setter private MediaFolderType type;

/**
* constructor for new, to be persisted entity.
Expand All @@ -59,22 +59,44 @@ public class SyncedFolder implements Serializable, Cloneable {
* @param account the account owning the synced folder
* @param uploadAction the action to be done after the upload
* @param enabled flag if synced folder config is active
* @param timestampMs the current timestamp in milliseconds
* @param type the type of the folder
*/
public SyncedFolder(String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
MediaFolderType type) {
long timestampMs, MediaFolderType type) {
this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction,
enabled, timestampMs, type);
}

/**
* constructor for wrapping existing folders.
*
* @param id id
*/
protected SyncedFolder(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
long timestampMs, MediaFolderType type) {
this.id = id;
this.localPath = localPath;
this.remotePath = remotePath;
this.wifiOnly = wifiOnly;
this.chargingOnly = chargingOnly;
this.subfolderByDate = subfolderByDate;
this.account = account;
this.uploadAction = uploadAction;
this.enabled = enabled;
this.setEnabled(enabled, timestampMs);
this.type = type;
}

/**
* @param timestampMs the current timestamp in milliseconds
*/
public void setEnabled(boolean enabled, long timestampMs) {
this.enabled = enabled;
this.enabledTimestampMs = enabled ? timestampMs : EMPTY_ENABLED_TIMESTAMP_MS;
}

public Object clone() {
try {
return super.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ public class SyncedFolderDisplayItem extends SyncedFolder {
*/
public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
List<String> filePaths, String folderName, long numberOfFiles, MediaFolderType type)
long timestampMs, List<String> filePaths, String folderName, long numberOfFiles,
MediaFolderType type)
{
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type);
this.filePaths = filePaths;
this.folderName = folderName;
this.numberOfFiles = numberOfFiles;
}

public SyncedFolderDisplayItem(long id, String localPath, String remotePath, Boolean wifiOnly, Boolean chargingOnly,
Boolean subfolderByDate, String account, Integer uploadAction, Boolean enabled,
String folderName, MediaFolderType type) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled, type);
long timestampMs, String folderName, MediaFolderType type) {
super(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate, account, uploadAction, enabled,
timestampMs, type);
this.folderName = folderName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.database.Cursor;
import android.net.Uri;

import com.nextcloud.client.core.Clock;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.owncloud.android.db.ProviderMeta;
Expand All @@ -37,6 +38,8 @@
import java.util.List;
import java.util.Observable;

import javax.inject.Inject;

import androidx.annotation.NonNull;

import static com.owncloud.android.datamodel.OCFile.PATH_SEPARATOR;
Expand All @@ -50,6 +53,8 @@ public class SyncedFolderProvider extends Observable {
private ContentResolver mContentResolver;
private AppPreferences preferences;

@Inject protected Clock clock;

/**
* constructor.
*
Expand Down Expand Up @@ -162,7 +167,7 @@ public int updateSyncedFolderEnabled(long id, Boolean enabled) {
// read sync folder object and update
SyncedFolder syncedFolder = createSyncedFolderFromCursor(cursor);

syncedFolder.setEnabled(enabled);
syncedFolder.setEnabled(enabled, clock.getCurrentTime());

// update sync folder object in db
result = updateSyncFolder(syncedFolder);
Expand Down Expand Up @@ -347,11 +352,13 @@ private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION));
Boolean enabled = cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED)) == 1;
long enabledTimestampMs = cursor.getLong(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS));
MediaFolderType type = MediaFolderType.getById(cursor.getInt(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE)));

syncedFolder = new SyncedFolder(id, localPath, remotePath, wifiOnly, chargingOnly, subfolderByDate,
accountName, uploadAction, enabled, type);
accountName, uploadAction, enabled, enabledTimestampMs, type);
}
return syncedFolder;
}
Expand All @@ -370,6 +377,7 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY, syncedFolder.getWifiOnly());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY, syncedFolder.getChargingOnly());
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.getSubfolderByDate());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT, syncedFolder.getAccount());
cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION, syncedFolder.getUploadAction());
Expand Down
3 changes: 2 additions & 1 deletion 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 = 49;
public static final int DB_VERSION = 50;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -220,6 +220,7 @@ static public class ProviderTableMeta implements BaseColumns {
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_ENABLED = "enabled";
public static final String SYNCED_FOLDER_ENABLED_TIMESTAMP_MS = "enabled_timestamp_ms";
public static final String SYNCED_FOLDER_TYPE = "type";
public static final String SYNCED_FOLDER_SUBFOLDER_BY_DATE = "subfolder_by_date";
public static final String SYNCED_FOLDER_ACCOUNT = "account";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import com.owncloud.android.ui.events.AccountRemovedEvent;
import com.owncloud.android.utils.EncryptionUtils;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.FilesSyncHelper;
import com.owncloud.android.utils.PushUtils;

import org.greenrobot.eventbus.EventBus;
Expand Down Expand Up @@ -129,7 +128,7 @@ protected Result onRunJob(@NotNull Params params) {
arbitraryDataProvider.deleteKeyForAccount(account.name, PENDING_FOR_REMOVAL);

// remove synced folders set for account
remoceSyncedFolders(context, account, arbitraryDataProvider);
remoceSyncedFolders(context, account);

// delete all uploads for account
uploadsStorageManager.removeAccountUploads(account);
Expand Down Expand Up @@ -174,7 +173,7 @@ private void unregisterPushNotifications(Context context, Account account, Arbit
}
}

private void remoceSyncedFolders(Context context, Account account, ArbitraryDataProvider arbitraryDataProvider) {
private void remoceSyncedFolders(Context context, Account account) {
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver(),
AppPreferencesImpl.fromContext(context));
List<SyncedFolder> syncedFolders = syncedFolderProvider.getSyncedFolders();
Expand All @@ -183,8 +182,6 @@ private void remoceSyncedFolders(Context context, Account account, ArbitraryData

for (SyncedFolder syncedFolder : syncedFolders) {
if (syncedFolder.getAccount().equals(account.name)) {
arbitraryDataProvider.deleteKeyForAccount(FilesSyncHelper.GLOBAL,
FilesSyncHelper.SYNCEDFOLDERINITIATED + syncedFolder.getId());
syncedFolderIds.add(syncedFolder.getId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
import android.os.Binder;
import android.text.TextUtils;

import com.nextcloud.client.core.Clock;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.SyncedFolder;
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
import com.owncloud.android.lib.common.accounts.AccountUtils;
Expand All @@ -58,6 +60,8 @@
import java.util.HashMap;
import java.util.Locale;

import javax.inject.Inject;

import androidx.annotation.NonNull;

/**
Expand Down Expand Up @@ -91,6 +95,7 @@ public class FileContentProvider extends ContentProvider {
public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20;
public static final int MINIMUM_PATH_SEGMENTS_SIZE = 1;

@Inject protected Clock clock;
private DataBaseHelper mDbHelper;
private Context mContext;
private UriMatcher mUriMatcher;
Expand Down Expand Up @@ -822,6 +827,7 @@ private void createSyncedFoldersTable(SQLiteDatabase db) {
+ ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY + " INTEGER, " // wifi_only
+ ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY + " INTEGER, " // charging only
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED + " INTEGER, " // enabled
+ ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER, " // enable date
+ ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE + " INTEGER, " // subfolder by date
+ ProviderTableMeta.SYNCED_FOLDER_ACCOUNT + " TEXT, " // account
+ ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION + " INTEGER, " // upload action
Expand Down Expand Up @@ -2013,6 +2019,30 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}

if (oldVersion < 50 && newVersion >= 50) {
Log_OC.i(SQL, "Entering in the #50 add persistent enable date to synced_folders table");
db.beginTransaction();
try {
db.execSQL(ALTER_TABLE + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " INTEGER ");

db.execSQL("UPDATE " + ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME + " SET " +
ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS + " = CASE " +
" WHEN enabled = 0 THEN " + SyncedFolder.EMPTY_ENABLED_TIMESTAMP_MS + " " +
" ELSE " + clock.getCurrentTime() +
" END ");

upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}

if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
}

@Override
Expand Down
Loading