Mad Aces v1.2.2.3版本的 MD5 值为:f29ebd7c5808053d9f3f3722a5db1688
以下内容为反编译后的 MediationConfigLoader.java 源代码,内容仅作参考
package com.heyzap.mediation.config;
import android.content.Context;
import android.content.SharedPreferences;
import com.heyzap.common.concurrency.ExecutorPool;
import com.heyzap.common.concurrency.ListenableFuture;
import com.heyzap.common.concurrency.SettableFuture;
import com.heyzap.common.net.APIClient;
import com.heyzap.http.JsonHttpResponseHandler;
import com.heyzap.http.RequestParams;
import com.heyzap.internal.Constants;
import com.heyzap.internal.ContextReference;
import com.heyzap.internal.HeaderActions;
import com.heyzap.internal.Logger;
import com.heyzap.internal.RetryManager;
import com.heyzap.internal.SwappableProvider;
import com.heyzap.mediation.ConcurrentLoaderStrategy;
import com.heyzap.mediation.FetchRequestStore;
import com.heyzap.mediation.adapter.AdapterPool;
import com.heyzap.mediation.adapter.AdapterScanner;
import com.heyzap.mediation.config.ConfigLoader;
import com.heyzap.mediation.display.MediatedDisplayConfigLoader;
import com.heyzap.mediation.filters.FilterManager;
import com.heyzap.sdk.ads.HeyzapAds;
import com.heyzap.sdk.mediation.adapter.HeyzapAdapter;
import com.heyzap.sdk.mediation.adapter.HeyzapCrossPromoAdapter;
import com.heyzap.sdk.segmentation.SQLitePastImpressionStore;
import com.heyzap.sdk.segmentation.SegmentManager;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;
public class MediationConfigLoader implements ConfigLoader {
private static final String CONFIGURATION_CACHE_KEY = "config.cache";
private static final String CONFIGURATION_USED_KEY = "config.used";
private final AdapterPool adapterPool;
private final AdapterScanner adapterScanner;
private final HeyzapAds.AdsConfig adsConfig;
private final SettableFuture<MediationConfig> configurationCacheFuture = SettableFuture.create();
private final ContextReference contextRef;
private final MediatedDisplayConfigLoader displayConfigLoader;
private final ScheduledExecutorService executorService;
private final FetchRequestStore fetchRequestStore;
private final FilterManager filterManager;
private final HeaderActions headerActions;
private final ConcurrentLoaderStrategy loaderStrategy;
private final HeyzapAds.NetworkCallbackListener networkCallbackListener;
private final ExecutorService uiThreadExecutorService;
public MediationConfigLoader(ContextReference contextReference, ScheduledExecutorService scheduledExecutorService, ExecutorService executorService, FetchRequestStore fetchRequestStore, HeyzapAds.AdsConfig adsConfig, HeyzapAds.NetworkCallbackListener networkCallbackListener) {
this.contextRef = contextReference;
this.executorService = scheduledExecutorService;
this.fetchRequestStore = fetchRequestStore;
this.uiThreadExecutorService = executorService;
this.adapterScanner = new AdapterScanner(contextReference);
this.networkCallbackListener = networkCallbackListener;
this.adapterPool = new AdapterPool(contextReference, this.fetchRequestStore, adsConfig, scheduledExecutorService, executorService, this.networkCallbackListener);
this.filterManager = new FilterManager(contextReference, scheduledExecutorService);
this.displayConfigLoader = new MediatedDisplayConfigLoader(contextReference);
this.loaderStrategy = new ConcurrentLoaderStrategy(this.adapterPool, scheduledExecutorService, this.fetchRequestStore);
this.adsConfig = adsConfig;
this.headerActions = new HeaderActions(executorService, scheduledExecutorService, contextReference);
}
@Override
public void start() {
if ((this.adsConfig.flags & 8) == 0) {
this.adapterPool.addAdapters(this.adapterScanner.scan());
} else {
this.adapterPool.addAdapters(Arrays.asList(HeyzapAdapter.class, HeyzapCrossPromoAdapter.class));
}
this.displayConfigLoader.start();
JSONObject configurationCache = getConfigurationCache(this.contextRef.getApp());
if (configurationCache != null) {
try {
this.configurationCacheFuture.set(new MediationConfig(this.contextRef, configurationCache, this.executorService, this.fetchRequestStore, this.adapterPool, this.displayConfigLoader, this.loaderStrategy, this.filterManager));
} catch (JSONException e) {
Logger.trace((Throwable) e);
}
}
new RetryManager(new RetryManager.RetryableTask() {
@Override
public void run() {
APIClient.get(MediationConfigLoader.this.contextRef.getApp(), "https://med.heyzap.com/start", new RequestParams(), new JsonHttpResponseHandler() {
@Override
public void onSuccess(int i, Header[] headerArr, JSONObject jSONObject) {
try {
MediationConfigLoader.this.headerActions.onHeaders(headerArr);
MediationConfigLoader.storeConfigurationCache(MediationConfigLoader.this.contextRef.getApp(), jSONObject);
if (!MediationConfigLoader.this.configurationCacheFuture.isDone()) {
MediationConfigLoader.this.configurationCacheFuture.set(new MediationConfig(MediationConfigLoader.this.contextRef, jSONObject, MediationConfigLoader.this.executorService, MediationConfigLoader.this.fetchRequestStore, MediationConfigLoader.this.adapterPool, MediationConfigLoader.this.displayConfigLoader, MediationConfigLoader.this.loaderStrategy, MediationConfigLoader.this.filterManager));
return;
}
try {
((SwappableProvider) ((MediationConfig) MediationConfigLoader.this.configurationCacheFuture.get()).getSegmentManager()).set(new SegmentManager(jSONObject.getJSONArray("segments"), new SQLitePastImpressionStore(MediationConfigLoader.this.contextRef.getApp())));
} catch (InterruptedException e2) {
} catch (ExecutionException e3) {
} catch (JSONException e4) {
}
} catch (JSONException e5) {
retry();
}
}
@Override
public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
MediationConfigLoader.this.headerActions.onHeaders(headerArr);
retry();
}
});
}
}, new RetryManager.ExponentialSchedule(2.0d, 4L, TimeUnit.SECONDS), this.executorService).start();
}
@Override
public void get(final ConfigLoader.MediationConfigListener mediationConfigListener) {
this.configurationCacheFuture.addListener(new Runnable() {
@Override
public void run() {
try {
mediationConfigListener.onConfigLoaded((MediationConfig) MediationConfigLoader.this.configurationCacheFuture.get());
} catch (InterruptedException e) {
Logger.trace((Throwable) e);
} catch (ExecutionException e2) {
Logger.trace((Throwable) e2);
}
}
}, ExecutorPool.getInstance());
}
public AdapterPool getPool() {
return this.adapterPool;
}
@Override
public ListenableFuture<MediationConfig> getFuture() {
return this.configurationCacheFuture;
}
public boolean isOnBoard(String str) {
return this.adapterPool.get(str) != null;
}
public static void storeConfigurationCache(Context context, JSONObject jSONObject) {
SharedPreferences.Editor edit = context.getSharedPreferences(Constants.PREFERENCES_KEY, 0).edit();
edit.putString(CONFIGURATION_CACHE_KEY, jSONObject.toString()).apply();
edit.putBoolean(CONFIGURATION_USED_KEY, false);
edit.apply();
}
private static JSONObject getConfigurationCache(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.PREFERENCES_KEY, 0);
String string = sharedPreferences.getString(CONFIGURATION_CACHE_KEY, "");
boolean z = sharedPreferences.getBoolean(CONFIGURATION_USED_KEY, true);
sharedPreferences.edit().putBoolean(CONFIGURATION_USED_KEY, true).apply();
if (string.equals("") || z) {
return null;
}
try {
return new JSONObject(string);
} catch (JSONException e) {
Logger.trace("MediationConfigLoader JSON Error!", e);
return null;
}
}
}