Skip to content

Commit

Permalink
v1.6.53
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Korney committed Feb 21, 2025
1 parent ac90662 commit 82f7c65
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 63 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.6.53] - 2025-02-21

### Added

- Persistent `AFFISE_DEVICE_ID`.

## [1.6.52] - 2025-02-04

### Added
Expand Down Expand Up @@ -199,6 +205,7 @@
- Improve `AffiseModuleManager`
- Update gradle for demo app.

[1.6.53]: https://github.com/affise/sdk-android/compare/v1.6.52...v1.6.53
[1.6.52]: https://github.com/affise/sdk-android/compare/v1.6.51...v1.6.52
[1.6.51]: https://github.com/affise/sdk-android/compare/v1.6.50...v1.6.51
[1.6.50]: https://github.com/affise/sdk-android/compare/v1.6.49...v1.6.50
Expand Down
88 changes: 46 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ For kotlin build script build.gradle.kts use:
```kotlin
dependencies {
// Add Affise library
implementation("com.affise:attribution:1.6.52")
implementation("com.affise:attribution:1.6.53")
// Add Affise modules
implementation("com.affise:module-advertising:1.6.52")
implementation("com.affise:module-androidid:1.6.52")
implementation("com.affise:module-link:1.6.52")
implementation("com.affise:module-network:1.6.52")
implementation("com.affise:module-phone:1.6.52")
implementation("com.affise:module-status:1.6.52")
implementation("com.affise:module-subscription:1.6.52")
// implementation("com.affise:module-rustore:1.6.52")
// implementation("com.affise:module-huawei:1.6.52")
implementation("com.affise:module-advertising:1.6.53")
implementation("com.affise:module-androidid:1.6.53")
implementation("com.affise:module-link:1.6.53")
implementation("com.affise:module-network:1.6.53")
implementation("com.affise:module-phone:1.6.53")
implementation("com.affise:module-status:1.6.53")
implementation("com.affise:module-subscription:1.6.53")
// implementation("com.affise:module-rustore:1.6.53")
// implementation("com.affise:module-huawei:1.6.53")
// Add install referrer
implementation("com.android.installreferrer:installreferrer:2.2")
}
Expand All @@ -124,27 +124,27 @@ For groovy build script build.gradle use:
```groovy
dependencies {
// Add Affise library
implementation 'com.affise:attribution:1.6.52'
implementation 'com.affise:attribution:1.6.53'
// Add Affise modules
implementation 'com.affise:module-advertising:1.6.52'
implementation 'com.affise:module-androidid:1.6.52'
implementation 'com.affise:module-link:1.6.52'
implementation 'com.affise:module-network:1.6.52'
implementation 'com.affise:module-phone:1.6.52'
implementation 'com.affise:module-status:1.6.52'
implementation 'com.affise:module-subscription:1.6.52'
// implementation 'com.affise:module-rustore:1.6.52'
// implementation 'com.affise:module-huawei:1.6.52'
implementation 'com.affise:module-advertising:1.6.53'
implementation 'com.affise:module-androidid:1.6.53'
implementation 'com.affise:module-link:1.6.53'
implementation 'com.affise:module-network:1.6.53'
implementation 'com.affise:module-phone:1.6.53'
implementation 'com.affise:module-status:1.6.53'
implementation 'com.affise:module-subscription:1.6.53'
// implementation 'com.affise:module-rustore:1.6.53'
// implementation 'com.affise:module-huawei:1.6.53'
// Add install referrer
implementation 'com.android.installreferrer:installreferrer:2.2'
}
```

### Integrate as file dependency

Download latest Affise SDK (`attribution-1.6.52.aar`)
Download latest Affise SDK (`attribution-1.6.53.aar`)
from [releases page](https://github.com/affise/sdk-android/releases) and place this binary to gradle application
module lib directory `app/libs/attribution-1.6.52.aar`
module lib directory `app/libs/attribution-1.6.53.aar`

Add library as gradle file dependency to application module build script
Add install referrer library
Expand All @@ -155,17 +155,17 @@ For kotlin build script build.gradle.kts use:
dependencies {
// ...
// Add Affise library
implementation(files("libs/attribution-1.6.52.aar"))
implementation(files("libs/attribution-1.6.53.aar"))
// Add Affise modules
implementation(files("libs/module-advertising-1.6.52.aar"))
implementation(files("libs/module-androidid-1.6.52.aar"))
implementation(files("libs/module-link-1.6.52.aar"))
implementation(files("libs/module-network-1.6.52.aar"))
implementation(files("libs/module-phone-1.6.52.aar"))
implementation(files("libs/module-status-1.6.52.aar"))
implementation(files("libs/module-subscription-1.6.52.aar"))
// implementation(files("libs/module-rustore-1.6.52.aar"))
// implementation(files("libs/module-huawei-1.6.52.aar"))
implementation(files("libs/module-advertising-1.6.53.aar"))
implementation(files("libs/module-androidid-1.6.53.aar"))
implementation(files("libs/module-link-1.6.53.aar"))
implementation(files("libs/module-network-1.6.53.aar"))
implementation(files("libs/module-phone-1.6.53.aar"))
implementation(files("libs/module-status-1.6.53.aar"))
implementation(files("libs/module-subscription-1.6.53.aar"))
// implementation(files("libs/module-rustore-1.6.53.aar"))
// implementation(files("libs/module-huawei-1.6.53.aar"))
// Add install referrer
implementation("com.android.installreferrer:installreferrer:2.2")
}
Expand All @@ -177,17 +177,17 @@ For groovy build script build.gradle use:
dependencies {
// ...
// Add Affise library
implementation files('libs/attribution-1.6.52.aar')
implementation files('libs/attribution-1.6.53.aar')
// Add Affise modules
implementation files('libs/module-advertising-1.6.52.aar')
implementation files('libs/module-androidid-1.6.52.aar')
implementation files('libs/module-link-1.6.52.aar')
implementation files('libs/module-network-1.6.52.aar')
implementation files('libs/module-phone-1.6.52.aar')
implementation files('libs/module-status-1.6.52.aar')
implementation files('libs/module-subscription-1.6.52.aar')
// implementation files('libs/module-rustore-1.6.52.aar')
// implementation files('libs/module-huawei-1.6.52.aar')
implementation files('libs/module-advertising-1.6.53.aar')
implementation files('libs/module-androidid-1.6.53.aar')
implementation files('libs/module-link-1.6.53.aar')
implementation files('libs/module-network-1.6.53.aar')
implementation files('libs/module-phone-1.6.53.aar')
implementation files('libs/module-status-1.6.53.aar')
implementation files('libs/module-subscription-1.6.53.aar')
// implementation files('libs/module-rustore-1.6.53.aar')
// implementation files('libs/module-huawei-1.6.53.aar')
// Add install referrer
implementation 'com.android.installreferrer:installreferrer:2.2'
}
Expand Down Expand Up @@ -1319,6 +1319,10 @@ Affise.getRandomUserId()

## Get random device Id

> **Note**
>
> Use [Affise AndroidId Module](#modules) to make `device id` more persistent on application reinstall
Use the next public method of SDK

For kotlin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ internal class AffiseComponent(
RemarketingUseCaseImpl()
}

private val persistentUseCase: PersistentUseCase by lazy {
PersistentUseCaseImpl()
}

/**
* SetPropertiesWhenInitUseCase
*/
Expand All @@ -315,7 +319,7 @@ internal class AffiseComponent(
* FirstAppOpenUseCase
*/
override val firstAppOpenUseCase: FirstAppOpenUseCase by lazy {
FirstAppOpenUseCase(sharedPreferences, activityCountProvider)
FirstAppOpenUseCase(sharedPreferences, activityCountProvider, persistentUseCase)
}

/**
Expand Down Expand Up @@ -526,7 +530,6 @@ internal class AffiseComponent(
*/
init {
sendGDPREventUseCase.sendForgetMeEvent()
firstAppOpenUseCase.onAppCreated()
sessionManager.init()
setPropertiesWhenInitUseCase.init(initProperties)
deeplinkManager.init()
Expand All @@ -551,6 +554,8 @@ internal class AffiseComponent(
sharedPreferences,
)
)
persistentUseCase.init(moduleManager)
firstAppOpenUseCase.onAppCreated()

storeInstallReferrerUseCase.onReferrerSetupFinished {
eventsManager.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PostBackModelToJsonStringConverter(
}

// PostBack index
put(UUID_INDEX_KEY, indexUseCase.getUuidIndex())
put(Parameters.UUID_INDEX_KEY, indexUseCase.getUuidIndex())

//Events
val eventsArray = JSONArray()
Expand Down Expand Up @@ -82,6 +82,5 @@ class PostBackModelToJsonStringConverter(
private const val SDK_EVENTS_KEY = "sdk_events"
private const val METRICS_EVENTS_KEY = "metrics_events"
private const val INTERNAL_EVENTS_KEY = "internal_events"
private const val UUID_INDEX_KEY = "uuid_index"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.affise.attribution.modules.advertising

import com.affise.attribution.modules.AffiseModuleApi

interface AdvertisingApi : AffiseModuleApi {
fun getAdvertisingId(): String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.affise.attribution.modules.androidid

import com.affise.attribution.modules.AffiseModuleApi

interface AndroidIdApi : AffiseModuleApi {
fun getAndroidId(): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ object Parameters {
const val AFFISE_SDK_EVENTS_COUNT = "affise_sdk_events_count"
const val AFFISE_METRICS_EVENTS_COUNT = "affise_metrics_events_count"
const val AFFISE_INTERNAL_EVENTS_COUNT = "affise_internal_events_count"
const val UUID_INDEX_KEY = "uuid_index"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import java.util.*

class FirstAppOpenUseCase(
private val preferences: SharedPreferences,
private val activityCountProvider: CurrentActiveActivityCountProvider
private val activityCountProvider: CurrentActiveActivityCountProvider,
private val persistentUseCase: PersistentUseCase
) {

private var firstRun: Boolean = false
Expand Down Expand Up @@ -52,7 +53,7 @@ class FirstAppOpenUseCase(
preferences.apply {
//Create affDevId
checkSaveString(AFF_DEVICE_ID) {
generateUUID().toString()
persistentUseCase.getAffDeviceId() ?: generateUUID().toString()
}
//Create affAltDevId
checkSaveString(AFF_ALT_DEVICE_ID) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.affise.attribution.usecase

import com.affise.attribution.modules.AffiseModuleManager

interface PersistentUseCase {
fun init(moduleManager: AffiseModuleManager)
fun getAffDeviceId(): String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.affise.attribution.usecase

import com.affise.attribution.modules.AffiseModuleApi
import com.affise.attribution.modules.AffiseModuleManager
import com.affise.attribution.modules.AffiseModules
import com.affise.attribution.modules.advertising.AdvertisingApi
import com.affise.attribution.modules.androidid.AndroidIdApi
import com.affise.attribution.utils.isValidUUID
import com.affise.attribution.utils.toFakeUUID

internal class PersistentUseCaseImpl : PersistentUseCase {

private var moduleManager: AffiseModuleManager? = null
private var affDeviceId: String? = null

override fun init(moduleManager: AffiseModuleManager) {
this.moduleManager = moduleManager
}

override fun getAffDeviceId(): String? {
if (affDeviceId != null) return affDeviceId
affDeviceId = uuidFromAndroidId() ?: uuidFromAdvertisingId()
return affDeviceId
}

private fun <T : AffiseModuleApi> getModule(module: AffiseModules): T? {
@Suppress("UNCHECKED_CAST")
return moduleManager?.getModule(module) as? T
}

private fun uuidFromAndroidId(): String? {
val moduleAndroidId: AndroidIdApi? = getModule(AffiseModules.AndroidId)
val androidId = moduleAndroidId?.getAndroidId()
?.lowercase()
?.toFakeUUID()
androidId ?: return null
if (!androidId.isValidUUID()) return null
return androidId
}

private fun uuidFromAdvertisingId(): String? {
val moduleAdvertising: AdvertisingApi? = getModule(AffiseModules.Advertising)
val advertisingId = moduleAdvertising?.getAdvertisingId()
?.lowercase()
advertisingId ?: return null
if (!advertisingId.isValidUUID()) return null
return advertisingId
}
}
25 changes: 24 additions & 1 deletion attribution/src/main/java/com/affise/attribution/utils/UUID.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,27 @@ private fun generateType1UUID(): UUID {

fun generateUUID() : UUID {
return generateType1UUID()
}
}

internal fun String.isValidUUID(): Boolean {
return !this.startsWith("00000000-", false)
}

internal fun String.toFakeUUID(): String {
var baseString = this
val uuidLength = 4*8

while (baseString.length < uuidLength) {
baseString += baseString
}

baseString = baseString.takeLast(uuidLength)

val uuid1 = baseString.substring(0, 8)
val uuid2 = baseString.substring(8, 12)
val uuid3 = baseString.substring(12, 16)
val uuid4 = baseString.substring(16, 20)
val uuid5 = baseString.substring(20, 32)

return "$uuid1-$uuid2-$uuid3-$uuid4-$uuid5"
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tasks.register('clean', Delete) {
}

ext {
affiseVersion = "1.6.52"
affiseVersion = "1.6.53"

compose_compiler_version = "1.4.8"
compose_bom = "2024.06.00"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import com.affise.attribution.module.advertising.parameters.GoogleAdvertisingPer
import com.affise.attribution.module.advertising.parameters.OaidMD5Provider
import com.affise.attribution.module.advertising.parameters.OaidProvider
import com.affise.attribution.modules.AffiseModule
import com.affise.attribution.modules.advertising.AdvertisingApi
import com.affise.attribution.parameters.ProviderType
import com.affise.attribution.parameters.base.PropertyProvider
import com.affise.attribution.parameters.providers.EmptyStringProvider

class AdvertisingModule : AffiseModule() {
class AdvertisingModule : AffiseModule(), AdvertisingApi {

override val version: String = BuildConfig.AFFISE_VERSION

Expand Down Expand Up @@ -101,4 +102,6 @@ class AdvertisingModule : AffiseModule() {
}

override fun providers(): List<PropertyProvider<*>> = providers

override fun getAdvertisingId(): String? = advManager?.getAdvertisingId()
}
Loading

0 comments on commit 82f7c65

Please sign in to comment.