From 5499441738a97cc2ebfb9a4b670c308291950050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Thu, 17 Nov 2022 10:05:30 +0100 Subject: [PATCH] Use Room DAO for ArbitraryDataProvider instead of contentResolver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Brey --- .../java/com/nextcloud/client/TestActivity.kt | 2 +- .../com/owncloud/android/utils/PushUtils.java | 6 +- app/src/main/AndroidManifest.xml | 4 - .../account/UserAccountManagerImpl.java | 2 +- .../client/database/DatabaseModule.kt | 18 +-- .../client/database/NextcloudDatabase.kt | 32 ++++ .../client/database/dao/ArbitraryDataDao.kt | 41 +++++ .../migrations/LegacyMigrationHelper.java | 5 +- .../com/nextcloud/client/di/AppModule.java | 6 +- .../client/jobs/AccountRemovalWork.kt | 2 +- .../nextcloud/client/jobs/FilesSyncWork.kt | 2 +- .../client/jobs/MediaFoldersDetectionWork.kt | 2 +- .../preferences/AppPreferencesImpl.java | 8 +- .../java/com/owncloud/android/MainApp.java | 2 +- .../datamodel/ArbitraryDataProvider.java | 151 +++--------------- .../android/datamodel/ArbitraryDataSet.kt | 27 ---- .../datamodel/ThumbnailsCacheManager.java | 2 +- .../com/owncloud/android/db/ProviderMeta.java | 2 - .../operations/CreateFolderOperation.java | 2 +- .../operations/RefreshFolderOperation.java | 2 +- .../RemoveRemoteEncryptedFileOperation.java | 2 +- .../operations/UploadFileOperation.java | 2 +- .../providers/FileContentProvider.java | 25 --- .../UsersAndGroupsSearchProvider.java | 2 +- .../android/ui/activity/DrawerActivity.java | 2 +- .../android/ui/activity/FileActivity.java | 2 +- .../ui/activity/ManageAccountsActivity.java | 4 +- .../ui/activity/NotificationsActivity.java | 2 +- .../android/ui/activity/SettingsActivity.java | 4 +- .../ui/activity/SyncedFoldersActivity.kt | 4 +- .../dialog/SetupEncryptionDialogFragment.java | 2 +- .../fragment/OCFileListBottomSheetDialog.java | 2 +- .../ui/helpers/FileOperationsHelper.java | 2 +- .../owncloud/android/utils/DisplayUtils.java | 2 +- .../android/utils/EncryptionUtils.java | 2 +- 35 files changed, 146 insertions(+), 231 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/client/database/dao/ArbitraryDataDao.kt delete mode 100644 app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataSet.kt diff --git a/app/src/debug/java/com/nextcloud/client/TestActivity.kt b/app/src/debug/java/com/nextcloud/client/TestActivity.kt index af92bf457e..521761061b 100644 --- a/app/src/debug/java/com/nextcloud/client/TestActivity.kt +++ b/app/src/debug/java/com/nextcloud/client/TestActivity.kt @@ -146,7 +146,7 @@ class TestActivity : override fun getFileOperationsHelper(): FileOperationsHelper { if (!this::fileOperation.isInitialized) { - fileOperation = FileOperationsHelper(this, userAccountManager, connectivityServiceMock, EditorUtils(ArbitraryDataProvider(contentResolver))) + fileOperation = FileOperationsHelper(this, userAccountManager, connectivityServiceMock, EditorUtils(ArbitraryDataProvider(baseContext))) } return fileOperation diff --git a/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java b/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java index 4f6e49e53f..e2b9a452e3 100644 --- a/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java +++ b/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java @@ -151,7 +151,7 @@ public final class PushUtils { private static void deleteRegistrationForAccount(Account account) { Context context = MainApp.getAppContext(); OwnCloudAccount ocAccount; - arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver()); + arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext()); try { ocAccount = new OwnCloudAccount(account, context); @@ -193,7 +193,7 @@ public final class PushUtils { } public static void pushRegistrationToServer(final UserAccountManager accountManager, final String token) { - arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext().getContentResolver()); + arbitraryDataProvider = new ArbitraryDataProvider(MainApp.getAppContext()); if (!TextUtils.isEmpty(MainApp.getAppContext().getResources().getString(R.string.push_server_url)) && !TextUtils.isEmpty(token)) { @@ -418,7 +418,7 @@ public final class PushUtils { Account[] accounts = accountManager.getAccounts(); - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context); String arbitraryValue; Gson gson = new Gson(); PushConfigurationState pushArbitraryData; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6bb4d2b4ba..c84445e4a2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -280,10 +280,6 @@ android:pathPrefix="/external_links" android:readPermission="false" android:writePermission="false" /> - . + * + */ + +package com.nextcloud.client.database.dao + +import androidx.room.Dao +import androidx.room.Query + +@Dao +interface ArbitraryDataDao { + @Query("INSERT INTO arbitrary_data(cloud_id, `key`, value) VALUES(:accountName, :key, :value)") + fun insertValue(accountName: String, key: String, value: String?) + + @Query("SELECT value FROM arbitrary_data WHERE cloud_id = :accountName AND `key` = :key LIMIT 1") + fun getValue(accountName: String, key: String): String? + + @Query("UPDATE arbitrary_data SET value = :value WHERE cloud_id = :accountName AND `key` = :key ") + fun updateValue(accountName: String, key: String, value: String?) + + @Query("DELETE FROM arbitrary_data WHERE cloud_id = :accountName AND `key` = :key") + fun deleteValue(accountName: String, key: String) +} diff --git a/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java b/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java index f98eb74ceb..a5b8b1098c 100644 --- a/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java +++ b/app/src/main/java/com/nextcloud/client/database/migrations/LegacyMigrationHelper.java @@ -41,6 +41,9 @@ public class LegacyMigrationHelper { private static final String TAG = LegacyMigrationHelper.class.getSimpleName(); + public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20; + + private static final String ALTER_TABLE = "ALTER TABLE "; private static final String ADD_COLUMN = " ADD COLUMN "; private static final String INTEGER = " INTEGER, "; @@ -176,7 +179,7 @@ public class LegacyMigrationHelper { db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.FILE_TABLE_NAME + ADD_COLUMN + ProviderMeta.ProviderTableMeta.FILE_ENCRYPTED_NAME + " TEXT "); } - if (oldVersion > FileContentProvider.ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION) { + if (oldVersion > ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION) { if (!checkIfColumnExists(db, ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME, ProviderMeta.ProviderTableMeta.CAPABILITIES_END_TO_END_ENCRYPTION)) { db.execSQL(ALTER_TABLE + ProviderMeta.ProviderTableMeta.CAPABILITIES_TABLE_NAME + diff --git a/app/src/main/java/com/nextcloud/client/di/AppModule.java b/app/src/main/java/com/nextcloud/client/di/AppModule.java index f71e71ddf5..7844f5632d 100644 --- a/app/src/main/java/com/nextcloud/client/di/AppModule.java +++ b/app/src/main/java/com/nextcloud/client/di/AppModule.java @@ -40,6 +40,7 @@ import com.nextcloud.client.core.Clock; import com.nextcloud.client.core.ClockImpl; import com.nextcloud.client.core.ThreadPoolAsyncRunner; import com.nextcloud.client.database.NextcloudDatabase; +import com.nextcloud.client.database.dao.ArbitraryDataDao; import com.nextcloud.client.device.DeviceInfo; import com.nextcloud.client.logger.FileLogHandler; import com.nextcloud.client.logger.Logger; @@ -118,9 +119,8 @@ class AppModule { } @Provides - ArbitraryDataProvider arbitraryDataProvider(Context context) { - final ContentResolver resolver = context.getContentResolver(); - return new ArbitraryDataProvider(resolver); + ArbitraryDataProvider arbitraryDataProvider(ArbitraryDataDao dao) { + return new ArbitraryDataProvider(dao); } @Provides diff --git a/app/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt b/app/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt index 1e657abd2d..63e9ac42cf 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt @@ -88,7 +88,7 @@ class AccountRemovalWork( return Result.failure() } val remoteWipe = inputData.getBoolean(REMOTE_WIPE, false) - val arbitraryDataProvider = ArbitraryDataProvider(context.contentResolver) + val arbitraryDataProvider = ArbitraryDataProvider(context) val user = optionalUser.get() backgroundJobManager.cancelPeriodicContactsBackup(user) val userRemoved = userAccountManager.removeUser(user) diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt index 8a0181a6e6..2908705dd9 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt @@ -134,7 +134,7 @@ class FilesSyncWork( } val user = optionalUser.get() val arbitraryDataProvider = if (lightVersion) { - ArbitraryDataProvider(contentResolver) + ArbitraryDataProvider(context) } else { null } diff --git a/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt b/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt index 41bc0ac31a..cbf59f0d78 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt @@ -84,7 +84,7 @@ class MediaFoldersDetectionWork constructor( @Suppress("LongMethod", "ComplexMethod", "NestedBlockDepth") // legacy code override fun doWork(): Result { - val arbitraryDataProvider = ArbitraryDataProvider(contentResolver) + val arbitraryDataProvider = ArbitraryDataProvider(context) val syncedFolderProvider = SyncedFolderProvider(contentResolver, preferences, clock) val gson = Gson() val mediaFoldersModel: MediaFoldersModel diff --git a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java index 28fb304101..8d33d71fd6 100644 --- a/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java +++ b/app/src/main/java/com/nextcloud/client/preferences/AppPreferencesImpl.java @@ -337,7 +337,7 @@ public final class AppPreferencesImpl implements AppPreferences { return defaultOrder; } - ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context); String value = dataProvider.getValue(user.getAccountName(), PREF__FOLDER_SORT_ORDER + "_" + type); @@ -347,7 +347,7 @@ public final class AppPreferencesImpl implements AppPreferences { @Override public void setSortOrder(FileSortOrder.Type type, FileSortOrder sortOrder) { User user = userAccountManager.getUser(); - ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context); dataProvider.storeOrUpdateKeyValue(user.getAccountName(), PREF__FOLDER_SORT_ORDER + "_" + type, sortOrder.name); } @@ -604,7 +604,7 @@ public final class AppPreferencesImpl implements AppPreferences { return defaultValue; } - ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context); FileDataStorageManager storageManager = new FileDataStorageManager(user, context.getContentResolver()); String value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder)); @@ -629,7 +629,7 @@ public final class AppPreferencesImpl implements AppPreferences { final String preferenceName, @Nullable final OCFile folder, final String value) { - ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context); dataProvider.storeOrUpdateKeyValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder), value); } diff --git a/app/src/main/java/com/owncloud/android/MainApp.java b/app/src/main/java/com/owncloud/android/MainApp.java index 1e52c30fbd..da8083efb6 100644 --- a/app/src/main/java/com/owncloud/android/MainApp.java +++ b/app/src/main/java/com/owncloud/android/MainApp.java @@ -413,7 +413,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector { } public static void initContactsBackup(UserAccountManager accountManager, BackgroundJobManager backgroundJobManager) { - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext); List users = accountManager.getAllUsers(); for (User user : users) { if (arbitraryDataProvider.getBooleanValue(user, PREFERENCE_CONTACTS_AUTOMATIC_BACKUP)) { diff --git a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java b/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java index de05dc1009..cd56c09f47 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java +++ b/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataProvider.java @@ -20,14 +20,13 @@ */ package com.owncloud.android.datamodel; -import android.content.ContentResolver; -import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; +import android.content.Context; import com.nextcloud.client.account.User; -import com.owncloud.android.db.ProviderMeta; -import com.owncloud.android.lib.common.utils.Log_OC; +import com.nextcloud.client.database.NextcloudDatabase; +import com.nextcloud.client.database.dao.ArbitraryDataDao; + +import javax.inject.Inject; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -40,25 +39,25 @@ public class ArbitraryDataProvider { public static final String DIRECT_EDITING_ETAG = "DIRECT_EDITING_ETAG"; public static final String PREDEFINED_STATUS = "PREDEFINED_STATUS"; - private static final String TAG = ArbitraryDataProvider.class.getSimpleName(); private static final String TRUE = "true"; - private ContentResolver contentResolver; + private final ArbitraryDataDao arbitraryDataDao; - public ArbitraryDataProvider(ContentResolver contentResolver) { - if (contentResolver == null) { - throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver"); - } - this.contentResolver = contentResolver; + /** + * @deprecated inject instead + */ + @Deprecated + public ArbitraryDataProvider(final Context context) { + this(NextcloudDatabase.getInstance(context).arbitraryDataDao()); } - public int deleteKeyForAccount(String account, String key) { - return contentResolver.delete( - ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " = ? AND " + - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + "= ?", - new String[]{account, key} - ); + @Inject + public ArbitraryDataProvider(final ArbitraryDataDao dao) { + this.arbitraryDataDao = dao; + } + + public void deleteKeyForAccount(String account, String key) { + arbitraryDataDao.deleteValue(account, key); } public void storeOrUpdateKeyValue(String accountName, String key, long newValue) { @@ -72,49 +71,11 @@ public class ArbitraryDataProvider { public void storeOrUpdateKeyValue(@NonNull String accountName, @NonNull String key, @Nullable String newValue) { - ArbitraryDataSet data = getArbitraryDataSet(accountName, key); - - String value; - if (newValue == null) { - value = ""; + final String currentValue = arbitraryDataDao.getValue(accountName, key); + if (currentValue != null) { + arbitraryDataDao.updateValue(accountName, key, newValue); } else { - value = newValue; - } - - if (data == null) { - Log_OC.v(TAG, "Adding arbitrary data with cloud id: " + accountName + " key: " + key - + " value: " + value); - - ContentValues cv = new ContentValues(); - cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID, accountName); - cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY, key); - cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE, value); - - Uri result = contentResolver.insert(ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, cv); - - if (result == null) { - Log_OC.v(TAG, "Failed to store arbitrary data with cloud id: " + accountName + " key: " + key - + " value: " + value); - } - } else { - Log_OC.v(TAG, "Updating arbitrary data with cloud id: " + accountName + " key: " + key - + " value: " + value); - ContentValues cv = new ContentValues(); - cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID, data.getCloudId()); - cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY, data.getKey()); - cv.put(ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE, value); - - int result = contentResolver.update( - ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, - cv, - ProviderMeta.ProviderTableMeta._ID + "=?", - new String[]{String.valueOf(data.getId())} - ); - - if (result == 0) { - Log_OC.v(TAG, "Failed to update arbitrary data with cloud id: " + accountName + " key: " + key - + " value: " + value); - } + arbitraryDataDao.insertValue(accountName, key, newValue); } } @@ -169,70 +130,10 @@ public class ArbitraryDataProvider { } public String getValue(String accountName, String key) { - Cursor cursor = contentResolver.query( - ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, - null, - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " = ? and " + - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + " = ?", - new String[]{accountName, key}, - null - ); - - if (cursor != null) { - if (cursor.moveToFirst()) { - String value = cursor.getString(cursor.getColumnIndexOrThrow( - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE)); - if (value == null) { - Log_OC.e(TAG, "Arbitrary value could not be created from cursor"); - } else { - cursor.close(); - return value; - } - } - cursor.close(); + final String value = arbitraryDataDao.getValue(accountName, key); + if (value == null) { return ""; - } else { - Log_OC.e(TAG, "DB error restoring arbitrary values."); } - - return ""; - } - - private ArbitraryDataSet getArbitraryDataSet(String accountName, String key) { - Cursor cursor = contentResolver.query( - ProviderMeta.ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, - null, - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID + " = ? and " + - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY + " = ?", - new String[]{accountName, key}, - null - ); - - ArbitraryDataSet dataSet = null; - if (cursor != null) { - if (cursor.moveToFirst()) { - int id = cursor.getInt(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta._ID)); - String dbAccount = cursor.getString(cursor.getColumnIndexOrThrow( - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID)); - String dbKey = cursor.getString(cursor.getColumnIndexOrThrow( - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY)); - String dbValue = cursor.getString(cursor.getColumnIndexOrThrow( - ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE)); - - if (id == -1) { - Log_OC.e(TAG, "Arbitrary value could not be created from cursor"); - } else { - if (dbValue == null) { - dbValue = ""; - } - dataSet = new ArbitraryDataSet(id, dbAccount, dbKey, dbValue); - } - } - cursor.close(); - } else { - Log_OC.e(TAG, "DB error restoring arbitrary values."); - } - - return dataSet; + return value; } } diff --git a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataSet.kt b/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataSet.kt deleted file mode 100644 index 3aa3027d8a..0000000000 --- a/app/src/main/java/com/owncloud/android/datamodel/ArbitraryDataSet.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2020 Tobias Kaminsky - * Copyright (C) 2020 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.owncloud.android.datamodel - -/** - * Data set for [ArbitraryDataProvider] - */ -internal class ArbitraryDataSet(val id: Int, val cloudId: String, val key: String, val value: String) diff --git a/app/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/app/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index c3f241a258..6c30604dea 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -1047,7 +1047,7 @@ public final class ThumbnailsCacheManager { String accountName = mUserId + "@" + mServerName; - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext); String eTag = arbitraryDataProvider.getValue(accountName, ThumbnailsCacheManager.AVATAR); long timestamp = arbitraryDataProvider.getLongValue(accountName, ThumbnailsCacheManager.AVATAR_TIMESTAMP); diff --git a/app/src/main/java/com/owncloud/android/db/ProviderMeta.java b/app/src/main/java/com/owncloud/android/db/ProviderMeta.java index 23fc26a8b1..43078dd89a 100644 --- a/app/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/app/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -72,8 +72,6 @@ public class ProviderMeta { + MainApp.getAuthority() + "/synced_folders"); public static final Uri CONTENT_URI_EXTERNAL_LINKS = Uri.parse(CONTENT_PREFIX + MainApp.getAuthority() + "/external_links"); - public static final Uri CONTENT_URI_ARBITRARY_DATA = Uri.parse(CONTENT_PREFIX - + MainApp.getAuthority() + "/arbitrary_data"); public static final Uri CONTENT_URI_VIRTUAL = Uri.parse(CONTENT_PREFIX + MainApp.getAuthority() + "/virtual"); public static final Uri CONTENT_URI_FILESYSTEM = Uri.parse(CONTENT_PREFIX + MainApp.getAuthority() + "/filesystem"); diff --git a/app/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java index 83ab79867a..a5085e6641 100644 --- a/app/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java @@ -106,7 +106,7 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper } private RemoteOperationResult encryptedCreate(OCFile parent, OwnCloudClient client) { - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context); String privateKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY); String publicKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY); diff --git a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java index f4f39c013d..f8fe78cfa1 100644 --- a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java @@ -296,7 +296,7 @@ public class RefreshFolderOperation extends RemoteOperation { } private void updateCapabilities() { - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(mContext); String oldDirectEditingEtag = arbitraryDataProvider.getValue(user, ArbitraryDataProvider.DIRECT_EDITING_ETAG); diff --git a/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java b/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java index 80ddf030cd..1efbf10a61 100644 --- a/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java @@ -84,7 +84,7 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation { this.user = user; this.fileName = fileName; - arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver()); + arbitraryDataProvider = new ArbitraryDataProvider(context); } /** diff --git a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java index 330d768f9b..6f35515fc9 100644 --- a/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java @@ -455,7 +455,7 @@ public class UploadFileOperation extends SyncOperation { boolean metadataExists = false; String token = null; - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext()); String privateKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY); String publicKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY); diff --git a/app/src/main/java/com/owncloud/android/providers/FileContentProvider.java b/app/src/main/java/com/owncloud/android/providers/FileContentProvider.java index 771045ad56..3dea010290 100644 --- a/app/src/main/java/com/owncloud/android/providers/FileContentProvider.java +++ b/app/src/main/java/com/owncloud/android/providers/FileContentProvider.java @@ -75,14 +75,12 @@ public class FileContentProvider extends ContentProvider { private static final int UPLOADS = 6; private static final int SYNCED_FOLDERS = 7; private static final int EXTERNAL_LINKS = 8; - private static final int ARBITRARY_DATA = 9; private static final int VIRTUAL = 10; private static final int FILESYSTEM = 11; private static final String TAG = FileContentProvider.class.getSimpleName(); // todo avoid string concatenation and use string formatting instead later. private static final String ERROR = "ERROR "; private static final int SINGLE_PATH_SEGMENT = 1; - public static final int ARBITRARY_DATA_TABLE_INTRODUCTION_VERSION = 20; public static final int MINIMUM_PATH_SEGMENTS_SIZE = 1; private static final String[] PROJECTION_CONTENT_TYPE = new String[]{ @@ -160,9 +158,6 @@ public class FileContentProvider extends ContentProvider { case EXTERNAL_LINKS: count = db.delete(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, where, whereArgs); break; - case ARBITRARY_DATA: - count = db.delete(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, where, whereArgs); - break; case VIRTUAL: count = db.delete(ProviderTableMeta.VIRTUAL_TABLE_NAME, where, whereArgs); break; @@ -361,16 +356,6 @@ public class FileContentProvider extends ContentProvider { } return insertedExternalLinkUri; - case ARBITRARY_DATA: - Uri insertedArbitraryDataUri; - long arbitraryDataId = db.insert(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values); - if (arbitraryDataId > 0) { - insertedArbitraryDataUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_ARBITRARY_DATA, - arbitraryDataId); - } else { - throw new SQLException("ERROR " + uri); - } - return insertedArbitraryDataUri; case VIRTUAL: Uri insertedVirtualUri; long virtualId = db.insert(ProviderTableMeta.VIRTUAL_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values); @@ -456,7 +441,6 @@ public class FileContentProvider extends ContentProvider { mUriMatcher.addURI(authority, "uploads/#", UPLOADS); mUriMatcher.addURI(authority, "synced_folders", SYNCED_FOLDERS); mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS); - mUriMatcher.addURI(authority, "arbitrary_data", ARBITRARY_DATA); mUriMatcher.addURI(authority, "virtual", VIRTUAL); mUriMatcher.addURI(authority, "filesystem", FILESYSTEM); @@ -525,9 +509,6 @@ public class FileContentProvider extends ContentProvider { case EXTERNAL_LINKS: tableName = ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME; break; - case ARBITRARY_DATA: - tableName = ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME; - break; case VIRTUAL: tableName = ProviderTableMeta.VIRTUAL_TABLE_NAME; break; @@ -567,9 +548,6 @@ public class FileContentProvider extends ContentProvider { case EXTERNAL_LINKS: order = ProviderTableMeta.EXTERNAL_LINKS_NAME; break; - case ARBITRARY_DATA: - order = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID; - break; case VIRTUAL: order = ProviderTableMeta.VIRTUAL_TYPE; break; @@ -659,8 +637,6 @@ public class FileContentProvider extends ContentProvider { return db.update(ProviderTableMeta.UPLOADS_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values, selection, selectionArgs); case SYNCED_FOLDERS: return db.update(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values, selection, selectionArgs); - case ARBITRARY_DATA: - return db.update(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values, selection, selectionArgs); case FILESYSTEM: return db.update(ProviderTableMeta.FILESYSTEM_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values, selection, selectionArgs); default: @@ -699,7 +675,6 @@ public class FileContentProvider extends ContentProvider { case UPLOADS: case SYNCED_FOLDERS: case EXTERNAL_LINKS: - case ARBITRARY_DATA: case VIRTUAL: case FILESYSTEM: String callingPackage = mContext.getPackageManager().getNameForUid(Binder.getCallingUid()); diff --git a/app/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java b/app/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java index 2299292cda..f949927657 100644 --- a/app/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java +++ b/app/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java @@ -377,7 +377,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider { @Override @SuppressFBWarnings("IOI_USE_OF_FILE_STREAM_CONSTRUCTORS") // TODO remove with API26 public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException { - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext()); String userId = uri.getQueryParameter("shareWith"); String displayName = uri.getQueryParameter("displayName"); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java index 39549d63df..f2beee5756 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java @@ -907,7 +907,7 @@ public abstract class DrawerActivity extends ToolbarActivity } externalLinksProvider = new ExternalLinksProvider(getContentResolver()); - arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); + arbitraryDataProvider = new ArbitraryDataProvider(this); } @Override diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index bc9bb3b800..1d8e946e74 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -644,7 +644,7 @@ public abstract class FileActivity extends DrawerActivity public void checkForNewDevVersionNecessary(Context context) { if (getResources().getBoolean(R.bool.dev_version_direct_download_enabled)) { - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(this); int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, APP_OPENED_COUNT); if (count > 10 || count == -1) { diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java index f4679bec50..2b67635801 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java @@ -142,7 +142,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap originalCurrentUser = currentUser.get().getAccountName(); } - arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); + arbitraryDataProvider = new ArbitraryDataProvider(this); multipleAccountsSupported = getResources().getBoolean(R.bool.multiaccount_support); @@ -426,7 +426,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap } // store pending account removal - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(this); arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PENDING_FOR_REMOVAL, String.valueOf(true)); // Cancel transfers diff --git a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java index 97c0d8dc78..90703e8aa6 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java @@ -146,7 +146,7 @@ public class NotificationsActivity extends DrawerActivity implements Notificatio R.string.push_notifications_not_implemented, Snackbar.LENGTH_INDEFINITE); } else { - final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); + final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(this); final String accountName = optionalUser.isPresent() ? optionalUser.get().getAccountName() : ""; final boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(accountName, UserAccountManager.ACCOUNT_USES_STANDARD_PASSWORD); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java index f9ddae3036..22bf7a0041 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/SettingsActivity.java @@ -606,7 +606,7 @@ public class SettingsActivity extends PreferenceActivity preferenceScreen.removePreference(preferenceCategorySyncedFolders); } else { // Upload on WiFi - final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); + final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(this); final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference("synced_folder_on_wifi"); pUploadOnWifiCheckbox.setChecked( @@ -872,7 +872,7 @@ public class SettingsActivity extends PreferenceActivity RequestCredentialsActivity.KEY_CHECK_RESULT_FALSE) == RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) { - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(this); String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC); AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.FallbackTheming_Dialog); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt index 061cbad6e7..7eb3c475a7 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.kt @@ -696,14 +696,14 @@ class SyncedFoldersActivity : backgroundJobManager.startImmediateFilesSyncJob(skipCustomFolders = false, overridePowerSaving = false) } else { val syncedFolderInitiatedKey = KEY_SYNCED_FOLDER_INITIATED_PREFIX + item.id - val arbitraryDataProvider = ArbitraryDataProvider(MainApp.getAppContext().contentResolver) + val arbitraryDataProvider = ArbitraryDataProvider(MainApp.getAppContext()) arbitraryDataProvider.deleteKeyForAccount("global", syncedFolderInitiatedKey) } } } private fun storeSyncedFolder(item: SyncedFolderDisplayItem) { - val arbitraryDataProvider = ArbitraryDataProvider(MainApp.getAppContext().contentResolver) + val arbitraryDataProvider = ArbitraryDataProvider(MainApp.getAppContext()) val storedId = syncedFolderProvider.storeSyncedFolder(item) if (storedId != -1L) { item.id = storedId diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java b/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java index 590ae645c3..94b0311e59 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.java @@ -132,7 +132,7 @@ public class SetupEncryptionDialogFragment extends DialogFragment implements Inj public Dialog onCreateDialog(Bundle savedInstanceState) { user = getArguments().getParcelable(ARG_USER); - arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver()); + arbitraryDataProvider = new ArbitraryDataProvider(getContext()); // Inflate the layout for the dialog LayoutInflater inflater = getActivity().getLayoutInflater(); diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java index f9fb3a839c..9d297b1426 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java @@ -103,7 +103,7 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog implements In binding.templates.setVisibility(View.VISIBLE); } - String json = new ArbitraryDataProvider(getContext().getContentResolver()) + String json = new ArbitraryDataProvider(getContext()) .getValue(user, ArbitraryDataProvider.DIRECT_EDITING); if (!json.isEmpty() && diff --git a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 57a4366307..b9331e3601 100755 --- a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -1120,7 +1120,7 @@ public class FileOperationsHelper { } public static boolean isEndToEndEncryptionSetup(Context context, User user) { - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context); String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY); String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY); diff --git a/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java b/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java index 7fa300947a..7936c23858 100644 --- a/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/DisplayUtils.java @@ -491,7 +491,7 @@ public final class DisplayUtils { ((View) callContext).setContentDescription(String.valueOf(user.toPlatformAccount().hashCode())); } - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context); final String accountName = user.getAccountName(); String serverName = accountName.substring(accountName.lastIndexOf('@') + 1); diff --git a/app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java b/app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java index 4c81cb4d2a..0cf7ac4aaa 100644 --- a/app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java @@ -231,7 +231,7 @@ public final class EncryptionUtils { } // decrypt metadata - ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver()); + ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context); String serializedEncryptedMetadata = (String) getMetadataOperationResult.getData().get(0); String privateKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY);