Mad Aces v1.2.2.3版本的 MD5 值为:f29ebd7c5808053d9f3f3722a5db1688
以下内容为反编译后的 MediatedDisplayConfigLoader.java 源代码,内容仅作参考
package com.heyzap.mediation.display;
import android.content.Context;
import android.util.DisplayMetrics;
import com.heyzap.common.concurrency.ExecutorPool;
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.ContextReference;
import com.heyzap.internal.Logger;
import com.heyzap.internal.RetryManager;
import com.heyzap.mediation.display.DisplayConfig;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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 MediatedDisplayConfigLoader implements DisplayConfigLoader {
protected static final int ATTEMPTS_BEFORE_CACHE = 3;
private static final String MEDIATION_CACHE_KEY = "mediation_cache";
private static final String SHARED_PREFS = "heyzap.mediation_display_config_loader";
private final ContextReference contextRef;
private SettableFuture<DisplayConfig> currentConfigFuture;
private final ScheduledExecutorService scheduledExecutorService;
public MediatedDisplayConfigLoader(ContextReference contextReference) {
this(contextReference, ExecutorPool.getInstance());
}
public MediatedDisplayConfigLoader(ContextReference contextReference, ScheduledExecutorService scheduledExecutorService) {
this.contextRef = contextReference;
this.scheduledExecutorService = scheduledExecutorService;
}
public void start() {
fetchNext();
}
@Override
public SettableFuture<DisplayConfig> peek() {
return this.currentConfigFuture;
}
@Override
public synchronized SettableFuture<DisplayConfig> consume() {
SettableFuture<DisplayConfig> settableFuture;
settableFuture = this.currentConfigFuture;
fetchNext();
return settableFuture;
}
public static DisplayConfig makeDisplayConfig(Context context, JSONObject jSONObject) throws JSONException {
DisplayConfig displayConfig = new DisplayConfig(jSONObject, context);
HashMap hashMap = new HashMap();
for (DisplayConfig.Network network : displayConfig.networks) {
if (!hashMap.containsKey(network.creativeType)) {
hashMap.put(network.creativeType, new ArrayList());
}
((List) hashMap.get(network.creativeType)).add(network.network);
}
return displayConfig;
}
protected static JSONObject getMediateCache(Context context) {
String string = context.getSharedPreferences(SHARED_PREFS, 0).getString(MEDIATION_CACHE_KEY, "");
if (string.equals("")) {
return null;
}
try {
return new JSONObject(string);
} catch (JSONException e) {
return null;
}
}
protected static void storeMediateCache(Context context, JSONObject jSONObject) {
context.getSharedPreferences(SHARED_PREFS, 0).edit().putString(MEDIATION_CACHE_KEY, jSONObject.toString()).apply();
}
private void fetchNext() {
SettableFuture<DisplayConfig> create = SettableFuture.create();
this.currentConfigFuture = create;
new RetryManager(new AnonymousClass1(create, getParams()), new RetryManager.ExponentialSchedule(1.5d, 5L, TimeUnit.SECONDS), this.scheduledExecutorService).start();
}
public class AnonymousClass1 extends RetryManager.RetryableTask {
private int attempts = 1;
final SettableFuture val$displayConfigFuture;
final RequestParams val$params;
AnonymousClass1(SettableFuture settableFuture, RequestParams requestParams) {
this.val$displayConfigFuture = settableFuture;
this.val$params = requestParams;
}
@Override
public boolean retry() {
if (this.attempts >= 3) {
JSONObject mediateCache = MediatedDisplayConfigLoader.getMediateCache(MediatedDisplayConfigLoader.this.contextRef.getApp());
if (mediateCache != null) {
try {
this.val$displayConfigFuture.set(MediatedDisplayConfigLoader.makeDisplayConfig(MediatedDisplayConfigLoader.this.contextRef.getApp(), mediateCache));
} catch (JSONException e) {
}
return false;
}
this.attempts = 1;
return super.retry();
}
this.attempts++;
return super.retry();
}
@Override
public void run() {
APIClient.get(MediatedDisplayConfigLoader.this.contextRef.getApp(), "https://med.heyzap.com/mediate", this.val$params, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int i, Header[] headerArr, JSONObject jSONObject) {
try {
DisplayConfig makeDisplayConfig = MediatedDisplayConfigLoader.makeDisplayConfig(MediatedDisplayConfigLoader.this.contextRef.getApp(), jSONObject);
MediatedDisplayConfigLoader.storeMediateCache(MediatedDisplayConfigLoader.this.contextRef.getApp(), jSONObject);
AnonymousClass1.this.val$displayConfigFuture.set(makeDisplayConfig);
} catch (JSONException e) {
Logger.log("Display config loader got json exception", e);
if (!AnonymousClass1.this.val$displayConfigFuture.isDone()) {
AnonymousClass1.this.retry();
}
}
}
@Override
public void onFailure(int i, Header[] headerArr, byte[] bArr, Throwable th) {
Logger.log("Display config loader failed to load /mediate", Integer.valueOf(i), th);
if (!AnonymousClass1.this.val$displayConfigFuture.isDone()) {
AnonymousClass1.this.retry();
}
}
});
}
}
private RequestParams getParams() {
RequestParams requestParams = new RequestParams();
DisplayMetrics displayMetrics = this.contextRef.getApp().getResources().getDisplayMetrics();
int i = displayMetrics.heightPixels;
int i2 = displayMetrics.widthPixels;
requestParams.put("orientation", displayMetrics.widthPixels > displayMetrics.heightPixels ? "landscape" : "portrait");
return requestParams;
}
}