Skip to content

Commit bccd391

Browse files
Ian BirdIanDBird
Ian Bird
authored andcommitted
[IMA/GMA] Fix race condition in adapters where we reported initialized too early
1 parent 5dd55ad commit bccd391

File tree

6 files changed

+54
-46
lines changed

6 files changed

+54
-46
lines changed

securesignals-gma-dev-app/src/main/java/com/uid2/dev/GMADevApplication.java

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.uid2.dev
2+
3+
import android.app.Application
4+
import android.util.Log
5+
import com.uid2.UID2Manager
6+
7+
class GMADevApplication : Application() {
8+
9+
override fun onCreate() {
10+
super.onCreate()
11+
12+
// Initialise the UID2Manager class. We will use it's DefaultNetworkSession rather than providing our own
13+
// custom implementation. This can be done to allow wrapping something like OkHttp.
14+
try {
15+
UID2Manager.init(
16+
context = this,
17+
isLoggingEnabled = true,
18+
)
19+
} catch (ex: Exception) {
20+
Log.e("IMADevApplication", "Error initialising UID2Manager", ex)
21+
}
22+
}
23+
}

securesignals-gma/src/main/java/com/uid2/securesignals/gma/UID2MediationAdapter.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public class UID2MediationAdapter : RtbAdapter() {
4545
UID2Manager.init(context)
4646
}
4747

48-
initializationCompleteCallback.onInitializationSucceeded()
48+
// After we've asked to initialize the manager, we should wait until it's complete before reporting success.
49+
// This will potentially allow any previously persisted identity to be fully restored before we allow any
50+
// signals to be collected.
51+
UID2Manager.getInstance().onInitialized = initializationCompleteCallback::onInitializationSucceeded
4952
}
5053

5154
/**

securesignals-ima-dev-app/src/main/java/com/uid2/dev/IMADevApplication.java

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.uid2.dev
2+
3+
import android.app.Application
4+
import android.util.Log
5+
import com.uid2.UID2Manager
6+
7+
class IMADevApplication : Application() {
8+
9+
override fun onCreate() {
10+
super.onCreate()
11+
12+
// Initialise the UID2Manager class. We will use it's DefaultNetworkSession rather than providing our own
13+
// custom implementation. This can be done to allow wrapping something like OkHttp.
14+
try {
15+
UID2Manager.init(
16+
context = this,
17+
isLoggingEnabled = true,
18+
)
19+
} catch (ex: Exception) {
20+
Log.e("IMADevApplication", "Error initialising UID2Manager", ex)
21+
}
22+
}
23+
}

securesignals-ima/src/main/java/com/uid2/securesignals/ima/UID2SecureSignalsAdapter.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public class UID2SecureSignalsAdapter : SecureSignalsAdapter {
4141
UID2Manager.init(context)
4242
}
4343

44-
callback.onSuccess()
44+
// After we've asked to initialize the manager, we should wait until it's complete before reporting success.
45+
// This will potentially allow any previously persisted identity to be fully restored before we allow any
46+
// signals to be collected.
47+
UID2Manager.getInstance().onInitialized = callback::onSuccess
4548
}
4649

4750
/**

0 commit comments

Comments
 (0)