From: masensio Date: Wed, 11 Nov 2015 10:08:32 +0000 (+0100) Subject: Read capabilities for showing Share Options X-Git-Tag: oc-android-1.9^2~21^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/35922a08c1c1c4627c8b07a5babe4add214079e7?hp=--cc Read capabilities for showing Share Options Updated library reference after merge in master --- 35922a08c1c1c4627c8b07a5babe4add214079e7 diff --git a/owncloud-android-library b/owncloud-android-library index 32ab89fc..b09969d0 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 32ab89fc308af2a51b9b7ded7fb40fc786dfd8a6 +Subproject commit b09969d078b3a790b01c8d61a7298a37439a9f24 diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 2d353d2b..237c8469 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -50,6 +50,8 @@ import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.status.CapabilityBooleanType; +import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.utils.FileStorageUtils; import java.io.FileInputStream; @@ -1737,4 +1739,183 @@ public class FileDataStorageManager { } } + + public OCCapability saveCapabilities(OCCapability capability){ + + // Prepare capabilities data + ContentValues cv = new ContentValues(); + cv.put(ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME, mAccount.name); + cv.put(ProviderTableMeta.CAPABILITIES_VERSION_MAYOR, capability.getVersionMayor()); + cv.put(ProviderTableMeta.CAPABILITIES_VERSION_MINOR, capability.getVersionMinor()); + cv.put(ProviderTableMeta.CAPABILITIES_VERSION_MICRO, capability.getVersionMicro()); + cv.put(ProviderTableMeta.CAPABILITIES_VERSION_STRING, capability.getVersionString()); + cv.put(ProviderTableMeta.CAPABILITIES_VERSION_EDITION, capability.getVersionEdition()); + cv.put(ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL, capability.getCorePollinterval()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED, capability.getFilesSharingApiEnabled().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED, + capability.getFilesSharingPublicEnabled().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED, + capability.getFilesSharingPublicPasswordEnforced().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED, + capability.getFilesSharingPublicExpireDateEnabled().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS, + capability.getFilesSharingPublicExpireDateDays()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED, + capability.getFilesSharingPublicExpireDateEnforced().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL, + capability.getFilesSharingPublicSendMail().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD, + capability.getFilesSharingPublicUpload().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL, + capability.getFilesSharingUserSendMail().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_RESHARING, capability.getFilesSharingResharing().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING, + capability.getFilesSharingFederationOutgoing().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING, + capability.getFilesSharingFederationIncoming().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING, capability.getFilesBigFileChuncking().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_FILES_UNDELETE, capability.getFilesUndelete().getValue()); + cv.put(ProviderTableMeta.CAPABILITIES_FILES_VERSIONING, capability.getFilesVersioning().getValue()); + + if (capabilityExists(mAccount.name)) { + if (getContentResolver() != null) { + getContentResolver().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES, cv, + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?", + new String[]{mAccount.name}); + } else { + try { + getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_CAPABILITIES, + cv, ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=?", + new String[]{mAccount.name}); + } catch (RemoteException e) { + Log_OC.e(TAG, + "Fail to insert insert file to database " + + e.getMessage()); + } + } + } else { + Uri result_uri = null; + if (getContentResolver() != null) { + result_uri = getContentResolver().insert( + ProviderTableMeta.CONTENT_URI_CAPABILITIES, cv); + } else { + try { + result_uri = getContentProviderClient().insert( + ProviderTableMeta.CONTENT_URI_CAPABILITIES, cv); + } catch (RemoteException e) { + Log_OC.e(TAG, + "Fail to insert insert capability to database " + + e.getMessage()); + } + } + if (result_uri != null) { + long new_id = Long.parseLong(result_uri.getPathSegments() + .get(1)); + capability.setId(new_id); + capability.setAccountName(mAccount.name); + } + } + + return capability; + } + + private boolean capabilityExists(String accountName) { + Cursor c = getCapabilityCursorForAccount(accountName); + boolean exists = false; + if (c != null) { + exists = c.moveToFirst(); + c.close(); + } + return exists; + } + + private Cursor getCapabilityCursorForAccount(String accountName){ + Cursor c = null; + if (getContentResolver() != null) { + c = getContentResolver() + .query(ProviderTableMeta.CONTENT_URI_CAPABILITIES, + null, + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=? ", + new String[]{accountName}, null); + } else { + try { + c = getContentProviderClient().query( + ProviderTableMeta.CONTENT_URI_CAPABILITIES, + null, + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + "=? ", + new String[]{accountName}, null); + } catch (RemoteException e) { + Log_OC.e(TAG, + "Couldn't determine capability existance, assuming non existance: " + + e.getMessage()); + } + } + + return c; + + } + public OCCapability getCapability(String accountName){ + OCCapability capability = null; + Cursor c = getCapabilityCursorForAccount(accountName); + + if (c.moveToFirst()) { + capability = createCapabilityInstance(c); + } + c.close(); + return capability; + } + + private OCCapability createCapabilityInstance(Cursor c) { + OCCapability capability = null; + if (c != null) { + capability = new OCCapability(); + capability.setId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID))); + capability.setAccountName(c.getString(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME))); + capability.setVersionMayor(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_MAYOR))); + capability.setVersionMinor(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_MINOR))); + capability.setVersionMicro(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_MICRO))); + capability.setVersionString(c.getString(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_STRING))); + capability.setVersionEdition(c.getString(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_VERSION_EDITION))); + capability.setCorePollinterval(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL))); + capability.setFilesSharingApiEnabled(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED)))); + capability.setFilesSharingPublicEnabled(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED)))); + capability.setFilesSharingPublicPasswordEnforced(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED)))); + capability.setFilesSharingPublicExpireDateEnabled(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED)))); + capability.setFilesSharingPublicExpireDateDays(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS))); + capability.setFilesSharingPublicExpireDateEnforced(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED)))); + capability.setFilesSharingPublicSendMail(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL)))); + capability.setFilesSharingPublicUpload(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD)))); + capability.setFilesSharingUserSendMail(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL)))); + capability.setFilesSharingResharing(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_RESHARING)))); + capability.setFilesSharingFederationOutgoing(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING)))); + capability.setFilesSharingFederationIncoming(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING)))); + capability.setFilesBigFileChuncking(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING)))); + capability.setFilesUndelete(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_UNDELETE)))); + capability.setFilesVersioning(CapabilityBooleanType.fromValue(c.getInt(c + .getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_VERSIONING)))); + + } + return capability; + } } diff --git a/src/com/owncloud/android/db/ProviderMeta.java b/src/com/owncloud/android/db/ProviderMeta.java index 82ad94e9..1c674339 100644 --- a/src/com/owncloud/android/db/ProviderMeta.java +++ b/src/com/owncloud/android/db/ProviderMeta.java @@ -31,7 +31,7 @@ import com.owncloud.android.MainApp; public class ProviderMeta { public static final String DB_NAME = "filelist"; - public static final int DB_VERSION = 12; + public static final int DB_VERSION = 13; private ProviderMeta() { } @@ -39,6 +39,7 @@ public class ProviderMeta { static public class ProviderTableMeta implements BaseColumns { public static final String FILE_TABLE_NAME = "filelist"; public static final String OCSHARES_TABLE_NAME = "ocshares"; + public static final String CAPABILITIES_TABLE_NAME = "capabilities"; public static final Uri CONTENT_URI = Uri.parse("content://" + MainApp.getAuthority() + "/"); public static final Uri CONTENT_URI_FILE = Uri.parse("content://" @@ -47,6 +48,8 @@ public class ProviderMeta { + MainApp.getAuthority() + "/dir"); public static final Uri CONTENT_URI_SHARE = Uri.parse("content://" + MainApp.getAuthority() + "/shares"); + public static final Uri CONTENT_URI_CAPABILITIES = Uri.parse("content://" + + MainApp.getAuthority() + "/capabilities"); public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file"; public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file"; @@ -62,7 +65,7 @@ public class ProviderMeta { public static final String FILE_STORAGE_PATH = "media_path"; public static final String FILE_PATH = "path"; public static final String FILE_ACCOUNT_OWNER = "file_owner"; - public static final String FILE_LAST_SYNC_DATE = "last_sync_date"; // _for_properties, but let's keep it as it is + public static final String FILE_LAST_SYNC_DATE = "last_sync_date";// _for_properties, but let's keep it as it is public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data"; public static final String FILE_KEEP_IN_SYNC = "keep_in_sync"; public static final String FILE_ETAG = "etag"; @@ -97,5 +100,34 @@ public class ProviderMeta { public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE + " collate nocase asc"; + // Columns of capabilities table + public static final String CAPABILITIES_ACCOUNT_NAME = "account"; + public static final String CAPABILITIES_VERSION_MAYOR = "version_mayor"; + public static final String CAPABILITIES_VERSION_MINOR = "version_minor"; + public static final String CAPABILITIES_VERSION_MICRO = "version_micro"; + public static final String CAPABILITIES_VERSION_STRING = "version_string"; + public static final String CAPABILITIES_VERSION_EDITION = "version_edition"; + public static final String CAPABILITIES_CORE_POLLINTERVAL = "core_pollinterval"; + public static final String CAPABILITIES_SHARING_API_ENABLED = "sharing_api_enabled"; + public static final String CAPABILITIES_SHARING_PUBLIC_ENABLED = "sharing_public_enabled"; + public static final String CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED = "sharing_public_password_enforced"; + public static final String CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED = + "sharing_public_expire_date_enabled"; + public static final String CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS = + "sharing_public_expire_date_days"; + public static final String CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED = + "sharing_public_expire_date_enforced"; + public static final String CAPABILITIES_SHARING_PUBLIC_SEND_MAIL = "sharing_public_send_mail"; + public static final String CAPABILITIES_SHARING_PUBLIC_UPLOAD = "sharing_public_upload"; + public static final String CAPABILITIES_SHARING_USER_SEND_MAIL = "sharing_user_send_mail"; + public static final String CAPABILITIES_SHARING_RESHARING = "sharing_resharing"; + public static final String CAPABILITIES_SHARING_FEDERATION_OUTGOING = "sharing_federation_outgoing"; + public static final String CAPABILITIES_SHARING_FEDERATION_INCOMING = "sharing_federation_incoming"; + public static final String CAPABILITIES_FILES_BIGFILECHUNKING = "files_bigfilechunking"; + public static final String CAPABILITIES_FILES_UNDELETE = "files_undelete"; + public static final String CAPABILITIES_FILES_VERSIONING = "files_versioning"; + + public static final String CAPABILITIES_DEFAULT_SORT_ORDER = CAPABILITIES_ACCOUNT_NAME + + " collate nocase asc"; } } diff --git a/src/com/owncloud/android/files/FileMenuFilter.java b/src/com/owncloud/android/files/FileMenuFilter.java index 66ada1c0..25d3027a 100644 --- a/src/com/owncloud/android/files/FileMenuFilter.java +++ b/src/com/owncloud/android/files/FileMenuFilter.java @@ -35,6 +35,8 @@ import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; +import com.owncloud.android.lib.resources.status.CapabilityBooleanType; +import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.activity.ComponentsGetter; @@ -200,7 +202,10 @@ public class FileMenuFilter { } // SHARE FILE, with Users - if (!shareAllowed || mFile == null) { + OCCapability capability = mComponentsGetter.getStorageManager().getCapability(mAccount.name); + boolean shareApiEnabled = capability != null && + (capability.getFilesSharingApiEnabled().isTrue() || capability.getFilesSharingApiEnabled().isUnknown()); + if (!shareAllowed || mFile == null || !shareApiEnabled ) { toHide.add(R.id.action_share_with_users); } else { toShow.add(R.id.action_share_with_users); diff --git a/src/com/owncloud/android/operations/GetCapabilitiesOperarion.java b/src/com/owncloud/android/operations/GetCapabilitiesOperarion.java new file mode 100644 index 00000000..0a63449d --- /dev/null +++ b/src/com/owncloud/android/operations/GetCapabilitiesOperarion.java @@ -0,0 +1,51 @@ +/** + * ownCloud Android client application + * + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.owncloud.android.operations; + +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation; +import com.owncloud.android.lib.resources.status.OCCapability; +import com.owncloud.android.operations.common.SyncOperation; + +/** + * Get and save capabilities from the server + */ +public class GetCapabilitiesOperarion extends SyncOperation { + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + GetRemoteCapabilitiesOperation getCapabilities = new GetRemoteCapabilitiesOperation(); + RemoteOperationResult result = getCapabilities.execute(client); + + if (result.isSuccess()){ + // Read data from the result + if( result.getData()!= null && result.getData().size() > 0) { + OCCapability capability = (OCCapability) result.getData().get(0); + + // Save the capabilities into database + getStorageManager().saveCapabilities(capability); + } + } + + return result; + } + +} diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index adb4ac4c..71baf23d 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -187,6 +187,7 @@ public class RefreshFolderOperation extends RemoteOperation { if (OCFile.ROOT_PATH.equals(mLocalFolder.getRemotePath()) && !mSyncFullAccount) { updateOCVersion(client); + } result = checkForChanges(client); @@ -231,10 +232,24 @@ public class RefreshFolderOperation extends RemoteOperation { RemoteOperationResult result = update.execute(client); if (result.isSuccess()) { mIsShareSupported = update.getOCVersion().isSharedSupported(); + + // Update Capabilities for this account + if (update.getOCVersion().isVersionWithCapabilitiesAPI()) { + updateCapabilities(client); + } else { + Log_OC.d(TAG, "Capabilities API disabled"); + } + } + } + + private void updateCapabilities(OwnCloudClient client){ + GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion(); + RemoteOperationResult result = getCapabilities.execute(mStorageManager,mContext); + if (!result.isSuccess()){ + Log_OC.d(TAG, "Update Capabilities unsuccessfully"); } } - private RemoteOperationResult checkForChanges(OwnCloudClient client) { mRemoteFolderChanged = true; RemoteOperationResult result = null; diff --git a/src/com/owncloud/android/operations/common/SyncOperation.java b/src/com/owncloud/android/operations/common/SyncOperation.java index 5fb5c8cf..3d917d2a 100644 --- a/src/com/owncloud/android/operations/common/SyncOperation.java +++ b/src/com/owncloud/android/operations/common/SyncOperation.java @@ -20,16 +20,15 @@ package com.owncloud.android.operations.common; -import com.owncloud.android.MainApp; +import android.content.Context; +import android.os.Handler; + import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import android.content.Context; -import android.os.Handler; - /** * Operation which execution involves both interactions with an ownCloud server and diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index d94d5b5a..e652bade 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -22,20 +22,6 @@ package com.owncloud.android.providers; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; - -import com.owncloud.android.MainApp; -import com.owncloud.android.R; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.db.ProviderMeta; -import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; -import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.utils.FileStorageUtils; - import android.accounts.Account; import android.accounts.AccountManager; import android.content.ContentProvider; @@ -54,6 +40,19 @@ import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; import android.text.TextUtils; +import com.owncloud.android.MainApp; +import com.owncloud.android.R; +import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.db.ProviderMeta; +import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; +import com.owncloud.android.lib.common.accounts.AccountUtils; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.utils.FileStorageUtils; + +import java.io.File; +import java.util.ArrayList; + /** * The ContentProvider for the ownCloud App. */ @@ -61,99 +60,14 @@ public class FileContentProvider extends ContentProvider { private DataBaseHelper mDbHelper; - // Projection for filelist table - private static HashMap mFileProjectionMap; - static { - mFileProjectionMap = new HashMap(); - mFileProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID); - mFileProjectionMap.put(ProviderTableMeta.FILE_PARENT, - ProviderTableMeta.FILE_PARENT); - mFileProjectionMap.put(ProviderTableMeta.FILE_PATH, - ProviderTableMeta.FILE_PATH); - mFileProjectionMap.put(ProviderTableMeta.FILE_NAME, - ProviderTableMeta.FILE_NAME); - mFileProjectionMap.put(ProviderTableMeta.FILE_CREATION, - ProviderTableMeta.FILE_CREATION); - mFileProjectionMap.put(ProviderTableMeta.FILE_MODIFIED, - ProviderTableMeta.FILE_MODIFIED); - mFileProjectionMap.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, - ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA); - mFileProjectionMap.put(ProviderTableMeta.FILE_CONTENT_LENGTH, - ProviderTableMeta.FILE_CONTENT_LENGTH); - mFileProjectionMap.put(ProviderTableMeta.FILE_CONTENT_TYPE, - ProviderTableMeta.FILE_CONTENT_TYPE); - mFileProjectionMap.put(ProviderTableMeta.FILE_STORAGE_PATH, - ProviderTableMeta.FILE_STORAGE_PATH); - mFileProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, - ProviderTableMeta.FILE_LAST_SYNC_DATE); - mFileProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, - ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA); - mFileProjectionMap.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, - ProviderTableMeta.FILE_KEEP_IN_SYNC); - mFileProjectionMap.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, - ProviderTableMeta.FILE_ACCOUNT_OWNER); - mFileProjectionMap.put(ProviderTableMeta.FILE_ETAG, - ProviderTableMeta.FILE_ETAG); - mFileProjectionMap.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, - ProviderTableMeta.FILE_SHARED_VIA_LINK); - mFileProjectionMap.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, - ProviderTableMeta.FILE_SHARED_WITH_SHAREE); - mFileProjectionMap.put(ProviderTableMeta.FILE_PUBLIC_LINK, - ProviderTableMeta.FILE_PUBLIC_LINK); - mFileProjectionMap.put(ProviderTableMeta.FILE_PERMISSIONS, - ProviderTableMeta.FILE_PERMISSIONS); - mFileProjectionMap.put(ProviderTableMeta.FILE_REMOTE_ID, - ProviderTableMeta.FILE_REMOTE_ID); - mFileProjectionMap.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, - ProviderTableMeta.FILE_UPDATE_THUMBNAIL); - mFileProjectionMap.put(ProviderTableMeta.FILE_IS_DOWNLOADING, - ProviderTableMeta.FILE_IS_DOWNLOADING); - mFileProjectionMap.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, - ProviderTableMeta.FILE_ETAG_IN_CONFLICT); - } - private static final int SINGLE_FILE = 1; private static final int DIRECTORY = 2; private static final int ROOT_DIRECTORY = 3; private static final int SHARES = 4; + private static final int CAPABILITIES = 5; private static final String TAG = FileContentProvider.class.getSimpleName(); - // Projection for ocshares table - private static HashMap mOCSharesProjectionMap; - static { - mOCSharesProjectionMap = new HashMap(); - mOCSharesProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, - ProviderTableMeta.OCSHARES_FILE_SOURCE); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, - ProviderTableMeta.OCSHARES_ITEM_SOURCE); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, - ProviderTableMeta.OCSHARES_SHARE_TYPE); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_WITH, - ProviderTableMeta.OCSHARES_SHARE_WITH); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_PATH, - ProviderTableMeta.OCSHARES_PATH); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_PERMISSIONS, - ProviderTableMeta.OCSHARES_PERMISSIONS); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARED_DATE, - ProviderTableMeta.OCSHARES_SHARED_DATE); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, - ProviderTableMeta.OCSHARES_EXPIRATION_DATE); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_TOKEN, - ProviderTableMeta.OCSHARES_TOKEN); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, - ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, - ProviderTableMeta.OCSHARES_IS_DIRECTORY); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_USER_ID, - ProviderTableMeta.OCSHARES_USER_ID); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, - ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED); - mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, - ProviderTableMeta.OCSHARES_ACCOUNT_OWNER); - } - private UriMatcher mUriMatcher; @Override @@ -253,6 +167,9 @@ public class FileContentProvider extends ContentProvider { case SHARES: count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs); break; + case CAPABILITIES: + count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs); + break; default: //Log_OC.e(TAG, "Unknown uri " + uri); throw new IllegalArgumentException("Unknown uri: " + uri.toString()); @@ -338,6 +255,17 @@ public class FileContentProvider extends ContentProvider { updateFilesTableAccordingToShareInsertion(db, values); return insertedShareUri; + case CAPABILITIES: + Uri insertedCapUri = null; + long id = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values); + if (id >0) { + insertedCapUri = + ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, id); + } else { + throw new SQLException("ERROR " + uri); + + } + return insertedCapUri; default: throw new IllegalArgumentException("Unknown uri id: " + uri); @@ -379,6 +307,8 @@ public class FileContentProvider extends ContentProvider { mUriMatcher.addURI(authority, "dir/#", DIRECTORY); mUriMatcher.addURI(authority, "shares/", SHARES); mUriMatcher.addURI(authority, "shares/#", SHARES); + mUriMatcher.addURI(authority, "capabilities/", CAPABILITIES); + mUriMatcher.addURI(authority, "capabilities/#", CAPABILITIES); return true; } @@ -417,7 +347,6 @@ public class FileContentProvider extends ContentProvider { SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder(); sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME); - sqlQuery.setProjectionMap(mFileProjectionMap); switch (mUriMatcher.match(uri)) { case ROOT_DIRECTORY: @@ -435,7 +364,13 @@ public class FileContentProvider extends ContentProvider { break; case SHARES: sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME); - sqlQuery.setProjectionMap(mOCSharesProjectionMap); + if (uri.getPathSegments().size() > 1) { + sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + + uri.getPathSegments().get(1)); + } + break; + case CAPABILITIES: + sqlQuery.setTables(ProviderTableMeta.CAPABILITIES_TABLE_NAME); if (uri.getPathSegments().size() > 1) { sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1)); @@ -447,11 +382,16 @@ public class FileContentProvider extends ContentProvider { String order; if (TextUtils.isEmpty(sortOrder)) { - if (mUriMatcher.match(uri) == SHARES) { - order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER; - } else { - - order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER; + switch (mUriMatcher.match(uri)) { + case SHARES: + order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER; + break; + case CAPABILITIES: + order = ProviderTableMeta.CAPABILITIES_DEFAULT_SORT_ORDER; + break; + default: // Files + order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER; + break; } } else { order = sortOrder; @@ -496,6 +436,10 @@ public class FileContentProvider extends ContentProvider { return db.update( ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs ); + case CAPABILITIES: + return db.update( + ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs + ); default: return db.update( ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs @@ -539,30 +483,30 @@ public class FileContentProvider extends ContentProvider { // files table Log_OC.i("SQL", "Entering in onCreate"); db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "(" - + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " - + ProviderTableMeta.FILE_NAME + " TEXT, " - + ProviderTableMeta.FILE_PATH + " TEXT, " - + ProviderTableMeta.FILE_PARENT + " INTEGER, " - + ProviderTableMeta.FILE_CREATION + " INTEGER, " - + ProviderTableMeta.FILE_MODIFIED + " INTEGER, " - + ProviderTableMeta.FILE_CONTENT_TYPE + " TEXT, " - + ProviderTableMeta.FILE_CONTENT_LENGTH + " INTEGER, " - + ProviderTableMeta.FILE_STORAGE_PATH + " TEXT, " - + ProviderTableMeta.FILE_ACCOUNT_OWNER + " TEXT, " - + ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, " - + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, " - + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, " - + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " - + ProviderTableMeta.FILE_ETAG + " TEXT, " - + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER, " - + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, " - + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null," - + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null," - + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean - + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER," //boolean - + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT," - + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);" - ); + + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + + ProviderTableMeta.FILE_NAME + " TEXT, " + + ProviderTableMeta.FILE_PATH + " TEXT, " + + ProviderTableMeta.FILE_PARENT + " INTEGER, " + + ProviderTableMeta.FILE_CREATION + " INTEGER, " + + ProviderTableMeta.FILE_MODIFIED + " INTEGER, " + + ProviderTableMeta.FILE_CONTENT_TYPE + " TEXT, " + + ProviderTableMeta.FILE_CONTENT_LENGTH + " INTEGER, " + + ProviderTableMeta.FILE_STORAGE_PATH + " TEXT, " + + ProviderTableMeta.FILE_ACCOUNT_OWNER + " TEXT, " + + ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, " + + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, " + + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, " + + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " + + ProviderTableMeta.FILE_ETAG + " TEXT, " + + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER, " + + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, " + + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null," + + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null," + + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean + + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER," //boolean + + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT," + + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);" + ); // Create table ocshares db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "(" @@ -581,6 +525,10 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, " + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" ); + + // Create table capabilities + createCapabilitiesTable(db); + } @Override @@ -797,9 +745,52 @@ public class FileContentProvider extends ContentProvider { Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); + if (oldVersion < 13 && newVersion >= 13) { + Log_OC.i("SQL", "Entering in the #13 ADD in onUpgrade"); + db.beginTransaction(); + try { + // Create capabilities table + createCapabilitiesTable(db); + upgraded = true; + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + if (!upgraded) + Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + + ", newVersion == " + newVersion); + } } + private void createCapabilitiesTable(SQLiteDatabase db){ + // Create table capabilities + db.execSQL("CREATE TABLE " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + "(" + + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + " TEXT, " + + ProviderTableMeta.CAPABILITIES_VERSION_MAYOR + " INTEGER, " + + ProviderTableMeta.CAPABILITIES_VERSION_MINOR + " INTEGER, " + + ProviderTableMeta.CAPABILITIES_VERSION_MICRO + " INTEGER, " + + ProviderTableMeta.CAPABILITIES_VERSION_STRING + " TEXT, " + + ProviderTableMeta.CAPABILITIES_VERSION_EDITION + " TEXT, " + + ProviderTableMeta.CAPABILITIES_CORE_POLLINTERVAL + " INTEGER, " + + ProviderTableMeta.CAPABILITIES_SHARING_API_ENABLED + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_ENABLED + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_PASSWORD_ENFORCED + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENABLED + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_DAYS + " INTEGER, " + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_EXPIRE_DATE_ENFORCED + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_SEND_MAIL + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_PUBLIC_UPLOAD + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_USER_SEND_MAIL + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_RESHARING + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_OUTGOING + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_SHARING_FEDERATION_INCOMING + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + " INTEGER, " // boolean + + ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + " INTEGER );" ); // boolean + } /** * Version 10 of database does not modify its scheme. It coincides with the upgrade of the ownCloud account names