OurPlay v5.5.9版本的 MD5 值为:d4e139798f4c2243a1145c8af5e21046
以下内容为反编译后的 ProxyDelayService.java 源代码,内容仅作参考
package com.excelliance.kxqp.gs.service;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import com.alipay.sdk.util.i;
import com.excelliance.kxqp.annotation.ChildThread;
import com.excelliance.kxqp.gs.bean.CityBean;
import com.excelliance.kxqp.gs.bean.PingIpInfo;
import com.excelliance.kxqp.gs.bean.ProxyConfigHelper;
import com.excelliance.kxqp.gs.bean.ReginBean;
import com.excelliance.kxqp.gs.k.b;
import com.excelliance.kxqp.gs.thpool.tp;
import com.excelliance.kxqp.gs.util.aq;
import com.excelliance.kxqp.gs.util.ay;
import com.excelliance.kxqp.gs.util.az;
import com.excelliance.kxqp.gs.util.bd;
import com.excelliance.kxqp.gs.util.bf;
import com.excelliance.kxqp.gs.util.by;
import com.excelliance.kxqp.gs.util.cd;
import com.excelliance.kxqp.gs.util.cn;
import com.excelliance.kxqp.gs.util.s;
import com.excelliance.kxqp.util.aj;
import com.umeng.union.internal.d;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ProxyDelayService extends Service {
private int d;
private static final ConcurrentHashMap<String, ConcurrentHashMap<String, Float>> f8211b = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, Float> c = new ConcurrentHashMap<>();
public static final List<String> f8210a = new ArrayList();
@Override
public IBinder onBind(Intent intent) {
return null;
}
static {
f8210a.add("com.exce.wv");
f8210a.add("com.android.vending");
f8210a.add("com.google.android.gms");
f8210a.add("com.excean.android.vending");
f8210a.add("com.excean.gspace.vip");
f8210a.add("com.excean.gspace.google.card");
f8210a.add("com.excean.gspace.google.account");
f8210a.add("com.google.android.play.games");
}
public static void a(String str, float f) {
if (c != null) {
synchronized (c) {
c.put(str, Float.valueOf(f));
}
}
}
public static float a(String str) {
Float f;
float floatValue = (c == null || (f = c.get(str)) == null) ? 10000.0f : f.floatValue();
az.d("ttlDelay", "key delay:" + floatValue);
return floatValue;
}
@Override
public void onCreate() {
super.onCreate();
Log.d("ProxyDelayService", "onCreate: ");
}
@Override
public int onStartCommand(Intent intent, int i, int i2) {
az.d("ProxyDelayService", "onStartCommand: startId:" + i2);
this.d = i2;
if (intent != null) {
String action = intent.getAction();
az.a();
az.d("ProxyDelayService", "action:" + action);
if ("com.excean.gspace.check_local_proxy_delay".equals(action)) {
d(intent.getStringExtra("netAp"));
} else if ("com.excean.gspace.game_server_delay_config".equals(action)) {
a(intent);
} else if ("com.excean.gspace.check_app_video_type".equals(action)) {
d();
}
}
return super.onStartCommand(intent, i, i2);
}
public void b(final String str) {
az.i("ProxyDelayService", "checkAllIpTtlDelay netAp:" + str);
tp.f(new Runnable() {
@Override
public void run() {
ReginBean reginBean;
ReginBean reginBean2;
Map<String, List<ReginBean>> e = b.a().e();
Map<String, List<ReginBean>> d = b.a().d();
if (s.a(e) && s.a(d)) {
return;
}
HashMap hashMap = new HashMap();
HashMap hashMap2 = new HashMap();
Iterator<Map.Entry<String, List<ReginBean>>> it = e.entrySet().iterator();
while (it.hasNext()) {
List<ReginBean> value = it.next().getValue();
if (value != null && value.size() > 0 && (reginBean2 = value.get(0)) != null && !cd.a(reginBean2.ip) && !hashMap.containsKey(reginBean2.ip)) {
PingIpInfo pingIpInfo = new PingIpInfo();
pingIpInfo.ip = reginBean2.ip;
pingIpInfo.port = reginBean2.port;
pingIpInfo.ipType = PingIpInfo.IP_PLOY_TYPE_FLAG;
if (hashMap.containsKey(reginBean2.ip)) {
if (!hashMap2.containsKey(pingIpInfo)) {
hashMap2.put(pingIpInfo.ip, pingIpInfo);
}
} else {
az.i("ProxyDelayService", "checkAllIpTtlDelay ploy pingIpInfo:" + pingIpInfo);
hashMap2.put(pingIpInfo.ip, pingIpInfo);
hashMap.put(reginBean2.ip, pingIpInfo);
}
}
}
HashMap hashMap3 = new HashMap();
Iterator<Map.Entry<String, List<ReginBean>>> it2 = d.entrySet().iterator();
while (it2.hasNext()) {
List<ReginBean> value2 = it2.next().getValue();
if (value2 != null && value2.size() > 0 && (reginBean = value2.get(0)) != null && !cd.a(reginBean.ip)) {
PingIpInfo pingIpInfo2 = new PingIpInfo();
pingIpInfo2.ip = reginBean.ip;
pingIpInfo2.port = reginBean.port;
pingIpInfo2.ipType = PingIpInfo.IP_LOAD_TYPE_FLAG;
if (hashMap.containsKey(reginBean.ip)) {
if (!hashMap3.containsKey(pingIpInfo2)) {
hashMap3.put(pingIpInfo2.ip, pingIpInfo2);
}
} else {
az.i("ProxyDelayService", "checkAllIpTtlDelay load pingIpInfo:" + pingIpInfo2);
hashMap3.put(pingIpInfo2.ip, pingIpInfo2);
hashMap.put(reginBean.ip, pingIpInfo2);
}
}
}
if (s.a(hashMap)) {
return;
}
Iterator it3 = hashMap.entrySet().iterator();
while (it3.hasNext()) {
PingIpInfo pingIpInfo3 = (PingIpInfo) ((Map.Entry) it3.next()).getValue();
ProxyDelayService.a(pingIpInfo3, 0L);
if (hashMap2.containsKey(pingIpInfo3.ip)) {
ProxyDelayService.a(pingIpInfo3.ip + PingIpInfo.IP_PLOY_TYPE_FLAG, pingIpInfo3.delayTime);
}
if (hashMap3.containsKey(pingIpInfo3.ip)) {
ProxyDelayService.a(pingIpInfo3.ip + PingIpInfo.IP_LOAD_TYPE_FLAG, pingIpInfo3.delayTime);
}
}
ProxyDelayService.this.e(str);
}
});
}
@ChildThread
public static void a(PingIpInfo pingIpInfo, long j) {
BufferedReader bufferedReader;
boolean z;
pingIpInfo.delayTime = 2000.0f;
if (TextUtils.isEmpty(pingIpInfo.ip)) {
pingIpInfo.delayTime = 2000.0f;
return;
}
String str = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("ping -c 1 -w 500 " + pingIpInfo.ip).getInputStream()));
long currentTimeMillis = System.currentTimeMillis();
z = false;
long j2 = j;
while (true) {
if (j2 > 0) {
if (!bufferedReader.ready()) {
if (j2 > 0 && j2 < 5) {
break;
}
try {
Thread.sleep(5L);
j2 = (j - System.currentTimeMillis()) + currentTimeMillis;
if (j2 <= 0) {
z = bufferedReader.ready();
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
z = true;
break;
}
} else {
break;
}
}
} catch (Exception e2) {
az.d("ProxyDelayService", "pingIpDelay ip:" + pingIpInfo + " e:" + e2.getMessage());
e2.printStackTrace();
}
if (j > 0 && !z) {
Log.e("ProxyDelayService", "delay timeout " + j);
return;
}
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
if (readLine.contains("avg")) {
az.d("ProxyDelayService", "pingIpDelay ip:" + pingIpInfo + " str:" + readLine);
str = c(readLine);
}
}
az.d("ProxyDelayService", "pingIpDelay ip:" + pingIpInfo + " delay:" + str);
if (!TextUtils.isEmpty(str)) {
pingIpInfo.delayTime = Float.parseFloat(str);
}
az.d("ProxyDelayService", "pingIpDelay end ip:" + pingIpInfo);
}
private static String c(String str) {
int indexOf = str.indexOf("=");
if (indexOf <= 0) {
return null;
}
String substring = str.substring(0, indexOf);
String substring2 = str.substring(indexOf);
String[] split = substring.split("/");
String[] split2 = substring2.split("/");
for (int i = 0; i < split.length; i++) {
if (TextUtils.equals(split[i], "avg")) {
if (split2.length > i) {
return split2[i];
}
return null;
}
}
return null;
}
private void d() {
tp.f(new Runnable() {
@Override
public void run() {
try {
JSONObject j = cn.j(ProxyDelayService.this.getApplicationContext());
az.d("ProxyDelayService", "checkAppType request:" + cn.b(j.toString()));
String a2 = bd.a("https://sdk.ourplay.com.cn/appType.php", j.toString());
az.d("ProxyDelayService", "checkAppType response:" + a2);
az.d("ProxyDelayService", "------------------应用类型列表(如果包名包含在内,那么该应用是视频类应用)-----------------");
az.d("ProxyDelayService", cn.a(a2));
az.d("ProxyDelayService", "------------------end-----------------");
ProxyDelayService.a(ProxyDelayService.this.getApplicationContext(), a2);
ProxyDelayService.this.stopSelf(ProxyDelayService.this.d);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public static void a(Context context, String str) {
by.a(context, "sp_proxy_delay_config").a("sp_key_app_type_list", str);
}
private void a(final Intent intent) {
tp.f(new Runnable() {
@Override
public void run() {
Map<String, List<ReginBean>> d;
ReginBean reginBean;
String stringExtra = intent.getStringExtra("pkgs");
if (TextUtils.isEmpty(stringExtra)) {
return;
}
Context applicationContext = ProxyDelayService.this.getApplicationContext();
az.i("ProxyDelayService", "ProxyDelayService/checkGameProxyDelayConfig() called with: pkgs = 【" + stringExtra + "】");
if (ProxyDelayService.b(applicationContext).isEmpty()) {
ProxyDelayService.a(applicationContext);
}
if (TextUtils.isEmpty(stringExtra)) {
return;
}
JSONObject i = cn.i(applicationContext);
JSONArray jSONArray = new JSONArray();
if (stringExtra.contains(i.f491b)) {
for (String str : stringExtra.split(i.f491b)) {
if (!ProxyDelayService.f8210a.contains(str)) {
jSONArray.put(str);
}
}
} else if (!ProxyDelayService.f8210a.contains(stringExtra)) {
jSONArray.put(stringExtra);
}
az.d("ProxyDelayService", "pkgArr:" + jSONArray.toString());
JSONArray jSONArray2 = new JSONArray();
if (ProxyConfigHelper.getInstance(applicationContext) != null && (d = b.a().d()) != null && d.size() > 0) {
Iterator<Map.Entry<String, List<ReginBean>>> it = d.entrySet().iterator();
while (it.hasNext()) {
List<ReginBean> value = it.next().getValue();
if (value != null && value.size() > 0 && (reginBean = value.get(0)) != null) {
jSONArray2.put(reginBean.groupid);
}
}
}
az.d("ProxyDelayService", "groupids:" + jSONArray2.toString());
try {
i.put("pkgs", jSONArray);
i.put("groupids", jSONArray2);
az.d("ProxyDelayService", "request:" + i.toString());
az.d("ProxyDelayService", "checkGameProxyDelayConfig request:" + cn.b(i.toString()));
String a2 = bd.a("https://api.ourplay.com.cn/deloydload/ping", i.toString());
az.d("ProxyDelayService", "checkGameProxyDelayConfig response:" + a2);
String a3 = cn.a(a2);
az.d("ProxyDelayService", "------------------以下为应用的服务器延迟配置(游戏服务器到代理服务器延迟-》服务器下发)-----------------");
ProxyDelayService.a("ProxyDelayService", a3);
az.d("ProxyDelayService", "------------------end-----------------");
JSONObject optJSONObject = new JSONObject(a3).optJSONObject("data");
for (int i2 = 0; i2 < jSONArray.length(); i2++) {
String string = jSONArray.getString(i2);
JSONArray optJSONArray = optJSONObject.optJSONArray(string);
ProxyDelayService.a("ProxyDelayService", "delayConfig " + string + ":" + optJSONArray);
aj.a().a(by.a(applicationContext, "sp_proxy_delay_config").c(), string, optJSONArray.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
ProxyDelayService.this.stopSelf(ProxyDelayService.this.d);
}
});
}
public static void a(String str, String str2) {
if (az.isDebug) {
int length = str2.length();
int i = d.C0683d.f17582a;
int i2 = 0;
int i3 = 0;
while (i2 < 100) {
if (length > i) {
Log.e(str, str2.substring(i3, i));
i2++;
i3 = i;
i += d.C0683d.f17582a;
} else {
Log.e(str, str2.substring(i3, length));
return;
}
}
}
}
public static String a() {
float floatValue;
String str = "";
if (c != null) {
float f = -1.0f;
for (Map.Entry<String, Float> entry : c.entrySet()) {
String key = entry.getKey();
Float value = entry.getValue();
if (key.contains(PingIpInfo.IP_PLOY_TYPE_FLAG)) {
if (f == -1.0f) {
floatValue = value.floatValue();
} else if (value.floatValue() < f) {
floatValue = value.floatValue();
}
f = floatValue;
str = key;
}
}
}
az.d("ProxyDelayService", "getOptimalSpecialProxy:" + str);
return str;
}
public static ReginBean a(Context context, String str, boolean z) {
ReginBean reginBean;
List<CityBean> a2;
List<ReginBean> list;
JSONArray jSONArray;
boolean z2;
int i;
float f;
String a3 = aj.a().a(by.a(context, "sp_proxy_delay_config").c(), str);
az.d("ProxyDelayService", "getOptimalReginBean gameConfig:" + a3 + " isTempUseVipArea:" + z);
if (TextUtils.isEmpty(a3)) {
az.d("ProxyDelayService", "------------------没有找到最优节点,缺少游戏服务器延迟配置-----------------");
return null;
}
try {
jSONArray = new JSONArray(a3);
} catch (Exception e) {
e = e;
reginBean = null;
}
if (jSONArray.length() == 0) {
return null;
}
List<String> b2 = b(context);
if (!cn.l(context) && !z) {
z2 = false;
az.d("ProxyDelayService", "videoTypeList:" + b2);
reginBean = null;
for (i = 0; i < jSONArray.length(); i++) {
try {
JSONObject jSONObject = (JSONObject) jSONArray.get(i);
String optString = jSONObject.optString("groupid");
try {
f = Float.parseFloat(jSONObject.optString("delay"));
} catch (Exception e2) {
e2.printStackTrace();
f = 0.0f;
}
ReginBean configBeanByGroupId = ProxyConfigHelper.getInstance(context) != null ? ProxyConfigHelper.getConfigBeanByGroupId(b.a().d(), optString) : null;
if (configBeanByGroupId != null) {
if (!configBeanByGroupId.isHide() && !configBeanByGroupId.isShowOnly()) {
boolean z3 = configBeanByGroupId.vipgroup == 1;
if (z2 && !z3) {
az.d("ProxyDelayService", "当前VIP用户需要从高速节点中选择");
} else if (!aq.q() && aq.m() && z3) {
az.d("ProxyDelayService", "K版本两天前高速节点不能用");
az.d("ProxyDelayService", ":" + configBeanByGroupId);
} else if (!z2 && z3) {
az.d("ProxyDelayService", "当前免费用户不可选择高速节点");
az.d("ProxyDelayService", ":" + configBeanByGroupId);
} else if (!TextUtils.isEmpty(configBeanByGroupId.id) && configBeanByGroupId.id.contains("cn")) {
az.d("ProxyDelayService", "排除中国大陆节点");
az.d("ProxyDelayService", ":" + configBeanByGroupId);
} else if ((configBeanByGroupId.appType == 1) ^ b2.contains(str)) {
az.d("ProxyDelayService", "节点类型和应用类型不匹配(video和非video)");
az.d("ProxyDelayService", ":" + configBeanByGroupId);
} else {
float a4 = a(configBeanByGroupId.ip + PingIpInfo.IP_LOAD_TYPE_FLAG);
if (a4 == 0.0f) {
az.d("ProxyDelayService", "以下节点配置延迟不可用");
az.d("ProxyDelayService", ":" + configBeanByGroupId);
} else {
configBeanByGroupId.timeDelay = f + a4;
az.d("ProxyDelayService", " areaId:" + configBeanByGroupId.id + " delay:" + f + " ttlDelay:" + a4 + " ip:" + configBeanByGroupId.ip + " port:" + configBeanByGroupId.port + " pkg:" + str);
if (reginBean != null && configBeanByGroupId.timeDelay >= reginBean.timeDelay) {
}
reginBean = configBeanByGroupId;
}
}
}
az.d("ProxyDelayService", "当前排除隐藏的节点");
}
} catch (Exception e3) {
e = e3;
e.printStackTrace();
az.d("ProxyDelayService", "最优节点配置:" + reginBean);
if (reginBean == null) {
}
return reginBean;
}
}
az.d("ProxyDelayService", "最优节点配置:" + reginBean);
if (reginBean == null) {
Map<String, List<ReginBean>> d = b.a().d();
if (d != null && (a2 = ay.a(by.a(context, "sp_city_config").b("sp_city_config", ""), !aq.v())) != null && a2.size() > 0 && (list = d.get(a2.get(0).getId())) != null && list.size() > 0) {
return list.get(0);
}
az.d("ProxyDelayService", "------------------没有找到最优节点,也许是还没全部检测完呢-----------------");
}
return reginBean;
}
z2 = true;
az.d("ProxyDelayService", "videoTypeList:" + b2);
reginBean = null;
while (i < jSONArray.length()) {
}
az.d("ProxyDelayService", "最优节点配置:" + reginBean);
if (reginBean == null) {
}
return reginBean;
}
public static void a(Context context) {
Intent intent = new Intent("com.excean.gspace.check_app_video_type");
intent.setComponent(new ComponentName(context.getPackageName(), "com.excelliance.kxqp.gs.service.ProxyDelayService"));
try {
context.startService(intent);
} catch (Exception unused) {
}
}
public static void b(Context context, String str) {
Intent intent = new Intent("com.excean.gspace.game_server_delay_config");
intent.setComponent(new ComponentName(context.getPackageName(), "com.excelliance.kxqp.gs.service.ProxyDelayService"));
intent.putExtra("pkgs", str);
try {
context.startService(intent);
} catch (Exception unused) {
}
}
public static List<String> b(Context context) {
String a2 = cn.a(by.a(context, "sp_proxy_delay_config").b("sp_key_app_type_list", ""));
ArrayList arrayList = new ArrayList();
if (!TextUtils.isEmpty(a2)) {
try {
JSONArray optJSONArray = new JSONObject(a2).optJSONObject("data").optJSONArray("video");
for (int i = 0; i < optJSONArray.length(); i++) {
arrayList.add(optJSONArray.getString(i));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return arrayList;
}
public static void c(Context context) {
boolean b2 = bf.b(context);
String str = "other";
if (bf.a(context)) {
str = bf.d(context);
} else if (b2) {
str = bf.g(context);
}
Intent intent = new Intent("com.excean.gspace.check_local_proxy_delay");
intent.putExtra("netAp", str);
intent.setComponent(new ComponentName(context.getPackageName(), "com.excelliance.kxqp.gs.service.ProxyDelayService"));
try {
context.startService(intent);
} catch (Exception unused) {
}
}
private void d(final String str) {
tp.f(new Runnable() {
@Override
public void run() {
ConcurrentHashMap unused = ProxyDelayService.c = (ConcurrentHashMap) ProxyDelayService.f8211b.get(str);
if (ProxyDelayService.c == null) {
ConcurrentHashMap unused2 = ProxyDelayService.c = new ConcurrentHashMap();
ProxyDelayService.f8211b.put(str, ProxyDelayService.c);
}
ProxyDelayService.this.f(str);
if (ProxyConfigHelper.getInstance(ProxyDelayService.this.getApplicationContext()) != null) {
ProxyDelayService.this.b(str);
}
}
});
}
public synchronized void e(String str) {
if (c != null && c.size() > 0) {
JSONObject jSONObject = new JSONObject();
for (Map.Entry<String, Float> entry : c.entrySet()) {
try {
jSONObject.put(entry.getKey(), String.valueOf(entry.getValue()));
} catch (JSONException e) {
e.printStackTrace();
}
}
JSONObject jSONObject2 = new JSONObject();
try {
jSONObject2.put(str, jSONObject);
} catch (JSONException e2) {
e2.printStackTrace();
}
by.a(getApplicationContext(), "sp_proxy_delay_config").a("sp_key_local_ttl_config_icmp" + str, jSONObject2.toString());
}
}
public void f(String str) {
String b2 = by.a(getApplicationContext(), "sp_proxy_delay_config").b("sp_key_local_ttl_config_icmp" + str, "");
if (TextUtils.isEmpty(b2)) {
return;
}
try {
JSONObject jSONObject = new JSONObject(b2).getJSONObject(str);
Iterator<String> keys = jSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
a(next, Float.parseFloat(jSONObject.optString(next)));
}
az.d("ProxyDelayService", "loadLocalProxyDelay cache ttl:" + c);
} catch (Exception e) {
e.printStackTrace();
}
}
}