Skip to content

Commit

Permalink
refactor(capture-sdk): Clean up before pushing changes
Browse files Browse the repository at this point in the history
PP-596
  • Loading branch information
abolfazlimahdi committed Jul 10, 2024
1 parent c361916 commit c68dfbe
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import net.gini.android.bank.api.models.ResolvedPayment
import net.gini.android.bank.api.models.toResolvedPayment
import net.gini.android.bank.api.requests.ErrorEvent
import net.gini.android.bank.api.requests.toAmplitudeRequestBody
import net.gini.android.bank.api.requests.toResolvePaymentBody
import net.gini.android.bank.api.response.toConfiguration
import net.gini.android.core.api.DocumentRemoteSource
import net.gini.android.core.api.requests.ApiException
Expand All @@ -25,7 +26,7 @@ class BankApiDocumentRemoteSource internal constructor(

suspend fun resolvePaymentRequests(accessToken: String, id: String, input: ResolvePaymentInput): ResolvedPayment = withContext(coroutineContext) {
val response = SafeApiRequest.apiRequest {
documentService.resolvePaymentRequests(bearerHeaderMap(accessToken, contentType = giniApiType.giniJsonMediaType), id, input.toAmplitudeRequestBody())
documentService.resolvePaymentRequests(bearerHeaderMap(accessToken, contentType = giniApiType.giniJsonMediaType), id, input.toResolvePaymentBody())
}
response.body()?.toResolvedPayment() ?: throw ApiException.forResponse("Empty response body", response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ data class AmplitudeEvent(
val osName: String,
val carrier: String,
val language: String,
val appSetId: String,
val eventProperties: Map<String, Any>? = null,
val userProperties: Map<String, Any>? = null,
val appVersion: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ data class AmplitudeEventBody(
@Json(name = "os_name") val osName: String,
@Json(name = "carrier") val carrier: String,
@Json(name = "language") val language: String,
@Json(name = "app_set_id") val appSetId: String,
@Json(name = "ip") val ip: String = "\$remote",
@Json(name = "event_properties") val eventProperties: Map<String, Any>? = null,
@Json(name = "user_properties") val userProperties: Map<String, Any>? = null,
Expand All @@ -53,7 +52,6 @@ internal fun AmplitudeEvent.toAmplitudeEventBody() = AmplitudeEventBody(
osName = osName,
carrier = carrier,
language = language,
appSetId = appSetId,
eventProperties = eventProperties,
userProperties = userProperties,
appVersion = appVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ internal data class ResolvePaymentBody(
@Json(name = "purpose") val purpose: String,
)

internal fun ResolvePaymentInput.toAmplitudeRequestBody() = ResolvePaymentBody(
internal fun ResolvePaymentInput.toResolvePaymentBody() = ResolvePaymentBody(
recipient, iban, bic, amount, purpose
)
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class GiniCaptureDefaultNetworkService(
osName = event.osName,
carrier = event.carrier,
language = event.language,
appSetId = event.appSetId,
eventProperties = event.eventProperties,
userProperties = event.userProperties,
appVersion = event.appVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ data class AmplitudeEventModel(
val osName: String,
val carrier: String,
val language: String,
val appSetId: String,
val eventProperties: Map<String, Any>? = null,
val userProperties: Map<String, Any>? = null,
val appVersion: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ internal class AmplitudeUserAnalyticsEventTracker(
private lateinit var userProperties: Map<String, Any>

private val contextProvider: DeviceInfo = DeviceInfo(
context,
shouldTrackAdid = false
context
)

override fun setUserProperty(userProperties: Set<UserAnalyticsUserProperty>) {
Expand Down Expand Up @@ -87,7 +86,6 @@ internal class AmplitudeUserAnalyticsEventTracker(
osName = contextProvider.osName,
carrier = contextProvider.carrier ?: "unknown",
language = contextProvider.language,
appSetId = contextProvider.appSetId ?: "unknown",
eventProperties = finalProperties,
userProperties = userProperties,
appVersion = "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.content.res.Resources
import android.os.Build
import android.provider.Settings.Secure
import android.telephony.TelephonyManager
import org.slf4j.LoggerFactory
import java.lang.reflect.InvocationTargetException
import java.util.Locale
import java.util.UUID

class DeviceInfo(private val context: Context, shouldTrackAdid: Boolean) {
var shouldTrackAdid = true
class DeviceInfo(private val context: Context) {

private var cachedInfo: CachedInfo? = null
get() {
if (field == null) {
Expand All @@ -28,7 +25,6 @@ class DeviceInfo(private val context: Context, shouldTrackAdid: Boolean) {
* Internal class serves as a cache
*/
inner class CachedInfo {
var advertisingId: String?
val versionName: String?
val osName: String
val osVersion: String
Expand All @@ -37,10 +33,8 @@ class DeviceInfo(private val context: Context, shouldTrackAdid: Boolean) {
val model: String
val carrier: String?
val language: String
var appSetId: String?

init {
advertisingId = fetchAdvertisingId()
versionName = fetchVersionName()
osName = OS_NAME
osVersion = fetchOsVersion()
Expand All @@ -49,7 +43,6 @@ class DeviceInfo(private val context: Context, shouldTrackAdid: Boolean) {
model = fetchModel()
carrier = fetchCarrier()
language = fetchLanguage()
appSetId = fetchAppSetId()
}

/**
Expand Down Expand Up @@ -113,70 +106,6 @@ class DeviceInfo(private val context: Context, shouldTrackAdid: Boolean) {
return locale.language
}

private fun fetchAdvertisingId(): String? {
if (!shouldTrackAdid) {
return null
}

// This should not be called on the main thread.
return if ("Amazon" == fetchManufacturer()) {
fetchAndCacheAmazonAdvertisingId
} else {
fetchAndCacheGoogleAdvertisingId
}
}

private fun fetchAppSetId(): String? {
try {
val AppSet = Class
.forName("com.google.android.gms.appset.AppSet")
val getClient = AppSet.getMethod("getClient", Context::class.java)
val appSetIdClient = getClient.invoke(null, context)
val getAppSetIdInfo = appSetIdClient.javaClass.getMethod("getAppSetIdInfo")
val taskWithAppSetInfo = getAppSetIdInfo.invoke(appSetIdClient)
val Tasks = Class.forName("com.google.android.gms.tasks.Tasks")
val await =
Tasks.getMethod("await", Class.forName("com.google.android.gms.tasks.Task"))
val appSetInfo = await.invoke(null, taskWithAppSetInfo)
val getId = appSetInfo.javaClass.getMethod("getId")
appSetId = getId.invoke(appSetInfo) as String
} catch (e: ClassNotFoundException) {
LOG.warn("Google Play Services SDK not found for app set id!")
} catch (e: InvocationTargetException) {
LOG.warn("Google Play Services not available for app set id")
} catch (e: Exception) {
LOG.error("Encountered an error connecting to Google Play Services for app set id")
}
return appSetId
}

private val fetchAndCacheAmazonAdvertisingId: String?
get() {
val cr = context.contentResolver
advertisingId = Secure.getString(cr, SETTING_ADVERTISING_ID)
return advertisingId
}
private val fetchAndCacheGoogleAdvertisingId: String?
get() {
try {
val AdvertisingIdClient = Class
.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient")
val getAdvertisingInfo = AdvertisingIdClient.getMethod(
"getAdvertisingIdInfo",
Context::class.java
)
val advertisingInfo = getAdvertisingInfo.invoke(null, context)
val getId = advertisingInfo.javaClass.getMethod("getId")
advertisingId = getId.invoke(advertisingInfo) as String
} catch (e: ClassNotFoundException) {
LOG.warn("Google Play Services SDK not found for advertising id!")
} catch (e: InvocationTargetException) {
LOG.warn("Google Play Services not available for advertising id")
} catch (e: Exception) {
LOG.error("Encountered an error connecting to Google Play Services for advertising id")
}
return advertisingId
}
}

fun prefetch() {
Expand All @@ -200,18 +129,8 @@ class DeviceInfo(private val context: Context, shouldTrackAdid: Boolean) {
get() = cachedInfo!!.carrier
val language: String
get() = cachedInfo!!.language
val appSetId: String?
get() = cachedInfo!!.appSetId // other causes// failed to get providers list

companion object {
const val OS_NAME = "android"
const val SETTING_ADVERTISING_ID = "advertising_id"
fun generateUUID(): String {
return UUID.randomUUID().toString()
}
}

init {
this.shouldTrackAdid = shouldTrackAdid
}
}

0 comments on commit c68dfbe

Please sign in to comment.