Idle Tower v2.48版本的 MD5 值为:56f20496f6a85726b376356ed2ecee23
以下内容为反编译后的 Yodo1MasAdConfigCheckHelper.java 源代码,内容仅作参考
package com.yodo1.mas.helper;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.vungle.warren.VungleApiClient;
import com.yodo1.mas.Yodo1MasLog;
import com.yodo1.mas.banner.Yodo1MasBannerHelper;
import com.yodo1.mas.debugger.main.Yodo1MasDebuggerItem;
import com.yodo1.mas.error.Yodo1MasError;
import com.yodo1.mas.utils.Yodo1MasUtils;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONException;
import org.json.JSONObject;
public class Yodo1MasAdConfigCheckHelper {
private static final long INTERVAL_TIME = 14400000;
private static final String TAG = "AdConfigCheckHelper";
private static Yodo1MasAdConfigCheckHelper helper;
private String latestAdConfig;
private long latestTime = 0;
private volatile boolean isGettingAdConfig = false;
private volatile boolean isWaitingForRest = false;
private Yodo1MasAdConfigCheckHelper() {
}
public static Yodo1MasAdConfigCheckHelper getInstance() {
if (helper == null) {
synchronized (Yodo1MasHelper.class) {
if (helper == null) {
helper = new Yodo1MasAdConfigCheckHelper();
}
}
}
return helper;
}
public boolean isWaitingForRest() {
return this.isWaitingForRest;
}
public void saveAdConfig(String str) {
if (TextUtils.isEmpty(str)) {
return;
}
this.latestAdConfig = str;
this.latestTime = System.currentTimeMillis();
Yodo1MasLog.d(TAG, "saveAdConfig: latestAdConfigTime : " + this.latestTime);
}
public void checkTheNewAdConfig(Activity activity, String str) {
if (this.isGettingAdConfig) {
Yodo1MasLog.d(TAG, "dealWithCheckNewAdConfig: current is doing get ad config no need do it again");
return;
}
if (this.isGettingAdConfig || this.latestTime == 0 || System.currentTimeMillis() - this.latestTime <= INTERVAL_TIME || !isNetworkConnected(activity)) {
return;
}
String sdkVersion = Yodo1MasHelper.getInstance().getSdkVersion();
String appVersion = Yodo1MasHelper.getInstance().getAppVersion(activity);
String appkey = Yodo1MasHelper.getInstance().getAppkey();
String gaid = Yodo1MasHelper.getInstance().getGaid();
this.latestTime = System.currentTimeMillis();
if (!TextUtils.isEmpty(sdkVersion) && !TextUtils.isEmpty(appVersion) && !TextUtils.isEmpty(appkey)) {
this.isGettingAdConfig = true;
getAdConfig(activity, appkey, sdkVersion, appVersion, gaid);
return;
}
Yodo1MasLog.d(TAG, "checkTheNewAdConfig: something is wrong and can not get ad config, sdkVersion:" + sdkVersion + " appVersion:" + appVersion + " appKey:" + appkey);
}
private boolean isNetworkConnected(Activity activity) {
NetworkInfo activeNetworkInfo;
return (activity == null || (activeNetworkInfo = ((ConnectivityManager) activity.getSystemService("connectivity")).getActiveNetworkInfo()) == null || !activeNetworkInfo.isConnected()) ? false : true;
}
public void getAdConfig(final Activity activity, String str, String str2, String str3, String str4) {
boolean metaData = Yodo1MasUtils.getMetaData((Context) activity, "com.yodo1.mas.DEBUG", false);
StringBuilder sb = new StringBuilder();
if (metaData) {
Yodo1MasLog.d(TAG, "getAdConfig: current is debug no need do the update action");
return;
}
Yodo1MasLog.d(TAG, "start get ad config...");
sb.append("https://sdk.mas.yodo1.com/v1/init/");
sb.append(str);
Headers.Builder builder = new Headers.Builder();
builder.add("sdk-version", str2);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("sdk_version", str2);
jSONObject.put(Yodo1MasDebuggerItem.KEY_APP_VERSION, str3);
if (!TextUtils.isEmpty(str4) && !Yodo1MasHelper.getInstance().isCOPPAAgeRestricted()) {
jSONObject.put(VungleApiClient.GAID, str4);
}
} catch (JSONException e) {
e.printStackTrace();
}
RequestBody create = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jSONObject.toString());
OkHttpClient okHttpClient = new OkHttpClient();
Request.Builder builder2 = new Request.Builder();
builder2.url(sb.toString());
builder2.headers(builder.build());
builder2.post(create);
okHttpClient.newCall(builder2.build()).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException iOException) {
Yodo1MasAdConfigCheckHelper.this.isGettingAdConfig = false;
Yodo1MasLog.d(Yodo1MasAdConfigCheckHelper.TAG, "onFailure: getAdConfig failed (Error Code: " + Yodo1MasError.CODE_CONFIG_NETWORK + ", " + iOException.getLocalizedMessage());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Yodo1MasLog.d(Yodo1MasAdConfigCheckHelper.TAG, "onResponse - code:" + response.code());
Yodo1MasAdConfigCheckHelper.this.isGettingAdConfig = false;
if (response.code() == 200) {
Yodo1MasLog.d(Yodo1MasAdConfigCheckHelper.TAG, "onResponse: getAdConfig successed");
ResponseBody body = response.body();
if (body != null) {
String string = body.string();
String formatAdConfig = Yodo1MasAdConfigCheckHelper.this.formatAdConfig(string);
Yodo1MasAdConfigCheckHelper yodo1MasAdConfigCheckHelper = Yodo1MasAdConfigCheckHelper.this;
String formatAdConfig2 = yodo1MasAdConfigCheckHelper.formatAdConfig(yodo1MasAdConfigCheckHelper.latestAdConfig);
if (formatAdConfig2 != null && !formatAdConfig2.equals(formatAdConfig)) {
Yodo1MasAdConfigCheckHelper.this.latestAdConfig = string;
if (Yodo1MasHelper.getInstance().isFullScreenAdShowing()) {
Yodo1MasAdConfigCheckHelper.this.isWaitingForRest = true;
Yodo1MasLog.d(Yodo1MasAdConfigCheckHelper.TAG, "There is an ad showing, mark it and waiting for the ad to close");
return;
} else {
Yodo1MasAdConfigCheckHelper.this.resetAds(activity, string);
return;
}
}
Yodo1MasLog.d(Yodo1MasAdConfigCheckHelper.TAG, "The content of ad config has not changed, no need to reset the Ads");
return;
}
Yodo1MasLog.d(Yodo1MasAdConfigCheckHelper.TAG, "getAdConfig failed (Error Code: -100501,body is null");
return;
}
Yodo1MasLog.d(Yodo1MasAdConfigCheckHelper.TAG, "getAdConfig failed (Error Code: -100501, response code:" + response.code() + " response message:" + response.message() + ")");
}
});
}
public String formatAdConfig(String str) {
if (TextUtils.isEmpty(str)) {
return null;
}
try {
JsonObject asJsonObject = JsonParser.parseString(str).getAsJsonObject();
if (asJsonObject.has("update_at")) {
asJsonObject.remove("update_at");
}
if (asJsonObject.has(Yodo1MasDebuggerItem.KEY_TEST_MODE)) {
asJsonObject.remove(Yodo1MasDebuggerItem.KEY_TEST_MODE);
}
return asJsonObject.toString();
} catch (Exception e) {
Yodo1MasLog.d(TAG, "formatAdConfig: error: " + e.getMessage());
return null;
}
}
public void resetAds(Activity activity, String str) {
Yodo1MasLog.d(TAG, "resetAds: ");
this.isWaitingForRest = false;
Yodo1MasBannerHelper.getInstance().resetAllYodo1MasBannerAdView(activity, true);
Yodo1MasBannerHelper.getInstance().setKeepCheckingV2(true);
Yodo1MasHelper.getInstance().resetAllAdsAdapters();
Yodo1MasHelper.getInstance().dealWithGetAdConfigResponse(activity, str, Yodo1MasUtils.getMetaData((Context) activity, "com.yodo1.mas.DEBUG", false), Yodo1MasUtils.getMetaData((Context) activity, "com.yodo1.mas.Config", false), null, Yodo1MasHelper.getInstance().getPackageName(activity));
}
public void resetAdsAfterAdShowEnd(Activity activity) {
Yodo1MasLog.d(TAG, "resetAdsAfterAdShowEnd: ");
resetAds(activity, this.latestAdConfig);
}
}