Skip to content

Commit

Permalink
Switched to use latest version of Auth SDK (#1)
Browse files Browse the repository at this point in the history
* Bumped versions higher to fix compile error with
newer Java SDK environments.

* Updated to latest version of auth sdk.
  • Loading branch information
mbalfour-amzn authored Nov 1, 2024
1 parent 0f158fd commit 4d8bf04
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 40 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins {
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.android.library") version "8.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.21" apply false
id("com.android.library") version "8.3.2" apply false
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ guava = { module = "com.google.guava:guava", version.ref = "guava" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter-engine" }

[plugins]
jvm = { id = "org.jetbrains.kotlin.jvm", version = "1.9.20" }
jvm = { id = "org.jetbrains.kotlin.jvm", version = "1.9.21" }
31 changes: 16 additions & 15 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ android {
}

dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")

implementation("com.google.android.gms:play-services-location:21.0.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.7.3")
implementation("androidx.work:work-runtime-ktx:2.9.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation("aws.sdk.kotlin:location:1.2.21")
implementation("com.google.android.gms:play-services-location:21.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.9.0")
implementation("androidx.work:work-runtime-ktx:2.9.1")
implementation("com.google.code.gson:gson:2.11.0")
implementation("androidx.datastore:datastore-preferences:1.1.1")
implementation("aws.sdk.kotlin:location:1.3.65")

if (findProject(":authSdk") != null) {
implementation(project(":authSdk"))
} else {
implementation("software.amazon.location:auth:0.2.5")
implementation("software.amazon.location:auth:1.1.0")
}

val roomVersion = "2.6.1"
Expand All @@ -108,10 +108,11 @@ dependencies {
kapt("androidx.room:room-compiler:$roomVersion")

testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-test:1.9.20")
testImplementation("io.mockk:mockk:1.13.10")
testImplementation("org.mockito:mockito-core:3.12.4" )
testImplementation("org.jetbrains.kotlin:kotlin-test:2.0.21")
testImplementation("io.mockk:mockk:1.13.13")
testImplementation("org.mockito:mockito-core:5.14.2")
testImplementation("aws.sdk.kotlin:aws-http:1.3.65")

androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.location.Location
import android.os.Build
import androidx.annotation.RequiresPermission
import androidx.room.Room
import aws.sdk.kotlin.services.location.LocationClient
import aws.sdk.kotlin.services.location.model.BatchEvaluateGeofencesResponse
import aws.sdk.kotlin.services.location.model.ResourceNotFoundException
import aws.smithy.kotlin.runtime.time.epochMilliseconds
Expand Down Expand Up @@ -51,6 +52,7 @@ private const val PREFS_NAME = "software.amazon.location.tracking.client"
*/
class LocationTracker {
private var clientConfig: LocationTrackerConfig
private var locationClient: LocationClient

constructor(
context: Context,
Expand Down Expand Up @@ -86,6 +88,7 @@ class LocationTracker {
locationCredentialsProvider: LocationCredentialsProvider,
clientConfig: LocationTrackerConfig,
) {
this.locationClient = LocationClient(locationCredentialsProvider.getLocationClientConfig())
this.context = context
this.clientConfig = clientConfig
this.locationCredentialsProvider = locationCredentialsProvider
Expand Down Expand Up @@ -253,6 +256,10 @@ class LocationTracker {
return location
}

fun getLocationClient():LocationClient {
return locationClient
}

/**
* Retrieves the device location from AWS location services.
* @return The device Location from AWS or null if the device location is not found or an error occurs.
Expand All @@ -261,7 +268,7 @@ class LocationTracker {
validateAndRefreshLocationCredentials()
return try {
val deviceLocation = httpClient.getTrackerDeviceLocation(
locationCredentialsProvider?.getLocationClient(),
getLocationClient(),
)
deviceLocation.let {
Location("").apply {
Expand Down Expand Up @@ -299,7 +306,7 @@ class LocationTracker {
validateAndRefreshLocationCredentials()
return try {
httpClient.batchEvaluateGeofences(
locationCredentialsProvider?.getLocationClient(),
getLocationClient(),
locationEntry,
deviceId,
identityId,
Expand Down Expand Up @@ -342,7 +349,7 @@ class LocationTracker {
}.toTypedArray()

val result = httpClient.updateTrackerDeviceLocation(
locationCredentialsProvider?.getLocationClient(),
getLocationClient(),
locationsToUpload,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import androidx.work.WorkManager
import androidx.work.WorkerParameters
import aws.sdk.kotlin.services.location.LocationClient
import aws.sdk.kotlin.services.location.model.BatchUpdateDevicePositionResponse
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.util.PlatformProvider
import com.google.android.gms.location.CurrentLocationRequest
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationAvailability
Expand All @@ -27,6 +29,7 @@ import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkConstructor
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.runs
import io.mockk.unmockkAll
Expand Down Expand Up @@ -74,8 +77,14 @@ class BackgroundTrackingWorkerTest {
private lateinit var locationCredentialsProvider: LocationCredentialsProvider
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient
private lateinit var gsonBuilderMock: GsonBuilder
@OptIn(InternalApi::class)
@Before
fun setUp() {
// These are mocked out so that the construction of LocationClient doesn't crash
// from trying to access null Build.VERSION fields.
mockkObject(PlatformProvider.System)
every { PlatformProvider.System.isAndroid } returns false

context = mockk(relaxed = true)
every { context.applicationContext } returns mockk()
workerParameters = mockk<WorkerParameters>(relaxed = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import aws.sdk.kotlin.services.location.model.BatchEvaluateGeofencesResponse
import aws.sdk.kotlin.services.location.model.BatchUpdateDevicePositionResponse
import aws.sdk.kotlin.services.location.model.GetDevicePositionResponse
import aws.sdk.kotlin.services.location.model.PositionalAccuracy
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.time.Instant
import aws.smithy.kotlin.runtime.util.PlatformProvider
import com.google.android.gms.location.CurrentLocationRequest
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationAvailability
Expand Down Expand Up @@ -84,13 +86,20 @@ class LocationClientTest {
private lateinit var gsonBuilderMock: GsonBuilder
private val coroutineScope = CoroutineScope(Dispatchers.Default)

@OptIn(InternalApi::class)
@Before
fun setUp() {
// These are mocked out so that the construction of LocationClient doesn't crash
// from trying to access null Build.VERSION fields.
mockkObject(PlatformProvider.System)
every { PlatformProvider.System.isAndroid } returns false

context = mockk(relaxed = true)
locationManager = mockk()
serviceCallback = mockk()
locationTrackingCallback = mockk()
locationCredentialsProvider = mockk()
every { locationCredentialsProvider.getLocationClientConfig()} returns {}
locationClientConfig = LocationTrackerConfig(
trackerName = TRACKER_NAME,
logLevel = TrackingSdkLogLevel.DEBUG,
Expand Down Expand Up @@ -381,9 +390,9 @@ class LocationClientTest {
val mockAmazonLocationClient = mockk<LocationClient>()
coEvery { locationCredentialsProvider.isCredentialsValid() } returns true
coEvery { locationCredentialsProvider.verifyAndRefreshCredentials() } just runs
coEvery {
locationCredentialsProvider.getLocationClient()
} returns mockAmazonLocationClient
mockkConstructor(LocationTracker::class)
every { anyConstructed<LocationTracker>().getLocationClient() } returns mockAmazonLocationClient

val batchEvaluateGeofencesResponse = BatchEvaluateGeofencesResponse.invoke {
errors = listOf()
}
Expand Down Expand Up @@ -417,9 +426,9 @@ class LocationClientTest {
val mockAmazonLocationClient = mockk<LocationClient>()
coEvery { locationCredentialsProvider.isCredentialsValid() } returns true
coEvery { locationCredentialsProvider.verifyAndRefreshCredentials() } just runs
coEvery {
locationCredentialsProvider.getLocationClient()
} returns mockAmazonLocationClient
mockkConstructor(LocationTracker::class)
every { anyConstructed<LocationTracker>().getLocationClient() } returns mockAmazonLocationClient

val mockGetDevicePositionResult = GetDevicePositionResponse.invoke {
position = listOf(27.51551, 23.5444)
sampleTime = Instant.now()
Expand All @@ -443,9 +452,8 @@ class LocationClientTest {
val mockAmazonLocationClient = mockk<LocationClient>()
coEvery { locationCredentialsProvider.isCredentialsValid() } returns true
coEvery { locationCredentialsProvider.verifyAndRefreshCredentials() } just runs
coEvery {
locationCredentialsProvider.getLocationClient()
} returns mockAmazonLocationClient
mockkConstructor(LocationTracker::class)
every { anyConstructed<LocationTracker>().getLocationClient() } returns mockAmazonLocationClient

val result = BatchUpdateDevicePositionResponse.invoke {
errors = listOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,20 @@ class LocationUpdateTest {
@Test
fun `test update Tracker Device Locations`() {
val locationCredentialProvider = mockk<LocationCredentialsProvider>()
mockkConstructor(LocationClient::class)
val mockAmazonLocationClient = mockk<LocationClient>()
val mockLocation = mockk<Location>()
val mockDeviceIdProvider = mockk<DeviceIdProvider>()

val deviceID = "mockDeviceID"
every { mockDeviceIdProvider.getDeviceID() } returns deviceID
coEvery {
locationCredentialProvider.getLocationClient()
} returns mockAmazonLocationClient
val currentTimeMillis = System.currentTimeMillis()
every { mockLocation.time } returns currentTimeMillis
every { mockLocation.latitude } returns 23.455
every { mockLocation.longitude } returns 103.556
val exception = Exception("Mock exception")
coEvery {
mockAmazonLocationClient.batchUpdateDevicePosition(any())
anyConstructed<LocationClient>().batchUpdateDevicePosition(any())
} throws exception

val amazonTrackingHttpClient = AmazonTrackingHttpClient(context, "mockTrackerName")
Expand All @@ -91,9 +89,6 @@ class LocationUpdateTest {

val deviceID = "mockDeviceID"
every { mockDeviceIdProvider.getDeviceID() } returns deviceID
coEvery {
locationCredentialProvider.getLocationClient()
} returns mockAmazonLocationClient
val amazonTrackingHttpClient = AmazonTrackingHttpClient(context, "mockTrackerName")

val mockGetDevicePositionResult = mockk<GetDevicePositionResponse>()
Expand Down Expand Up @@ -128,9 +123,6 @@ class LocationUpdateTest {
every { mockLocation.longitude } returns 103.556

val mockBatchUpdateDevicePositionResult = mockk<BatchUpdateDevicePositionResponse>()
coEvery {
locationCredentialProvider.getLocationClient()
} returns mockAmazonLocationClient
coEvery {
mockAmazonLocationClient.batchUpdateDevicePosition(any())
} returns mockBatchUpdateDevicePositionResult
Expand Down

0 comments on commit 4d8bf04

Please sign in to comment.