그늘 v4.6.9版本的 MD5 值为:45bd3dac9e441bb87fea09c92b437adc
以下内容为反编译后的 n0.java 源代码,内容仅作参考
package ph;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.text.TextUtils;
import androidx.exifinterface.media.ExifInterface;
import com.bumptech.glide.load.Key;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.wind.imlib.db.manager.CommSettingManager;
import com.xiaomi.push.service.g0;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
public class n0 {
public static Context f11892h;
public static n0 i;
public static a f11893j;
public static String f11894k;
public final b f11898c;
public final String f11899d;
public static final HashMap f11891g = new HashMap();
public static boolean f11895l = false;
public final HashMap f11896a = new HashMap();
public long f11900e = 0;
public long f11901f = 0;
public final m0 f11897b = new o0();
public interface a {
}
public interface b {
}
public n0(Context context, g0.a aVar, String str, String str2) {
this.f11899d = PushConstants.PUSH_TYPE_NOTIFY;
this.f11898c = aVar;
this.f11899d = PushConstants.PUSH_TYPE_NOTIFY;
f11894k = str == null ? context.getPackageName() : str;
if (str2 == null) {
try {
f11892h.getPackageManager().getPackageInfo(f11892h.getPackageName(), 16384);
} catch (Exception unused) {
}
}
}
public static String a() {
NetworkInfo activeNetworkInfo;
Context context = f11892h;
if (context == null) {
return "unknown";
}
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null) {
return "unknown";
}
if (activeNetworkInfo.getType() == 1) {
return "WIFI-UNKNOWN";
}
return activeNetworkInfo.getTypeName() + "-" + activeNetworkInfo.getSubtypeName();
} catch (Throwable unused) {
return "unknown";
}
}
public static synchronized n0 f() {
n0 n0Var;
synchronized (n0.class) {
n0Var = i;
if (n0Var == null) {
throw new IllegalStateException("the host manager is not initialized yet.");
}
}
return n0Var;
}
public static synchronized void g(Context context, g0.a aVar) {
synchronized (n0.class) {
Context applicationContext = context.getApplicationContext();
f11892h = applicationContext;
if (applicationContext == null) {
f11892h = context;
}
if (i == null) {
if (f11893j == null) {
i = new n0(context, aVar, CommSettingManager.PUSH_KEY, "2.2");
} else {
i = new g0.b(context, aVar);
}
}
}
}
public static synchronized void h(com.xiaomi.push.service.g0 g0Var) {
synchronized (n0.class) {
f11893j = g0Var;
i = null;
}
}
public static void i(String str, String str2) {
HashMap hashMap = f11891g;
k0 k0Var = (k0) hashMap.get(str);
synchronized (hashMap) {
if (k0Var == null) {
k0 k0Var2 = new k0(str);
k0Var2.f(604800000L);
k0Var2.g(str2);
hashMap.put(str, k0Var2);
} else {
k0Var.g(str2);
}
}
}
public static String q() {
Throwable th2;
BufferedInputStream bufferedInputStream;
FileInputStream fileInputStream;
byte[] bArr;
byte[] digest;
try {
File file = new File(f11892h.getFilesDir(), "host_fallbacks");
if (file.isFile()) {
fileInputStream = new FileInputStream(file);
try {
bufferedInputStream = new BufferedInputStream(fileInputStream);
} catch (Throwable th3) {
th2 = th3;
bufferedInputStream = null;
}
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] bArr2 = new byte[8192];
while (true) {
try {
int read = bufferedInputStream.read(bArr2, 0, 8192);
if (read <= 0) {
break;
}
byteArrayOutputStream.write(bArr2, 0, read);
} catch (Exception e10) {
e10.printStackTrace();
ke.c.x(bufferedInputStream);
ke.c.x(byteArrayOutputStream);
bArr = null;
}
}
bArr = byteArrayOutputStream.toByteArray();
ke.c.x(bufferedInputStream);
ke.c.x(byteArrayOutputStream);
String str = f11892h.getPackageName() + "_key_salt";
if (!TextUtils.isEmpty(str)) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(str.getBytes());
digest = messageDigest.digest();
} catch (Exception unused) {
}
String str2 = new String(u0.K(digest, bArr), StandardCharsets.UTF_8);
kh.b.l("load host fallbacks = " + str2);
return str2;
}
digest = null;
String str22 = new String(u0.K(digest, bArr), StandardCharsets.UTF_8);
kh.b.l("load host fallbacks = " + str22);
return str22;
} catch (Throwable th4) {
th2 = th4;
try {
kh.b.d("load host exception " + th2.getMessage());
return null;
} finally {
ke.c.x(bufferedInputStream);
ke.c.x(fileInputStream);
}
}
}
} catch (Throwable th5) {
th2 = th5;
bufferedInputStream = null;
fileInputStream = null;
}
return null;
}
public String b(ArrayList arrayList, String str, String str2) {
ArrayList<String> arrayList2 = new ArrayList<>();
ArrayList arrayList3 = new ArrayList();
arrayList3.add(new u("type", str));
if (str.equals("wap")) {
String b10 = x.b(f11892h);
try {
int length = b10.length();
byte[] bytes = b10.getBytes(Key.STRING_CHARSET_NAME);
for (int i10 = 0; i10 < bytes.length; i10++) {
byte b11 = bytes[i10];
int i11 = b11 & 240;
if (i11 != 240) {
bytes[i10] = (byte) (((b11 & 15) ^ ((byte) (((b11 >> 4) + length) & 15))) | i11);
}
}
b10 = new String(bytes);
} catch (UnsupportedEncodingException unused) {
}
arrayList3.add(new u("conpt", b10));
}
arrayList3.add(new u("reserved", PushConstants.PUSH_TYPE_THROUGH_MESSAGE));
arrayList3.add(new u("uuid", str2));
arrayList3.add(new u("list", wf.d.j(arrayList)));
com.xiaomi.push.service.b a10 = com.xiaomi.push.service.b.a(f11892h);
if (TextUtils.isEmpty(a10.f5739d)) {
a10.f5739d = com.xiaomi.push.service.b.c(a10.f5740e, "mipush_country_code", "mipush_country_code.lock", a10.f5737b);
}
arrayList3.add(new u("countrycode", a10.f5739d));
arrayList3.add(new u("push_sdk_vc", String.valueOf(50300)));
k0 o10 = o("resolver.msg.xiaomi.net");
String format = String.format(Locale.US, "https://%1$s/gslb/?ver=5.0", "resolver.msg.xiaomi.net");
if (o10 == null) {
arrayList2.add(format);
HashMap hashMap = f11891g;
synchronized (hashMap) {
k0 k0Var = (k0) hashMap.get("resolver.msg.xiaomi.net");
if (k0Var != null) {
Iterator<String> it2 = k0Var.d(true).iterator();
while (it2.hasNext()) {
arrayList2.add(String.format(Locale.US, "https://%1$s/gslb/?ver=5.0", it2.next()));
}
}
}
} else {
arrayList2 = o10.c(format);
}
Iterator<String> it3 = arrayList2.iterator();
IOException e10 = null;
while (it3.hasNext()) {
Uri.Builder buildUpon = Uri.parse(it3.next()).buildUpon();
Iterator it4 = arrayList3.iterator();
while (it4.hasNext()) {
w wVar = (w) it4.next();
buildUpon.appendQueryParameter(wVar.a(), wVar.b());
}
try {
b bVar = this.f11898c;
if (bVar == null) {
return x.c(f11892h, new URL(buildUpon.toString()));
}
return ((g0.a) bVar).a(buildUpon.toString());
} catch (IOException e11) {
e10 = e11;
}
}
if (e10 == null) {
return null;
}
kh.b.d("network exception: " + e10.getMessage());
throw e10;
}
public final ArrayList<k0> c(ArrayList<String> arrayList) {
String str;
long j10;
JSONObject jSONObject;
JSONObject jSONObject2;
r();
synchronized (this.f11896a) {
k();
for (String str2 : this.f11896a.keySet()) {
if (!arrayList.contains(str2)) {
arrayList.add(str2);
}
}
}
HashMap hashMap = f11891g;
synchronized (hashMap) {
for (Object obj : hashMap.values().toArray()) {
k0 k0Var = (k0) obj;
if (!k0Var.k()) {
f11891g.remove(k0Var.f11774d);
}
}
}
if (!arrayList.contains("resolver.msg.xiaomi.net")) {
arrayList.add("resolver.msg.xiaomi.net");
}
ArrayList<k0> arrayList2 = new ArrayList<>(arrayList.size());
for (int i10 = 0; i10 < arrayList.size(); i10++) {
arrayList2.add(null);
}
try {
if (x.k(f11892h)) {
str = "wifi";
} else {
str = "wap";
}
String b10 = b(arrayList, str, this.f11899d);
if (!TextUtils.isEmpty(b10)) {
JSONObject jSONObject3 = new JSONObject(b10);
kh.b.l(b10);
if ("OK".equalsIgnoreCase(jSONObject3.getString(ExifInterface.LATITUDE_SOUTH))) {
JSONObject jSONObject4 = jSONObject3.getJSONObject("R");
String string = jSONObject4.getString("province");
String string2 = jSONObject4.getString("city");
String string3 = jSONObject4.getString("isp");
String string4 = jSONObject4.getString(IjkMediaPlayer.OnNativeInvokeListener.ARG_IP);
String string5 = jSONObject4.getString("country");
JSONObject jSONObject5 = jSONObject4.getJSONObject(str);
kh.b.n("get bucket: net=" + string3 + ", hosts=" + jSONObject5.toString());
int i11 = 0;
while (i11 < arrayList.size()) {
String str3 = arrayList.get(i11);
JSONArray optJSONArray = jSONObject5.optJSONArray(str3);
if (optJSONArray == null) {
kh.b.d("no bucket found for " + str3);
jSONObject = jSONObject5;
} else {
k0 k0Var2 = new k0(str3);
int i12 = 0;
while (i12 < optJSONArray.length()) {
String string6 = optJSONArray.getString(i12);
if (!TextUtils.isEmpty(string6)) {
jSONObject2 = jSONObject5;
k0Var2.j(new s0(string6, optJSONArray.length() - i12));
} else {
jSONObject2 = jSONObject5;
}
i12++;
jSONObject5 = jSONObject2;
}
jSONObject = jSONObject5;
arrayList2.set(i11, k0Var2);
k0Var2.i = string5;
k0Var2.f11775e = string;
k0Var2.f11777g = string3;
k0Var2.f11778h = string4;
k0Var2.f11776f = string2;
if (jSONObject4.has("stat-percent")) {
k0Var2.f11781l = jSONObject4.getDouble("stat-percent");
}
if (jSONObject4.has("stat-domain")) {
jSONObject4.getString("stat-domain");
}
if (jSONObject4.has("ttl")) {
k0Var2.f(jSONObject4.getInt("ttl") * 1000);
}
k0Var2.a();
}
i11++;
jSONObject5 = jSONObject;
}
JSONObject optJSONObject = jSONObject4.optJSONObject("reserved");
if (optJSONObject != null) {
if (jSONObject4.has("reserved-ttl")) {
j10 = jSONObject4.getInt("reserved-ttl") * 1000;
} else {
j10 = 604800000;
}
Iterator<String> keys = optJSONObject.keys();
while (keys.hasNext()) {
String next = keys.next();
JSONArray optJSONArray2 = optJSONObject.optJSONArray(next);
if (optJSONArray2 == null) {
kh.b.d("no bucket found for " + next);
} else {
k0 k0Var3 = new k0(next);
k0Var3.f(j10);
for (int i13 = 0; i13 < optJSONArray2.length(); i13++) {
String string7 = optJSONArray2.getString(i13);
if (!TextUtils.isEmpty(string7)) {
k0Var3.j(new s0(string7, optJSONArray2.length() - i13));
}
}
HashMap hashMap2 = f11891g;
synchronized (hashMap2) {
this.f11897b.getClass();
hashMap2.put(next, k0Var3);
}
}
}
}
}
}
} catch (Exception e10) {
kh.b.d("failed to get bucket " + e10.getMessage());
}
for (int i14 = 0; i14 < arrayList.size(); i14++) {
k0 k0Var4 = arrayList2.get(i14);
if (k0Var4 != null) {
j(arrayList.get(i14), k0Var4);
}
}
p();
return arrayList2;
}
public final JSONObject d() {
JSONObject jSONObject;
synchronized (this.f11896a) {
jSONObject = new JSONObject();
jSONObject.put("ver", 2);
JSONArray jSONArray = new JSONArray();
for (l0 l0Var : this.f11896a.values()) {
jSONArray.put(l0Var.a());
}
jSONObject.put("data", jSONArray);
JSONArray jSONArray2 = new JSONArray();
for (k0 k0Var : f11891g.values()) {
jSONArray2.put(k0Var.e());
}
jSONObject.put("reserved", jSONArray2);
}
return jSONObject;
}
public final k0 e(String str, boolean z10) {
k0 k0Var;
kh.b.m("HostManager", "-->getFallbacksByHost(): host=", str, ", fetchRemoteIfNeed=", Boolean.valueOf(z10));
if (!TextUtils.isEmpty(str)) {
this.f11897b.getClass();
k0 o10 = o(str);
if (o10 != null && o10.k()) {
return o10;
}
if (z10 && x.h(f11892h)) {
if (System.currentTimeMillis() - this.f11901f > this.f11900e * 60 * 1000) {
this.f11901f = System.currentTimeMillis();
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(str);
k0Var = c(arrayList).get(0);
if (k0Var != null) {
this.f11900e = 0L;
if (k0Var != null) {
return k0Var;
}
} else {
long j10 = this.f11900e;
if (j10 < 15) {
this.f11900e = j10 + 1;
}
}
}
k0Var = null;
if (k0Var != null) {
}
}
return new p0(str, o10);
}
throw new IllegalArgumentException("the host is empty");
}
public final void j(String str, k0 k0Var) {
if (!TextUtils.isEmpty(str) && k0Var != null) {
this.f11897b.getClass();
synchronized (this.f11896a) {
k();
if (this.f11896a.containsKey(str)) {
((l0) this.f11896a.get(str)).e(k0Var);
} else {
l0 l0Var = new l0(str);
l0Var.e(k0Var);
this.f11896a.put(str, l0Var);
}
}
return;
}
throw new IllegalArgumentException("the argument is invalid " + str + ", " + k0Var);
}
public final void k() {
synchronized (this.f11896a) {
if (!f11895l) {
f11895l = true;
this.f11896a.clear();
String q = q();
if (!TextUtils.isEmpty(q)) {
m(q);
kh.b.l("loading the new hosts succeed");
}
}
}
}
public final void l() {
ArrayList<String> arrayList;
synchronized (this.f11896a) {
k();
arrayList = new ArrayList<>(this.f11896a.keySet());
int size = arrayList.size();
while (true) {
size--;
if (size < 0) {
break;
}
l0 l0Var = (l0) this.f11896a.get(arrayList.get(size));
if (l0Var != null && l0Var.b() != null) {
arrayList.remove(size);
}
}
}
ArrayList<k0> c4 = c(arrayList);
for (int i10 = 0; i10 < arrayList.size(); i10++) {
if (c4.get(i10) != null) {
j(arrayList.get(i10), c4.get(i10));
}
}
}
public final void m(String str) {
synchronized (this.f11896a) {
this.f11896a.clear();
JSONObject jSONObject = new JSONObject(str);
if (jSONObject.optInt("ver") == 2) {
JSONArray optJSONArray = jSONObject.optJSONArray("data");
if (optJSONArray != null) {
for (int i10 = 0; i10 < optJSONArray.length(); i10++) {
l0 l0Var = new l0();
l0Var.d(optJSONArray.getJSONObject(i10));
this.f11896a.put(l0Var.f11836a, l0Var);
}
}
JSONArray optJSONArray2 = jSONObject.optJSONArray("reserved");
if (optJSONArray2 != null) {
for (int i11 = 0; i11 < optJSONArray2.length(); i11++) {
JSONObject jSONObject2 = optJSONArray2.getJSONObject(i11);
String optString = jSONObject2.optString("host");
if (!TextUtils.isEmpty(optString)) {
try {
k0 k0Var = new k0(optString);
k0Var.i(jSONObject2);
f11891g.put(k0Var.f11774d, k0Var);
kh.b.d("load local reserved host for " + k0Var.f11774d);
} catch (JSONException unused) {
kh.b.d("parse reserved host fail.");
}
}
}
}
} else {
throw new JSONException("Bad version");
}
}
}
public final String n() {
StringBuilder sb2 = new StringBuilder();
synchronized (this.f11896a) {
for (Map.Entry entry : this.f11896a.entrySet()) {
sb2.append((String) entry.getKey());
sb2.append(":\n");
sb2.append(((l0) entry.getValue()).toString());
sb2.append("\n");
}
}
return sb2.toString();
}
public final k0 o(String str) {
l0 l0Var;
k0 b10;
synchronized (this.f11896a) {
k();
l0Var = (l0) this.f11896a.get(str);
}
if (l0Var != null && (b10 = l0Var.b()) != null) {
return b10;
}
return null;
}
public final void p() {
Throwable th2;
FileOutputStream fileOutputStream;
BufferedOutputStream bufferedOutputStream;
Exception e10;
synchronized (this.f11896a) {
BufferedOutputStream bufferedOutputStream2 = null;
r3 = null;
byte[] digest = null;
bufferedOutputStream2 = null;
BufferedOutputStream bufferedOutputStream3 = null;
try {
String jSONObject = d().toString();
kh.b.l("persist host fallbacks = " + jSONObject);
if (!TextUtils.isEmpty(jSONObject)) {
fileOutputStream = f11892h.openFileOutput("host_fallbacks", 0);
try {
bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
try {
try {
String str = f11892h.getPackageName() + "_key_salt";
if (!TextUtils.isEmpty(str)) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(str.getBytes());
digest = messageDigest.digest();
} catch (Exception unused) {
}
}
byte[] bytes = jSONObject.getBytes(StandardCharsets.UTF_8);
SecretKeySpec secretKeySpec = new SecretKeySpec(digest, "AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec(u0.f12145r);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(1, secretKeySpec, ivParameterSpec);
bufferedOutputStream.write(cipher.doFinal(bytes));
bufferedOutputStream.flush();
bufferedOutputStream3 = bufferedOutputStream;
} catch (Exception e11) {
e10 = e11;
kh.b.d("persist bucket failure: " + e10.getMessage());
ke.c.x(bufferedOutputStream);
ke.c.x(fileOutputStream);
}
} catch (Throwable th3) {
th2 = th3;
bufferedOutputStream2 = bufferedOutputStream;
ke.c.x(bufferedOutputStream2);
ke.c.x(fileOutputStream);
throw th2;
}
} catch (Exception e12) {
bufferedOutputStream = null;
e10 = e12;
} catch (Throwable th4) {
th2 = th4;
ke.c.x(bufferedOutputStream2);
ke.c.x(fileOutputStream);
throw th2;
}
} else {
fileOutputStream = null;
}
ke.c.x(bufferedOutputStream3);
} catch (Exception e13) {
bufferedOutputStream = null;
e10 = e13;
fileOutputStream = null;
} catch (Throwable th5) {
th2 = th5;
fileOutputStream = null;
}
ke.c.x(fileOutputStream);
}
}
public final void r() {
synchronized (this.f11896a) {
for (l0 l0Var : this.f11896a.values()) {
l0Var.c();
}
while (true) {
for (boolean z10 = false; !z10; z10 = true) {
for (String str : this.f11896a.keySet()) {
if (((l0) this.f11896a.get(str)).f11837b.isEmpty()) {
break;
}
}
}
this.f11896a.remove(str);
}
}
}
}