Skip to content

Commit

Permalink
Clean up fingerprinting-related classes (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshafrir-stripe authored Mar 24, 2020
1 parent e2ec0fe commit 60ede4d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal class StripeApiRepository @JvmOverloads internal constructor(
FingerprintRequestFactory(context),
private val fingerprintDataRepository: FingerprintDataRepository =
FingerprintDataRepository.Default(context),
private val uidParamsFactory: UidParamsFactory = UidParamsFactory.create(context),
private val uidParamsFactory: UidParamsFactory = UidParamsFactory(context),
private val analyticsDataFactory: AnalyticsDataFactory =
AnalyticsDataFactory(context, publishableKey),
private val networkUtils: StripeNetworkUtils = StripeNetworkUtils(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class StripeNetworkUtils @VisibleForTesting constructor(
private val uidParamsFactory: UidParamsFactory
) {
constructor(context: Context) : this(
UidParamsFactory.create(context)
UidParamsFactory(context)
)

internal fun paramsWithUid(intentParams: Map<String, *>): Map<String, *> {
Expand Down
9 changes: 1 addition & 8 deletions stripe/src/main/java/com/stripe/android/StripeUid.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
package com.stripe.android

internal data class StripeUid internal constructor(val value: String) {
internal companion object {
@JvmSynthetic
internal fun create(uid: String): StripeUid {
return StripeUid(uid)
}
}
}
internal data class StripeUid(val value: String)
11 changes: 6 additions & 5 deletions stripe/src/main/java/com/stripe/android/UidParamsFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ internal class UidParamsFactory constructor(
private val packageName: String,
private val uidSupplier: Supplier<StripeUid>
) {
constructor(context: Context) : this(
packageName = context.packageName,
uidSupplier = UidSupplier(context)
)

fun createParams(): Map<String, String> {
val guid = uidSupplier.get().value

Expand Down Expand Up @@ -35,11 +40,7 @@ internal class UidParamsFactory constructor(
}
}

internal companion object {
internal fun create(context: Context): UidParamsFactory {
return UidParamsFactory(context.packageName, UidSupplier(context))
}

private companion object {
private const val FIELD_MUID = "muid"
private const val FIELD_GUID = "guid"
}
Expand Down
10 changes: 7 additions & 3 deletions stripe/src/main/java/com/stripe/android/UidSupplier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import android.provider.Settings
internal class UidSupplier(context: Context) : Supplier<StripeUid> {
private val contentResolver: ContentResolver = context.applicationContext.contentResolver

private val deviceId: String?
@SuppressLint("HardwareIds")
get() {
return Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
}

@SuppressLint("HardwareIds")
override fun get(): StripeUid {
return StripeUid.create(
Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) ?: ""
)
return StripeUid(deviceId.orEmpty())
}
}
2 changes: 1 addition & 1 deletion stripe/src/test/java/com/stripe/android/FakeUidSupplier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ internal class FakeUidSupplier @JvmOverloads constructor(
) : Supplier<StripeUid> {

override fun get(): StripeUid {
return StripeUid.create(value)
return StripeUid(value)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.stripe.android

import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class UidParamsFactoryTest {

@Test
fun testCreate() {
val uidParams = UidParamsFactory("com.app", FakeUidSupplier())
.createParams()
assertEquals(2, uidParams.size)
assertTrue(uidParams.containsKey("muid"))
assertTrue(uidParams.containsKey("guid"))
assertThat(uidParams.keys)
.containsExactly("muid", "guid")
}
}

0 comments on commit 60ede4d

Please sign in to comment.