MD5 校验值:27cf44ec6e0720408f5ef017a90a3331
GetCtrlInfoTask.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.gau.go.gostaticsdk.scheduler; import android.content.Context; import android.content.SharedPreferences; import com.gau.go.gostaticsdk.StatisticsManager; import com.gau.go.gostaticsdk.beans.CtrlBean; import com.gau.go.gostaticsdk.utiltool.UtilTool; import com.jiubang.commerce.mopub.dilute.MopubDiluteCfg; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Random; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class GetCtrlInfoTask extends SchedulerTask { private static final String COMMA = ","; private static String CTRLINFO_DEBUG_URL = "http://61.145.124.212:8084/GOClientData/DC"; private static final String CTRLINFO_THREAD_NAME = "get_ctrlinfo_thread"; private static final String CTRLINFO_URL = "http://goupdate.3g.cn/GOClientData/DC"; private static final String DEBUG_CTRL_INFO = "{\"ctrl_info\":[{\"bn\":\"20140808001\",\"country\":\"us,cn\",\"channel\":\"\",\"version_code\":\"\",\"os_version_code\":\"\",\"network\":\"0\",\"duration\":\"720\",\"user_type\":\"0\",\"user_ratio\":\"100\",\"stat_id\":\"201\",\"upload_cycle\":\"1\",\"valid_time\":\"1411603200\"},]}"; private static final String KEY = "get_ctrl_info_task"; private static final int MILL_PER_HOUR = 3600000; private static final String REQUEST_KEY_ANDROID_ID = "android_id"; private static final String REQUEST_KEY_PRD_ID = "prd_id"; private static final String REQUEST_KEY_VERSION = "version"; public static final String SP_USER_RATIO = "user_ratio"; public static final int USER_RATIO_MAX = 100; private static final int USER_TYPE_ALL = 0; private static final String VERSION_NAME_V120 = "20150723"; private GetCtrlInfoCallBack mCallBack; private Context mContext; private int mUserRatio = -1; private boolean httpConnectedOK = false; private String lastUri = ""; private String requestInfo = ""; public boolean mIsNetWorkOK = false; public interface GetCtrlInfoCallBack { void onFinish(Map<String, CtrlBean> map, boolean z); void onStart(); } public GetCtrlInfoTask(Context context, long j, long j2) { setKey(context, KEY); this.mContext = context; initUserRatio(context); setIntervalTime(j2); setStartTime(System.currentTimeMillis() + j); } public int initUserRatio(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences("ctrl_sp", 0); if (!sharedPreferences.contains(SP_USER_RATIO)) { SharedPreferences sharedPreferences2 = context.getSharedPreferences(StatisticsManager.CTRL_SP_NAME + context.getPackageName(), 0); SharedPreferences.Editor edit = sharedPreferences2.edit(); this.mUserRatio = sharedPreferences2.getInt(SP_USER_RATIO, -1); if (this.mUserRatio == -1) { this.mUserRatio = new Random().nextInt(100); edit.putInt(SP_USER_RATIO, this.mUserRatio); edit.commit(); } } else { this.mUserRatio = sharedPreferences.getInt(SP_USER_RATIO, -1); SharedPreferences sharedPreferences3 = context.getSharedPreferences(StatisticsManager.CTRL_SP_NAME + context.getPackageName(), 0); if (this.mUserRatio != -1) { SharedPreferences.Editor edit2 = sharedPreferences3.edit(); edit2.putInt(SP_USER_RATIO, this.mUserRatio); edit2.commit(); sharedPreferences.edit().remove(SP_USER_RATIO).commit(); } } return this.mUserRatio; } public void setmCallBack(GetCtrlInfoCallBack getCtrlInfoCallBack) { this.mCallBack = getCtrlInfoCallBack; } @Override public void execute() { new Thread(CTRLINFO_THREAD_NAME) { @Override public void run() { Map<String, CtrlBean> map = null; if (GetCtrlInfoTask.this.mCallBack != null) { GetCtrlInfoTask.this.mCallBack.onStart(); } if (GetCtrlInfoTask.this.mIsNetWorkOK) { String ctrlInfo = GetCtrlInfoTask.this.getCtrlInfo(); if (UtilTool.isStringNoValue(ctrlInfo)) { GetCtrlInfoTask.this.httpConnectedOK = false; } else { GetCtrlInfoTask.this.httpConnectedOK = true; map = GetCtrlInfoTask.this.parsedCtrlInfo(ctrlInfo); GetCtrlInfoTask.this.writeCtrlInfoToFile(ctrlInfo, map); } GetCtrlInfoTask.this.mCallBack.onFinish(map, GetCtrlInfoTask.this.httpConnectedOK); return; } GetCtrlInfoTask.this.httpConnectedOK = false; GetCtrlInfoTask.this.mCallBack.onFinish(null, GetCtrlInfoTask.this.httpConnectedOK); } }.start(); } public void writeCtrlInfoToFile(String str, Map<String, CtrlBean> map) { StringBuffer stringBuffer = new StringBuffer("\r\n\r\n\r\nTime:" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date(System.currentTimeMillis())) + "\r\nConnect uri:" + this.lastUri + "\r\n" + str + "\r\n"); stringBuffer.append("RequestInfo:" + this.requestInfo + "\r\n"); stringBuffer.append("UserInfo: userRatio:" + this.mUserRatio + ", userContry:" + StatisticsManager.sCountry + "\r\n"); stringBuffer.append("Newest ctrlBean In DB:"); for (String str2 : map.keySet()) { stringBuffer.append("\r\n"); CtrlBean ctrlBean = map.get(str2); String bn = ctrlBean.getBn(); String updateTime = ctrlBean.getUpdateTime(); stringBuffer.append("[ctrlBean: funid:" + ctrlBean.getFunID() + ", bn:" + bn + ", updateTime:" + updateTime + ", priority:" + ctrlBean.getPriority() + ", interval:" + ctrlBean.getIntervalTime() + ", validTime:" + ctrlBean.getValidTime() + "]"); } try { FileOutputStream openFileOutput = this.mContext.openFileOutput("CtrlInfoLog.txt", 32768); openFileOutput.write(stringBuffer.toString().getBytes()); openFileOutput.close(); } catch (Exception e) { } } public Map<String, CtrlBean> parsedCtrlInfo(String str) { HashMap hashMap = new HashMap(); try { JSONArray jSONArray = new JSONObject(str).getJSONArray("ctrl_info"); int i = 0; while (true) { int i2 = i; if (i2 >= jSONArray.length()) { break; } JSONObject jSONObject = (JSONObject) jSONArray.opt(i2); String string = jSONObject.getString("bn"); String string2 = jSONObject.getString(MopubDiluteCfg.COUNTRY); String string3 = jSONObject.getString("channel"); String string4 = jSONObject.getString("version_code"); String string5 = jSONObject.getString("os_version_code"); int i3 = jSONObject.getInt("network"); long j = jSONObject.getLong("valid_time"); int i4 = jSONObject.getInt("user_type"); int i5 = jSONObject.getInt(SP_USER_RATIO); String string6 = jSONObject.getString("stat_id"); String string7 = jSONObject.getString("upload_cycle"); String string8 = jSONObject.getString("update_time"); int i6 = jSONObject.getInt(LogFactory.PRIORITY_KEY); if (isUserRatioFit(i5) && isCountryFit(string2) && isChannelFit(string3) && isVersionCodeFit(string4) && isOsVersionCodeFit(string5) && isUserTypeFit(i4)) { long longValue = 3600000 * Long.valueOf(string7).longValue(); if (!UtilTool.isStringNoValue(string6)) { for (String str2 : string6.split(COMMA)) { if (!UtilTool.isStringNoValue(str2)) { putCtrlBean(hashMap, new CtrlBean(j, longValue, string, string8, Integer.valueOf(str2.trim()).intValue(), System.currentTimeMillis(), i3, i6)); } } } } i = i2 + 1; } } catch (Error e) { } catch (JSONException e2) { e2.printStackTrace(); } return hashMap; } private void putCtrlBean(Map<String, CtrlBean> map, CtrlBean ctrlBean) { CtrlBean ctrlBean2 = map.get(String.valueOf(ctrlBean.getFunID())); if (ctrlBean2 == null || ctrlBean2.getPriority() < ctrlBean.getPriority()) { map.put(String.valueOf(ctrlBean.getFunID()), ctrlBean); } } private boolean isUserTypeFit(int i) { if (i == 0) { return true; } return StatisticsManager.sIsNew; } private boolean isUserRatioFit(int i) { if (this.mUserRatio == -1) { initUserRatio(this.mContext); } return this.mUserRatio < i; } private boolean isOsVersionCodeFit(String str) { return isInfoFit(String.valueOf(StatisticsManager.sOSVersionCode), str); } private boolean isVersionCodeFit(String str) { return isInfoFit(String.valueOf(StatisticsManager.sVersionCode), str); } private boolean isChannelFit(String str) { return isInfoFit(StatisticsManager.sChannel, str); } private boolean isCountryFit(String str) { return isInfoFit(StatisticsManager.sCountry, str); } private boolean isInfoFit(String str, String str2) { if (UtilTool.isStringNoValue(str2) || UtilTool.isStringNoValue(str)) { return true; } for (String str3 : str2.split(COMMA)) { if (str3.trim().equalsIgnoreCase(str)) { return true; } } return false; } public String getCtrlInfo() { HttpPost httpPost; if (StatisticsManager.sDebugMode) { httpPost = new HttpPost(CTRLINFO_DEBUG_URL); } else { httpPost = new HttpPost(CTRLINFO_URL); } if (StatisticsManager.sDebugMode) { UtilTool.log(StatisticsManager.TAG, "get ctrl info url: " + CTRLINFO_DEBUG_URL); } try { this.requestInfo = getCtrlInfoParams(); if (StatisticsManager.sDebugMode) { UtilTool.log(StatisticsManager.TAG, "get ctrl info requestInfo: " + this.requestInfo); } this.lastUri = httpPost.getURI().toString(); httpPost.setEntity(new StringEntity(this.requestInfo)); HttpResponse execute = new DefaultHttpClient().execute(httpPost); if (execute.getStatusLine().getStatusCode() != 200) { return null; } String entityUtils = EntityUtils.toString(execute.getEntity()); if (StatisticsManager.sDebugMode) { UtilTool.log(StatisticsManager.TAG, "get ctrl info: " + entityUtils); return entityUtils; } return entityUtils; } catch (Exception e) { UtilTool.printException(e); return null; } catch (Throwable th) { return null; } } private String getCtrlInfoParams() { JSONArray jSONArray = new JSONArray(); JSONObject jSONObject = new JSONObject(); try { jSONObject.put(REQUEST_KEY_PRD_ID, this.mContext.getPackageName()); jSONObject.put(REQUEST_KEY_ANDROID_ID, StatisticsManager.sAndroidId); jSONObject.put("version", VERSION_NAME_V120); jSONArray.put(jSONObject); } catch (Exception e) { } return jSONArray.toString(); } }