Skip to content
Merged
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
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ dependencies {
implementation "com.google.android.gms:play-services-ads:$rootProject.ext.playServicesAdsVersion"
implementation "com.google.android.ump:user-messaging-platform:$rootProject.ext.userMessagingPlatformVersion"

// Liftoff Monetize mediation via AdMob
implementation "com.google.ads.mediation:vungle:$rootProject.ext.liftoffMediationAdapterVersion"
implementation "com.vungle:vungle-ads:$rootProject.ext.vungleAdsVersion"

// Play In-App Updates
implementation "com.google.android.play:app-update:$rootProject.ext.playAppUpdateVersion"

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">

<uses-sdk tools:overrideLibrary="ca.psiphon,com.google.android.gms.ads.impl,com.google.android.gms.ads"/>
<uses-sdk tools:overrideLibrary="ca.psiphon,com.google.android.gms.ads.impl,com.google.android.gms.ads,com.vungle.mediation,com.google.android.ads.consent,com.google.android.gms.common"/>
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/com/psiphon3/ads/ConsentManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.psiphon3.ads

import android.app.Activity
import android.content.Context
import android.os.Build
import com.google.android.ump.ConsentInformation
import com.google.android.ump.ConsentRequestParameters
import com.google.android.ump.UserMessagingPlatform
Expand All @@ -41,9 +42,15 @@ class ConsentManager private constructor(context: Context) {
}
}

private val consentInformation = UserMessagingPlatform.getConsentInformation(context)
// UMP requires API >= 23; on pre-M this is null and all methods become no-ops.
private val consentInformation: ConsentInformation? =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
UserMessagingPlatform.getConsentInformation(context)
else null

fun gatherConsent(activity: Activity): Completable {
val info = consentInformation ?: return Completable.complete()

return Completable.create { emitter ->
if (activity.isFinishing || activity.isDestroyed) {
if (!emitter.isDisposed) {
Expand All @@ -57,7 +64,7 @@ class ConsentManager private constructor(context: Context) {
val params = ConsentRequestParameters.Builder()
.build()

consentInformation.requestConsentInfoUpdate(
info.requestConsentInfoUpdate(
activity,
params,
{
Expand Down Expand Up @@ -92,6 +99,8 @@ class ConsentManager private constructor(context: Context) {
}

fun showPrivacyOptionsForm(activity: Activity): Completable {
consentInformation ?: return Completable.complete()

return Completable.create { emitter ->
if (activity.isFinishing || activity.isDestroyed) {
if (!emitter.isDisposed) {
Expand All @@ -114,10 +123,10 @@ class ConsentManager private constructor(context: Context) {
}
}

fun canRequestAds(): Boolean = consentInformation.canRequestAds()
fun canRequestAds(): Boolean = consentInformation?.canRequestAds() ?: false

fun isPrivacyOptionsRequired(): Boolean {
return consentInformation.privacyOptionsRequirementStatus ==
return consentInformation?.privacyOptionsRequirementStatus ==
ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED
}
}
}
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ ext {
pagingVersion = '2.1.2'
locationServicesVersion = '21.0.1'
geoHashVersion = '0.22'
playServicesAdsVersion = '24.6.0'
userMessagingPlatformVersion = '3.1.0'
playServicesAdsVersion = '24.9.0'
userMessagingPlatformVersion = '4.0.0'
liftoffMediationAdapterVersion = '7.7.0.1'
vungleAdsVersion = '7.7.0'
coreKtxVersion = '1.16.0'
playAppUpdateVersion = '2.1.0'
}
Expand Down