13Poker by gametower unlimited gems v0.4版本的 MD5 值为:51324fc0f195c34821074948ab266846
以下内容为反编译后的 AdsProviderImpl.java 源代码,内容仅作参考
package com.adeco.adsdk.mediation;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import com.adeco.adsdk.ads.util.FileCacheUtils;
import com.adeco.adsdk.mediation.AdsProvider;
import com.adeco.adsdk.model.Ad;
import com.adeco.adsdk.model.AdOptions;
import com.adeco.adsdk.model.AdParameters;
import com.adeco.adsdk.model.AppWall;
import com.adeco.adsdk.model.AppWallItem;
import com.adeco.adsdk.model.InterstitialAd;
import com.adeco.adsdk.net.ServerCommunicationException;
import com.adeco.adsdk.net.ServerGateway;
import com.flurry.android.AdCreative;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class AdsProviderImpl extends AdsProvider {
private static final long EXPIRE_TIME = 600000;
private static final String LOGTAG = "AdsProvider";
private static final String PREFERENCE_LAST_DATE = "com.adeco.adsdk.mediation.AdsController.PREFERENCE_DATE";
private static final String REQUEST_AD_URL = "http://ads.net2share.com/adnetworks/index.jsp";
private static final String REQUEST_DIALOG_URL = "http://ads.net2share.com/ad/1.0/ad.json?request_type=dialog";
private static final String REQUEST_INTERSTITIAL_URL = "http://ads.net2share.com/ad/1.0/ad.json?request_type=interstitial";
private static final String REQUEST_URL = "http://ads.net2share.com/ad/1.0/ad.json?request_type=mma";
private static final String REQUEST_VIDEO_URL = "http://ads.net2share.com/ad/1.0/ad.json?request_type=video";
private final Context context;
private static AdsProviderImpl singleton = null;
private static final ScheduledThreadPoolExecutor EXECUTOR = new ScheduledThreadPoolExecutor(5);
private final List<AdsProviderTask> tasks = new ArrayList();
private final Handler handler = new Handler(Looper.getMainLooper());
public static String buildUri(String baseUri, Map<String, String> httpParams) {
Uri.Builder b = Uri.parse(baseUri).buildUpon();
for (Map.Entry<String, String> e : httpParams.entrySet()) {
b.appendQueryParameter(e.getKey(), e.getValue() != null ? URLEncoder.encode(e.getValue()) : "");
}
return b.build().toString();
}
public static abstract class AdsProviderTask implements Runnable {
private AdsProvider.Callback callback;
private boolean canceled;
private final Handler handler = new Handler(Looper.getMainLooper());
private final AdParameters params;
private final AdsProviderImpl provider;
private AdsProvider.Result result;
private final AdsProvider.Result.Type type;
protected abstract void doLoad(Map<String, Object> map) throws ServerCommunicationException;
AdsProviderTask(AdsProvider.Result.Type type, AdParameters params, AdsProviderImpl parent) {
this.type = type;
this.provider = parent;
if (params == null) {
throw new NullPointerException();
}
this.params = params;
}
public AdParameters getParams() {
return this.params;
}
public void setCallback(AdsProvider.Callback callback) {
this.callback = callback;
}
public AdsProvider.Result execute() {
boolean success = true;
Map<String, Object> extra = new HashMap<>();
extra.put(AdsProvider.EXTRA_FROM, this.callback);
try {
doLoad(extra);
} catch (ServerCommunicationException e) {
extra.put(AdsProvider.EXTRA_ERROR, e);
success = false;
}
return new AdsProvider.Result(this.type, extra, success);
}
@Override
public void run() {
if (!isCanceled()) {
this.result = execute();
this.handler.post(new Runnable() {
@Override
public void run() {
AdsProviderTask.this.onPostExecute(AdsProviderTask.this.result);
}
});
}
}
public void cancel() {
this.canceled = true;
}
public boolean isCanceled() {
return this.canceled;
}
protected void onPostExecute(AdsProvider.Result result) {
if (!isCanceled()) {
this.provider.onTaskExecuted(this, result);
if (this.callback != null) {
this.callback.onResult(this.provider, result);
}
}
}
public AdsProvider.Callback getCallback() {
return this.callback;
}
}
private static class RetreiveOptionsTask<T extends Ad> extends AdsProviderTask {
private static final String CACHE_OPTIONS = "com.adeco.adsdk.mediation.AdsController.RetreiveOptionsTask.CACHE_OPTIONS1";
private static final String SHARED_PREFERENCES = "com.adeco.adsdk.mediation.AdsController.AdsProviderTask.SHARED_PREFERENCES1";
private final Class<? extends Ad> adClass;
private final Context context;
private final String key;
private final SharedPreferences prefs;
private final String url;
RetreiveOptionsTask(AdsProviderImpl parent, AdParameters params, Context context, String url, Class<? extends Ad> adClass, String key) {
super(AdsProvider.Result.Type.OPTIONS, params, parent);
this.prefs = context.getSharedPreferences(SHARED_PREFERENCES, 0);
this.context = context;
this.url = url;
this.adClass = adClass;
this.key = key;
}
private String getCacheOptionsKey(AdParameters params) {
return params.getUniqueKey(CACHE_OPTIONS + this.adClass.getName() + this.key);
}
private String getPreferenceLastDateKey(AdParameters params) {
return params.getUniqueKey(AdsProviderImpl.PREFERENCE_LAST_DATE + this.adClass.getName() + this.key);
}
@Override
protected void doLoad(Map<String, Object> extras) throws ServerCommunicationException {
synchronized (RetreiveOptionsTask.class) {
AdOptions<T> opt = null;
long prevDate = this.prefs.getLong(getPreferenceLastDateKey(getParams()), 0L);
if (Math.abs(System.currentTimeMillis() - prevDate) < 600000) {
opt = (AdOptions) FileCacheUtils.get(getCacheOptionsKey(getParams()), this.context);
}
if (opt == null) {
Map<String, String> httpParams = getParams().buildParams();
httpParams.putAll(AdsProviderImpl.getDeviceParams(this.context));
httpParams.put("event", "r");
JSONObject object = ServerGateway.getInstance().sendGetRequestJSON(AdsProviderImpl.buildUri(this.url, httpParams), null);
try {
opt = AdOptions.parse(object, this.adClass);
this.prefs.edit().putLong(getPreferenceLastDateKey(getParams()), System.currentTimeMillis()).commit();
FileCacheUtils.put(opt, getCacheOptionsKey(getParams()), this.context);
} catch (JSONException e) {
throw new ServerCommunicationException(4, e);
}
}
extras.put(AdsProvider.EXTRA_AD_OPTIONS, opt);
}
}
@Override
protected void onPostExecute(AdsProvider.Result result) {
super.onPostExecute(result);
}
}
private static class LoadAppWallTask extends AdsProviderTask {
private static final String SHARED_PREFERENCES = "com.adeco.adsdk.mediation.AdsController.LoadApPWallTask.SHARED_PREFERENCES1";
private final Context context;
LoadAppWallTask(AdsProvider.Result.Type type, AdParameters params, AdsProviderImpl parent, Context context) {
super(type, params, parent);
this.context = context;
}
private String getPreferenceLastDateKey(AdParameters params) {
return params.getUniqueKey("com.adeco.adsdk.mediation.AdsController.PREFERENCE_DATEappwall");
}
private String getCacheOptionsKey(AdParameters params) {
return params.getUniqueKey("com.adeco.adsdk.mediation.AdsController.CACHEappwall");
}
@Override
protected void doLoad(Map<String, Object> extras) throws ServerCommunicationException {
AppWall appWall;
AppWall appWall2;
extras.put(AdsProvider.EXTRA_FROM, getCallback());
SharedPreferences prefs = this.context.getSharedPreferences(SHARED_PREFERENCES, 0);
long prevDate = prefs.getLong(getPreferenceLastDateKey(getParams()), 0L);
if (Math.abs(System.currentTimeMillis() - prevDate) >= 600000) {
appWall = null;
} else {
AppWall appWall3 = (AppWall) FileCacheUtils.get(getCacheOptionsKey(getParams()), this.context);
appWall = appWall3;
}
if (appWall == null) {
Map<String, String> httpParams = getParams().buildParams();
httpParams.putAll(AdsProviderImpl.getDeviceParams(this.context));
httpParams.put("event", "r");
String url = AdsProviderImpl.buildUri("http://ads.net2share.com/temporary_api/1.0/ad.json?type=app&incent=false", httpParams);
JSONObject response = ServerGateway.getInstance().sendGetRequestJSON(url, null);
try {
ArrayList<AppWallItem> itemList = new ArrayList<>();
JSONArray items = response.getJSONArray("campaings");
for (int i = 0; i < items.length(); i++) {
JSONObject item = items.getJSONObject(i);
itemList.add(new AppWallItem(item.getDouble("payout"), item.getString("description"), item.getString("title"), item.getString("packagename"), new String[0], item.getString("type"), item.getString("icon"), item.getString("link")));
}
JSONObject globalOpt = response.getJSONObject("global_opt");
appWall2 = new AppWall(globalOpt.getBoolean("incent"), globalOpt.getString("title"), itemList);
} catch (JSONException e) {
e = e;
}
try {
prefs.edit().putLong(getPreferenceLastDateKey(getParams()), System.currentTimeMillis()).commit();
FileCacheUtils.put(appWall2, getCacheOptionsKey(getParams()), this.context);
} catch (JSONException e2) {
e = e2;
throw new ServerCommunicationException(4, e);
}
} else {
appWall2 = appWall;
}
extras.put("com.adeco.adsdk.mediation.AdsProvider.EXTRA_AD", appWall2);
}
}
private static class LoadAdTask extends AdsProviderTask {
private final Context activity;
private final Ad ad;
LoadAdTask(AdsProviderImpl parent, Ad ad, AdParameters params, Context activity) {
super(AdsProvider.Result.Type.AD, params, parent);
this.activity = activity;
this.ad = ad;
}
@Override
protected void doLoad(Map<String, Object> extras) throws ServerCommunicationException {
extras.put("com.adeco.adsdk.mediation.AdsProvider.EXTRA_AD", this.ad);
extras.put(AdsProvider.EXTRA_FROM, getCallback());
Map<String, String> httpParams = getParams().buildParams();
httpParams.putAll(AdsProviderImpl.getDeviceParams(this.activity));
httpParams.put("network", this.ad.getName());
int i = 1;
for (String key : this.ad.getKeys()) {
httpParams.put("reg" + i, key);
i++;
}
httpParams.put("event", "r");
String url = AdsProviderImpl.buildUri(AdsProviderImpl.REQUEST_AD_URL, httpParams);
String response = ServerGateway.getInstance().sendGetRequestString(url);
extras.put(AdsProvider.EXTRA_AD_DATA, response);
extras.put(AdsProvider.EXTRA_AD_BASE_URL, response);
}
}
public AdsProviderImpl(Context context) {
this.context = context.getApplicationContext();
}
private synchronized void execute(final AdsProviderTask task, AdsProvider.Callback callback) {
task.setCallback(callback);
this.handler.post(new Runnable() {
@Override
public void run() {
AdsProviderImpl.this.tasks.add(task);
ThreadPoolExecutor executor = AdsProviderImpl.EXECUTOR;
executor.execute(task);
}
});
}
private AdsProvider.Result executeSync(AdsProviderTask task) throws ServerCommunicationException {
validateNotAppThread();
AdsProvider.Result result = task.execute();
if (!result.success()) {
throw ((ServerCommunicationException) result.getExtras().get(AdsProvider.EXTRA_ERROR));
}
return result;
}
@Override
public synchronized void cancel(AdsProvider.Callback callback) {
Iterator<AdsProviderTask> it = this.tasks.iterator();
while (it.hasNext()) {
AdsProviderTask task = it.next();
if (task.callback == callback) {
it.remove();
task.cancel();
}
}
}
private final void validateNotAppThread() {
if (Looper.getMainLooper() == Looper.myLooper()) {
throw new RuntimeException("This method can not be called from the main application thread");
}
}
@Override
public void retreiveAdOptions(AdsProvider.Callback callback, AdParameters params) {
execute(new RetreiveOptionsTask(this, params, this.context, REQUEST_URL, Ad.class, AdCreative.kFormatBanner), callback);
}
@Override
public AdsProvider.Result retreiveAdOptionsSync(AdParameters params) throws ServerCommunicationException {
return executeSync(new RetreiveOptionsTask(this, params, this.context, REQUEST_URL, Ad.class, AdCreative.kFormatBanner));
}
@Override
public void retreiveInterstitialOptions(AdsProvider.Callback callback, AdParameters params) {
execute(new RetreiveOptionsTask(this, params, this.context, REQUEST_INTERSTITIAL_URL, InterstitialAd.class, "interstitial"), callback);
}
@Override
public AdsProvider.Result retreiveInterstitialOptionsSync(AdParameters params) throws ServerCommunicationException {
return executeSync(new RetreiveOptionsTask(this, params, this.context, REQUEST_INTERSTITIAL_URL, InterstitialAd.class, "interstitial"));
}
@Override
public void loadAd(Ad ad, AdParameters params, AdsProvider.Callback callback) {
execute(new LoadAdTask(this, ad, params, this.context), callback);
}
@Override
public AdsProvider.Result loadAdSync(Ad ad, AdParameters params) throws ServerCommunicationException {
return executeSync(new LoadAdTask(this, ad, params, this.context));
}
void onTaskExecuted(AdsProviderTask task, AdsProvider.Result result) {
if (this.tasks.contains(task)) {
this.tasks.remove(task);
}
}
@Override
public AdsProvider.Result retreiveDialogOptionsSync(AdParameters params) throws ServerCommunicationException {
return executeSync(new RetreiveOptionsTask(this, params, this.context, REQUEST_DIALOG_URL, InterstitialAd.class, "dialog"));
}
@Override
public AdsProvider.Result retreiveVideoOptionsSync(AdParameters params) throws ServerCommunicationException {
return executeSync(new RetreiveOptionsTask(this, params, this.context, REQUEST_VIDEO_URL, InterstitialAd.class, "dialog"));
}
@Override
public AdsProvider.Result loadAppWallSync(AdParameters params) throws ServerCommunicationException {
return executeSync(new LoadAppWallTask(AdsProvider.Result.Type.APP_WALL, params, this, this.context));
}
}