Idle Egg Factory v2.1.5版本的 MD5 值为:7d2ba6677008ca521af0101bb927d72a
以下内容为反编译后的 FacebookMediationAdapter.java 源代码,内容仅作参考
package com.applovin.mediation.adapters;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
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.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.nativeAds.MaxNativeAd;
import com.applovin.mediation.nativeAds.MaxNativeAdView;
import com.applovin.sdk.AppLovinSdk;
import com.applovin.sdk.AppLovinSdkUtils;
import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.AdExperienceType;
import com.facebook.ads.AdListener;
import com.facebook.ads.AdOptionsView;
import com.facebook.ads.AdSettings;
import com.facebook.ads.AdSize;
import com.facebook.ads.AdView;
import com.facebook.ads.AudienceNetworkAds;
import com.facebook.ads.BidderTokenProvider;
import com.facebook.ads.BuildConfig;
import com.facebook.ads.InterstitialAd;
import com.facebook.ads.InterstitialAdExtendedListener;
import com.facebook.ads.MediaView;
import com.facebook.ads.NativeAd;
import com.facebook.ads.NativeAdBase;
import com.facebook.ads.NativeAdListener;
import com.facebook.ads.NativeAdView;
import com.facebook.ads.NativeBannerAd;
import com.facebook.ads.RewardedVideoAd;
import com.facebook.ads.RewardedVideoAdExtendedListener;
import com.facebook.internal.security.CertificateUtil;
import com.safedk.android.analytics.brandsafety.creatives.discoveries.l;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
public class FacebookMediationAdapter extends MediationAdapterBase implements MaxInterstitialAdapter, MaxRewardedInterstitialAdapter, MaxRewardedAdapter, MaxAdViewAdapter, MaxSignalProvider {
private static final AtomicBoolean INITIALIZED = new AtomicBoolean();
private static MaxAdapter.InitializationStatus sStatus;
private AdView mAdView;
private InterstitialAd mInterstitialAd;
private NativeAd mNativeAd;
private NativeBannerAd mNativeBannerAd;
private RewardedVideoAd mRewardedInterAd;
private RewardedVideoAd mRewardedVideoAd;
private final AtomicBoolean onInterstitialAdHiddenCalled;
private final AtomicBoolean onRewardedAdHiddenCalled;
private final AtomicBoolean onRewardedAdVideoCompletedCalled;
@Override
public String getAdapterVersion() {
return "6.12.0.1";
}
public FacebookMediationAdapter(AppLovinSdk appLovinSdk) {
super(appLovinSdk);
this.onInterstitialAdHiddenCalled = new AtomicBoolean();
this.onRewardedAdVideoCompletedCalled = new AtomicBoolean();
this.onRewardedAdHiddenCalled = new AtomicBoolean();
}
@Override
public void initialize(MaxAdapterInitializationParameters maxAdapterInitializationParameters, Activity activity, final MaxAdapter.OnCompletionListener onCompletionListener) {
updateAdSettings(maxAdapterInitializationParameters);
if (INITIALIZED.compareAndSet(false, true)) {
sStatus = MaxAdapter.InitializationStatus.INITIALIZING;
ArrayList<String> stringArrayList = maxAdapterInitializationParameters.getServerParameters().getStringArrayList("placement_ids");
AudienceNetworkAds.InitListener initListener = new AudienceNetworkAds.InitListener() {
@Override
public void onInitialized(AudienceNetworkAds.InitResult initResult) {
if (initResult.isSuccess()) {
FacebookMediationAdapter.this.log("Facebook SDK successfully finished initialization: " + initResult.getMessage());
MaxAdapter.InitializationStatus unused = FacebookMediationAdapter.sStatus = MaxAdapter.InitializationStatus.INITIALIZED_SUCCESS;
onCompletionListener.onCompletion(FacebookMediationAdapter.sStatus, null);
return;
}
FacebookMediationAdapter.this.log("Facebook SDK failed to finished initialization: " + initResult.getMessage());
MaxAdapter.InitializationStatus unused2 = FacebookMediationAdapter.sStatus = MaxAdapter.InitializationStatus.INITIALIZED_FAILURE;
onCompletionListener.onCompletion(FacebookMediationAdapter.sStatus, initResult.getMessage());
}
};
if (maxAdapterInitializationParameters.isTesting()) {
AdSettings.setDebugBuild(true);
}
log("Initializing Facebook SDK with placements: " + stringArrayList);
AudienceNetworkAds.buildInitSettings(getContext(activity)).withMediationService(getMediationIdentifier()).withPlacementIds(stringArrayList).withInitListener(initListener).initialize();
return;
}
log("Facebook attempted initialization already - marking initialization as completed");
onCompletionListener.onCompletion(sStatus, null);
}
@Override
public String getSdkVersion() {
return getVersionString(BuildConfig.class, l.l);
}
@Override
public void onDestroy() {
InterstitialAd interstitialAd = this.mInterstitialAd;
if (interstitialAd != null) {
interstitialAd.destroy();
this.mInterstitialAd = null;
}
RewardedVideoAd rewardedVideoAd = this.mRewardedVideoAd;
if (rewardedVideoAd != null) {
rewardedVideoAd.destroy();
this.mRewardedVideoAd = null;
}
RewardedVideoAd rewardedVideoAd2 = this.mRewardedInterAd;
if (rewardedVideoAd2 != null) {
rewardedVideoAd2.destroy();
this.mRewardedInterAd = null;
}
AdView adView = this.mAdView;
if (adView != null) {
adView.destroy();
this.mAdView = null;
}
NativeAd nativeAd = this.mNativeAd;
if (nativeAd != null) {
nativeAd.unregisterView();
this.mNativeAd.destroy();
this.mNativeAd = null;
}
NativeBannerAd nativeBannerAd = this.mNativeBannerAd;
if (nativeBannerAd != null) {
nativeBannerAd.unregisterView();
this.mNativeBannerAd.destroy();
this.mNativeBannerAd = null;
}
}
@Override
public void collectSignal(MaxAdapterSignalCollectionParameters maxAdapterSignalCollectionParameters, Activity activity, MaxSignalCollectionListener maxSignalCollectionListener) {
log("Collecting signal...");
updateAdSettings(maxAdapterSignalCollectionParameters);
maxSignalCollectionListener.onSignalCollected(BidderTokenProvider.getBidderToken(getContext(activity)));
}
@Override
public void loadInterstitialAd(MaxAdapterResponseParameters maxAdapterResponseParameters, Activity activity, MaxInterstitialAdapterListener maxInterstitialAdapterListener) {
String thirdPartyAdPlacementId = maxAdapterResponseParameters.getThirdPartyAdPlacementId();
log("Loading interstitial ad: " + thirdPartyAdPlacementId + "...");
updateAdSettings(maxAdapterResponseParameters);
InterstitialAd interstitialAd = new InterstitialAd(activity.getApplicationContext(), thirdPartyAdPlacementId);
this.mInterstitialAd = interstitialAd;
InterstitialAd.InterstitialAdLoadConfigBuilder withAdListener = interstitialAd.buildLoadAdConfig().withAdListener(new InterstitialAdListener(maxInterstitialAdapterListener));
if (this.mInterstitialAd.isAdLoaded() && !this.mInterstitialAd.isAdInvalidated()) {
log("An interstitial ad has been loaded already");
maxInterstitialAdapterListener.onInterstitialAdLoaded();
} else {
log("Loading bidding interstitial ad...");
this.mInterstitialAd.loadAd(withAdListener.withBid(maxAdapterResponseParameters.getBidResponse()).build());
}
}
@Override
public void showInterstitialAd(MaxAdapterResponseParameters maxAdapterResponseParameters, Activity activity, MaxInterstitialAdapterListener maxInterstitialAdapterListener) {
log("Showing interstitial ad: " + maxAdapterResponseParameters.getThirdPartyAdPlacementId() + "...");
InterstitialAd interstitialAd = this.mInterstitialAd;
if (interstitialAd != null && interstitialAd.isAdLoaded()) {
if (!this.mInterstitialAd.isAdInvalidated()) {
this.mInterstitialAd.show();
return;
} else {
log("Unable to show interstitial - ad expired...");
maxInterstitialAdapterListener.onInterstitialAdDisplayFailed(MaxAdapterError.AD_EXPIRED);
return;
}
}
log("Unable to show interstitial - no ad loaded...");
maxInterstitialAdapterListener.onInterstitialAdDisplayFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", 0, "Interstitial ad not ready"));
}
@Override
public void loadRewardedInterstitialAd(MaxAdapterResponseParameters maxAdapterResponseParameters, Activity activity, final MaxRewardedInterstitialAdapterListener maxRewardedInterstitialAdapterListener) {
final String thirdPartyAdPlacementId = maxAdapterResponseParameters.getThirdPartyAdPlacementId();
log("Loading rewarded interstitial: " + thirdPartyAdPlacementId + "...");
updateAdSettings(maxAdapterResponseParameters);
RewardedVideoAd rewardedVideoAd = new RewardedVideoAd(activity.getApplicationContext(), thirdPartyAdPlacementId);
this.mRewardedInterAd = rewardedVideoAd;
RewardedVideoAd.RewardedVideoAdLoadConfigBuilder withAdListener = rewardedVideoAd.buildLoadAdConfig().withAdExperience(AdExperienceType.AD_EXPERIENCE_TYPE_REWARDED_INTERSTITIAL).withAdListener(new RewardedVideoAdExtendedListener() {
private boolean hasGrantedReward;
@Override
public void onAdLoaded(Ad ad) {
FacebookMediationAdapter.this.log("Rewarded interstitial ad loaded: " + thirdPartyAdPlacementId);
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdLoaded();
}
@Override
public void onError(Ad ad, AdError adError) {
MaxAdapterError maxError = FacebookMediationAdapter.toMaxError(adError);
FacebookMediationAdapter.this.log("Rewarded interstitial ad (" + thirdPartyAdPlacementId + ") failed to load with error: " + maxError);
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdLoadFailed(maxError);
}
@Override
public void onAdClicked(Ad ad) {
FacebookMediationAdapter.this.log("Rewarded interstitial ad clicked: " + thirdPartyAdPlacementId);
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdClicked();
}
@Override
public void onRewardedVideoClosed() {
if (FacebookMediationAdapter.this.onRewardedAdHiddenCalled.compareAndSet(false, true)) {
if (this.hasGrantedReward || FacebookMediationAdapter.this.shouldAlwaysRewardUser()) {
MaxReward reward = FacebookMediationAdapter.this.getReward();
FacebookMediationAdapter.this.log("Rewarded user with reward: " + reward);
maxRewardedInterstitialAdapterListener.onUserRewarded(reward);
}
FacebookMediationAdapter.this.log("Rewarded interstitial ad hidden: " + thirdPartyAdPlacementId);
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdHidden();
return;
}
FacebookMediationAdapter.this.log("Rewarded interstitial ad hidden: " + thirdPartyAdPlacementId);
}
@Override
public void onRewardedVideoCompleted() {
FacebookMediationAdapter.this.log("Rewarded interstitial ad video completed: " + thirdPartyAdPlacementId);
if (FacebookMediationAdapter.this.onRewardedAdVideoCompletedCalled.compareAndSet(false, true)) {
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdVideoCompleted();
this.hasGrantedReward = true;
}
}
@Override
public void onLoggingImpression(Ad ad) {
FacebookMediationAdapter.this.log("Rewarded interstitial ad logging impression: " + thirdPartyAdPlacementId);
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdDisplayed();
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdVideoStarted();
}
@Override
public void onRewardedVideoActivityDestroyed() {
FacebookMediationAdapter.this.log("Rewarded interstitial ad Activity destroyed: " + thirdPartyAdPlacementId);
if (FacebookMediationAdapter.this.onRewardedAdVideoCompletedCalled.compareAndSet(false, true)) {
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdVideoCompleted();
}
if (FacebookMediationAdapter.this.onRewardedAdHiddenCalled.compareAndSet(false, true)) {
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdHidden();
}
}
});
if (this.mRewardedInterAd.isAdLoaded() && !this.mRewardedInterAd.isAdInvalidated()) {
log("A rewarded interstitial ad has been loaded already");
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdLoaded();
} else {
log("Loading bidding rewarded interstitial ad...");
this.mRewardedInterAd.loadAd(withAdListener.withBid(maxAdapterResponseParameters.getBidResponse()).build());
}
}
@Override
public void showRewardedInterstitialAd(MaxAdapterResponseParameters maxAdapterResponseParameters, Activity activity, MaxRewardedInterstitialAdapterListener maxRewardedInterstitialAdapterListener) {
log("Showing rewarded interstitial ad: " + maxAdapterResponseParameters.getThirdPartyAdPlacementId() + "...");
RewardedVideoAd rewardedVideoAd = this.mRewardedInterAd;
if (rewardedVideoAd != null && rewardedVideoAd.isAdLoaded()) {
if (!this.mRewardedInterAd.isAdInvalidated()) {
configureReward(maxAdapterResponseParameters);
this.mRewardedInterAd.show();
return;
} else {
log("Unable to show rewarded interstitial ad - ad expired...");
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdDisplayFailed(MaxAdapterError.AD_EXPIRED);
return;
}
}
log("Unable to show rewarded interstitial ad - no ad loaded...");
maxRewardedInterstitialAdapterListener.onRewardedInterstitialAdDisplayFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", 0, "Rewarded Interstitial ad not ready"));
}
@Override
public void loadRewardedAd(MaxAdapterResponseParameters maxAdapterResponseParameters, Activity activity, MaxRewardedAdapterListener maxRewardedAdapterListener) {
String thirdPartyAdPlacementId = maxAdapterResponseParameters.getThirdPartyAdPlacementId();
log("Loading rewarded: " + thirdPartyAdPlacementId + "...");
updateAdSettings(maxAdapterResponseParameters);
RewardedVideoAd rewardedVideoAd = new RewardedVideoAd(activity.getApplicationContext(), thirdPartyAdPlacementId);
this.mRewardedVideoAd = rewardedVideoAd;
RewardedVideoAd.RewardedVideoAdLoadConfigBuilder withAdListener = rewardedVideoAd.buildLoadAdConfig().withAdListener(new RewardedAdListener(maxRewardedAdapterListener));
if (this.mRewardedVideoAd.isAdLoaded() && !this.mRewardedVideoAd.isAdInvalidated()) {
log("A rewarded ad has been loaded already");
maxRewardedAdapterListener.onRewardedAdLoaded();
} else {
log("Loading bidding rewarded ad...");
this.mRewardedVideoAd.loadAd(withAdListener.withBid(maxAdapterResponseParameters.getBidResponse()).build());
}
}
@Override
public void showRewardedAd(MaxAdapterResponseParameters maxAdapterResponseParameters, Activity activity, MaxRewardedAdapterListener maxRewardedAdapterListener) {
log("Showing rewarded ad: " + maxAdapterResponseParameters.getThirdPartyAdPlacementId() + "...");
RewardedVideoAd rewardedVideoAd = this.mRewardedVideoAd;
if (rewardedVideoAd != null && rewardedVideoAd.isAdLoaded()) {
if (!this.mRewardedVideoAd.isAdInvalidated()) {
configureReward(maxAdapterResponseParameters);
this.mRewardedVideoAd.show();
return;
} else {
log("Unable to show rewarded ad - ad expired...");
maxRewardedAdapterListener.onRewardedAdDisplayFailed(MaxAdapterError.AD_EXPIRED);
return;
}
}
log("Unable to show rewarded ad - no ad loaded...");
maxRewardedAdapterListener.onRewardedAdDisplayFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_AD_DISPLAY_FAILED, "Ad Display Failed", 0, "Rewarded ad not ready"));
}
@Override
public void loadAdViewAd(MaxAdapterResponseParameters maxAdapterResponseParameters, MaxAdFormat maxAdFormat, Activity activity, MaxAdViewAdapterListener maxAdViewAdapterListener) {
String thirdPartyAdPlacementId = maxAdapterResponseParameters.getThirdPartyAdPlacementId();
boolean z = maxAdapterResponseParameters.getServerParameters().getBoolean("is_native");
StringBuilder sb = new StringBuilder();
sb.append("Loading");
sb.append(z ? " native " : " ");
sb.append(maxAdFormat.getLabel());
sb.append(" ad: ");
sb.append(thirdPartyAdPlacementId);
sb.append("...");
log(sb.toString());
updateAdSettings(maxAdapterResponseParameters);
if (z) {
NativeAd nativeAd = new NativeAd(getContext(activity), thirdPartyAdPlacementId);
this.mNativeAd = nativeAd;
nativeAd.loadAd(nativeAd.buildLoadAdConfig().withAdListener(new NativeAdViewListener(maxAdapterResponseParameters.getServerParameters(), maxAdFormat, activity, maxAdViewAdapterListener)).withBid(maxAdapterResponseParameters.getBidResponse()).build());
} else {
AdView adView = new AdView(getContext(activity), thirdPartyAdPlacementId, toAdSize(maxAdFormat));
this.mAdView = adView;
adView.loadAd(adView.buildLoadAdConfig().withAdListener(new AdViewListener(maxAdFormat, maxAdViewAdapterListener)).withBid(maxAdapterResponseParameters.getBidResponse()).build());
}
}
@Override
public void loadNativeAd(MaxAdapterResponseParameters maxAdapterResponseParameters, Activity activity, MaxNativeAdAdapterListener maxNativeAdAdapterListener) {
boolean z = BundleUtils.getBoolean("is_native_banner", maxAdapterResponseParameters.getServerParameters());
String thirdPartyAdPlacementId = maxAdapterResponseParameters.getThirdPartyAdPlacementId();
StringBuilder sb = new StringBuilder();
sb.append("Loading native ");
sb.append(z ? "banner " : "");
sb.append("ad: ");
sb.append(thirdPartyAdPlacementId);
sb.append("...");
log(sb.toString());
updateAdSettings(maxAdapterResponseParameters);
Context context = getContext(activity);
if (z) {
NativeBannerAd nativeBannerAd = new NativeBannerAd(context, thirdPartyAdPlacementId);
this.mNativeBannerAd = nativeBannerAd;
nativeBannerAd.loadAd(nativeBannerAd.buildLoadAdConfig().withAdListener(new MaxNativeAdListener(maxAdapterResponseParameters.getServerParameters(), context, maxNativeAdAdapterListener)).withBid(maxAdapterResponseParameters.getBidResponse()).build());
} else {
NativeAd nativeAd = new NativeAd(context, thirdPartyAdPlacementId);
this.mNativeAd = nativeAd;
nativeAd.loadAd(nativeAd.buildLoadAdConfig().withAdListener(new MaxNativeAdListener(maxAdapterResponseParameters.getServerParameters(), context, maxNativeAdAdapterListener)).withBid(maxAdapterResponseParameters.getBidResponse()).build());
}
}
private AdSize toAdSize(MaxAdFormat maxAdFormat) {
if (maxAdFormat == MaxAdFormat.BANNER) {
return AdSize.BANNER_HEIGHT_50;
}
if (maxAdFormat == MaxAdFormat.LEADER) {
return AdSize.BANNER_HEIGHT_90;
}
if (maxAdFormat == MaxAdFormat.MREC) {
return AdSize.RECTANGLE_HEIGHT_250;
}
throw new IllegalArgumentException("Invalid ad format: " + maxAdFormat);
}
private void updateAdSettings(MaxAdapterParameters maxAdapterParameters) {
Bundle serverParameters = maxAdapterParameters.getServerParameters();
if (serverParameters.containsKey("video_autoplay")) {
AdSettings.setVideoAutoplay(serverParameters.getBoolean("video_autoplay"));
}
Boolean privacySetting = getPrivacySetting("isAgeRestrictedUser", maxAdapterParameters);
if (privacySetting != null) {
AdSettings.setMixedAudience(privacySetting.booleanValue());
}
String string = serverParameters.getString("test_device_ids", null);
if (!TextUtils.isEmpty(string)) {
AdSettings.addTestDevices(Arrays.asList(string.split(",")));
}
AdSettings.setMediationService(getMediationIdentifier());
}
private Boolean getPrivacySetting(String str, MaxAdapterParameters maxAdapterParameters) {
try {
return (Boolean) maxAdapterParameters.getClass().getMethod(str, new Class[0]).invoke(maxAdapterParameters, new Object[0]);
} catch (Exception e) {
log("Error getting privacy setting " + str + " with exception: ", e);
return AppLovinSdk.VERSION_CODE >= 9140000 ? null : false;
}
}
public static MaxAdapterError toMaxError(AdError adError) {
int errorCode = adError.getErrorCode();
MaxAdapterError maxAdapterError = MaxAdapterError.UNSPECIFIED;
if (errorCode != 2006) {
if (errorCode != 2100) {
if (errorCode != 9001) {
if (errorCode != 2008) {
if (errorCode != 2009) {
switch (errorCode) {
case 1000:
maxAdapterError = MaxAdapterError.NO_CONNECTION;
break;
case 1001:
maxAdapterError = MaxAdapterError.NO_FILL;
break;
default:
switch (errorCode) {
case 2000:
break;
case 2001:
break;
case 2002:
break;
case 2003:
case 2004:
break;
default:
switch (errorCode) {
case 6001:
case 6002:
case 6003:
maxAdapterError = new MaxAdapterError(MaxAdapterError.ERROR_CODE_MISSING_REQUIRED_NATIVE_AD_ASSETS, "Missing Native Ad Assets");
break;
default:
switch (errorCode) {
case 7003:
maxAdapterError = MaxAdapterError.INVALID_CONFIGURATION;
break;
}
}
}
case 1002:
maxAdapterError = MaxAdapterError.INVALID_LOAD_STATE;
break;
}
return new MaxAdapterError(maxAdapterError.getErrorCode(), maxAdapterError.getErrorMessage(), errorCode, adError.getErrorMessage());
}
maxAdapterError = MaxAdapterError.TIMEOUT;
return new MaxAdapterError(maxAdapterError.getErrorCode(), maxAdapterError.getErrorMessage(), errorCode, adError.getErrorMessage());
}
maxAdapterError = MaxAdapterError.SERVER_ERROR;
return new MaxAdapterError(maxAdapterError.getErrorCode(), maxAdapterError.getErrorMessage(), errorCode, adError.getErrorMessage());
}
maxAdapterError = MaxAdapterError.INTERNAL_ERROR;
return new MaxAdapterError(maxAdapterError.getErrorCode(), maxAdapterError.getErrorMessage(), errorCode, adError.getErrorMessage());
}
maxAdapterError = MaxAdapterError.INVALID_LOAD_STATE;
return new MaxAdapterError(maxAdapterError.getErrorCode(), maxAdapterError.getErrorMessage(), errorCode, adError.getErrorMessage());
}
maxAdapterError = MaxAdapterError.INTERNAL_ERROR;
return new MaxAdapterError(maxAdapterError.getErrorCode(), maxAdapterError.getErrorMessage(), errorCode, adError.getErrorMessage());
}
private String getMediationIdentifier() {
return "APPLOVIN_" + AppLovinSdk.VERSION + CertificateUtil.DELIMITER + getAdapterVersion();
}
public MaxNativeAdView createMaxNativeAdView(MaxNativeAd maxNativeAd, String str, Activity activity) {
if (AppLovinSdk.VERSION_CODE >= 11010000) {
return new MaxNativeAdView(maxNativeAd, str, getApplicationContext());
}
return new MaxNativeAdView(maxNativeAd, str, activity);
}
public Context getContext(Activity activity) {
return activity != null ? activity.getApplicationContext() : getApplicationContext();
}
private class InterstitialAdListener implements InterstitialAdExtendedListener {
private final MaxInterstitialAdapterListener listener;
@Override
public void onRewardedAdCompleted() {
}
@Override
public void onRewardedAdServerFailed() {
}
@Override
public void onRewardedAdServerSucceeded() {
}
InterstitialAdListener(MaxInterstitialAdapterListener maxInterstitialAdapterListener) {
this.listener = maxInterstitialAdapterListener;
}
@Override
public void onAdLoaded(Ad ad) {
FacebookMediationAdapter.this.log("Interstitial ad loaded: " + ad.getPlacementId());
this.listener.onInterstitialAdLoaded();
}
@Override
public void onError(Ad ad, AdError adError) {
MaxAdapterError maxError = FacebookMediationAdapter.toMaxError(adError);
FacebookMediationAdapter.this.log("Interstitial ad (" + ad.getPlacementId() + ") failed to load with error: " + maxError);
this.listener.onInterstitialAdLoadFailed(maxError);
}
@Override
public void onAdClicked(Ad ad) {
FacebookMediationAdapter.this.log("Interstitial ad clicked: " + ad.getPlacementId());
this.listener.onInterstitialAdClicked();
}
@Override
public void onLoggingImpression(Ad ad) {
FacebookMediationAdapter.this.log("Interstitial ad logging impression: " + ad.getPlacementId());
this.listener.onInterstitialAdDisplayed();
}
@Override
public void onInterstitialDisplayed(Ad ad) {
FacebookMediationAdapter.this.log("Interstitial ad displayed: " + ad.getPlacementId());
}
@Override
public void onInterstitialDismissed(Ad ad) {
FacebookMediationAdapter.this.log("Interstitial ad hidden: " + ad.getPlacementId());
if (FacebookMediationAdapter.this.onInterstitialAdHiddenCalled.compareAndSet(false, true)) {
this.listener.onInterstitialAdHidden();
}
}
@Override
public void onInterstitialActivityDestroyed() {
FacebookMediationAdapter.this.log("Interstitial ad Activity destroyed");
if (FacebookMediationAdapter.this.onInterstitialAdHiddenCalled.compareAndSet(false, true)) {
this.listener.onInterstitialAdHidden();
}
}
}
private class RewardedAdListener implements RewardedVideoAdExtendedListener {
private boolean hasGrantedReward;
private final MaxRewardedAdapterListener listener;
RewardedAdListener(MaxRewardedAdapterListener maxRewardedAdapterListener) {
this.listener = maxRewardedAdapterListener;
}
@Override
public void onAdLoaded(Ad ad) {
FacebookMediationAdapter.this.log("Rewarded ad loaded: " + ad.getPlacementId());
this.listener.onRewardedAdLoaded();
}
@Override
public void onError(Ad ad, AdError adError) {
MaxAdapterError maxError = FacebookMediationAdapter.toMaxError(adError);
FacebookMediationAdapter.this.log("Rewarded ad (" + ad.getPlacementId() + ") failed to load with error (" + maxError);
this.listener.onRewardedAdLoadFailed(maxError);
}
@Override
public void onAdClicked(Ad ad) {
FacebookMediationAdapter.this.log("Rewarded ad clicked: " + ad.getPlacementId());
this.listener.onRewardedAdClicked();
}
@Override
public void onRewardedVideoClosed() {
FacebookMediationAdapter.this.log("Rewarded ad hidden");
if (FacebookMediationAdapter.this.onRewardedAdHiddenCalled.compareAndSet(false, true)) {
if (this.hasGrantedReward || FacebookMediationAdapter.this.shouldAlwaysRewardUser()) {
MaxReward reward = FacebookMediationAdapter.this.getReward();
FacebookMediationAdapter.this.log("Rewarded user with reward: " + reward);
this.listener.onUserRewarded(reward);
}
this.listener.onRewardedAdHidden();
}
}
@Override
public void onRewardedVideoCompleted() {
FacebookMediationAdapter.this.log("Rewarded ad video completed");
if (FacebookMediationAdapter.this.onRewardedAdVideoCompletedCalled.compareAndSet(false, true)) {
this.listener.onRewardedAdVideoCompleted();
this.hasGrantedReward = true;
}
}
@Override
public void onLoggingImpression(Ad ad) {
FacebookMediationAdapter.this.log("Rewarded ad logging impression: " + ad.getPlacementId());
this.listener.onRewardedAdDisplayed();
this.listener.onRewardedAdVideoStarted();
}
@Override
public void onRewardedVideoActivityDestroyed() {
FacebookMediationAdapter.this.log("Rewarded ad Activity destroyed");
if (FacebookMediationAdapter.this.onRewardedAdVideoCompletedCalled.compareAndSet(false, true)) {
this.listener.onRewardedAdVideoCompleted();
}
if (FacebookMediationAdapter.this.onRewardedAdHiddenCalled.compareAndSet(false, true)) {
this.listener.onRewardedAdHidden();
}
}
}
private class AdViewListener implements AdListener {
final MaxAdFormat adFormat;
final MaxAdViewAdapterListener listener;
AdViewListener(MaxAdFormat maxAdFormat, MaxAdViewAdapterListener maxAdViewAdapterListener) {
this.adFormat = maxAdFormat;
this.listener = maxAdViewAdapterListener;
}
@Override
public void onAdLoaded(Ad ad) {
FacebookMediationAdapter.this.log(this.adFormat.getLabel() + " ad loaded: " + ad.getPlacementId());
this.listener.onAdViewAdLoaded(FacebookMediationAdapter.this.mAdView);
}
@Override
public void onError(Ad ad, AdError adError) {
MaxAdapterError maxError = FacebookMediationAdapter.toMaxError(adError);
FacebookMediationAdapter.this.log(this.adFormat.getLabel() + " ad (" + ad.getPlacementId() + ") failed to load with error (" + maxError);
this.listener.onAdViewAdLoadFailed(maxError);
}
@Override
public void onAdClicked(Ad ad) {
FacebookMediationAdapter.this.log(this.adFormat.getLabel() + " ad clicked: " + ad.getPlacementId());
this.listener.onAdViewAdClicked();
}
@Override
public void onLoggingImpression(Ad ad) {
FacebookMediationAdapter.this.log(this.adFormat.getLabel() + " ad displayed: " + ad.getPlacementId());
this.listener.onAdViewAdDisplayed();
}
}
private class NativeAdViewListener implements NativeAdListener {
final WeakReference<Activity> activityRef;
final MaxAdFormat adFormat;
final MaxAdViewAdapterListener listener;
final Bundle serverParameters;
NativeAdViewListener(Bundle bundle, MaxAdFormat maxAdFormat, Activity activity, MaxAdViewAdapterListener maxAdViewAdapterListener) {
this.serverParameters = bundle;
this.activityRef = new WeakReference<>(activity);
this.adFormat = maxAdFormat;
this.listener = maxAdViewAdapterListener;
}
@Override
public void onAdLoaded(Ad ad) {
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " ad loaded: " + ad.getPlacementId());
if (FacebookMediationAdapter.this.mNativeAd != null && FacebookMediationAdapter.this.mNativeAd == ad) {
if (FacebookMediationAdapter.this.mNativeAd.isAdInvalidated()) {
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " ad failed to load: ad is no longer valid");
this.listener.onAdViewAdLoadFailed(MaxAdapterError.AD_EXPIRED);
return;
}
if (this.adFormat == MaxAdFormat.MREC) {
this.listener.onAdViewAdLoaded(NativeAdView.render(FacebookMediationAdapter.this.getContext(this.activityRef.get()), FacebookMediationAdapter.this.mNativeAd));
return;
} else {
if (AppLovinSdk.VERSION_CODE >= 9140000) {
renderNativeAdView();
return;
}
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " failed to load: AppLovin SDK version must be at least 9.14.0");
this.listener.onAdViewAdLoadFailed(MaxAdapterError.INVALID_CONFIGURATION);
return;
}
}
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " ad failed to load: no fill");
this.listener.onAdViewAdLoadFailed(MaxAdapterError.NO_FILL);
}
@Override
public void onMediaDownloaded(Ad ad) {
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " successfully downloaded media: " + ad.getPlacementId());
}
@Override
public void onError(Ad ad, AdError adError) {
MaxAdapterError maxError = FacebookMediationAdapter.toMaxError(adError);
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " ad (" + ad.getPlacementId() + ") failed to load with error: " + maxError);
this.listener.onAdViewAdLoadFailed(maxError);
}
@Override
public void onLoggingImpression(Ad ad) {
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " shown: " + ad.getPlacementId());
this.listener.onAdViewAdDisplayed();
}
@Override
public void onAdClicked(Ad ad) {
FacebookMediationAdapter.this.log("Native " + this.adFormat.getLabel() + " clicked: " + ad.getPlacementId());
this.listener.onAdViewAdClicked();
}
private void renderNativeAdView() {
AppLovinSdkUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
MaxNativeAdView createMaxNativeAdView;
Activity activity = NativeAdViewListener.this.activityRef.get();
Context context = FacebookMediationAdapter.this.getContext(activity);
MediaView mediaView = new MediaView(context);
MediaView mediaView2 = new MediaView(context);
MaxNativeAd build = new MaxNativeAd.Builder().setAdFormat(NativeAdViewListener.this.adFormat).setTitle(FacebookMediationAdapter.this.mNativeAd.getAdHeadline()).setAdvertiser(FacebookMediationAdapter.this.mNativeAd.getAdvertiserName()).setBody(FacebookMediationAdapter.this.mNativeAd.getAdBodyText()).setCallToAction(FacebookMediationAdapter.this.mNativeAd.getAdCallToAction()).setIconView(mediaView).setMediaView(mediaView2).setOptionsView(new AdOptionsView(context, FacebookMediationAdapter.this.mNativeAd, null)).build();
String string = BundleUtils.getString("template", "", NativeAdViewListener.this.serverParameters);
if (string.contains("vertical")) {
if (AppLovinSdk.VERSION_CODE < 9140500) {
FacebookMediationAdapter.this.log("Vertical native banners are only supported on MAX SDK 9.14.5 and above. Default native template will be used.");
}
if (string.equals("vertical")) {
createMaxNativeAdView = FacebookMediationAdapter.this.createMaxNativeAdView(build, NativeAdViewListener.this.adFormat == MaxAdFormat.LEADER ? "vertical_leader_template" : "vertical_media_banner_template", activity);
} else {
createMaxNativeAdView = FacebookMediationAdapter.this.createMaxNativeAdView(build, string, activity);
}
} else if (AppLovinSdk.VERSION_CODE < 9140500) {
FacebookMediationAdapter facebookMediationAdapter = FacebookMediationAdapter.this;
if (!AppLovinSdkUtils.isValidString(string)) {
string = "no_body_banner_template";
}
createMaxNativeAdView = facebookMediationAdapter.createMaxNativeAdView(build, string, activity);
} else {
FacebookMediationAdapter facebookMediationAdapter2 = FacebookMediationAdapter.this;
if (!AppLovinSdkUtils.isValidString(string)) {
string = "media_banner_template";
}
createMaxNativeAdView = facebookMediationAdapter2.createMaxNativeAdView(build, string, activity);
}
ArrayList arrayList = new ArrayList();
if (build.getIconView() != null && createMaxNativeAdView.getIconContentView() != null) {
arrayList.add(createMaxNativeAdView.getIconContentView());
}
ViewGroup mediaContentViewGroup = AppLovinSdk.VERSION_CODE >= 11000000 ? createMaxNativeAdView.getMediaContentViewGroup() : createMaxNativeAdView.getMediaContentView();
if (build.getMediaView() != null && mediaContentViewGroup != null) {
arrayList.add(mediaContentViewGroup);
}
if (AppLovinSdkUtils.isValidString(build.getTitle()) && createMaxNativeAdView.getTitleTextView() != null) {
arrayList.add(createMaxNativeAdView.getTitleTextView());
}
if (AppLovinSdkUtils.isValidString(build.getCallToAction()) && createMaxNativeAdView.getCallToActionButton() != null) {
arrayList.add(createMaxNativeAdView.getCallToActionButton());
}
if (AppLovinSdkUtils.isValidString(build.getAdvertiser()) && createMaxNativeAdView.getAdvertiserTextView() != null) {
arrayList.add(createMaxNativeAdView.getAdvertiserTextView());
}
if (AppLovinSdkUtils.isValidString(build.getBody()) && createMaxNativeAdView.getBodyTextView() != null) {
arrayList.add(createMaxNativeAdView.getBodyTextView());
}
FacebookMediationAdapter.this.mNativeAd.registerViewForInteraction(createMaxNativeAdView, mediaView2, mediaView, arrayList);
NativeAdViewListener.this.listener.onAdViewAdLoaded(createMaxNativeAdView);
}
});
}
}
private class MaxNativeAdListener implements NativeAdListener {
final Context context;
final MaxNativeAdAdapterListener listener;
final Bundle serverParameters;
MaxNativeAdListener(Bundle bundle, Context context, MaxNativeAdAdapterListener maxNativeAdAdapterListener) {
this.serverParameters = bundle;
this.context = context;
this.listener = maxNativeAdAdapterListener;
}
@Override
public void onAdLoaded(Ad ad) {
FacebookMediationAdapter.this.log("Native ad loaded: " + ad.getPlacementId());
final NativeAdBase nativeAdBase = FacebookMediationAdapter.this.mNativeAd != null ? FacebookMediationAdapter.this.mNativeAd : FacebookMediationAdapter.this.mNativeBannerAd;
if (nativeAdBase == null || nativeAdBase != ad) {
FacebookMediationAdapter.this.log("Native ad failed to load: no fill");
this.listener.onNativeAdLoadFailed(MaxAdapterError.NO_FILL);
return;
}
if (nativeAdBase.isAdInvalidated()) {
FacebookMediationAdapter.this.log("Native ad failed to load: ad is no longer valid");
this.listener.onNativeAdLoadFailed(MaxAdapterError.AD_EXPIRED);
return;
}
if (AppLovinSdkUtils.isValidString(BundleUtils.getString("template", "", this.serverParameters)) && TextUtils.isEmpty(nativeAdBase.getAdHeadline())) {
FacebookMediationAdapter.this.e("Native ad (" + nativeAdBase + ") does not have required assets.");
this.listener.onNativeAdLoadFailed(new MaxAdapterError(MaxAdapterError.ERROR_CODE_MISSING_REQUIRED_NATIVE_AD_ASSETS, "Missing Native Ad Assets"));
return;
}
AppLovinSdkUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
final MediaView mediaView = new MediaView(MaxNativeAdListener.this.context);
Drawable preloadedIconViewDrawable = nativeAdBase.getPreloadedIconViewDrawable();
final NativeAdBase.Image adIcon = nativeAdBase.getAdIcon();
if (preloadedIconViewDrawable != null) {
MaxNativeAdListener maxNativeAdListener = MaxNativeAdListener.this;
maxNativeAdListener.handleNativeAdLoaded(nativeAdBase, preloadedIconViewDrawable, mediaView, maxNativeAdListener.context);
} else {
if (adIcon != null) {
FacebookMediationAdapter.this.getCachingExecutorService().execute(new Runnable() {
@Override
public void run() {
Drawable drawable = null;
if (AppLovinSdkUtils.isValidString(adIcon.getUrl())) {
FacebookMediationAdapter.this.log("Adding native ad icon (" + adIcon.getUrl() + ") to queue to be fetched");
Future<Drawable> createDrawableFuture = FacebookMediationAdapter.this.createDrawableFuture(adIcon.getUrl(), MaxNativeAdListener.this.context.getResources());
int i = BundleUtils.getInt("image_task_timeout_seconds", 10, MaxNativeAdListener.this.serverParameters);
if (createDrawableFuture != null) {
try {
drawable = createDrawableFuture.get(i, TimeUnit.SECONDS);
} catch (Throwable th) {
FacebookMediationAdapter.this.e("Image fetching tasks failed", th);
}
}
}
MaxNativeAdListener.this.handleNativeAdLoaded(nativeAdBase, drawable, mediaView, MaxNativeAdListener.this.context);
}
});
return;
}
FacebookMediationAdapter.this.log("No native ad icon (optional) available for the current creative.");
MaxNativeAdListener maxNativeAdListener2 = MaxNativeAdListener.this;
maxNativeAdListener2.handleNativeAdLoaded(nativeAdBase, null, mediaView, maxNativeAdListener2.context);
}
}
});
}
@Override
public void onMediaDownloaded(Ad ad) {
FacebookMediationAdapter.this.log("Native ad successfully downloaded media: " + ad.getPlacementId());
}
@Override
public void onError(Ad ad, AdError adError) {
MaxAdapterError maxError = FacebookMediationAdapter.toMaxError(adError);
FacebookMediationAdapter.this.log("Native ad (" + ad.getPlacementId() + ") failed to load with error (" + maxError);
this.listener.onNativeAdLoadFailed(maxError);
}
@Override
public void onLoggingImpression(Ad ad) {
FacebookMediationAdapter.this.log("Native shown: " + ad.getPlacementId());
this.listener.onNativeAdDisplayed(null);
}
@Override
public void onAdClicked(Ad ad) {
FacebookMediationAdapter.this.log("Native clicked: " + ad.getPlacementId());
this.listener.onNativeAdClicked();
}
public void handleNativeAdLoaded(NativeAdBase nativeAdBase, Drawable drawable, MediaView mediaView, Context context) {
float mediaWidth;
int mediaHeight;
boolean z = nativeAdBase instanceof NativeAd;
MaxNativeAd.MaxNativeAdImage maxNativeAdImage = (!z || nativeAdBase.getAdCoverImage() == null) ? null : new MaxNativeAd.MaxNativeAdImage(Uri.parse(nativeAdBase.getAdCoverImage().getUrl()));
MaxNativeAd.Builder optionsView = new MaxNativeAd.Builder().setAdFormat(MaxAdFormat.NATIVE).setTitle(nativeAdBase.getAdHeadline()).setAdvertiser(nativeAdBase.getAdvertiserName()).setBody(nativeAdBase.getAdBodyText()).setCallToAction(nativeAdBase.getAdCallToAction()).setIcon(new MaxNativeAd.MaxNativeAdImage(drawable)).setOptionsView(new AdOptionsView(context, nativeAdBase, null));
if (z && AppLovinSdk.VERSION_CODE >= 11040399) {
optionsView.setMainImage(maxNativeAdImage);
}
float f = 0.0f;
if (nativeAdBase instanceof NativeBannerAd) {
ImageView imageView = new ImageView(context);
imageView.setImageDrawable(drawable);
optionsView.setMediaView(imageView);
if (drawable != null) {
mediaWidth = drawable.getIntrinsicWidth();
mediaHeight = drawable.getIntrinsicHeight();
}
if (AppLovinSdk.VERSION_CODE >= 11040000) {
optionsView.setMediaContentAspectRatio(f);
}
this.listener.onNativeAdLoaded(new MaxFacebookNativeAd(optionsView), null);
}
optionsView.setMediaView(mediaView);
mediaWidth = mediaView.getMediaWidth();
mediaHeight = mediaView.getMediaHeight();
f = mediaWidth / mediaHeight;
if (AppLovinSdk.VERSION_CODE >= 11040000) {
}
this.listener.onNativeAdLoaded(new MaxFacebookNativeAd(optionsView), null);
}
}
public class MaxFacebookNativeAd extends MaxNativeAd {
private MaxFacebookNativeAd(MaxNativeAd.Builder builder) {
super(builder);
}
@Override
public void prepareViewForInteraction(MaxNativeAdView maxNativeAdView) {
ArrayList arrayList = new ArrayList();
if (AppLovinSdkUtils.isValidString(getTitle()) && maxNativeAdView.getTitleTextView() != null) {
arrayList.add(maxNativeAdView.getTitleTextView());
}
if (AppLovinSdkUtils.isValidString(getAdvertiser()) && maxNativeAdView.getAdvertiserTextView() != null) {
arrayList.add(maxNativeAdView.getAdvertiserTextView());
}
if (AppLovinSdkUtils.isValidString(getBody()) && maxNativeAdView.getBodyTextView() != null) {
arrayList.add(maxNativeAdView.getBodyTextView());
}
if (AppLovinSdkUtils.isValidString(getCallToAction()) && maxNativeAdView.getCallToActionButton() != null) {
arrayList.add(maxNativeAdView.getCallToActionButton());
}
if (getIcon() != null && maxNativeAdView.getIconImageView() != null) {
arrayList.add(maxNativeAdView.getIconImageView());
}
if (getMediaView() != null && maxNativeAdView.getMediaContentViewGroup() != null) {
arrayList.add(maxNativeAdView.getMediaContentViewGroup());
}
prepareForInteraction(arrayList, maxNativeAdView);
}
@Override
public boolean prepareForInteraction(List<View> list, ViewGroup viewGroup) {
Ad ad = FacebookMediationAdapter.this.mNativeAd != null ? FacebookMediationAdapter.this.mNativeAd : FacebookMediationAdapter.this.mNativeBannerAd;
if (ad == null) {
FacebookMediationAdapter.this.e("Failed to register native ad views: native ad is null.");
return false;
}
ImageView imageView = null;
Iterator<View> it = list.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
View next = it.next();
if (next instanceof ImageView) {
imageView = (ImageView) next;
break;
}
}
if (!(ad instanceof NativeBannerAd)) {
((NativeAd) ad).registerViewForInteraction(viewGroup, (MediaView) getMediaView(), imageView, list);
return true;
}
if (imageView != null) {
((NativeBannerAd) ad).registerViewForInteraction(viewGroup, imageView, list);
return true;
}
if (getMediaView() != null) {
((NativeBannerAd) ad).registerViewForInteraction(viewGroup, (ImageView) getMediaView(), list);
return true;
}
FacebookMediationAdapter.this.e("Failed to register native ad view for interaction: icon image view and media view are null");
return false;
}
}
}