HYDK v3.0.0版本的 MD5 值为:36b96e4c5561390bc72ab66c2f29a92f
以下内容为反编译后的 hk2.java 源代码,内容仅作参考
package p.a.y.e.a.s.e.net;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Process;
import android.text.TextUtils;
import com.xiaomi.push.service.module.PushChannelRegion;
import io.netty.handler.codec.memcache.binary.BinaryMemcacheOpcodes;
import io.netty.handler.codec.rtsp.RtspHeaders;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class hk2 {
public static Context lite_else;
private static hk2 lite_goto;
private static a lite_long;
private static String lite_this;
private static String lite_void;
private long lite_byte;
private String lite_case;
public Map<String, ek2> lite_do;
public b lite_for;
private gk2 lite_if;
private String lite_int;
private long lite_new;
private final long lite_try;
public static Map<String, dk2> lite_char = new HashMap();
public static boolean lite_break = false;
public interface a {
hk2 lite_do(Context context, gk2 gk2Var, b bVar, String str);
}
public interface b {
String a(String str);
}
public hk2(Context context, gk2 gk2Var, b bVar, String str) {
this(context, gk2Var, bVar, str, null, null);
}
public hk2(Context context, gk2 gk2Var, b bVar, String str, String str2, String str3) {
this.lite_do = new HashMap();
this.lite_int = "0";
this.lite_new = 0L;
this.lite_try = 15L;
this.lite_byte = 0L;
this.lite_case = "isp_prov_city_country_ip";
this.lite_for = bVar;
this.lite_if = gk2Var == null ? new ik2(this) : gk2Var;
this.lite_int = str;
lite_this = str2 == null ? context.getPackageName() : str2;
lite_void = str3 == null ? lite_native() : str3;
}
private ArrayList<dk2> lite_byte(ArrayList<String> arrayList) {
JSONObject jSONObject;
JSONObject jSONObject2;
lite_double();
synchronized (this.lite_do) {
lite_break();
for (String str : this.lite_do.keySet()) {
if (!arrayList.contains(str)) {
arrayList.add(str);
}
}
}
boolean isEmpty = lite_char.isEmpty();
synchronized (lite_char) {
for (Object obj : lite_char.values().toArray()) {
dk2 dk2Var = (dk2) obj;
if (!dk2Var.lite_short()) {
lite_char.remove(dk2Var.lite_int);
isEmpty = true;
}
}
}
if (!arrayList.contains(lite_class())) {
arrayList.add(lite_class());
}
ArrayList<dk2> arrayList2 = new ArrayList<>(arrayList.size());
for (int i = 0; i < arrayList.size(); i++) {
arrayList2.add(null);
}
try {
String str2 = gi2.lite_const(lite_else) ? "wifi" : "wap";
String lite_try = lite_try(arrayList, str2, this.lite_int, isEmpty);
if (!TextUtils.isEmpty(lite_try)) {
JSONObject jSONObject3 = new JSONObject(lite_try);
td2.lite_long(lite_try);
if ("OK".equalsIgnoreCase(jSONObject3.getString("S"))) {
JSONObject jSONObject4 = jSONObject3.getJSONObject("R");
String string = jSONObject4.getString("province");
String string2 = jSONObject4.getString("city");
String string3 = jSONObject4.getString("isp");
String string4 = jSONObject4.getString("ip");
String string5 = jSONObject4.getString("country");
JSONObject jSONObject5 = jSONObject4.getJSONObject(str2);
td2.lite_this("get bucket: net=" + string3 + ", hosts=" + jSONObject5.toString());
int i2 = 0;
while (i2 < arrayList.size()) {
String str3 = arrayList.get(i2);
JSONArray optJSONArray = jSONObject5.optJSONArray(str3);
if (optJSONArray == null) {
td2.lite_char("no bucket found for " + str3);
jSONObject = jSONObject5;
} else {
dk2 dk2Var2 = new dk2(str3);
int i3 = 0;
while (i3 < optJSONArray.length()) {
String string6 = optJSONArray.getString(i3);
if (TextUtils.isEmpty(string6)) {
jSONObject2 = jSONObject5;
} else {
jSONObject2 = jSONObject5;
dk2Var2.lite_char(new mk2(string6, optJSONArray.length() - i3));
}
i3++;
jSONObject5 = jSONObject2;
}
jSONObject = jSONObject5;
arrayList2.set(i2, dk2Var2);
dk2Var2.lite_char = string5;
dk2Var2.lite_new = string;
dk2Var2.lite_byte = string3;
dk2Var2.lite_case = string4;
dk2Var2.lite_try = string2;
if (jSONObject4.has("stat-percent")) {
dk2Var2.lite_byte(jSONObject4.getDouble("stat-percent"));
}
if (jSONObject4.has("stat-domain")) {
dk2Var2.lite_const(jSONObject4.getString("stat-domain"));
}
if (jSONObject4.has(RtspHeaders.Values.TTL)) {
dk2Var2.lite_case(jSONObject4.getInt(RtspHeaders.Values.TTL) * 1000);
}
lite_long(dk2Var2.lite_if());
}
i2++;
jSONObject5 = jSONObject;
}
JSONObject optJSONObject = jSONObject4.optJSONObject("reserved");
if (optJSONObject != null) {
long j = jSONObject4.has("reserved-ttl") ? jSONObject4.getInt("reserved-ttl") * 1000 : 604800000L;
Iterator<String> keys = optJSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
JSONArray optJSONArray2 = optJSONObject.optJSONArray(next);
if (optJSONArray2 == null) {
td2.lite_char("no bucket found for " + next);
} else {
dk2 dk2Var3 = new dk2(next);
dk2Var3.lite_case(j);
for (int i4 = 0; i4 < optJSONArray2.length(); i4++) {
String string7 = optJSONArray2.getString(i4);
if (!TextUtils.isEmpty(string7)) {
dk2Var3.lite_char(new mk2(string7, optJSONArray2.length() - i4));
}
}
synchronized (lite_char) {
if (this.lite_if.a(next)) {
lite_char.put(next, dk2Var3);
}
}
}
}
}
}
}
} catch (Exception e) {
StringBuilder b2 = r5.b("failed to get bucket ");
b2.append(e.getMessage());
td2.lite_char(b2.toString());
}
for (int i5 = 0; i5 < arrayList.size(); i5++) {
dk2 dk2Var4 = arrayList2.get(i5);
if (dk2Var4 != null) {
lite_this(arrayList.get(i5), dk2Var4);
}
}
lite_super();
return arrayList2;
}
public static synchronized void lite_else(Context context, gk2 gk2Var, b bVar, String str, String str2, String str3) {
synchronized (hk2.class) {
Context applicationContext = context.getApplicationContext();
lite_else = applicationContext;
if (applicationContext == null) {
lite_else = context;
}
if (lite_goto == null) {
a aVar = lite_long;
if (aVar == null) {
lite_goto = new hk2(context, gk2Var, bVar, str, str2, str3);
} else {
lite_goto = aVar.lite_do(context, gk2Var, bVar, str);
}
}
}
}
public static synchronized hk2 lite_for() {
hk2 hk2Var;
synchronized (hk2.class) {
hk2Var = lite_goto;
if (hk2Var == null) {
throw new IllegalStateException("the host manager is not initialized yet.");
}
}
return hk2Var;
}
public static synchronized void lite_goto(a aVar) {
synchronized (hk2.class) {
lite_long = aVar;
lite_goto = null;
}
}
public static String lite_int() {
ConnectivityManager connectivityManager;
NetworkInfo activeNetworkInfo;
Context context = lite_else;
if (context == null) {
return "unknown";
}
try {
connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
} catch (Throwable unused) {
}
if (connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null) {
return "unknown";
}
if (activeNetworkInfo.getType() != 1) {
return activeNetworkInfo.getTypeName() + te2.lite_final + activeNetworkInfo.getSubtypeName();
}
WifiManager wifiManager = (WifiManager) lite_else.getSystemService("wifi");
if (wifiManager != null && wifiManager.getConnectionInfo() != null) {
return "WIFI-" + wifiManager.getConnectionInfo().getSSID();
}
return "unknown";
}
private String lite_native() {
try {
PackageInfo packageInfo = lite_else.getPackageManager().getPackageInfo(lite_else.getPackageName(), 16384);
return packageInfo != null ? packageInfo.versionName : "0";
} catch (Exception unused) {
return "0";
}
}
public static String lite_new(String str) {
try {
int length = str.length();
byte[] bytes = str.getBytes("UTF-8");
for (int i = 0; i < bytes.length; i++) {
byte b2 = bytes[i];
int i2 = b2 & 240;
if (i2 != 240) {
bytes[i] = (byte) (((b2 & BinaryMemcacheOpcodes.PREPEND) ^ ((byte) (((b2 >> 4) + length) & 15))) | i2);
}
}
return new String(bytes);
} catch (UnsupportedEncodingException unused) {
return str;
}
}
public static void lite_void(String str, String str2) {
dk2 dk2Var = lite_char.get(str);
synchronized (lite_char) {
if (dk2Var == null) {
dk2 dk2Var2 = new dk2(str);
dk2Var2.lite_case(604800000L);
dk2Var2.lite_else(str2);
lite_char.put(str, dk2Var2);
} else {
dk2Var.lite_else(str2);
}
}
}
public boolean lite_break() {
synchronized (this.lite_do) {
if (lite_break) {
return true;
}
lite_break = true;
this.lite_do.clear();
try {
String lite_while = lite_while();
if (!TextUtils.isEmpty(lite_while)) {
lite_final(lite_while);
td2.lite_long("loading the new hosts succeed");
return true;
}
} catch (Throwable th) {
td2.lite_char("load bucket failure: " + th.getMessage());
}
return false;
}
}
public JSONObject lite_case() {
JSONObject jSONObject;
synchronized (this.lite_do) {
jSONObject = new JSONObject();
jSONObject.put("ver", 2);
JSONArray jSONArray = new JSONArray();
Iterator<ek2> it = this.lite_do.values().iterator();
while (it.hasNext()) {
jSONArray.put(it.next().lite_new());
}
jSONObject.put("data", jSONArray);
JSONArray jSONArray2 = new JSONArray();
Iterator<dk2> it2 = lite_char.values().iterator();
while (it2.hasNext()) {
jSONArray2.put(it2.next().lite_try());
}
jSONObject.put("reserved", jSONArray2);
}
return jSONObject;
}
public dk2 lite_catch(String str) {
return lite_if(str, true);
}
public void lite_char() {
synchronized (this.lite_do) {
this.lite_do.clear();
}
}
public String lite_class() {
String lite_if = tp2.lite_do(lite_else).lite_if();
return (TextUtils.isEmpty(lite_if) || PushChannelRegion.China.name().equals(lite_if)) ? "resolver.msg.xiaomi.net" : "resolver.msg.global.xiaomi.net";
}
public void lite_const() {
ArrayList<String> arrayList;
synchronized (this.lite_do) {
lite_break();
arrayList = new ArrayList<>(this.lite_do.keySet());
for (int size = arrayList.size() - 1; size >= 0; size--) {
ek2 ek2Var = this.lite_do.get(arrayList.get(size));
if (ek2Var != null && ek2Var.lite_do() != null) {
arrayList.remove(size);
}
}
}
ArrayList<dk2> lite_byte = lite_byte(arrayList);
for (int i = 0; i < arrayList.size(); i++) {
if (lite_byte.get(i) != null) {
lite_this(arrayList.get(i), lite_byte.get(i));
}
}
}
public dk2 lite_do(String str) {
if (TextUtils.isEmpty(str)) {
throw new IllegalArgumentException("the url is empty");
}
return lite_if(new URL(str).getHost(), true);
}
public void lite_double() {
String next;
synchronized (this.lite_do) {
Iterator<ek2> it = this.lite_do.values().iterator();
while (it.hasNext()) {
it.next().lite_byte(true);
}
while (true) {
for (boolean z = false; !z; z = true) {
Iterator<String> it2 = this.lite_do.keySet().iterator();
while (it2.hasNext()) {
next = it2.next();
if (this.lite_do.get(next).lite_int().isEmpty()) {
break;
}
}
}
this.lite_do.remove(next);
}
}
}
public void lite_final(String str) {
synchronized (this.lite_do) {
this.lite_do.clear();
JSONObject jSONObject = new JSONObject(str);
if (jSONObject.optInt("ver") != 2) {
throw new JSONException("Bad version");
}
JSONArray optJSONArray = jSONObject.optJSONArray("data");
for (int i = 0; i < optJSONArray.length(); i++) {
ek2 lite_if = new ek2().lite_if(optJSONArray.getJSONObject(i));
this.lite_do.put(lite_if.lite_for(), lite_if);
}
JSONArray optJSONArray2 = jSONObject.optJSONArray("reserved");
for (int i2 = 0; i2 < optJSONArray2.length(); i2++) {
dk2 lite_do = new dk2("").lite_do(optJSONArray2.getJSONObject(i2));
lite_char.put(lite_do.lite_int, lite_do);
}
}
}
public dk2 lite_float(String str) {
ek2 ek2Var;
dk2 lite_do;
synchronized (this.lite_do) {
lite_break();
ek2Var = this.lite_do.get(str);
}
if (ek2Var == null || (lite_do = ek2Var.lite_do()) == null) {
return null;
}
return lite_do;
}
public dk2 lite_if(String str, boolean z) {
dk2 lite_throw;
if (TextUtils.isEmpty(str)) {
throw new IllegalArgumentException("the host is empty");
}
if (!this.lite_if.a(str)) {
return null;
}
dk2 lite_float = lite_float(str);
return (lite_float == null || !lite_float.lite_short()) ? (z && gi2.lite_catch(lite_else) && (lite_throw = lite_throw(str)) != null) ? lite_throw : new jk2(this, str, lite_float) : lite_float;
}
public String lite_import() {
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) lite_else.getSystemService("activity")).getRunningAppProcesses();
if (runningAppProcesses == null) {
return "com.xiaomi";
}
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
if (runningAppProcessInfo.pid == Process.myPid()) {
return runningAppProcessInfo.processName;
}
}
return "com.xiaomi";
}
public void lite_long(String str) {
this.lite_case = str;
}
public String lite_short() {
StringBuilder sb = new StringBuilder();
synchronized (this.lite_do) {
for (Map.Entry<String, ek2> entry : this.lite_do.entrySet()) {
sb.append(entry.getKey());
sb.append(":\n");
sb.append(entry.getValue().toString());
sb.append("\n");
}
}
return sb.toString();
}
public void lite_super() {
synchronized (this.lite_do) {
try {
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(lite_else.openFileOutput(lite_import(), 0)));
String jSONObject = lite_case().toString();
if (!TextUtils.isEmpty(jSONObject)) {
bufferedWriter.write(jSONObject);
}
bufferedWriter.close();
} catch (Exception e) {
td2.lite_char("persist bucket failure: " + e.getMessage());
}
}
}
public void lite_this(String str, dk2 dk2Var) {
if (TextUtils.isEmpty(str) || dk2Var == null) {
throw new IllegalArgumentException("the argument is invalid " + str + ", " + dk2Var);
}
if (this.lite_if.a(str)) {
synchronized (this.lite_do) {
lite_break();
if (this.lite_do.containsKey(str)) {
this.lite_do.get(str).lite_try(dk2Var);
} else {
ek2 ek2Var = new ek2(str);
ek2Var.lite_try(dk2Var);
this.lite_do.put(str, ek2Var);
}
}
}
}
public dk2 lite_throw(String str) {
if (System.currentTimeMillis() - this.lite_byte <= this.lite_new * 60 * 1000) {
return null;
}
this.lite_byte = System.currentTimeMillis();
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(str);
dk2 dk2Var = lite_byte(arrayList).get(0);
if (dk2Var != null) {
this.lite_new = 0L;
return dk2Var;
}
long j = this.lite_new;
if (j >= 15) {
return null;
}
this.lite_new = j + 1;
return null;
}
public String lite_try(ArrayList<String> arrayList, String str, String str2, boolean z) {
ArrayList<String> arrayList2 = new ArrayList<>();
ArrayList arrayList3 = new ArrayList();
arrayList3.add(new di2("type", str));
if (str.equals("wap")) {
arrayList3.add(new di2("conpt", lite_new(gi2.lite_byte(lite_else))));
}
if (z) {
arrayList3.add(new di2("reserved", "1"));
}
arrayList3.add(new di2("uuid", str2));
arrayList3.add(new di2("list", ni2.lite_int(arrayList, te2.lite_const)));
arrayList3.add(new di2("countrycode", tp2.lite_do(lite_else).lite_try()));
dk2 lite_float = lite_float(lite_class());
String format = String.format(Locale.US, "http://%1$s/gslb/?ver=4.0", lite_class());
if (lite_float == null) {
arrayList2.add(format);
synchronized (lite_char) {
dk2 dk2Var = lite_char.get("resolver.msg.xiaomi.net");
if (dk2Var != null) {
Iterator<String> it = dk2Var.lite_new(true).iterator();
while (it.hasNext()) {
arrayList2.add(String.format(Locale.US, "http://%1$s/gslb/?ver=4.0", it.next()));
}
}
}
} else {
arrayList2 = lite_float.lite_int(format);
}
Iterator<String> it2 = arrayList2.iterator();
IOException e = null;
while (it2.hasNext()) {
Uri.Builder buildUpon = Uri.parse(it2.next()).buildUpon();
Iterator it3 = arrayList3.iterator();
while (it3.hasNext()) {
fi2 fi2Var = (fi2) it3.next();
buildUpon.appendQueryParameter(fi2Var.a(), fi2Var.b());
}
try {
b bVar = this.lite_for;
return bVar == null ? gi2.lite_case(lite_else, new URL(buildUpon.toString())) : bVar.a(buildUpon.toString());
} catch (IOException e2) {
e = e2;
}
}
if (e == null) {
return null;
}
StringBuilder b2 = r5.b("network exception: ");
b2.append(e.getMessage());
td2.lite_char(b2.toString());
throw e;
}
public String lite_while() {
BufferedReader bufferedReader;
File file;
try {
file = new File(lite_else.getFilesDir(), lite_import());
} catch (Throwable th) {
th = th;
bufferedReader = null;
}
if (!file.isFile()) {
ws2.lite_if(null);
return null;
}
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
try {
StringBuilder sb = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
return sb.toString();
}
sb.append(readLine);
}
} catch (Throwable th2) {
th = th2;
try {
td2.lite_char("load host exception " + th.getMessage());
return null;
} finally {
ws2.lite_if(bufferedReader);
}
}
}
}