Skip to content

Commit

Permalink
[DO NOT MERGE] AdMob 4.22.1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
chauduyphanvu committed Nov 16, 2023
1 parent 1586192 commit 2c9d32d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion AdMobAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
minSdk = 21
targetSdk = 33
// If you touch the following line, don't forget to update scripts/get_rc_version.zsh
android.defaultConfig.versionName = System.getenv("VERSION_OVERRIDE") ?: "4.22.1.0.1"
android.defaultConfig.versionName = System.getenv("VERSION_OVERRIDE") ?: "4.22.1.0.2"

buildConfigField(
"String",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import kotlin.coroutines.resume

class AdMobAdapter : PartnerAdapter {
Expand All @@ -49,9 +51,12 @@ class AdMobAdapter : PartnerAdapter {
else value.joinToString()
}"
)
MobileAds.setRequestConfiguration(
RequestConfiguration.Builder().setTestDeviceIds(value).build()
)
// There have been known ANRs when calling setRequestConfiguration() on the main thread.
CoroutineScope(IO).launch {
MobileAds.setRequestConfiguration(
RequestConfiguration.Builder().setTestDeviceIds(value).build()
)
}
}

/**
Expand Down Expand Up @@ -127,9 +132,13 @@ class AdMobAdapter : PartnerAdapter {
): Result<Unit> {
PartnerLogController.log(SETUP_STARTED)

// Since Chartboost Mediation is the mediator, no need to initialize AdMob's partner SDKs.
// https://developers.google.com/android/reference/com/google/android/gms/ads/MobileAds?hl=en#disableMediationAdapterInitialization(android.content.Context)
MobileAds.disableMediationAdapterInitialization(context)
withContext(IO) {
// Since Chartboost Mediation is the mediator, no need to initialize AdMob's partner SDKs.
// https://developers.google.com/android/reference/com/google/android/gms/ads/MobileAds?hl=en#disableMediationAdapterInitialization(android.content.Context)
//
// There have been known ANRs when calling disableMediationAdapterInitialization() on the main thread.
MobileAds.disableMediationAdapterInitialization(context)
}

return suspendCancellableCoroutine { continuation ->
fun resumeOnce(result: Result<Unit>) {
Expand Down Expand Up @@ -211,16 +220,19 @@ class AdMobAdapter : PartnerAdapter {
else COPPA_NOT_SUBJECT
)

MobileAds.setRequestConfiguration(
MobileAds.getRequestConfiguration().toBuilder()
.setTagForChildDirectedTreatment(
if (isSubjectToCoppa) {
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE
} else {
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE
}
).build()
)
// There have been known ANRs when calling setRequestConfiguration() on the main thread.
CoroutineScope(IO).launch {
MobileAds.setRequestConfiguration(
MobileAds.getRequestConfiguration().toBuilder()
.setTagForChildDirectedTreatment(
if (isSubjectToCoppa) {
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE
} else {
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE
}
).build()
)
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Note the first digit of every adapter version corresponds to the major version of the Chartboost Mediation SDK compatible with that adapter.
Adapters are compatible with any Chartboost Mediation SDK version within that major version.

### 4.22.1.0.2
- Offload `setRequestConfiguration()` and `disableMediationAdapterInitialization()` calls to background threads to avoid ANRs.

### 4.22.1.0.1
- Guard against multiple continuation resumes wherever possible.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The Chartboost Mediation AdMob adapter mediates AdMob via the Chartboost Mediati

In your `build.gradle`, add the following entry:
```
implementation "com.chartboost:chartboost-mediation-adapter-admob:4.22.1.0.1"
implementation "com.chartboost:chartboost-mediation-adapter-admob:4.22.1.0.2"
```

## Contributions
Expand Down

0 comments on commit 2c9d32d

Please sign in to comment.