Aqara Home v2.4.1版本的 MD5 值为:529779ac2bc0131db52a1fc3098d2b35

以下内容为反编译后的 eg.java 源代码,内容仅作参考


package com.loc;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.huawei.hms.push.constant.RemoteMessageConst;
import com.xiaomi.mipush.sdk.MiPushCommandMessage;
import java.net.URL;
import java.util.ArrayList;
import org.bouncycastle.crypto.tls.DTLSRecordLayer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public final class eg {
    public static int a = 1;
    public static int b = 2;
    public static eg f5994e;
    public Context f5999j;
    public String f6000k;
    public long c = 0;
    public boolean d = false;
    public ArrayList<String> f5995f = new ArrayList<>();
    public du f5996g = new du();
    public du f5997h = new du();
    public long f5998i = DTLSRecordLayer.f28507t;
    public boolean f6001l = false;

    public eg(Context context) {
        this.f5999j = context;
    }

    public static synchronized eg a(Context context) {
        eg egVar;
        synchronized (eg.class) {
            if (f5994e == null) {
                f5994e = new eg(context);
            }
            egVar = f5994e;
        }
        return egVar;
    }

    public static boolean a(String[] strArr, String[] strArr2) {
        if (strArr == null || strArr.length == 0 || strArr2 == null || strArr2.length == 0 || strArr.length != strArr2.length) {
            return false;
        }
        int length = strArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            if (!strArr[i2].equals(strArr2[i2])) {
                return false;
            }
        }
        return true;
    }

    public static String[] a(JSONArray jSONArray, int i2) throws JSONException {
        if (jSONArray == null || jSONArray.length() == 0) {
            return new String[0];
        }
        int length = jSONArray.length();
        String[] strArr = new String[length];
        for (int i3 = 0; i3 < length; i3++) {
            String string = jSONArray.getString(i3);
            if (!TextUtils.isEmpty(string)) {
                if (i2 == b) {
                    string = "[" + string + "]";
                }
                strArr[i3] = string;
            }
        }
        return strArr;
    }

    public du b(int i2) {
        return i2 == b ? this.f5997h : this.f5996g;
    }

    public static void b(eg egVar, int i2) {
        if (egVar.b(i2).a() == null || egVar.b(i2).a().length <= 0) {
            return;
        }
        String str = egVar.b(i2).a()[0];
        if (str.equals(egVar.f6000k) || egVar.f5995f.contains(str)) {
            return;
        }
        egVar.f6000k = str;
        SharedPreferences.Editor a2 = es.a(egVar.f5999j, "cbG9jaXA");
        es.a(a2, "last_ip", str);
        es.a(a2);
    }

    private synchronized void b(boolean z2, final int i2) {
        if (!z2) {
            if (!em.v() && this.f6001l) {
                return;
            }
        }
        if (this.c != 0) {
            long currentTimeMillis = System.currentTimeMillis();
            if (currentTimeMillis - this.c < this.f5998i) {
                return;
            }
            if (currentTimeMillis - this.c < 60000) {
                return;
            }
        }
        this.c = System.currentTimeMillis();
        this.f6001l = true;
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        StringBuffer stringBuffer = new StringBuffer();
        for (StackTraceElement stackTraceElement : stackTrace) {
            stringBuffer.append(stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber() + "),");
        }
        ab.d().submit(new Runnable() {
            @Override
            public final void run() {
                int i3;
                StringBuilder sb = new StringBuilder("http://");
                sb.append(em.y());
                sb.append("?host=dualstack.apilocate.amap.com&query=");
                sb.append(i2 == eg.b ? 6 : 4);
                String sb2 = sb.toString();
                eh ehVar = new eh();
                ehVar.f6002f = sb2;
                ehVar.b(sb2);
                try {
                    aw.a();
                    JSONObject jSONObject = new JSONObject(new String(aw.b(ehVar)));
                    String[] a2 = eg.a(jSONObject.optJSONArray("ips"), eg.a);
                    if (a2.length > 0 && !eg.a(a2, eg.this.b(eg.a).a())) {
                        eg.this.b(eg.a).a(a2);
                        eg.b(eg.this, eg.a);
                    }
                    String[] a3 = eg.a(jSONObject.optJSONArray("ipsv6"), eg.b);
                    if (a3.length > 0 && !eg.a(a3, eg.this.b(eg.b).a())) {
                        eg.this.b(eg.b).a(a3);
                        eg.b(eg.this, eg.b);
                    }
                    if ((jSONObject.has("ips") || jSONObject.has("ipsv6")) && jSONObject.has(RemoteMessageConst.TTL) && (i3 = jSONObject.getInt(RemoteMessageConst.TTL)) > 30) {
                        eg.this.f5998i = i3 * 1000;
                    }
                } catch (Throwable th) {
                    th.printStackTrace();
                    JSONObject jSONObject2 = new JSONObject();
                    try {
                        jSONObject2.put("key", "dnsError");
                        jSONObject2.put(MiPushCommandMessage.KEY_REASON, th.getMessage());
                    } catch (Throwable unused) {
                    }
                    er.a(eg.this.f5999j, "O018", jSONObject2);
                }
            }
        });
    }

    public static String c(int i2) {
        return i2 == b ? "last_ip_6" : "last_ip_4";
    }

    private void d(int i2) {
        if (b(i2).d()) {
            SharedPreferences.Editor a2 = es.a(this.f5999j, "cbG9jaXA");
            try {
                a2.remove(c(i2));
            } catch (Throwable th) {
                en.a(th, "SpUtil", "setPrefsLong");
            }
            es.a(a2);
            b(i2).a(false);
        }
    }

    private String e(int i2) {
        String str;
        int i3 = 0;
        b(false, i2);
        String[] a2 = b(i2).a();
        if (a2 == null || a2.length <= 0) {
            String a3 = es.a(this.f5999j, "cbG9jaXA", c(i2), (String) null);
            if (TextUtils.isEmpty(a3) || this.f5995f.contains(a3)) {
                return "";
            }
            b(i2).a(a3);
            b(i2).b(a3);
            b(i2).a(true);
            return "";
        }
        int length = a2.length;
        while (true) {
            if (i3 >= length) {
                str = null;
                break;
            }
            str = a2[i3];
            if (!this.f5995f.contains(str)) {
                break;
            }
            i3++;
        }
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        b(i2).a(str);
        return str;
    }

    public final String a(ej ejVar, int i2) {
        try {
            if (em.w() && ejVar != null) {
                String c = ejVar.c();
                String host = new URL(c).getHost();
                if (!"http://abroad.apilocate.amap.com/mobile/binary".equals(c) && !"abroad.apilocate.amap.com".equals(host)) {
                    String str = "apilocate.amap.com".equalsIgnoreCase(host) ? "httpdns.apilocate.amap.com" : host;
                    String e2 = e(i2);
                    if (!TextUtils.isEmpty(e2)) {
                        if (i2 == b) {
                            ejVar.f6009h = c.replace(host, e2);
                        } else {
                            ejVar.f6008g = c.replace(host, e2);
                        }
                        ejVar.b().put("host", str);
                        ejVar.c(str);
                        return e2;
                    }
                }
            }
        } catch (Throwable unused) {
        }
        return null;
    }

    public final void a(int i2) {
        if (b(i2).e()) {
            d(i2);
            return;
        }
        this.f5995f.add(b(i2).b());
        d(i2);
        b(true, i2);
    }

    public final void a(boolean z2, int i2) {
        b(i2).b(z2);
        if (z2) {
            String c = b(i2).c();
            String b2 = b(i2).b();
            if (TextUtils.isEmpty(b2) || b2.equals(c)) {
                return;
            }
            SharedPreferences.Editor a2 = es.a(this.f5999j, "cbG9jaXA");
            es.a(a2, c(i2), b2);
            es.a(a2);
        }
    }
}