Skip to content

Commit

Permalink
[HB-6722] AdMob 4.22.3.0.4 (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
chauduyphanvu authored Nov 16, 2023
1 parent 65e7dcd commit fb01c72
Show file tree
Hide file tree
Showing 4 changed files with 40 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.3.0.3"
android.defaultConfig.versionName = System.getenv("VERSION_OVERRIDE") ?: "4.22.3.0.4"

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,13 @@ 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 +133,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 +221,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
9 changes: 9 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.3.0.4
- Offload `setRequestConfiguration()` and `disableMediationAdapterInitialization()` calls to background threads to avoid ANRs.

### 4.22.3.0.3
- Add support for adaptive banner sizes.

Expand All @@ -15,9 +18,15 @@ Adapters are compatible with any Chartboost Mediation SDK version within that ma
### 4.22.3.0.0
- This version of the adapter has been certified with Google Mobile Ads SDK 22.3.0.

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

### 4.22.2.0.0
- This version of the adapter has been certified with Google Mobile Ads SDK 22.2.0.

### 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.3.0.3"
implementation "com.chartboost:chartboost-mediation-adapter-admob:4.22.3.0.4"
```

## Contributions
Expand Down

0 comments on commit fb01c72

Please sign in to comment.