Skip to content

Commit

Permalink
fix: fix app set id null issue (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingzhuozhen authored Sep 9, 2022
1 parent 942d053 commit 0cdc238
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class AndroidContextPlugin : Plugin {
}
if (!configuration.newDeviceIdPerInstall && configuration.useAdvertisingIdForDeviceId && !contextProvider.isLimitAdTrackingEnabled()) {
val advertisingId = contextProvider.advertisingId
if (validDeviceId(advertisingId)) {
if (advertisingId != null && validDeviceId(advertisingId)) {
amplitude.setDeviceId(advertisingId)
return
}
}
if (configuration.useAppSetIdForDeviceId) {
val appSetId = contextProvider.appSetId
if (validDeviceId(appSetId)) {
amplitude.setDeviceId("{$appSetId}S")
if (appSetId != null && validDeviceId(appSetId)) {
amplitude.setDeviceId("${appSetId}S")
return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
* Internal class serves as a cache
*/
inner class CachedInfo {
var advertisingId: String
var advertisingId: String?
val country: String?
val versionName: String?
val osName: String
Expand All @@ -48,7 +48,7 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
val language: String
var limitAdTrackingEnabled: Boolean = true
val gpsEnabled: Boolean
var appSetId: String
var appSetId: String?

init {
advertisingId = fetchAdvertisingId()
Expand Down Expand Up @@ -201,7 +201,7 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
return locale.language
}

private fun fetchAdvertisingId(): String {
private fun fetchAdvertisingId(): String? {
// This should not be called on the main thread.
return if ("Amazon" == fetchManufacturer()) {
fetchAndCacheAmazonAdvertisingId
Expand All @@ -210,7 +210,7 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
}
}

private fun fetchAppSetId(): String {
private fun fetchAppSetId(): String? {
try {
val AppSet = Class
.forName("com.google.android.gms.appset.AppSet")
Expand All @@ -237,14 +237,14 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
return appSetId
}

private val fetchAndCacheAmazonAdvertisingId: String
private val fetchAndCacheAmazonAdvertisingId: String?
private get() {
val cr = context.contentResolver
limitAdTrackingEnabled = Secure.getInt(cr, SETTING_LIMIT_AD_TRACKING, 0) == 1
advertisingId = Secure.getString(cr, SETTING_ADVERTISING_ID)
return advertisingId
}
private val fetchAndCacheGoogleAdvertisingId: String
private val fetchAndCacheGoogleAdvertisingId: String?
private get() {
try {
val AdvertisingIdClient = Class
Expand Down Expand Up @@ -338,9 +338,9 @@ class AndroidContextProvider(private val context: Context, locationListening: Bo
get() = cachedInfo!!.country
val language: String
get() = cachedInfo!!.language
val advertisingId: String
val advertisingId: String?
get() = cachedInfo!!.advertisingId
val appSetId: String
val appSetId: String?
get() = cachedInfo!!.appSetId // other causes// failed to get providers list
// Don't crash if the device does not have location services.

Expand Down

0 comments on commit 0cdc238

Please sign in to comment.