Cyber Surfer v5.2.5版本的 MD5 值为:db13c5fce988de393e52d2679f934b22
以下内容为反编译后的 GoogleMediationAdapter.java 源代码,内容仅作参考
package com.applovin.mediation.adapters;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.amazon.aps.shared.util.APSSharedUtil;
import com.applovin.impl.sdk.utils.AppLovinSdkExtraParameterKey;
import com.applovin.impl.sdk.utils.BundleUtils;
import com.applovin.mediation.MaxAdFormat;
import com.applovin.mediation.MaxReward;
import com.applovin.mediation.adapter.MaxAdViewAdapter;
import com.applovin.mediation.adapter.MaxAdapter;
import com.applovin.mediation.adapter.MaxAdapterError;
import com.applovin.mediation.adapter.MaxInterstitialAdapter;
import com.applovin.mediation.adapter.MaxRewardedAdapter;
import com.applovin.mediation.adapter.MaxRewardedInterstitialAdapter;
import com.applovin.mediation.adapter.MaxSignalProvider;
import com.applovin.mediation.adapter.listeners.MaxAdViewAdapterListener;
import com.applovin.mediation.adapter.listeners.MaxAppOpenAdapterListener;
import com.applovin.mediation.adapter.listeners.MaxInterstitialAdapterListener;
import com.applovin.mediation.adapter.listeners.MaxNativeAdAdapterListener;
import com.applovin.mediation.adapter.listeners.MaxRewardedAdapterListener;
import com.applovin.mediation.adapter.listeners.MaxRewardedInterstitialAdapterListener;
import com.applovin.mediation.adapter.listeners.MaxSignalCollectionListener;
import com.applovin.mediation.adapter.parameters.MaxAdapterInitializationParameters;
import com.applovin.mediation.adapter.parameters.MaxAdapterParameters;
import com.applovin.mediation.adapter.parameters.MaxAdapterResponseParameters;
import com.applovin.mediation.adapter.parameters.MaxAdapterSignalCollectionParameters;
import com.applovin.mediation.adapters.GoogleMediationAdapter;
import com.applovin.mediation.nativeAds.MaxNativeAd;
import com.applovin.mediation.nativeAds.MaxNativeAdView;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkUtils;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.AdFormat;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdLoader;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MediaContent;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.OnUserEarnedRewardListener;
import com.google.android.gms.ads.RequestConfiguration;
import com.google.android.gms.ads.ResponseInfo;
import com.google.android.gms.ads.appopen.AppOpenAd;
import com.google.android.gms.ads.initialization.AdapterStatus;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import com.google.android.gms.ads.nativead.MediaView;
import com.google.android.gms.ads.nativead.NativeAd;
import com.google.android.gms.ads.nativead.NativeAdOptions;
import com.google.android.gms.ads.nativead.NativeAdView;
import com.google.android.gms.ads.query.QueryInfo;
import com.google.android.gms.ads.query.QueryInfoGenerationCallback;
import com.google.android.gms.ads.rewarded.RewardItem;
import com.google.android.gms.ads.rewarded.RewardedAd;
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 com.google.firebase.analytics.FirebaseAnalytics;
import com.safedk.android.analytics.brandsafety.DetectTouchUtils;
import com.safedk.android.utils.h;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
public class GoogleMediationAdapter extends MediationAdapterBase implements MaxSignalProvider, MaxInterstitialAdapter, MaxRewardedInterstitialAdapter, MaxRewardedAdapter, MaxAdViewAdapter {
private static final int ADVERTISER_VIEW_TAG = 8;
private static final int BODY_VIEW_TAG = 4;
private static final int CALL_TO_ACTION_VIEW_TAG = 5;
private static final int ICON_VIEW_TAG = 3;
private static final int MEDIA_VIEW_CONTAINER_TAG = 2;
private static final int TITLE_LABEL_TAG = 1;
private static final AtomicBoolean initialized = new AtomicBoolean();
private static MaxAdapter.InitializationStatus status;
private AdView adView;
private AppOpenAd appOpenAd;
private AppOpenAdListener appOpenAdListener;
private InterstitialAd appOpenInterstitialAd;
private AppOpenAdListener appOpenInterstitialAdListener;
private InterstitialAd interstitialAd;
private NativeAd nativeAd;
private NativeAdView nativeAdView;
private RewardedAd rewardedAd;
private RewardedAdListener rewardedAdListener;
private RewardedInterstitialAd rewardedInterstitialAd;
private RewardedInterstitialAdListener rewardedInterstitialAdListener;
private class AdViewListener extends AdListener {
final MaxAdFormat adFormat;
final MaxAdViewAdapterListener listener;
final String placementId;
AdViewListener(final String placementId, final MaxAdFormat adFormat, final MaxAdViewAdapterListener listener) {
this.placementId = placementId;
this.adFormat = adFormat;
this.listener = listener;
}
@Override
public void onAdClosed() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log(this.adFormat.getLabel() + " ad closed");
}
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log(this.adFormat.getLabel() + " ad (" + this.placementId + ") failed to load with error code: " + maxError);
this.listener.onAdViewAdLoadFailed(maxError);
}
@Override
public void onAdImpression() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log(this.adFormat.getLabel() + " ad shown: " + this.placementId);
this.listener.onAdViewAdDisplayed();
}
@Override
public void onAdLoaded() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log(this.adFormat.getLabel() + " ad loaded: " + this.placementId);
if (AppLovinSdk.VERSION_CODE < 9150000) {
this.listener.onAdViewAdLoaded(GoogleMediationAdapter.this.adView);
return;
}
Bundle bundle = new Bundle(3);
ResponseInfo responseInfo = GoogleMediationAdapter.this.adView.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
if (AppLovinSdkUtils.isValidString(responseId)) {
bundle.putString("creative_id", responseId);
}
AdSize adSize = GoogleMediationAdapter.this.adView.getAdSize();
if (adSize != null) {
bundle.putInt("ad_width", adSize.getWidth());
bundle.putInt("ad_height", adSize.getHeight());
}
this.listener.onAdViewAdLoaded(GoogleMediationAdapter.this.adView, bundle);
}
@Override
public void onAdOpened() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log(this.adFormat.getLabel() + " ad opened");
this.listener.onAdViewAdClicked();
}
}
public class AppOpenAdListener extends FullScreenContentCallback {
private final MaxAppOpenAdapterListener listener;
private final String placementId;
AppOpenAdListener(final String placementId, final MaxAppOpenAdapterListener listener) {
this.placementId = placementId;
this.listener = listener;
}
@Override
public void onAdClicked() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open ad clicked: " + this.placementId);
this.listener.onAppOpenAdClicked();
}
@Override
public void onAdDismissedFullScreenContent() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open ad hidden: " + this.placementId);
this.listener.onAppOpenAdHidden();
}
@Override
public void onAdFailedToShowFullScreenContent(final AdError adError) {
MaxAdapterError maxAdapterError = new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad display failed", adError.getCode(), adError.getMessage());
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open ad (" + this.placementId + ") failed to show with error: " + maxAdapterError);
this.listener.onAppOpenAdDisplayFailed(maxAdapterError);
}
@Override
public void onAdImpression() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open ad impression recorded: " + this.placementId);
this.listener.onAppOpenAdDisplayed();
}
@Override
public void onAdShowedFullScreenContent() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open ad shown: " + this.placementId);
}
}
public static class AutoMeasuringMediaView extends MediaView {
AutoMeasuringMediaView(final Context context) {
super(context);
}
@Override
public boolean dispatchTouchEvent(MotionEvent motionEvent) {
DetectTouchUtils.viewOnTouch(h.f9464a, this, motionEvent);
return super.dispatchTouchEvent(motionEvent);
}
public void m238x814cf4b() {
measure(View.MeasureSpec.makeMeasureSpec(getWidth(), 1073741824), View.MeasureSpec.makeMeasureSpec(getHeight(), 1073741824));
layout(getLeft(), getTop(), getRight(), getBottom());
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
requestLayout();
}
@Override
public void onMeasure(int i, int i2) {
if (1 == 0) {
setMeasuredDimension(0, 0);
} else {
super.onMeasure(i, i2);
}
}
@Override
public void requestLayout() {
super.requestLayout();
post(new Runnable() {
@Override
public final void run() {
GoogleMediationAdapter.AutoMeasuringMediaView.this.m238x814cf4b();
}
});
}
}
public class InterstitialAdListener extends FullScreenContentCallback {
private final MaxInterstitialAdapterListener listener;
private final String placementId;
InterstitialAdListener(final String placementId, final MaxInterstitialAdapterListener listener) {
this.placementId = placementId;
this.listener = listener;
}
@Override
public void onAdClicked() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Interstitial ad clicked: " + this.placementId);
this.listener.onInterstitialAdClicked();
}
@Override
public void onAdDismissedFullScreenContent() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Interstitial ad hidden: " + this.placementId);
this.listener.onInterstitialAdHidden();
}
@Override
public void onAdFailedToShowFullScreenContent(final AdError adError) {
MaxAdapterError maxAdapterError = new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", adError.getCode(), adError.getMessage());
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Interstitial ad (" + this.placementId + ") failed to show with error: " + maxAdapterError);
this.listener.onInterstitialAdDisplayFailed(maxAdapterError);
}
@Override
public void onAdImpression() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Interstitial ad impression recorded: " + this.placementId);
this.listener.onInterstitialAdDisplayed();
}
@Override
public void onAdShowedFullScreenContent() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Interstitial ad shown: " + this.placementId);
}
}
private class MaxGoogleNativeAd extends MaxNativeAd {
public MaxGoogleNativeAd(final MaxNativeAd.Builder builder) {
super(builder);
}
@Override
public boolean prepareForInteraction(final List<View> clickableViews, final ViewGroup container) {
ViewGroup viewGroup;
MediaView mediaView;
MediaContent mediaContent;
NativeAd nativeAd = GoogleMediationAdapter.this.nativeAd;
if (nativeAd == null) {
GoogleMediationAdapter.this.e("Failed to register native ad views: native ad is null.");
return false;
}
GoogleMediationAdapter.this.nativeAdView = new NativeAdView(container.getContext());
if (container instanceof MaxNativeAdView) {
MaxNativeAdView maxNativeAdView = (MaxNativeAdView) container;
View mainView = maxNativeAdView.getMainView();
maxNativeAdView.removeView(mainView);
GoogleMediationAdapter.this.nativeAdView.addView(mainView);
maxNativeAdView.addView(GoogleMediationAdapter.this.nativeAdView);
GoogleMediationAdapter.this.nativeAdView.setIconView(maxNativeAdView.getIconImageView());
GoogleMediationAdapter.this.nativeAdView.setHeadlineView(maxNativeAdView.getTitleTextView());
GoogleMediationAdapter.this.nativeAdView.setAdvertiserView(maxNativeAdView.getAdvertiserTextView());
GoogleMediationAdapter.this.nativeAdView.setBodyView(maxNativeAdView.getBodyTextView());
GoogleMediationAdapter.this.nativeAdView.setCallToActionView(maxNativeAdView.getCallToActionButton());
View mediaView2 = getMediaView();
if (mediaView2 instanceof MediaView) {
GoogleMediationAdapter.this.nativeAdView.setMediaView((MediaView) mediaView2);
} else if (mediaView2 instanceof ImageView) {
GoogleMediationAdapter.this.nativeAdView.setImageView(mediaView2);
}
GoogleMediationAdapter.this.nativeAdView.setNativeAd(nativeAd);
} else {
for (View view : clickableViews) {
Object tag = view.getTag();
if (tag != null) {
int intValue = ((Integer) tag).intValue();
if (intValue == 1) {
GoogleMediationAdapter.this.nativeAdView.setHeadlineView(view);
} else if (intValue == 3) {
GoogleMediationAdapter.this.nativeAdView.setIconView(view);
} else if (intValue == 4) {
GoogleMediationAdapter.this.nativeAdView.setBodyView(view);
} else if (intValue == 5) {
GoogleMediationAdapter.this.nativeAdView.setCallToActionView(view);
} else if (intValue == 8) {
GoogleMediationAdapter.this.nativeAdView.setAdvertiserView(view);
}
}
}
View mediaView3 = getMediaView();
if (mediaView3 == null || (viewGroup = (ViewGroup) mediaView3.getParent()) == null) {
return true;
}
viewGroup.removeView(mediaView3);
boolean z = (viewGroup instanceof RelativeLayout) || (viewGroup instanceof FrameLayout);
if (!z && (mediaView3 instanceof MediaView) && (mediaContent = (mediaView = (MediaView) mediaView3).getMediaContent()) != null && mediaContent.hasVideoContent()) {
mediaView3 = new AutoMeasuringMediaView(container.getContext());
mediaView.setMediaContent(nativeAd.getMediaContent());
}
GoogleMediationAdapter.this.nativeAdView.addView(mediaView3, new ViewGroup.LayoutParams(-1, -1));
if (mediaView3 instanceof MediaView) {
GoogleMediationAdapter.this.nativeAdView.setMediaView((MediaView) mediaView3);
} else if (mediaView3 instanceof ImageView) {
GoogleMediationAdapter.this.nativeAdView.setImageView((ImageView) mediaView3);
}
GoogleMediationAdapter.this.nativeAdView.setNativeAd(nativeAd);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-1, -1);
if (z) {
viewGroup.addView(GoogleMediationAdapter.this.nativeAdView, layoutParams);
} else {
GoogleMediationAdapter.this.nativeAdView.measure(View.MeasureSpec.makeMeasureSpec(viewGroup.getWidth(), 1073741824), View.MeasureSpec.makeMeasureSpec(viewGroup.getHeight(), 1073741824));
GoogleMediationAdapter.this.nativeAdView.layout(0, 0, viewGroup.getWidth(), viewGroup.getHeight());
viewGroup.addView(GoogleMediationAdapter.this.nativeAdView);
}
}
return true;
}
@Override
public void prepareViewForInteraction(final MaxNativeAdView maxNativeAdView) {
prepareForInteraction(Collections.emptyList(), maxNativeAdView);
}
}
private class NativeAdListener extends AdListener implements NativeAd.OnNativeAdLoadedListener {
final Context context;
final MaxNativeAdAdapterListener listener;
final String placementId;
final Bundle serverParameters;
public NativeAdListener(final MaxAdapterResponseParameters parameters, final Context context, final MaxNativeAdAdapterListener listener) {
this.placementId = parameters.getThirdPartyAdPlacementId();
this.serverParameters = parameters.getServerParameters();
this.context = context;
this.listener = listener;
}
@Override
public void onAdClicked() {
GoogleMediationAdapter.this.log("Native ad clicked");
this.listener.onNativeAdClicked();
}
@Override
public void onAdClosed() {
GoogleMediationAdapter.this.log("Native ad closed");
}
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native ad (" + this.placementId + ") failed to load with error: " + maxError);
this.listener.onNativeAdLoadFailed(maxError);
}
@Override
public void onAdImpression() {
GoogleMediationAdapter.this.log("Native ad shown");
this.listener.onNativeAdDisplayed(null);
}
@Override
public void onAdOpened() {
GoogleMediationAdapter.this.log("Native ad opened");
}
@Override
public void onNativeAdLoaded(final NativeAd nativeAd) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native ad loaded: " + this.placementId);
GoogleMediationAdapter.this.nativeAd = nativeAd;
if (!AppLovinSdkUtils.isValidString(BundleUtils.getString("template", "", this.serverParameters)) || !TextUtils.isEmpty(nativeAd.getHeadline())) {
AppLovinSdkUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
float f;
MediaView mediaView;
Drawable drawable;
MediaContent mediaContent = nativeAd.getMediaContent();
List<NativeAd.Image> images = nativeAd.getImages();
if (mediaContent != null) {
MediaView mediaView2 = new MediaView(NativeAdListener.this.context);
mediaView2.setMediaContent(mediaContent);
drawable = mediaContent.getMainImage();
f = mediaContent.getAspectRatio();
mediaView = mediaView2;
} else {
if (images != null && images.size() > 0) {
ImageView imageView = new ImageView(NativeAdListener.this.context);
Drawable drawable2 = images.get(0).getDrawable();
if (drawable2 != null) {
imageView.setImageDrawable(drawable2);
f = drawable2.getIntrinsicWidth() / drawable2.getIntrinsicHeight();
drawable = null;
mediaView = imageView;
}
}
f = 0.0f;
mediaView = null;
drawable = null;
}
NativeAd.Image icon = nativeAd.getIcon();
MaxNativeAd.Builder mediaView3 = new MaxNativeAd.Builder().setAdFormat(MaxAdFormat.NATIVE).setTitle(nativeAd.getHeadline()).setAdvertiser(nativeAd.getAdvertiser()).setBody(nativeAd.getBody()).setCallToAction(nativeAd.getCallToAction()).setIcon(icon != null ? icon.getDrawable() != null ? new MaxNativeAd.MaxNativeAdImage(icon.getDrawable()) : new MaxNativeAd.MaxNativeAdImage(icon.getUri()) : null).setMediaView(mediaView);
if (AppLovinSdk.VERSION_CODE >= 11040399) {
mediaView3.setMainImage(new MaxNativeAd.MaxNativeAdImage(drawable));
}
if (AppLovinSdk.VERSION_CODE >= 11040000) {
mediaView3.setMediaContentAspectRatio(f);
}
if (AppLovinSdk.VERSION_CODE >= 11070000) {
mediaView3.setStarRating(nativeAd.getStarRating());
}
MaxGoogleNativeAd maxGoogleNativeAd = new MaxGoogleNativeAd(mediaView3);
ResponseInfo responseInfo = nativeAd.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
Bundle bundle = new Bundle(1);
bundle.putString("creative_id", responseId);
NativeAdListener.this.listener.onNativeAdLoaded(maxGoogleNativeAd, bundle);
}
});
return;
}
GoogleMediationAdapter googleMediationAdapter2 = GoogleMediationAdapter.this;
googleMediationAdapter2.e("Native ad (" + nativeAd + ") does not have required assets.");
this.listener.onNativeAdLoadFailed(new MaxAdapterError((int) MaxAdapterError.ERROR_CODE_MISSING_REQUIRED_NATIVE_AD_ASSETS, "Missing Native Ad Assets"));
}
}
private class NativeAdViewListener extends AdListener implements NativeAd.OnNativeAdLoadedListener {
final WeakReference<Activity> activityRef;
final MaxAdFormat adFormat;
final MaxAdViewAdapterListener listener;
final String placementId;
final Bundle serverParameters;
NativeAdViewListener(final MaxAdapterResponseParameters parameters, final MaxAdFormat adFormat, final Activity activity, final MaxAdViewAdapterListener listener) {
this.placementId = parameters.getThirdPartyAdPlacementId();
this.serverParameters = parameters.getServerParameters();
this.activityRef = new WeakReference<>(activity);
this.adFormat = adFormat;
this.listener = listener;
}
@Override
public void onAdClicked() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native " + this.adFormat.getLabel() + " ad clicked");
this.listener.onAdViewAdClicked();
}
@Override
public void onAdClosed() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native " + this.adFormat.getLabel() + " ad closed");
this.listener.onAdViewAdCollapsed();
}
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native " + this.adFormat.getLabel() + " ad (" + this.placementId + ") failed to load with error: " + maxError);
this.listener.onAdViewAdLoadFailed(maxError);
}
@Override
public void onAdImpression() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native " + this.adFormat.getLabel() + " ad shown");
this.listener.onAdViewAdDisplayed();
}
@Override
public void onAdOpened() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native " + this.adFormat.getLabel() + " ad opened");
this.listener.onAdViewAdExpanded();
}
@Override
public void onNativeAdLoaded(final NativeAd nativeAd) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Native " + this.adFormat.getLabel() + " ad loaded: " + this.placementId);
if (TextUtils.isEmpty(nativeAd.getHeadline())) {
GoogleMediationAdapter googleMediationAdapter2 = GoogleMediationAdapter.this;
googleMediationAdapter2.log("Native " + this.adFormat.getLabel() + " ad failed to load: Google native ad is missing one or more required assets");
this.listener.onAdViewAdLoadFailed(MaxAdapterError.INVALID_CONFIGURATION);
nativeAd.destroy();
return;
}
GoogleMediationAdapter.this.nativeAd = nativeAd;
final Activity activity = this.activityRef.get();
final Context context = GoogleMediationAdapter.this.getContext(activity);
final MediaView mediaView = new MediaView(context);
MediaContent mediaContent = nativeAd.getMediaContent();
if (mediaContent != null) {
mediaView.setMediaContent(mediaContent);
}
NativeAd.Image icon = nativeAd.getIcon();
final MaxNativeAd build = new MaxNativeAd.Builder().setAdFormat(this.adFormat).setTitle(nativeAd.getHeadline()).setBody(nativeAd.getBody()).setCallToAction(nativeAd.getCallToAction()).setIcon(icon != null ? icon.getDrawable() != null ? new MaxNativeAd.MaxNativeAdImage(icon.getDrawable()) : new MaxNativeAd.MaxNativeAdImage(icon.getUri()) : null).setMediaView(mediaView).build();
final String string = BundleUtils.getString("template", "", this.serverParameters);
if (string.contains("vertical") && AppLovinSdk.VERSION_CODE < 9140500) {
GoogleMediationAdapter.this.log("Vertical native banners are only supported on MAX SDK 9.14.5 and above. Default horizontal native template will be used.");
}
AppLovinSdkUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
MaxNativeAdView maxNativeAdView = AppLovinSdk.VERSION_CODE >= 11010000 ? new MaxNativeAdView(build, string, context) : new MaxNativeAdView(build, string, activity);
GoogleMediationAdapter.this.nativeAdView = new NativeAdView(context);
GoogleMediationAdapter.this.nativeAdView.setIconView(maxNativeAdView.getIconContentView());
GoogleMediationAdapter.this.nativeAdView.setHeadlineView(maxNativeAdView.getTitleTextView());
GoogleMediationAdapter.this.nativeAdView.setBodyView(maxNativeAdView.getBodyTextView());
GoogleMediationAdapter.this.nativeAdView.setMediaView(mediaView);
GoogleMediationAdapter.this.nativeAdView.setCallToActionView(maxNativeAdView.getCallToActionButton());
GoogleMediationAdapter.this.nativeAdView.setNativeAd(nativeAd);
GoogleMediationAdapter.this.nativeAdView.addView(maxNativeAdView);
ResponseInfo responseInfo = nativeAd.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
if (AppLovinSdk.VERSION_CODE < 9150000 || !AppLovinSdkUtils.isValidString(responseId)) {
NativeAdViewListener.this.listener.onAdViewAdLoaded(GoogleMediationAdapter.this.nativeAdView);
return;
}
Bundle bundle = new Bundle(1);
bundle.putString("creative_id", responseId);
NativeAdViewListener.this.listener.onAdViewAdLoaded(GoogleMediationAdapter.this.nativeAdView, bundle);
}
});
}
}
public class RewardedAdListener extends FullScreenContentCallback {
private boolean hasGrantedReward;
private final MaxRewardedAdapterListener listener;
private final String placementId;
RewardedAdListener(final String placementId, final MaxRewardedAdapterListener listener) {
this.placementId = placementId;
this.listener = listener;
}
@Override
public void onAdClicked() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded ad clicked: " + this.placementId);
this.listener.onRewardedAdClicked();
}
@Override
public void onAdDismissedFullScreenContent() {
this.listener.onRewardedAdVideoCompleted();
if (this.hasGrantedReward || GoogleMediationAdapter.this.shouldAlwaysRewardUser()) {
MaxReward reward = GoogleMediationAdapter.this.getReward();
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded user with reward: " + reward);
this.listener.onUserRewarded(reward);
}
GoogleMediationAdapter googleMediationAdapter2 = GoogleMediationAdapter.this;
googleMediationAdapter2.log("Rewarded ad hidden: " + this.placementId);
this.listener.onRewardedAdHidden();
}
@Override
public void onAdFailedToShowFullScreenContent(final AdError adError) {
MaxAdapterError maxAdapterError = new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", adError.getCode(), adError.getMessage());
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded ad (" + this.placementId + ") failed to show with error: " + maxAdapterError);
this.listener.onRewardedAdDisplayFailed(maxAdapterError);
}
@Override
public void onAdImpression() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded ad impression recorded: " + this.placementId);
this.listener.onRewardedAdDisplayed();
}
@Override
public void onAdShowedFullScreenContent() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded ad shown: " + this.placementId);
this.listener.onRewardedAdVideoStarted();
}
}
public class RewardedInterstitialAdListener extends FullScreenContentCallback {
private boolean hasGrantedReward;
private final MaxRewardedInterstitialAdapterListener listener;
private final String placementId;
private RewardedInterstitialAdListener(final String placementId, final MaxRewardedInterstitialAdapterListener listener) {
this.placementId = placementId;
this.listener = listener;
}
@Override
public void onAdClicked() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad clicked: " + this.placementId);
this.listener.onRewardedInterstitialAdClicked();
}
@Override
public void onAdDismissedFullScreenContent() {
this.listener.onRewardedInterstitialAdVideoCompleted();
if (this.hasGrantedReward || GoogleMediationAdapter.this.shouldAlwaysRewardUser()) {
MaxReward reward = GoogleMediationAdapter.this.getReward();
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad rewarded user with reward: " + reward);
this.listener.onUserRewarded(reward);
}
GoogleMediationAdapter googleMediationAdapter2 = GoogleMediationAdapter.this;
googleMediationAdapter2.log("Rewarded interstitial ad hidden: " + this.placementId);
this.listener.onRewardedInterstitialAdHidden();
}
@Override
public void onAdFailedToShowFullScreenContent(final AdError adError) {
MaxAdapterError maxAdapterError = new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", adError.getCode(), adError.getMessage());
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad (" + this.placementId + ") failed to show with error: " + maxAdapterError);
this.listener.onRewardedInterstitialAdDisplayFailed(maxAdapterError);
}
@Override
public void onAdImpression() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad impression recorded: " + this.placementId);
this.listener.onRewardedInterstitialAdDisplayed();
}
@Override
public void onAdShowedFullScreenContent() {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad shown: " + this.placementId);
this.listener.onRewardedInterstitialAdVideoStarted();
}
}
public GoogleMediationAdapter(final AppLovinSdk sdk) {
super(sdk);
}
private AdRequest createAdRequestWithParameters(final boolean isBiddingAd, final MaxAdFormat adFormat, final MaxAdapterParameters parameters, final Context context) {
boolean z;
AdRequest.Builder builder = new AdRequest.Builder();
Bundle serverParameters = parameters.getServerParameters();
Bundle bundle = new Bundle(6);
if (isBiddingAd) {
z = "dv360".equalsIgnoreCase(BundleUtils.getString("bidder", "", serverParameters));
bundle.putString("query_info_type", z ? "requester_type_3" : "requester_type_2");
if (AppLovinSdk.VERSION_CODE >= 11000000 && adFormat.isAdViewAd()) {
Object obj = parameters.getLocalExtraParameters().get(AppLovinSdkExtraParameterKey.IS_ADAPTIVE_BANNER);
if ((obj instanceof String) && "true".equalsIgnoreCase((String) obj)) {
AdSize adSize = toAdSize(adFormat, true, parameters, context);
bundle.putInt("adaptive_banner_w", adSize.getWidth());
bundle.putInt("adaptive_banner_h", adSize.getHeight());
}
}
if (parameters instanceof MaxAdapterResponseParameters) {
String bidResponse = ((MaxAdapterResponseParameters) parameters).getBidResponse();
if (AppLovinSdkUtils.isValidString(bidResponse)) {
builder.setAdString(bidResponse);
}
}
} else {
z = false;
}
if (serverParameters.getBoolean("set_mediation_identifier", true)) {
builder.setRequestAgent(z ? "applovin_dv360" : "applovin");
}
String string = BundleUtils.getString("event_id", serverParameters);
if (AppLovinSdkUtils.isValidString(string)) {
bundle.putString("placement_req_id", string);
}
Boolean hasUserConsent = parameters.hasUserConsent();
if (hasUserConsent != null && !hasUserConsent.booleanValue()) {
bundle.putString("npa", "1");
}
Boolean isDoNotSell = parameters.isDoNotSell();
if (isDoNotSell == null || !isDoNotSell.booleanValue()) {
PreferenceManager.getDefaultSharedPreferences(context).edit().remove("gad_rdp").commit();
} else {
bundle.putInt("rdp", 1);
PreferenceManager.getDefaultSharedPreferences(context).edit().putInt("gad_rdp", 1).commit();
}
if (AppLovinSdk.VERSION_CODE >= 11000000) {
Map<String, Object> localExtraParameters = parameters.getLocalExtraParameters();
Object obj2 = localExtraParameters.get("google_max_ad_content_rating");
if (obj2 instanceof String) {
bundle.putString("max_ad_content_rating", (String) obj2);
}
Object obj3 = localExtraParameters.get("google_content_url");
if (obj3 instanceof String) {
builder.setContentUrl((String) obj3);
}
Object obj4 = localExtraParameters.get("google_neighbouring_content_url_strings");
if (obj4 instanceof List) {
try {
builder.setNeighboringContentUrls((List) obj4);
} catch (Throwable th) {
e("Neighbouring content URL strings extra param needs to be of type List<String>.", th);
}
}
}
builder.addNetworkExtrasBundle(AdMobAdapter.class, bundle);
return builder.build();
}
private int getAdChoicesPlacement(MaxAdapterResponseParameters parameters) {
if (AppLovinSdk.VERSION_CODE >= 11000000) {
Map<String, Object> localExtraParameters = parameters.getLocalExtraParameters();
Object obj = localExtraParameters != null ? localExtraParameters.get("admob_ad_choices_placement") : null;
if (isValidAdChoicesPlacement(obj)) {
return ((Integer) obj).intValue();
}
return 1;
}
return 1;
}
private int getAdaptiveBannerWidth(final MaxAdapterParameters parameters, final Context context) {
if (AppLovinSdk.VERSION_CODE >= 11000000) {
Object obj = parameters.getLocalExtraParameters().get("adaptive_banner_width");
if (obj instanceof Integer) {
return ((Integer) obj).intValue();
}
if (obj != null) {
e("Expected parameter \"adaptive_banner_width\" to be of type Integer, received: " + obj.getClass());
}
}
return AppLovinSdkUtils.pxToDp(context, getApplicationWindowWidth(context));
}
public static int getApplicationWindowWidth(final Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService("window");
if (Build.VERSION.SDK_INT >= 30) {
return windowManager.getCurrentWindowMetrics().getBounds().width();
}
Display defaultDisplay = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
defaultDisplay.getMetrics(displayMetrics);
return displayMetrics.widthPixels;
}
public Context getContext(Activity activity) {
return activity != null ? activity.getApplicationContext() : getApplicationContext();
}
private boolean isValidAdChoicesPlacement(Object placementObj) {
if (placementObj instanceof Integer) {
Integer num = (Integer) placementObj;
if (num.intValue() == 0 || num.intValue() == 1 || num.intValue() == 3 || num.intValue() == 2) {
return true;
}
}
return false;
}
private void setRequestConfiguration(final MaxAdapterParameters parameters) {
RequestConfiguration.Builder builder = MobileAds.getRequestConfiguration().toBuilder();
Boolean isAgeRestrictedUser = parameters.isAgeRestrictedUser();
if (isAgeRestrictedUser != null) {
builder.setTagForChildDirectedTreatment(isAgeRestrictedUser.booleanValue() ? 1 : 0);
}
MobileAds.setRequestConfiguration(builder.build());
}
private AdFormat toAdFormat(final MaxAdapterSignalCollectionParameters parameters) {
MaxAdFormat adFormat = parameters.getAdFormat();
return parameters.getServerParameters().getBoolean("is_native") || adFormat == MaxAdFormat.NATIVE ? AdFormat.NATIVE : adFormat.isAdViewAd() ? AdFormat.BANNER : adFormat == MaxAdFormat.INTERSTITIAL ? AdFormat.INTERSTITIAL : adFormat == MaxAdFormat.REWARDED ? AdFormat.REWARDED : adFormat == MaxAdFormat.REWARDED_INTERSTITIAL ? AdFormat.REWARDED_INTERSTITIAL : adFormat == MaxAdFormat.APP_OPEN ? AdFormat.APP_OPEN_AD : AdFormat.UNKNOWN;
}
private AdSize toAdSize(final MaxAdFormat adFormat, final boolean isAdaptiveBanner, final MaxAdapterParameters parameters, final Context context) {
if (adFormat == MaxAdFormat.BANNER || adFormat == MaxAdFormat.LEADER) {
return isAdaptiveBanner ? AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(context, getAdaptiveBannerWidth(parameters, context)) : adFormat == MaxAdFormat.BANNER ? AdSize.BANNER : AdSize.LEADERBOARD;
} else if (adFormat == MaxAdFormat.MREC) {
return AdSize.MEDIUM_RECTANGLE;
} else {
throw new IllegalArgumentException("Unsupported ad format: " + adFormat);
}
}
public static MaxAdapterError toMaxError(final AdError googleAdsError) {
int code = googleAdsError.getCode();
MaxAdapterError maxAdapterError = MaxAdapterError.UNSPECIFIED;
if (code != 0) {
if (code != 1) {
if (code != 2) {
if (code != 3) {
switch (code) {
case 8:
case 11:
maxAdapterError = MaxAdapterError.INVALID_CONFIGURATION;
break;
}
}
maxAdapterError = MaxAdapterError.NO_FILL;
} else {
maxAdapterError = MaxAdapterError.NO_CONNECTION;
}
}
maxAdapterError = MaxAdapterError.BAD_REQUEST;
} else {
maxAdapterError = MaxAdapterError.INTERNAL_ERROR;
}
return new MaxAdapterError(maxAdapterError.getErrorCode(), maxAdapterError.getErrorMessage(), code, googleAdsError.getMessage());
}
private static void updateMuteState(final MaxAdapterResponseParameters parameters) {
Bundle serverParameters = parameters.getServerParameters();
if (serverParameters.containsKey("is_muted")) {
MobileAds.setAppMuted(serverParameters.getBoolean("is_muted"));
}
}
@Override
public void collectSignal(final MaxAdapterSignalCollectionParameters parameters, final Activity activity, final MaxSignalCollectionListener callback) {
setRequestConfiguration(parameters);
Context context = getContext(activity);
QueryInfo.generate(context, toAdFormat(parameters), createAdRequestWithParameters(true, parameters.getAdFormat(), parameters, context), new QueryInfoGenerationCallback() {
@Override
public void onFailure(final String errorMessage) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Signal collection failed with error: " + errorMessage);
callback.onSignalCollectionFailed(errorMessage);
}
@Override
public void onSuccess(final QueryInfo queryInfo) {
GoogleMediationAdapter.this.log("Signal collection successful");
callback.onSignalCollected(queryInfo.getQuery());
}
});
}
@Override
public String getAdapterVersion() {
return "22.4.0.1";
}
@Override
public String getSdkVersion() {
return String.valueOf(MobileAds.getVersion());
}
@Override
public void initialize(final MaxAdapterInitializationParameters parameters, final Activity activity, final MaxAdapter.OnCompletionListener onCompletionListener) {
log("Initializing Google SDK...");
if (!initialized.compareAndSet(false, true)) {
onCompletionListener.onCompletion(status, null);
return;
}
Context context = getContext(activity);
MobileAds.disableMediationAdapterInitialization(context);
if (!parameters.getServerParameters().getBoolean("init_without_callback", false)) {
status = MaxAdapter.InitializationStatus.INITIALIZING;
MobileAds.initialize(context, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(final InitializationStatus initializationStatus) {
AdapterStatus adapterStatus = initializationStatus.getAdapterStatusMap().get("com.google.android.gms.ads.MobileAds");
AdapterStatus.State initializationState = adapterStatus != null ? adapterStatus.getInitializationState() : null;
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Initialization complete with status " + initializationState);
MaxAdapter.InitializationStatus unused = GoogleMediationAdapter.status = AdapterStatus.State.READY == initializationState ? MaxAdapter.InitializationStatus.INITIALIZED_SUCCESS : MaxAdapter.InitializationStatus.INITIALIZED_UNKNOWN;
onCompletionListener.onCompletion(GoogleMediationAdapter.status, null);
}
});
return;
}
status = MaxAdapter.InitializationStatus.DOES_NOT_APPLY;
MobileAds.initialize(context);
onCompletionListener.onCompletion(status, null);
}
@Override
public void loadAdViewAd(final MaxAdapterResponseParameters parameters, final MaxAdFormat adFormat, final Activity activity, final MaxAdViewAdapterListener listener) {
String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
boolean isValidString = AppLovinSdkUtils.isValidString(parameters.getBidResponse());
boolean z = parameters.getServerParameters().getBoolean("is_native");
StringBuilder sb = new StringBuilder("Loading ");
sb.append(isValidString ? "bidding " : "");
sb.append(z ? "native " : "");
sb.append(adFormat.getLabel());
sb.append(" ad for placement id: ");
sb.append(thirdPartyAdPlacementId);
sb.append(APSSharedUtil.TRUNCATE_SEPARATOR);
log(sb.toString());
setRequestConfiguration(parameters);
Context context = getContext(activity);
AdRequest createAdRequestWithParameters = createAdRequestWithParameters(isValidString, adFormat, parameters, context);
if (z) {
NativeAdOptions.Builder builder = new NativeAdOptions.Builder();
builder.setAdChoicesPlacement(getAdChoicesPlacement(parameters));
builder.setRequestMultipleImages(adFormat == MaxAdFormat.MREC);
NativeAdViewListener nativeAdViewListener = new NativeAdViewListener(parameters, adFormat, activity, listener);
new AdLoader.Builder(context, thirdPartyAdPlacementId).withNativeAdOptions(builder.build()).forNativeAd(nativeAdViewListener).withAdListener(nativeAdViewListener).build().loadAd(createAdRequestWithParameters);
return;
}
AdView adView = new AdView(context);
this.adView = adView;
adView.setAdUnitId(thirdPartyAdPlacementId);
this.adView.setAdListener(new AdViewListener(thirdPartyAdPlacementId, adFormat, listener));
this.adView.setAdSize(toAdSize(adFormat, parameters.getServerParameters().getBoolean(AppLovinSdkExtraParameterKey.IS_ADAPTIVE_BANNER, false), parameters, context));
this.adView.loadAd(createAdRequestWithParameters);
}
@Override
public void loadAppOpenAd(final MaxAdapterResponseParameters parameters, Activity activity, final MaxAppOpenAdapterListener listener) {
final String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
boolean isValidString = AppLovinSdkUtils.isValidString(parameters.getBidResponse());
boolean z = parameters.getServerParameters().getBoolean("is_inter_placement");
StringBuilder sb = new StringBuilder("Loading ");
sb.append(isValidString ? "bidding " : "");
sb.append("app open ");
sb.append(z ? "interstitial " : "");
sb.append("ad: ");
sb.append(thirdPartyAdPlacementId);
sb.append(APSSharedUtil.TRUNCATE_SEPARATOR);
log(sb.toString());
updateMuteState(parameters);
setRequestConfiguration(parameters);
Context context = getContext(activity);
if (z) {
InterstitialAd.load(context, thirdPartyAdPlacementId, createAdRequestWithParameters(isValidString, MaxAdFormat.INTERSTITIAL, parameters, activity), new InterstitialAdLoadCallback() {
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open interstitial ad (" + thirdPartyAdPlacementId + ") failed to load with error: " + maxError);
listener.onAppOpenAdLoadFailed(maxError);
}
@Override
public void onAdLoaded(final InterstitialAd ad) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open interstitial ad loaded: " + thirdPartyAdPlacementId + APSSharedUtil.TRUNCATE_SEPARATOR);
GoogleMediationAdapter.this.appOpenInterstitialAd = ad;
GoogleMediationAdapter.this.appOpenInterstitialAdListener = new AppOpenAdListener(thirdPartyAdPlacementId, listener);
GoogleMediationAdapter.this.appOpenInterstitialAd.setFullScreenContentCallback(GoogleMediationAdapter.this.appOpenInterstitialAdListener);
ResponseInfo responseInfo = GoogleMediationAdapter.this.appOpenInterstitialAd.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
if (!AppLovinSdkUtils.isValidString(responseId)) {
listener.onAppOpenAdLoaded();
return;
}
Bundle bundle = new Bundle(1);
bundle.putString("creative_id", responseId);
listener.onAppOpenAdLoaded(bundle);
}
});
} else {
AppOpenAd.load(context, thirdPartyAdPlacementId, createAdRequestWithParameters(isValidString, MaxAdFormat.APP_OPEN, parameters, activity), AppLovinSdkUtils.getOrientation(context), new AppOpenAd.AppOpenAdLoadCallback() {
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open ad (" + thirdPartyAdPlacementId + ") failed to load with error: " + maxError);
listener.onAppOpenAdLoadFailed(maxError);
}
@Override
public void onAdLoaded(final AppOpenAd ad) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("App open ad loaded: " + thirdPartyAdPlacementId + APSSharedUtil.TRUNCATE_SEPARATOR);
GoogleMediationAdapter.this.appOpenAd = ad;
GoogleMediationAdapter.this.appOpenAdListener = new AppOpenAdListener(thirdPartyAdPlacementId, listener);
ad.setFullScreenContentCallback(GoogleMediationAdapter.this.appOpenAdListener);
ResponseInfo responseInfo = GoogleMediationAdapter.this.appOpenAd.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
if (!AppLovinSdkUtils.isValidString(responseId)) {
listener.onAppOpenAdLoaded();
return;
}
Bundle bundle = new Bundle(1);
bundle.putString("creative_id", responseId);
listener.onAppOpenAdLoaded(bundle);
}
});
}
}
@Override
public void loadInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxInterstitialAdapterListener listener) {
final String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
boolean isValidString = AppLovinSdkUtils.isValidString(parameters.getBidResponse());
StringBuilder sb = new StringBuilder("Loading ");
sb.append(isValidString ? "bidding " : "");
sb.append("interstitial ad: ");
sb.append(thirdPartyAdPlacementId);
sb.append(APSSharedUtil.TRUNCATE_SEPARATOR);
log(sb.toString());
updateMuteState(parameters);
setRequestConfiguration(parameters);
InterstitialAd.load(activity, thirdPartyAdPlacementId, createAdRequestWithParameters(isValidString, MaxAdFormat.INTERSTITIAL, parameters, activity), new InterstitialAdLoadCallback() {
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Interstitial ad (" + thirdPartyAdPlacementId + ") failed to load with error: " + maxError);
listener.onInterstitialAdLoadFailed(maxError);
}
@Override
public void onAdLoaded(final InterstitialAd ad) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Interstitial ad loaded: " + thirdPartyAdPlacementId + APSSharedUtil.TRUNCATE_SEPARATOR);
GoogleMediationAdapter.this.interstitialAd = ad;
GoogleMediationAdapter.this.interstitialAd.setFullScreenContentCallback(new InterstitialAdListener(thirdPartyAdPlacementId, listener));
ResponseInfo responseInfo = GoogleMediationAdapter.this.interstitialAd.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
if (AppLovinSdk.VERSION_CODE < 9150000 || !AppLovinSdkUtils.isValidString(responseId)) {
listener.onInterstitialAdLoaded();
return;
}
Bundle bundle = new Bundle(1);
bundle.putString("creative_id", responseId);
listener.onInterstitialAdLoaded(bundle);
}
});
}
@Override
public void loadNativeAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxNativeAdAdapterListener listener) {
String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
boolean isValidString = AppLovinSdkUtils.isValidString(parameters.getBidResponse());
StringBuilder sb = new StringBuilder("Loading ");
sb.append(isValidString ? "bidding " : "");
sb.append(" native ad for placement id: ");
sb.append(thirdPartyAdPlacementId);
sb.append(APSSharedUtil.TRUNCATE_SEPARATOR);
log(sb.toString());
setRequestConfiguration(parameters);
Context applicationContext = activity != null ? activity.getApplicationContext() : getApplicationContext();
AdRequest createAdRequestWithParameters = createAdRequestWithParameters(isValidString, MaxAdFormat.NATIVE, parameters, applicationContext);
NativeAdOptions.Builder builder = new NativeAdOptions.Builder();
builder.setAdChoicesPlacement(getAdChoicesPlacement(parameters));
builder.setRequestMultipleImages(BundleUtils.getString("template", "", parameters.getServerParameters()).contains(FirebaseAnalytics.Param.MEDIUM));
NativeAdListener nativeAdListener = new NativeAdListener(parameters, applicationContext, listener);
new AdLoader.Builder(applicationContext, thirdPartyAdPlacementId).withNativeAdOptions(builder.build()).forNativeAd(nativeAdListener).withAdListener(nativeAdListener).build().loadAd(createAdRequestWithParameters);
}
@Override
public void loadRewardedAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedAdapterListener listener) {
final String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
boolean isValidString = AppLovinSdkUtils.isValidString(parameters.getBidResponse());
StringBuilder sb = new StringBuilder("Loading ");
sb.append(isValidString ? "bidding " : "");
sb.append("rewarded ad: ");
sb.append(thirdPartyAdPlacementId);
sb.append(APSSharedUtil.TRUNCATE_SEPARATOR);
log(sb.toString());
updateMuteState(parameters);
setRequestConfiguration(parameters);
RewardedAd.load(activity, thirdPartyAdPlacementId, createAdRequestWithParameters(isValidString, MaxAdFormat.REWARDED, parameters, activity), new RewardedAdLoadCallback() {
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded ad (" + thirdPartyAdPlacementId + ") failed to load with error: " + maxError);
listener.onRewardedAdLoadFailed(maxError);
}
@Override
public void onAdLoaded(final RewardedAd ad) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded ad loaded: " + thirdPartyAdPlacementId + APSSharedUtil.TRUNCATE_SEPARATOR);
GoogleMediationAdapter.this.rewardedAd = ad;
GoogleMediationAdapter.this.rewardedAdListener = new RewardedAdListener(thirdPartyAdPlacementId, listener);
GoogleMediationAdapter.this.rewardedAd.setFullScreenContentCallback(GoogleMediationAdapter.this.rewardedAdListener);
ResponseInfo responseInfo = GoogleMediationAdapter.this.rewardedAd.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
if (AppLovinSdk.VERSION_CODE < 9150000 || !AppLovinSdkUtils.isValidString(responseId)) {
listener.onRewardedAdLoaded();
return;
}
Bundle bundle = new Bundle(1);
bundle.putString("creative_id", responseId);
listener.onRewardedAdLoaded(bundle);
}
});
}
@Override
public void loadRewardedInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedInterstitialAdapterListener listener) {
final String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
boolean isValidString = AppLovinSdkUtils.isValidString(parameters.getBidResponse());
StringBuilder sb = new StringBuilder("Loading ");
sb.append(isValidString ? "bidding " : "");
sb.append("rewarded interstitial ad: ");
sb.append(thirdPartyAdPlacementId);
sb.append(APSSharedUtil.TRUNCATE_SEPARATOR);
log(sb.toString());
updateMuteState(parameters);
setRequestConfiguration(parameters);
RewardedInterstitialAd.load(activity, thirdPartyAdPlacementId, createAdRequestWithParameters(isValidString, MaxAdFormat.REWARDED_INTERSTITIAL, parameters, activity), new RewardedInterstitialAdLoadCallback() {
@Override
public void onAdFailedToLoad(final LoadAdError loadAdError) {
MaxAdapterError maxError = GoogleMediationAdapter.toMaxError(loadAdError);
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad (" + thirdPartyAdPlacementId + ") failed to load with error: " + maxError);
listener.onRewardedInterstitialAdLoadFailed(maxError);
}
@Override
public void onAdLoaded(final RewardedInterstitialAd ad) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad loaded: " + thirdPartyAdPlacementId);
GoogleMediationAdapter.this.rewardedInterstitialAd = ad;
GoogleMediationAdapter.this.rewardedInterstitialAdListener = new RewardedInterstitialAdListener(thirdPartyAdPlacementId, listener);
GoogleMediationAdapter.this.rewardedInterstitialAd.setFullScreenContentCallback(GoogleMediationAdapter.this.rewardedInterstitialAdListener);
ResponseInfo responseInfo = GoogleMediationAdapter.this.rewardedInterstitialAd.getResponseInfo();
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
if (AppLovinSdk.VERSION_CODE <= 9150000 || !AppLovinSdkUtils.isValidString(responseId)) {
listener.onRewardedInterstitialAdLoaded();
return;
}
Bundle bundle = new Bundle(1);
bundle.putString("creative_id", responseId);
listener.onRewardedInterstitialAdLoaded(bundle);
}
});
}
@Override
public void onDestroy() {
log("Destroy called for adapter " + this);
InterstitialAd interstitialAd = this.interstitialAd;
if (interstitialAd != null) {
interstitialAd.setFullScreenContentCallback(null);
this.interstitialAd = null;
}
AppOpenAd appOpenAd = this.appOpenAd;
if (appOpenAd != null) {
appOpenAd.setFullScreenContentCallback(null);
this.appOpenAd = null;
this.appOpenAdListener = null;
}
InterstitialAd interstitialAd2 = this.appOpenInterstitialAd;
if (interstitialAd2 != null) {
interstitialAd2.setFullScreenContentCallback(null);
this.appOpenInterstitialAd = null;
this.appOpenInterstitialAdListener = null;
}
RewardedInterstitialAd rewardedInterstitialAd = this.rewardedInterstitialAd;
if (rewardedInterstitialAd != null) {
rewardedInterstitialAd.setFullScreenContentCallback(null);
this.rewardedInterstitialAd = null;
this.rewardedInterstitialAdListener = null;
}
RewardedAd rewardedAd = this.rewardedAd;
if (rewardedAd != null) {
rewardedAd.setFullScreenContentCallback(null);
this.rewardedAd = null;
this.rewardedAdListener = null;
}
AdView adView = this.adView;
if (adView != null) {
adView.destroy();
this.adView = null;
}
NativeAd nativeAd = this.nativeAd;
if (nativeAd != null) {
nativeAd.destroy();
this.nativeAd = null;
}
NativeAdView nativeAdView = this.nativeAdView;
if (nativeAdView != null) {
nativeAdView.destroy();
this.nativeAdView = null;
}
}
@Override
public void showAppOpenAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxAppOpenAdapterListener listener) {
String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
boolean z = parameters.getServerParameters().getBoolean("is_inter_placement");
StringBuilder sb = new StringBuilder("Showing app open ");
sb.append(z ? "interstitial " : "");
sb.append("ad: ");
sb.append(thirdPartyAdPlacementId);
sb.append(APSSharedUtil.TRUNCATE_SEPARATOR);
log(sb.toString());
InterstitialAd interstitialAd = this.appOpenInterstitialAd;
if (interstitialAd != null) {
interstitialAd.show(activity);
return;
}
AppOpenAd appOpenAd = this.appOpenAd;
if (appOpenAd != null) {
appOpenAd.show(activity);
return;
}
log("App open ad failed to show: " + thirdPartyAdPlacementId);
listener.onAppOpenAdLoadFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad display failed", 0, "App open ad not ready"));
}
@Override
public void showInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxInterstitialAdapterListener listener) {
String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
log("Showing interstitial ad: " + thirdPartyAdPlacementId + APSSharedUtil.TRUNCATE_SEPARATOR);
InterstitialAd interstitialAd = this.interstitialAd;
if (interstitialAd != null) {
interstitialAd.show(activity);
return;
}
log("Interstitial ad failed to show: " + thirdPartyAdPlacementId);
listener.onInterstitialAdDisplayFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", 0, "Interstitial ad not ready"));
}
@Override
public void showRewardedAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedAdapterListener listener) {
final String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
log("Showing rewarded ad: " + thirdPartyAdPlacementId + APSSharedUtil.TRUNCATE_SEPARATOR);
if (this.rewardedAd != null) {
configureReward(parameters);
this.rewardedAd.show(activity, new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(final RewardItem rewardItem) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded ad user earned reward: " + thirdPartyAdPlacementId);
GoogleMediationAdapter.this.rewardedAdListener.hasGrantedReward = true;
}
});
return;
}
log("Rewarded ad failed to show: " + thirdPartyAdPlacementId);
listener.onRewardedAdDisplayFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", 0, "Rewarded ad not ready"));
}
@Override
public void showRewardedInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedInterstitialAdapterListener listener) {
final String thirdPartyAdPlacementId = parameters.getThirdPartyAdPlacementId();
log("Showing rewarded interstitial ad: " + thirdPartyAdPlacementId + APSSharedUtil.TRUNCATE_SEPARATOR);
if (this.rewardedInterstitialAd != null) {
configureReward(parameters);
this.rewardedInterstitialAd.show(activity, new OnUserEarnedRewardListener() {
@Override
public void onUserEarnedReward(final RewardItem rewardItem) {
GoogleMediationAdapter googleMediationAdapter = GoogleMediationAdapter.this;
googleMediationAdapter.log("Rewarded interstitial ad user earned reward: " + thirdPartyAdPlacementId);
GoogleMediationAdapter.this.rewardedInterstitialAdListener.hasGrantedReward = true;
}
});
return;
}
log("Rewarded interstitial ad failed to show: " + thirdPartyAdPlacementId);
listener.onRewardedInterstitialAdDisplayFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", 0, "Rewarded Interstitial ad not ready"));
}
}