Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.content.Context
import android.database.Cursor
import android.net.Uri
import androidx.annotation.VisibleForTesting
import androidx.core.net.toUri
import aws.sdk.kotlin.services.s3.model.CompletedPart
import aws.sdk.kotlin.services.s3.model.ObjectCannedAcl
import com.amplifyframework.core.Amplify
Expand Down Expand Up @@ -468,9 +469,8 @@ internal class TransferDB private constructor(context: Context) {
* @return The Uri of the part upload records that have the given
* mainUploadId value.
*/
private fun getTransferRecordIdUri(transferId: String): Uri = Uri.parse(
transferDBHelper.contentUri.toString() + "/transferId/" + transferId
)
private fun getTransferRecordIdUri(transferId: String): Uri =
"${transferDBHelper.contentUri}/transferId/$transferId".toUri()

/**
* Gets the Uri of part records of a multipart upload.
Expand All @@ -479,9 +479,7 @@ internal class TransferDB private constructor(context: Context) {
* @return The Uri of the part upload records that have the given
* mainUploadId value.
*/
private fun getPartUri(mainUploadId: Int): Uri = Uri.parse(
transferDBHelper.contentUri.toString() + "/part/" + mainUploadId
)
private fun getPartUri(mainUploadId: Int): Uri = "${transferDBHelper.contentUri}/part/$mainUploadId".toUri()

/**
* Gets the Uri of the records that have the given state.
Expand All @@ -490,9 +488,7 @@ internal class TransferDB private constructor(context: Context) {
* @return The Uri that is used to query transfer records with the given
* state.
*/
fun getStateUri(state: TransferState): Uri? = Uri.parse(
"${transferDBHelper.contentUri}/state/$state"
)
fun getStateUri(state: TransferState): Uri? = "${transferDBHelper.contentUri}/state/$state".toUri()

/**
* Create a string with the required number of placeholders
Expand Down Expand Up @@ -521,7 +517,7 @@ internal class TransferDB private constructor(context: Context) {
* @param id The id of the transfer.
* @return The Uri of the record specified by the id.
*/
private fun getRecordUri(id: Int): Uri = Uri.parse(transferDBHelper.contentUri.toString() + "/" + id)
private fun getRecordUri(id: Int): Uri = "${transferDBHelper.contentUri}/$id".toUri()

/**
* Inserts a transfer record into database with the given values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.database.sqlite.SQLiteOpenHelper
import android.database.sqlite.SQLiteQueryBuilder
import android.net.Uri
import android.text.TextUtils
import androidx.core.net.toUri
import com.amplifyframework.core.Amplify
import com.amplifyframework.core.category.CategoryType
import com.amplifyframework.storage.s3.AWSS3StoragePlugin
Expand Down Expand Up @@ -60,7 +61,7 @@ internal class TransferDBHelper(private val context: Context) : SQLiteOpenHelper
init {
val authority = context.applicationContext.packageName
database = writableDatabase
contentUri = Uri.parse("content://$authority/$BASE_PATH")
contentUri = "content://$authority/$BASE_PATH".toUri()
uriMatcher = UriMatcher(UriMatcher.NO_MATCH)

// The Uri of TRANSFERS is for all records in the table.
Expand Down Expand Up @@ -109,7 +110,7 @@ internal class TransferDBHelper(private val context: Context) : SQLiteOpenHelper
)
else -> throw IllegalArgumentException("Unknown URI: $uri")
}
return Uri.parse("$BASE_PATH/$id")
return "$BASE_PATH/$id".toUri()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.amplifyframework.storage.s3.transfer

import android.database.sqlite.SQLiteDatabase
import androidx.core.database.sqlite.transaction
import java.util.UUID

internal class TransferTable {
Expand Down Expand Up @@ -200,37 +201,35 @@ internal class TransferTable {
*/
@JvmStatic
fun onUpgrade(database: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
database.beginTransaction()

if (TABLE_VERSION_2 in (oldVersion + 1)..newVersion) {
addVersion2Columns(database)
}
if (TABLE_VERSION_3 in (oldVersion + 1)..newVersion) {
addVersion3Columns(database)
}
if (TABLE_VERSION_4 in (oldVersion + 1)..newVersion) {
addVersion4Columns(database)
}
if (TABLE_VERSION_5 in (oldVersion + 1)..newVersion) {
addVersion5Columns(database)
}
if (TABLE_VERSION_6 in (oldVersion + 1)..newVersion) {
addVersion6Columns(database)
}
if (TABLE_VERSION_7 in (oldVersion + 1)..newVersion) {
addVersion7Columns(database)
}
if (TABLE_VERSION_8 in (oldVersion + 1)..newVersion) {
addVersion8Columns(database)
}
if (TABLE_VERSION_9 in (oldVersion + 1)..newVersion) {
addVersion9Columns(database)
}
if (TABLE_VERSION_10 in (oldVersion + 1)..newVersion) {
addVersion10Columns(database)
database.transaction {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (TABLE_VERSION_2 in (oldVersion + 1)..newVersion) {
addVersion2Columns(database)
}
if (TABLE_VERSION_3 in (oldVersion + 1)..newVersion) {
addVersion3Columns(database)
}
if (TABLE_VERSION_4 in (oldVersion + 1)..newVersion) {
addVersion4Columns(database)
}
if (TABLE_VERSION_5 in (oldVersion + 1)..newVersion) {
addVersion5Columns(database)
}
if (TABLE_VERSION_6 in (oldVersion + 1)..newVersion) {
addVersion6Columns(database)
}
if (TABLE_VERSION_7 in (oldVersion + 1)..newVersion) {
addVersion7Columns(database)
}
if (TABLE_VERSION_8 in (oldVersion + 1)..newVersion) {
addVersion8Columns(database)
}
if (TABLE_VERSION_9 in (oldVersion + 1)..newVersion) {
addVersion9Columns(database)
}
if (TABLE_VERSION_10 in (oldVersion + 1)..newVersion) {
addVersion10Columns(database)
}
}
database.setTransactionSuccessful()
database.endTransaction()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class TransferWorkerObserver private constructor(
private val workManager: WorkManager,
private val transferStatusUpdater: TransferStatusUpdater,
private val transferDB: TransferDB
) : Observer<MutableList<WorkInfo>> {
) : Observer<List<WorkInfo>> {

private val coroutineScope =
CoroutineScope(Executors.newSingleThreadExecutor().asCoroutineDispatcher())
Expand Down Expand Up @@ -79,9 +79,9 @@ internal class TransferWorkerObserver private constructor(
}
}

override fun onChanged(workInfoList: MutableList<WorkInfo>?) {
override fun onChanged(workInfoList: List<WorkInfo>) {
coroutineScope.launch {
workInfoList?.forEach { workInfo ->
workInfoList.forEach { workInfo ->
val transferRecordId =
transferStatusUpdater.getTransferRecordIdForWorkInfo(workInfo.id.toString())
?: workInfo.outputData.getInt(BaseTransferWorker.OUTPUT_TRANSFER_RECORD_ID, -1)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ androidx-test-core = "1.5.0"
androidx-test-junit = "1.1.5"
androidx-test-orchestrator = "1.4.2"
androidx-test-runner = "1.5.2"
androidx-workmanager = "2.9.1"
androidx-workmanager = "2.11.2"
apollo = "4.3.1"
aws-kotlin = "1.5.15" # ensure proper aws-smithy version also set
aws-sdk = "2.81.1"
Expand Down
Loading