Mad Aces v1.2.2.3版本的 MD5 值为:f29ebd7c5808053d9f3f3722a5db1688
以下内容为反编译后的 HeyzapExchangeAdapter.java 源代码,内容仅作参考
package com.heyzap.sdk.mediation.adapter;
import com.heyzap.common.concurrency.FutureUtils;
import com.heyzap.common.concurrency.SettableFuture;
import com.heyzap.common.lifecycle.AdDisplay;
import com.heyzap.common.lifecycle.DisplayOptions;
import com.heyzap.common.lifecycle.DisplayResult;
import com.heyzap.common.lifecycle.FetchFailure;
import com.heyzap.common.lifecycle.FetchResult;
import com.heyzap.exchange.ExchangeClient;
import com.heyzap.exchange.ExchangeEventReporter;
import com.heyzap.internal.Analytics;
import com.heyzap.internal.Constants;
import com.heyzap.internal.Logger;
import com.heyzap.internal.RetryManager;
import com.heyzap.mediation.MediationResult;
import com.heyzap.mediation.abstr.AdUnitNetworkAdapter;
import com.heyzap.mediation.abstr.NetworkAdapter;
import com.heyzap.mediation.adapter.AdUnitStateManager;
import com.heyzap.mediation.adapter.FetchStateManager;
import com.heyzap.mediation.request.MediationRequest;
import com.heyzap.sdk.ads.HeyzapAds;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
public class HeyzapExchangeAdapter extends AdUnitNetworkAdapter {
private static final String CANON = "heyzap_exchange";
private static String DEFAULT_EXCHANGE_URL = "https://x.heyzap.com/_/0/ad";
private String exchangeUrl;
private ExchangeEventReporter reporter;
private final FetchStateManager<SettableFuture<ExchangeClientFetchResult>> fetchStateManager = new FetchStateManager<>();
private AdUnitStateManager adUnitStateManager = new AdUnitStateManager();
private WeakReference<ExchangeClient> lastShownClient = new WeakReference<>(null);
@Override
public boolean isInterstitialVideo() {
return false;
}
@Override
public Boolean isOnBoard() {
return true;
}
@Override
public String getMarketingName() {
return "Heyzap Exchange";
}
@Override
public String getMarketingVersion() {
return Analytics.HEYZAP_SDK_VERSION;
}
@Override
public String getCanonicalName() {
return CANON;
}
@Override
public AdDisplay show(MediationRequest mediationRequest, MediationResult mediationResult) {
AdDisplay adDisplay = new AdDisplay();
try {
HashMap hashMap = new HashMap();
hashMap.put("mediation_id", mediationResult.id);
hashMap.put("mediation_tag", mediationRequest.getTag());
hashMap.put("ad_unit", mediationRequest.getAdUnit().toString().toLowerCase(Locale.US));
switch (mediationRequest.getAdUnit()) {
case NATIVE:
adDisplay.displayEventStream.sendEvent(DisplayResult.UNSUPPORTED_AD_UNIT);
break;
case BANNER:
adDisplay = fetchAndShowBanner(mediationRequest.getBannerOptions(), hashMap);
break;
default:
adDisplay = showInterstitial(mediationRequest, hashMap, adDisplay);
break;
}
} catch (Exception e) {
Logger.error("Display Failed", e);
adDisplay.displayEventStream.sendEvent(new DisplayResult(e.getMessage()));
}
return adDisplay;
}
private AdDisplay showInterstitial(final MediationRequest mediationRequest, final Map<String, String> map, AdDisplay adDisplay) {
final ExchangeClient client;
SettableFuture<ExchangeClientFetchResult> settableFuture = this.fetchStateManager.get(mediationRequest.getAdUnit());
if (settableFuture.isDone()) {
try {
client = settableFuture.get().getClient();
} catch (Exception e) {
Logger.trace((Throwable) e);
}
if (client != null || !client.fetchListener.isDone()) {
adDisplay.displayEventStream.sendEvent(DisplayResult.NOT_READY);
} else {
this.uiThreadExecutorService.execute(new Runnable() {
@Override
public void run() {
HeyzapExchangeAdapter.this.lastShownClient = new WeakReference(client);
client.show(mediationRequest.getRequestingActivity(), mediationRequest.getAdUnit(), map);
}
});
adDisplay = client;
}
if (settableFuture.isDone()) {
this.fetchStateManager.set(mediationRequest.getAdUnit(), createFetchFuture());
attemptNextFetch(mediationRequest.getAdUnit());
}
return adDisplay;
}
client = null;
if (client != null) {
}
adDisplay.displayEventStream.sendEvent(DisplayResult.NOT_READY);
if (settableFuture.isDone()) {
}
return adDisplay;
}
private AdDisplay fetchAndShowBanner(HeyzapAds.BannerOptions bannerOptions, final Map<String, String> map) {
AdDisplay adDisplay;
final AdDisplay adDisplay2 = new AdDisplay();
try {
SettableFuture<ExchangeClientFetchResult> settableFuture = this.fetchStateManager.get(Constants.AdUnit.BANNER);
if (settableFuture == null || !settableFuture.isDone() || settableFuture.get().getClient().getRealBannerView() == null) {
this.fetchStateManager.set(Constants.AdUnit.BANNER, createFetchFuture());
this.fetchStateManager.start(Constants.AdUnit.BANNER);
final SettableFuture<ExchangeClient> fetch = ExchangeClient.fetch(getContextRef(), this.reporter, EnumSet.of(Constants.CreativeType.BANNER), this.exchangeUrl, bannerOptions, this.executorService, this.uiThreadExecutorService);
fetch.addListener(new Runnable() {
@Override
public void run() {
try {
ExchangeClient exchangeClient = (ExchangeClient) fetch.get();
if (exchangeClient.getRealBannerView() != null) {
exchangeClient.bindDisplayWithParams(map);
adDisplay2.clickEventStream = exchangeClient.clickEventStream;
adDisplay2.closeListener = exchangeClient.closeListener;
DisplayResult displayResult = new DisplayResult();
displayResult.bannerWrapper = exchangeClient;
adDisplay2.displayEventStream.sendEvent(displayResult);
}
} catch (Exception e) {
Logger.trace((Throwable) e);
}
}
}, this.executorService);
adDisplay = adDisplay2;
} else {
adDisplay2.displayEventStream = settableFuture.get().client.displayEventStream;
adDisplay2.clickEventStream = settableFuture.get().client.clickEventStream;
adDisplay = adDisplay2;
}
return adDisplay;
} catch (Exception e) {
adDisplay2.displayEventStream.sendEvent(new DisplayResult(e.getMessage()));
return adDisplay2;
}
}
@Override
public EnumSet<Constants.AdUnit> getAllAdUnitCapabilities() {
return EnumSet.of(Constants.AdUnit.INTERSTITIAL, Constants.AdUnit.INCENTIVIZED, Constants.AdUnit.VIDEO);
}
@Override
public EnumSet<Constants.AdUnit> getConfiguredAdUnitCapabilities() {
return EnumSet.of(Constants.AdUnit.INTERSTITIAL, Constants.AdUnit.INCENTIVIZED, Constants.AdUnit.VIDEO);
}
@Override
public EnumSet<Constants.AdUnit> getAdUnitsForCreativeType(Constants.CreativeType creativeType) {
switch (creativeType) {
case STATIC:
return EnumSet.of(Constants.AdUnit.INTERSTITIAL, Constants.AdUnit.VIDEO);
case INCENTIVIZED:
return EnumSet.of(Constants.AdUnit.INCENTIVIZED);
case BANNER:
return EnumSet.of(Constants.AdUnit.BANNER);
case VIDEO:
return EnumSet.of(Constants.AdUnit.VIDEO);
default:
return EnumSet.noneOf(Constants.AdUnit.class);
}
}
public EnumSet<Constants.CreativeType> getCreativeTypesForAdUnit(Constants.AdUnit adUnit) {
switch (adUnit) {
case BANNER:
return EnumSet.of(Constants.CreativeType.BANNER);
case INTERSTITIAL:
return EnumSet.of(Constants.CreativeType.STATIC);
case VIDEO:
return EnumSet.of(Constants.CreativeType.VIDEO);
case INCENTIVIZED:
return EnumSet.of(Constants.CreativeType.INCENTIVIZED);
default:
return EnumSet.noneOf(Constants.CreativeType.class);
}
}
@Override
public void addFetchStartedListener(final FetchResult.FetchStartedListener fetchStartedListener, ExecutorService executorService) {
this.fetchStateManager.addFetchStartedListener(new FetchStateManager.FetchStartedListener<SettableFuture<ExchangeClientFetchResult>>() {
@Override
public void onFetchStarted(Constants.AdUnit adUnit, SettableFuture<ExchangeClientFetchResult> settableFuture) {
fetchStartedListener.onFetchStarted(adUnit, settableFuture);
}
}, executorService);
}
@Override
public SettableFuture<FetchResult> awaitAvailability(Constants.AdUnit adUnit) {
return this.fetchStateManager.get(adUnit);
}
public class AnonymousClass4 implements Runnable {
final Constants.AdUnit val$adUnit;
AnonymousClass4(Constants.AdUnit adUnit) {
this.val$adUnit = adUnit;
}
@Override
public void run() {
new RetryManager(new RetryManager.RetryableTask() {
@Override
public void run() {
HeyzapExchangeAdapter.this.fetchStateManager.start(AnonymousClass4.this.val$adUnit);
final SettableFuture settableFuture = (SettableFuture) HeyzapExchangeAdapter.this.fetchStateManager.get(AnonymousClass4.this.val$adUnit);
SettableFuture<ExchangeClient> fetch = ExchangeClient.fetch(HeyzapExchangeAdapter.this.getContextRef(), HeyzapExchangeAdapter.this.reporter, HeyzapExchangeAdapter.this.getCreativeTypesForAdUnit(AnonymousClass4.this.val$adUnit), HeyzapExchangeAdapter.this.exchangeUrl, null, HeyzapExchangeAdapter.this.executorService, HeyzapExchangeAdapter.this.uiThreadExecutorService);
fetch.addListener(new FutureUtils.FutureRunnable<ExchangeClient>(fetch) {
@Override
public void run(ExchangeClient exchangeClient, Exception exc) {
FetchFailure fetchFailure;
if (exchangeClient != null) {
settableFuture.set(new ExchangeClientFetchResult(exchangeClient));
return;
}
if (exc != null) {
fetchFailure = new FetchFailure(Constants.FetchFailureReason.NO_FILL, exc.getMessage());
} else {
fetchFailure = new FetchFailure(Constants.FetchFailureReason.UNKNOWN, "Unknown error during fetch (No Exception)");
}
settableFuture.set(new ExchangeClientFetchResult(fetchFailure));
HeyzapExchangeAdapter.this.fetchStateManager.set(AnonymousClass4.this.val$adUnit, HeyzapExchangeAdapter.this.createFetchFuture());
retry();
}
}, HeyzapExchangeAdapter.this.uiThreadExecutorService);
}
}, new RetryManager.ExponentialSchedule(2.0d, 4L, TimeUnit.SECONDS), HeyzapExchangeAdapter.this.executorService).start();
}
}
private void attemptNextFetch(Constants.AdUnit adUnit) {
getFetchConsumer().consumeAny(Arrays.asList(adUnit), new AnonymousClass4(adUnit), this.executorService);
}
@Override
public SettableFuture<FetchResult> startAdUnits(Collection<Constants.AdUnit> collection) {
Set<Constants.AdUnit> start = this.adUnitStateManager.start(collection);
start.retainAll(getConfiguredAdUnitCapabilities());
final SettableFuture<FetchResult> create = SettableFuture.create();
if (start.size() > 0) {
ArrayList arrayList = new ArrayList();
for (Constants.AdUnit adUnit : start) {
attemptNextFetch(adUnit);
arrayList.add(awaitAvailability(adUnit));
}
FutureUtils.allOf(arrayList, this.executorService).addListener(new Runnable() {
@Override
public void run() {
create.set(new FetchResult());
}
}, this.executorService);
} else {
create.set(new FetchResult());
}
return create;
}
@Override
public boolean isAdUnitStarted(Collection<Constants.AdUnit> collection) {
return this.adUnitStateManager.allStarted(collection);
}
@Override
public Boolean isReady() {
return true;
}
@Override
public List<String> getPermissions() {
return Arrays.asList("android.permission.ACCESS_NETWORK_STATE", "android.permission.INTERNET");
}
@Override
public List<String> getActivities() {
return Arrays.asList("com.heyzap.sdk.ads.VASTActivity");
}
@Override
public void onInit() throws NetworkAdapter.ConfigurationError {
this.exchangeUrl = getConfiguration().optValue("url", DEFAULT_EXCHANGE_URL);
this.reporter = new ExchangeEventReporter(getContextRef(), this.executorService);
SettableFuture<ExchangeClientFetchResult> create = SettableFuture.create();
create.setException(new Throwable("Unsupported Ad Unit"));
this.fetchStateManager.setDefaultValue(create);
this.fetchStateManager.set(Constants.AdUnit.INTERSTITIAL, createFetchFuture());
this.fetchStateManager.set(Constants.AdUnit.INCENTIVIZED, createFetchFuture());
this.fetchStateManager.set(Constants.AdUnit.VIDEO, createFetchFuture());
onCallbackEvent(HeyzapAds.NetworkCallback.INITIALIZED);
}
public SettableFuture<ExchangeClientFetchResult> createFetchFuture() {
return SettableFuture.create();
}
public static class ExchangeClientFetchResult extends FetchResult {
private final ExchangeClient client;
public ExchangeClientFetchResult(FetchFailure fetchFailure) {
this.fetchFailure = fetchFailure;
this.success = false;
this.client = null;
}
public ExchangeClientFetchResult(ExchangeClient exchangeClient) {
this.client = exchangeClient;
this.success = true;
}
public ExchangeClient getClient() {
return this.client;
}
}
@Override
public Double getScoreOverride(DisplayOptions displayOptions) {
ExchangeClientFetchResult exchangeClientFetchResult = (ExchangeClientFetchResult) FutureUtils.getImmediatelyOrDefault(this.fetchStateManager.get(displayOptions.getAdUnit()), null);
return (exchangeClientFetchResult == null || exchangeClientFetchResult.getClient() == null) ? Double.valueOf(Double.MIN_VALUE) : exchangeClientFetchResult.client.getScore();
}
@Override
public boolean onBackPressed() {
ExchangeClient exchangeClient = this.lastShownClient.get();
if (exchangeClient == null) {
return false;
}
return exchangeClient.onBackPressed();
}
}