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 @@
481
483
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.OCFile;
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 @@ -344,4 +346,14 @@ private static Account migrateAccount(Context context, Account currentAccount, A
// will assume it succeeds, not a big deal otherwise
return newAccount;
}

/**
* Checks if an account owns the file (file's ownerId is the same as account name)
* @param file File to check
* @param account account to compare
* @return false if ownerId is not set or owner is a different account
*/
public static boolean accountOwnsFile(OCFile file, Account account) {
return !TextUtils.isEmpty(file.getOwnerId()) && account.name.split("@")[0].equals(file.getOwnerId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ public boolean saveFile(OCFile file) {
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading());
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
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());

boolean sameRemotePath = fileExists(file.getRemotePath());
if (sameRemotePath ||
Expand Down Expand Up @@ -443,6 +445,8 @@ private ContentValues createContentValueForFile(OCFile folder) {
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());

return cv;
}
Expand Down Expand Up @@ -479,6 +483,8 @@ private ContentValues createContentValueForFile(OCFile file, OCFile folder) {
cv.put(ProviderTableMeta.FILE_MOUNT_TYPE, file.getMountType().ordinal());
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());

return cv;
}
Expand Down Expand Up @@ -975,6 +981,8 @@ private OCFile createFileInstance(Cursor c) {
c.getColumnIndex(ProviderTableMeta.FILE_MOUNT_TYPE))]);
file.setPreviewAvailable(c.getInt(c.getColumnIndex(ProviderTableMeta.FILE_HAS_PREVIEW)) == 1);
file.setUnreadCommentsCount(c.getInt(c.getColumnIndex(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT)));
file.setOwnerId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_OWNER_ID)));
file.setOwnerDisplayName(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)));
}

return file;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
@Getter @Setter private boolean favorite;
@Getter @Setter private boolean encrypted;
@Getter @Setter private WebdavEntry.MountType mountType;
@Getter
@Setter
private int unreadCommentsCount;
@Getter @Setter private int unreadCommentsCount;
@Getter @Setter private String ownerId;
@Getter @Setter private String ownerDisplayName;

/**
* URI to the local path of the file contents, if stored in the device; cached after first call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -858,7 +859,7 @@ private int getAvatarDimension() {
return Math.round(r.getDimension(R.dimen.file_avatar_size));
}

private @Nullable
private @NotNull
Drawable doAvatarInBackground() {
Bitmap avatar = null;

Expand Down Expand Up @@ -923,7 +924,6 @@ Drawable doAvatarInBackground() {
// everything else
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;

}
} catch (Exception e) {
try {
Expand All @@ -936,15 +936,17 @@ Drawable doAvatarInBackground() {
get.releaseConnection();
}
}
}

if (avatar == null) {
try {
return TextDrawable.createAvatar(mAccount.name, mAvatarRadius);
} catch (Exception e) {
Log_OC.e(TAG, "Error generating fallback avatar");
} catch (Exception e1) {
return mResources.getDrawable(R.drawable.ic_user);
}
} else {
return BitmapUtils.bitmapToCircularBitmapDrawable(mResources, avatar);
}

return BitmapUtils.bitmapToCircularBitmapDrawable(mResources, avatar);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class ProviderMeta {

public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 42;
public static final int DB_VERSION = 43;

private ProviderMeta() {
}
Expand Down Expand Up @@ -106,6 +106,8 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String FILE_MOUNT_TYPE = "mount_type";
public static final String FILE_HAS_PREVIEW = "has_preview";
public static final String FILE_UNREAD_COMMENTS_COUNT = "unread_comments_count";
public static final String FILE_OWNER_ID = "owner_id";
public static final String FILE_OWNER_DISPLAY_NAME = "owner_display_name";

public static final String[] FILE_ALL_COLUMNS = {
_ID, FILE_PARENT, FILE_NAME, FILE_CREATION, FILE_MODIFIED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ private void createFilesTable(SQLiteDatabase db) {
+ ProviderTableMeta.FILE_SHARED_WITH_SHAREE + INTEGER
+ ProviderTableMeta.FILE_MOUNT_TYPE + INTEGER
+ ProviderTableMeta.FILE_HAS_PREVIEW + INTEGER
+ ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + " INTEGER);"
+ ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT + INTEGER
+ ProviderTableMeta.FILE_OWNER_ID + TEXT
+ ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + " TEXT);"
);
}

Expand Down Expand Up @@ -1860,6 +1862,26 @@ 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 < 43 && newVersion >= 43) {
Log_OC.i(SQL, "Entering in the #43 add ownerId and owner display name to file table");
db.beginTransaction();
try {
db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.FILE_OWNER_ID + " TEXT ");
db.execSQL(ALTER_TABLE + ProviderTableMeta.FILE_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.FILE_OWNER_DISPLAY_NAME + " TEXT ");

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