Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: previous Google ad Id from being null on cold launch #518

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ dependencies {
testImplementation project(':testutils')
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_version"

androidTestImplementation project(':testutils')
if (useOrchestrator()) {
Expand All @@ -167,6 +168,7 @@ dependencies {
}
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_version"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.mparticle.internal.database.services.AccessUtils
import com.mparticle.internal.database.services.MParticleDBManager
import com.mparticle.testutils.BaseCleanStartedEachTest
import com.mparticle.testutils.MPLatch
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.runTest
import org.json.JSONException
import org.junit.Assert
import org.junit.Before
Expand Down Expand Up @@ -104,7 +106,7 @@ class AppStateManagerInstrumentedTest : BaseCleanStartedEachTest() {

@Test
@Throws(InterruptedException::class)
fun testOnApplicationForeground() {
fun testOnApplicationForeground() = runTest(StandardTestDispatcher()) {
val latch: CountDownLatch = MPLatch(2)
val kitManagerTester = KitManagerTester(mContext, latch)
com.mparticle.AccessUtils.setKitManager(kitManagerTester)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class MPUtility {
private static String sOpenUDID;
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
private static final String TAG = MPUtility.class.toString();
private static AdIdInfo infoId = null;

public static long getAvailableMemory(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
Expand Down Expand Up @@ -122,18 +123,21 @@ public static boolean isEmpty(Collection collection) {
@WorkerThread
@Nullable
public static AdIdInfo getAdIdInfo(Context context) {
if (infoId != null) {
return infoId;
}
String packageName = context.getPackageName();
PackageManager packageManager = context.getPackageManager();
String installerName = packageManager.getInstallerPackageName(packageName);
if ((installerName != null && installerName.contains("com.amazon.venezia")) ||
"Amazon".equals(android.os.Build.MANUFACTURER)) {
AdIdInfo infoId = getAmazonAdIdInfo(context);
infoId = getAmazonAdIdInfo(context);
if (infoId == null) {
return getGoogleAdIdInfo(context);
}
return infoId;
} else {
AdIdInfo infoId = getGoogleAdIdInfo(context);
infoId = getGoogleAdIdInfo(context);
if (infoId == null) {
return getAmazonAdIdInfo(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import com.mparticle.identity.IdentityApi.SingleUserIdentificationCallback
import com.mparticle.identity.IdentityApiRequest
import com.mparticle.identity.MParticleUser
import com.mparticle.internal.listeners.InternalListenerManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.json.JSONObject
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicInteger
Expand Down Expand Up @@ -166,6 +169,9 @@ open class AppStateManager @JvmOverloads constructor(
interruptions
)
}
CoroutineScope(Dispatchers.IO).launch {
mConfigManager?.setPreviousAdId()
}
mLastForegroundTime = time

if (currentActivity != null) {
Expand Down Expand Up @@ -207,7 +213,6 @@ open class AppStateManager @JvmOverloads constructor(
if (isBackgrounded()) {
checkSessionTimeout()
logBackgrounded()
mConfigManager?.setPreviousAdId()
}
} catch (e: Exception) {
e.printStackTrace()
Expand Down Expand Up @@ -421,7 +426,9 @@ open class AppStateManager @JvmOverloads constructor(
internal class CheckAdIdRunnable(var configManager: ConfigManager?) : Runnable {
override fun run() {
val adIdInfo =
MPUtility.getAdIdInfo(MParticle.getInstance()?.Internal()?.appStateManager?.mContext)
MPUtility.getAdIdInfo(
MParticle.getInstance()?.Internal()?.appStateManager?.mContext
)
val currentAdId =
(if (adIdInfo == null) null else (if (adIdInfo.isLimitAdTrackingEnabled) null else adIdInfo.id))
val previousAdId = configManager?.previousAdId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.mparticle.mock.MockApplication
import com.mparticle.mock.MockContext
import com.mparticle.mock.MockSharedPreferences
import com.mparticle.testutils.AndroidUtils
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Assert
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -132,7 +134,7 @@ class AppStateManagerTest {
*/
@Test
@Throws(Exception::class)
fun testSecondActivityStart() {
fun testSecondActivityStart() = runTest(StandardTestDispatcher()) {
manager.onActivityPaused(activity)
Thread.sleep(1000)
Assert.assertEquals(true, manager.isBackgrounded())
Expand Down
Loading