-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from Parsely/coroutines
Migrate threading model to Coroutines - long running branch
- Loading branch information
Showing
32 changed files
with
1,414 additions
and
852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
parsely/src/main/java/com/parsely/parselyandroid/AdvertisementIdProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.parsely.parselyandroid | ||
|
||
import android.content.Context | ||
import android.provider.Settings | ||
import com.google.android.gms.ads.identifier.AdvertisingIdClient | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
internal class AdvertisementIdProvider( | ||
private val context: Context, | ||
coroutineScope: CoroutineScope | ||
) : IdProvider { | ||
|
||
private var adKey: String? = null | ||
|
||
init { | ||
coroutineScope.launch { | ||
try { | ||
adKey = AdvertisingIdClient.getAdvertisingIdInfo(context).id | ||
} catch (e: Exception) { | ||
ParselyTracker.PLog("No Google play services or error!") | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return advertisement id if the coroutine in the constructor finished executing AdvertisingIdClient#getAdvertisingIdInfo | ||
* null otherwise | ||
*/ | ||
override fun provide(): String? = adKey | ||
} | ||
|
||
internal class AndroidIdProvider(private val context: Context) : IdProvider { | ||
override fun provide(): String? { | ||
val uuid = try { | ||
Settings.Secure.getString( | ||
context.applicationContext.contentResolver, | ||
Settings.Secure.ANDROID_ID | ||
) | ||
} catch (ex: Exception) { | ||
null | ||
} | ||
ParselyTracker.PLog(String.format("Android ID: %s", uuid)) | ||
return uuid | ||
} | ||
} | ||
|
||
internal fun interface IdProvider { | ||
fun provide(): String? | ||
} |
Oops, something went wrong.