Fix lint issues with cursor indexes on compileSdk 31

Ref: https://stackoverflow.com/a/69979270

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey Vilas 2021-11-25 12:57:17 +01:00
parent 9b51a5f242
commit 8ee7bfd557
No known key found for this signature in database
GPG key ID: 2585783189A62105
15 changed files with 109 additions and 109 deletions

View file

@ -210,7 +210,7 @@ class ContactsBackupWork(
@Suppress("NestedBlockDepth")
private fun getContactFromCursor(cursor: Cursor): String {
val lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY))
val lookupKey = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.LOOKUP_KEY))
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey)
var vCard = ""
var inputStream: InputStream? = null

View file

@ -87,7 +87,7 @@ class ContactsImportWork(
for (i in 0 until cursor.count) {
val vCard = getContactFromCursor(cursor)
if (vCard != null) {
ownContactMap[vCard] = cursor.getLong(cursor.getColumnIndex("NAME_RAW_CONTACT_ID"))
ownContactMap[vCard] = cursor.getLong(cursor.getColumnIndexOrThrow("NAME_RAW_CONTACT_ID"))
}
cursor.moveToNext()
}
@ -114,7 +114,7 @@ class ContactsImportWork(
}
private fun getContactFromCursor(cursor: Cursor): VCard? {
val lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY))
val lookupKey = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.LOOKUP_KEY))
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey)
var vCard: VCard? = null
try {

View file

@ -176,7 +176,7 @@ public class ArbitraryDataProvider {
if (cursor != null) {
if (cursor.moveToFirst()) {
String value = cursor.getString(cursor.getColumnIndex(
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");
@ -207,12 +207,12 @@ public class ArbitraryDataProvider {
ArbitraryDataSet dataSet = null;
if (cursor != null) {
if (cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta._ID));
String dbAccount = cursor.getString(cursor.getColumnIndex(
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.getColumnIndex(
String dbKey = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_KEY));
String dbValue = cursor.getString(cursor.getColumnIndex(
String dbValue = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.ARBITRARY_DATA_VALUE));
if (id == -1) {

View file

@ -142,13 +142,13 @@ public class ExternalLinksProvider {
private ExternalLink createExternalLinkFromCursor(Cursor cursor) {
ExternalLink externalLink = null;
if (cursor != null) {
int id = cursor.getInt(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta._ID));
String iconUrl = cursor.getString(cursor.getColumnIndex(
int id = cursor.getInt(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta._ID));
String iconUrl = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_ICON_URL));
String language = cursor.getString(cursor.getColumnIndex(
String language = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE));
ExternalLinkType type;
switch (cursor.getString(cursor.getColumnIndex(
switch (cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TYPE))) {
case "link":
type = ExternalLinkType.LINK;
@ -163,10 +163,10 @@ public class ExternalLinksProvider {
type = ExternalLinkType.UNKNOWN;
break;
}
String name = cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_NAME));
String url = cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_URL));
String name = cursor.getString(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_NAME));
String url = cursor.getString(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_URL));
boolean redirect = cursor.getInt(
cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)) == 1;
cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_REDIRECT)) == 1;
externalLink = new ExternalLink(id, iconUrl, language, type, name, url, redirect);
}

View file

@ -850,9 +850,9 @@ public class FileDataStorageManager {
String[] fileId = new String[1];
do {
ContentValues cv = new ContentValues();
fileId[0] = String.valueOf(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta._ID)));
fileId[0] = String.valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta._ID)));
String oldFileStoragePath =
cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_STORAGE_PATH));
if (oldFileStoragePath.startsWith(sourcePath)) {
@ -975,7 +975,7 @@ public class FileDataStorageManager {
@Nullable
private OCFile createFileInstanceFromVirtual(Cursor cursor) {
long fileId = cursor.getLong(cursor.getColumnIndex(ProviderTableMeta.VIRTUAL_OCFILE_ID));
long fileId = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.VIRTUAL_OCFILE_ID));
return getFileById(fileId);
}
@ -983,12 +983,12 @@ public class FileDataStorageManager {
private OCFile createFileInstance(Cursor cursor) {
OCFile ocFile = null;
if (cursor != null) {
ocFile = new OCFile(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_PATH)));
ocFile = new OCFile(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PATH)));
ocFile.setDecryptedRemotePath(getString(cursor, ProviderTableMeta.FILE_PATH_DECRYPTED));
ocFile.setFileId(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta._ID)));
ocFile.setParentId(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta.FILE_PARENT)));
ocFile.setMimeType(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
ocFile.setStoragePath(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
ocFile.setFileId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta._ID)));
ocFile.setParentId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PARENT)));
ocFile.setMimeType(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_TYPE)));
ocFile.setStoragePath(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_STORAGE_PATH)));
if (ocFile.getStoragePath() == null) {
// try to find existing file and bind it with current account;
// with the current update of SynchronizeFolderOperation, this won't be
@ -999,37 +999,37 @@ public class FileDataStorageManager {
ocFile.setLastSyncDateForData(file.lastModified());
}
}
ocFile.setFileLength(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH)));
ocFile.setCreationTimestamp(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta.FILE_CREATION)));
ocFile.setModificationTimestamp(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
ocFile.setFileLength(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_LENGTH)));
ocFile.setCreationTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CREATION)));
ocFile.setModificationTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MODIFIED)));
ocFile.setModificationTimestampAtLastSyncForData(cursor.getLong(
cursor.getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
ocFile.setLastSyncDateForProperties(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
ocFile.setLastSyncDateForData(cursor.getLong(cursor.getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
ocFile.setEtag(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_ETAG)));
ocFile.setEtagOnServer(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_ETAG_ON_SERVER)));
ocFile.setSharedViaLink(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1);
ocFile.setSharedWithSharee(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
ocFile.setPermissions(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
ocFile.setRemoteId(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
ocFile.setUpdateThumbnailNeeded(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
ocFile.setDownloading(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1);
ocFile.setEtagInConflict(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
ocFile.setFavorite(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_FAVORITE)) == 1);
ocFile.setEncrypted(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_IS_ENCRYPTED)) == 1);
cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
ocFile.setLastSyncDateForProperties(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
ocFile.setLastSyncDateForData(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
ocFile.setEtag(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG)));
ocFile.setEtagOnServer(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_ON_SERVER)));
ocFile.setSharedViaLink(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1);
ocFile.setSharedWithSharee(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
ocFile.setPermissions(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PERMISSIONS)));
ocFile.setRemoteId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_REMOTE_ID)));
ocFile.setUpdateThumbnailNeeded(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
ocFile.setDownloading(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1);
ocFile.setEtagInConflict(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
ocFile.setFavorite(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_FAVORITE)) == 1);
ocFile.setEncrypted(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_ENCRYPTED)) == 1);
// if (ocFile.isEncrypted()) {
// ocFile.setFileName(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_NAME)));
// ocFile.setFileName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NAME)));
// }
ocFile.setMountType(WebdavEntry.MountType.values()[cursor.getInt(
cursor.getColumnIndex(ProviderTableMeta.FILE_MOUNT_TYPE))]);
ocFile.setPreviewAvailable(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_HAS_PREVIEW)) == 1);
ocFile.setUnreadCommentsCount(cursor.getInt(cursor.getColumnIndex(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT)));
ocFile.setOwnerId(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_OWNER_ID)));
ocFile.setOwnerDisplayName(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)));
ocFile.setNote(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_NOTE)));
ocFile.setRichWorkspace(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_RICH_WORKSPACE)));
cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MOUNT_TYPE))]);
ocFile.setPreviewAvailable(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_HAS_PREVIEW)) == 1);
ocFile.setUnreadCommentsCount(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT)));
ocFile.setOwnerId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_ID)));
ocFile.setOwnerDisplayName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)));
ocFile.setNote(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NOTE)));
ocFile.setRichWorkspace(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_RICH_WORKSPACE)));
String sharees = cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_SHAREES));
String sharees = cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHAREES));
if (sharees == null || NULL_STRING.equals(sharees) || sharees.isEmpty()) {
ocFile.setSharees(new ArrayList<>());
@ -2381,19 +2381,19 @@ public class FileDataStorageManager {
}
private String getString(Cursor cursor, String columnName) {
return cursor.getString(cursor.getColumnIndex(columnName));
return cursor.getString(cursor.getColumnIndexOrThrow(columnName));
}
private int getInt(Cursor cursor, String columnName) {
return cursor.getInt(cursor.getColumnIndex(columnName));
return cursor.getInt(cursor.getColumnIndexOrThrow(columnName));
}
private long getLong(Cursor cursor, String columnName) {
return cursor.getLong(cursor.getColumnIndex(columnName));
return cursor.getLong(cursor.getColumnIndexOrThrow(columnName));
}
private CapabilityBooleanType getBoolean(Cursor cursor, String columnName) {
return CapabilityBooleanType.fromValue(cursor.getInt(cursor.getColumnIndex(columnName)));
return CapabilityBooleanType.fromValue(cursor.getInt(cursor.getColumnIndexOrThrow(columnName)));
}
public ContentResolver getContentResolver() {

View file

@ -92,7 +92,7 @@ public class FilesystemDataProvider {
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String value = cursor.getString(cursor.getColumnIndex(
String value = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH));
if (value == null) {
Log_OC.e(TAG, "Cannot get local path");
@ -185,26 +185,26 @@ public class FilesystemDataProvider {
FileSystemDataSet dataSet = null;
if (cursor != null) {
if (cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta._ID));
String localPath = cursor.getString(cursor.getColumnIndex(
int id = cursor.getInt(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta._ID));
String localPath = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_LOCAL_PATH));
long modifiedAt = cursor.getLong(cursor.getColumnIndex(
long modifiedAt = cursor.getLong(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_MODIFIED));
boolean isFolder = false;
if (cursor.getInt(cursor.getColumnIndex(
if (cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_IS_FOLDER)) != 0) {
isFolder = true;
}
long foundAt = cursor.getLong(cursor.getColumnIndex(ProviderMeta.
long foundAt = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderMeta.
ProviderTableMeta.FILESYSTEM_FILE_FOUND_RECENTLY));
boolean isSentForUpload = false;
if (cursor.getInt(cursor.getColumnIndex(
if (cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.FILESYSTEM_FILE_SENT_FOR_UPLOAD)) != 0) {
isSentForUpload = true;
}
String crc32 = cursor.getString(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta.FILESYSTEM_CRC32));
String crc32 = cursor.getString(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta.FILESYSTEM_CRC32));
if (id == -1) {
Log_OC.e(TAG, "Arbitrary value could not be created from cursor");

View file

@ -96,9 +96,9 @@ public final class MediaProvider {
// since sdk 29 we have to manually distinct on bucket id
while (cursorFolders.moveToNext()) {
uniqueFolders.put(cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Images.Media.BUCKET_ID)),
cursorFolders.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_ID)),
cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME))
cursorFolders.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME))
);
}
cursorFolders.close();
@ -214,9 +214,9 @@ public final class MediaProvider {
// since sdk 29 we have to manually distinct on bucket id
while (cursorFolders.moveToNext()) {
uniqueFolders.put(cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Video.Media.BUCKET_ID)),
cursorFolders.getColumnIndexOrThrow(MediaStore.Video.Media.BUCKET_ID)),
cursorFolders.getString(
cursorFolders.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME))
cursorFolders.getColumnIndexOrThrow(MediaStore.Video.Media.BUCKET_DISPLAY_NAME))
);
}
cursorFolders.close();

View file

@ -333,32 +333,32 @@ public class SyncedFolderProvider extends Observable {
private SyncedFolder createSyncedFolderFromCursor(Cursor cursor) {
SyncedFolder syncedFolder = null;
if (cursor != null) {
long id = cursor.getLong(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta._ID));
String localPath = cursor.getString(cursor.getColumnIndex(
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderMeta.ProviderTableMeta._ID));
String localPath = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH));
String remotePath = cursor.getString(cursor.getColumnIndex(
String remotePath = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_REMOTE_PATH));
boolean wifiOnly = cursor.getInt(cursor.getColumnIndex(
boolean wifiOnly = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_WIFI_ONLY)) == 1;
boolean chargingOnly = cursor.getInt(cursor.getColumnIndex(
boolean chargingOnly = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_CHARGING_ONLY)) == 1;
boolean existing = cursor.getInt(cursor.getColumnIndex(
boolean existing = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_EXISTING)) == 1;
boolean subfolderByDate = cursor.getInt(cursor.getColumnIndex(
boolean subfolderByDate = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_BY_DATE)) == 1;
String accountName = cursor.getString(cursor.getColumnIndex(
String accountName = cursor.getString(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ACCOUNT));
int uploadAction = cursor.getInt(cursor.getColumnIndex(
int uploadAction = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION));
int nameCollisionPolicy = cursor.getInt(cursor.getColumnIndex(
int nameCollisionPolicy = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY));
boolean enabled = cursor.getInt(cursor.getColumnIndex(
boolean enabled = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED)) == 1;
long enabledTimestampMs = cursor.getLong(cursor.getColumnIndex(
long enabledTimestampMs = cursor.getLong(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_ENABLED_TIMESTAMP_MS));
MediaFolderType type = MediaFolderType.getById(cursor.getInt(cursor.getColumnIndex(
MediaFolderType type = MediaFolderType.getById(cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE)));
boolean hidden = cursor.getInt(cursor.getColumnIndex(
boolean hidden = cursor.getInt(cursor.getColumnIndexOrThrow(
ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN)) == 1;
syncedFolder = new SyncedFolder(id,

View file

@ -152,7 +152,7 @@ public class UploadsStorageManager extends Observable {
// read upload object and update
OCUpload upload = createOCUploadFromCursor(c);
String path = c.getString(c.getColumnIndex(ProviderTableMeta.UPLOADS_LOCAL_PATH));
String path = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_PATH));
Log_OC.v(
TAG,
"Updating " + path + " with status:" + status + " and result:"
@ -362,7 +362,7 @@ public class UploadsStorageManager extends Observable {
do {
rowsRead++;
rowsTotal++;
lastRowID = c.getLong(c.getColumnIndex(ProviderTableMeta._ID));
lastRowID = c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta._ID));
OCUpload upload = createOCUploadFromCursor(c);
if (upload == null) {
Log_OC.e(TAG, "OCUpload could not be created from cursor");
@ -398,29 +398,29 @@ public class UploadsStorageManager extends Observable {
private OCUpload createOCUploadFromCursor(Cursor c) {
OCUpload upload = null;
if (c != null) {
String localPath = c.getString(c.getColumnIndex(ProviderTableMeta.UPLOADS_LOCAL_PATH));
String remotePath = c.getString(c.getColumnIndex(ProviderTableMeta.UPLOADS_REMOTE_PATH));
String accountName = c.getString(c.getColumnIndex(ProviderTableMeta.UPLOADS_ACCOUNT_NAME));
String localPath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_PATH));
String remotePath = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_REMOTE_PATH));
String accountName = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_ACCOUNT_NAME));
upload = new OCUpload(localPath, remotePath, accountName);
upload.setFileSize(c.getLong(c.getColumnIndex(ProviderTableMeta.UPLOADS_FILE_SIZE)));
upload.setUploadId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
upload.setFileSize(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_FILE_SIZE)));
upload.setUploadId(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta._ID)));
upload.setUploadStatus(
UploadStatus.fromValue(c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_STATUS)))
UploadStatus.fromValue(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_STATUS)))
);
upload.setLocalAction(c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR)));
upload.setLocalAction(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR)));
upload.setNameCollisionPolicy(NameCollisionPolicy.deserialize(c.getInt(
c.getColumnIndex(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY))));
c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY))));
upload.setCreateRemoteFolder(c.getInt(
c.getColumnIndex(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER)) == 1);
upload.setUploadEndTimestamp(c.getLong(c.getColumnIndex(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP)));
c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER)) == 1);
upload.setUploadEndTimestamp(c.getLong(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_UPLOAD_END_TIMESTAMP)));
upload.setLastResult(UploadResult.fromValue(
c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_LAST_RESULT))));
upload.setCreatedBy(c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_CREATED_BY)));
upload.setUseWifiOnly(c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) == 1);
upload.setWhileChargingOnly(c.getInt(c.getColumnIndex(ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY))
c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_LAST_RESULT))));
upload.setCreatedBy(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_CREATED_BY)));
upload.setUseWifiOnly(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_WIFI_ONLY)) == 1);
upload.setWhileChargingOnly(c.getInt(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY))
== 1);
upload.setFolderUnlockToken(c.getString(c.getColumnIndex(ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN)));
upload.setFolderUnlockToken(c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN)));
}
return upload;
}

View file

@ -176,9 +176,9 @@ public class FileContentProvider extends ContentProvider {
long childId;
boolean isDir;
while (!children.isAfterLast()) {
childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
childId = children.getLong(children.getColumnIndexOrThrow(ProviderTableMeta._ID));
isDir = MimeType.DIRECTORY.equals(children.getString(
children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
children.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_TYPE)
));
if (isDir) {
count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
@ -208,7 +208,7 @@ public class FileContentProvider extends ContentProvider {
String remoteId = "";
try {
if (c != null && c.moveToFirst()) {
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
remoteId = c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.FILE_REMOTE_ID));
}
Log_OC.d(TAG, "Removing FILE " + remoteId);
@ -290,7 +290,7 @@ public class FileContentProvider extends ContentProvider {
// file is already inserted; race condition, let's avoid a duplicated entry
Uri insertedFileUri = ContentUris.withAppendedId(
ProviderTableMeta.CONTENT_URI_FILE,
doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))
doubleCheck.getLong(doubleCheck.getColumnIndexOrThrow(ProviderTableMeta._ID))
);
doubleCheck.close();
@ -683,7 +683,7 @@ public class FileContentProvider extends ContentProvider {
private boolean checkIfColumnExists(SQLiteDatabase database, String table, String column) {
Cursor cursor = database.rawQuery("SELECT * FROM " + table + " LIMIT 0", null);
boolean exists = cursor.getColumnIndex(column) != -1;
boolean exists = cursor.getColumnIndexOrThrow(column) != -1;
cursor.close();
return exists;
@ -990,9 +990,9 @@ public class FileContentProvider extends ContentProvider {
do {
// Update database
String oldPath = c.getString(
c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH));
c.getColumnIndexOrThrow(ProviderTableMeta.FILE_STORAGE_PATH));
OCFile file = new OCFile(
c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH)));
c.getString(c.getColumnIndexOrThrow(ProviderTableMeta.FILE_PATH)));
String newPath = FileStorageUtils.getDefaultSavePathFor(newAccountName, file);
ContentValues cv = new ContentValues();

View file

@ -155,7 +155,7 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
null)) {
if (cursor != null && cursor.moveToFirst()) {
// this check prevents a crash when last modification time is not available on certain phones
int columnIndex = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED);
int columnIndex = cursor.getColumnIndexOrThrow(DocumentsContract.Document.COLUMN_LAST_MODIFIED);
if (columnIndex >= 0) {
lastModified = cursor.getLong(columnIndex);
}

View file

@ -383,8 +383,8 @@ class BackupListAdapter(
)
if (cursor != null && cursor.count > 0) {
while (cursor.moveToNext()) {
val name = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME))
val type = cursor.getString(cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE))
val name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.RawContacts.ACCOUNT_NAME))
val type = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.RawContacts.ACCOUNT_TYPE))
val account = ContactsAccount(name, name, type)
if (!contactsAccounts.contains(account)) {
contactsAccounts.add(account)

View file

@ -77,7 +77,7 @@ object UriUtils {
).use { cursor ->
if (cursor != null) {
cursor.moveToFirst()
displayName = cursor.getString(cursor.getColumnIndex(displayNameColumn))
displayName = cursor.getString(cursor.getColumnIndexOrThrow(displayNameColumn))
}
}
} catch (e: Exception) {

View file

@ -112,7 +112,7 @@ public class AndroidCalendar {
}
private static int getColumnIndex(Cursor cur, String dbName) {
return dbName == null ? -1 : cur.getColumnIndex(dbName);
return dbName == null ? -1 : cur.getColumnIndexOrThrow(dbName);
}
private static long getLong(Cursor cur, String dbName) {

View file

@ -466,7 +466,7 @@ public class SaveCalendar implements Injectable {
}
private int getColumnIndex(Cursor cur, String dbName) {
return dbName == null ? -1 : cur.getColumnIndex(dbName);
return dbName == null ? -1 : cur.getColumnIndexOrThrow(dbName);
}
private String getString(Cursor cur, String dbName) {