CamScanner.apk(点击下载) / ZIDManager.java


package com.umeng.umzid;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.text.TextUtils;
import com.facebook.internal.NativeProtocol;
import com.umeng.analytics.pro.ak;
import com.umeng.commonsdk.statistics.common.DeviceConfig;
import com.vungle.warren.VungleApiClient;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.util.Calendar;
import java.util.Locale;
import java.util.UUID;
import org.json.JSONObject;

public class ZIDManager {

    /* renamed from: c  reason: collision with root package name */
    public static ZIDManager f46487c;

    /* renamed from: a  reason: collision with root package name */
    public boolean f46488a = false;

    /* renamed from: b  reason: collision with root package name */
    public boolean f46489b = false;

    public class a implements Runnable {

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ Context f46490a;

        /* renamed from: b  reason: collision with root package name */
        public final /* synthetic */ IZIDCompletionCallback f46491b;

        public a(Context context, IZIDCompletionCallback iZIDCompletionCallback) {
            this.f46490a = context;
            this.f46491b = iZIDCompletionCallback;
        }

        public void run() {
            String a10 = ZIDManager.a(ZIDManager.this, this.f46490a);
            if (TextUtils.isEmpty(a10)) {
                IZIDCompletionCallback iZIDCompletionCallback = this.f46491b;
                if (iZIDCompletionCallback != null) {
                    iZIDCompletionCallback.onFailure("1002", "获取zid失败");
                    return;
                }
                return;
            }
            IZIDCompletionCallback iZIDCompletionCallback2 = this.f46491b;
            if (iZIDCompletionCallback2 != null) {
                iZIDCompletionCallback2.onSuccess(a10);
            }
        }
    }

    public class b implements Runnable {

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ Context f46493a;

        public b(Context context) {
            this.f46493a = context;
        }

        /* JADX WARNING: Removed duplicated region for block: B:39:0x00b0  */
        /* JADX WARNING: Removed duplicated region for block: B:42:0x00c3  */
        public void run() {
            String str;
            String str2;
            String str3;
            String a10;
            SharedPreferences a11;
            SharedPreferences a12;
            SharedPreferences a13;
            SharedPreferences a14;
            ZIDManager zIDManager = ZIDManager.this;
            Context context = this.f46493a;
            if (!zIDManager.f46489b) {
                zIDManager.f46489b = true;
                JSONObject jSONObject = new JSONObject();
                String str4 = "";
                if (context != null) {
                    try {
                        SharedPreferences a15 = a.a(context);
                        if (a15 != null) {
                            str = a15.getString("zdata", null);
                            String id = Spy.getID();
                            jSONObject.put("zdata", id);
                            jSONObject.put("old_zdata", str);
                            if (context != null || (a14 = a.a(context)) == null) {
                                str2 = str4;
                            } else {
                                str2 = a14.getString("oaid", str4);
                                if (c.c(str2)) {
                                    str2 = c.a(str2);
                                }
                            }
                            String c9 = c.c(context);
                            jSONObject.put("old_oaid", str2);
                            jSONObject.put("oaid", c9);
                            if (context != null || (a13 = a.a(context)) == null) {
                                str3 = str4;
                            } else {
                                str3 = a13.getString("mac", str4);
                                if (c.c(str3)) {
                                    str3 = c.a(str3);
                                }
                            }
                            String b10 = c.b(context);
                            jSONObject.put("mac", b10);
                            jSONObject.put("old_mac", str3);
                            zIDManager.a(context, jSONObject);
                            jSONObject.put("aaid", c.a(context));
                            jSONObject.put("uabc", (context != null || (a12 = a.a(context)) == null) ? str4 : a12.getString("uabc", str4));
                            if (!(context == null || (a11 = a.a(context)) == null)) {
                                str4 = a11.getString("resetToken", str4);
                            }
                            if (!TextUtils.isEmpty(str4)) {
                                jSONObject.put("resetToken", str4);
                            }
                            a10 = a.a("https://aaid.umeng.com/api/updateZdata", jSONObject.toString());
                            if (!TextUtils.isEmpty(a10)) {
                                JSONObject jSONObject2 = new JSONObject(a10);
                                if (Boolean.valueOf(jSONObject2.optBoolean("suc")).booleanValue()) {
                                    c.f(context, id);
                                    c.a(context, b10);
                                    c.b(context, c9);
                                    String optString = jSONObject2.optString("aaid");
                                    if (!TextUtils.isEmpty(optString)) {
                                        c.e(context, optString);
                                    }
                                    String string = jSONObject2.getString("uabc");
                                    if (!TextUtils.isEmpty(string)) {
                                        c.d(context, string);
                                    }
                                    String string2 = jSONObject2.getString("resetToken");
                                    if (!TextUtils.isEmpty(string2)) {
                                        c.c(context, string2);
                                    }
                                }
                            }
                            zIDManager.f46489b = false;
                        }
                    } catch (Throwable unused) {
                    }
                }
                str = str4;
                String id2 = Spy.getID();
                jSONObject.put("zdata", id2);
                jSONObject.put("old_zdata", str);
                if (context != null) {
                }
                str2 = str4;
                String c92 = c.c(context);
                jSONObject.put("old_oaid", str2);
                jSONObject.put("oaid", c92);
                if (context != null) {
                }
                str3 = str4;
                String b102 = c.b(context);
                jSONObject.put("mac", b102);
                jSONObject.put("old_mac", str3);
                zIDManager.a(context, jSONObject);
                jSONObject.put("aaid", c.a(context));
                jSONObject.put("uabc", (context != null || (a12 = a.a(context)) == null) ? str4 : a12.getString("uabc", str4));
                str4 = a11.getString("resetToken", str4);
                if (!TextUtils.isEmpty(str4)) {
                }
                a10 = a.a("https://aaid.umeng.com/api/updateZdata", jSONObject.toString());
                if (!TextUtils.isEmpty(a10)) {
                }
                zIDManager.f46489b = false;
            }
        }
    }

    public class c implements Runnable {

        /* renamed from: a  reason: collision with root package name */
        public final /* synthetic */ Context f46495a;

        public c(Context context) {
            this.f46495a = context;
        }

        public void run() {
            ZIDManager.a(ZIDManager.this, this.f46495a);
        }
    }

    public static /* synthetic */ String a(ZIDManager zIDManager, Context context) {
        String str = null;
        if (!zIDManager.f46488a) {
            zIDManager.f46488a = true;
            JSONObject jSONObject = new JSONObject();
            try {
                String id = Spy.getID();
                jSONObject.put("zdata", id);
                String b10 = c.b(context);
                jSONObject.put("mac", b10);
                String c9 = c.c(context);
                jSONObject.put("oaid", c9);
                zIDManager.a(context, jSONObject);
                String a10 = a.a("https://aaid.umeng.com/api/postZdata", jSONObject.toString());
                if (!TextUtils.isEmpty(a10)) {
                    JSONObject jSONObject2 = new JSONObject(a10);
                    if (Boolean.valueOf(jSONObject2.optBoolean("suc")).booleanValue()) {
                        c.f(context, id);
                        c.a(context, b10);
                        c.b(context, c9);
                        str = jSONObject2.optString("aaid");
                        if (!TextUtils.isEmpty(str)) {
                            c.e(context, str);
                        }
                        String string = jSONObject2.getString("uabc");
                        if (!TextUtils.isEmpty(string)) {
                            c.d(context, string);
                        }
                        String string2 = jSONObject2.getString("resetToken");
                        if (!TextUtils.isEmpty(string2)) {
                            c.c(context, string2);
                        }
                    }
                }
            } catch (Throwable unused) {
            }
            zIDManager.f46488a = false;
        }
        return str;
    }

    public static synchronized ZIDManager getInstance() {
        ZIDManager zIDManager;
        synchronized (ZIDManager.class) {
            if (f46487c == null) {
                f46487c = new ZIDManager();
            }
            zIDManager = f46487c;
        }
        return zIDManager;
    }

    public static String getSDKVersion() {
        return "1.4.1";
    }

    /* JADX WARNING: Removed duplicated region for block: B:24:0x0077 A[SYNTHETIC, Splitter:B:24:0x0077] */
    /* JADX WARNING: Removed duplicated region for block: B:41:0x00c5  */
    /* JADX WARNING: Removed duplicated region for block: B:50:0x0100 A[SYNTHETIC, Splitter:B:50:0x0100] */
    /* JADX WARNING: Removed duplicated region for block: B:65:0x0146  */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x0148  */
    /* JADX WARNING: Removed duplicated region for block: B:69:0x0160  */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x0165  */
    /* JADX WARNING: Removed duplicated region for block: B:96:0x01e6  */
    public final JSONObject a(Context context, JSONObject jSONObject) {
        Object obj;
        int i10;
        Object obj2;
        String obj3;
        Object obj4;
        Object obj5;
        Object obj6;
        Method declaredMethod;
        SharedPreferences a10;
        Method declaredMethod2;
        Locale locale;
        String str = "";
        jSONObject.putOpt("zdata_ver", Spy.getVersion());
        try {
            String str2 = DeviceConfig.UNKNOW;
            Method declaredMethod3 = DeviceConfig.class.getDeclaredMethod("getAndroidId", Context.class);
            if (declaredMethod3 != null) {
                declaredMethod3.setAccessible(true);
                Object invoke = declaredMethod3.invoke(DeviceConfig.class, context);
                if (invoke != null && (invoke instanceof String)) {
                    obj = (String) invoke;
                    jSONObject.putOpt(VungleApiClient.ANDROID_ID, obj);
                    long j2 = 0;
                    String externalStorageState = Environment.getExternalStorageState();
                    if ((!"mounted".equals(externalStorageState) || "mounted_ro".equals(externalStorageState)) && Build.VERSION.SDK_INT >= 9) {
                        j2 = Environment.getExternalStorageDirectory().getFreeSpace();
                    }
                    jSONObject.putOpt("storage", Long.valueOf(j2));
                    jSONObject.putOpt(ak.f45419y, Build.VERSION.RELEASE);
                    Object obj7 = null;
                    if (context != null) {
                        try {
                            Configuration configuration = new Configuration();
                            configuration.setToDefaults();
                            Settings.System.getConfiguration(context.getContentResolver(), configuration);
                            locale = configuration.locale;
                        } catch (Throwable unused) {
                            locale = null;
                        }
                        if (locale == null) {
                            try {
                                locale = Locale.getDefault();
                            } catch (Throwable unused2) {
                            }
                        }
                        Calendar instance = Calendar.getInstance(locale);
                        if (instance != null) {
                            i10 = instance.getTimeZone().getRawOffset() / 3600000;
                            jSONObject.putOpt(ak.M, Integer.valueOf(i10));
                            jSONObject.putOpt("model", Build.MODEL);
                            String str3 = DeviceConfig.UNKNOW;
                            declaredMethod2 = DeviceConfig.class.getDeclaredMethod("getImeiNew", Context.class);
                            if (declaredMethod2 != null) {
                                declaredMethod2.setAccessible(true);
                                Object invoke2 = declaredMethod2.invoke(DeviceConfig.class, context);
                                if (invoke2 != null && (invoke2 instanceof String)) {
                                    obj2 = (String) invoke2;
                                    jSONObject.putOpt("imei", obj2);
                                    Method declaredMethod4 = Build.class.getDeclaredMethod("getString", String.class);
                                    declaredMethod4.setAccessible(true);
                                    obj3 = declaredMethod4.invoke(null, "net.hostname").toString();
                                    if (obj3 != null) {
                                        try {
                                            if (!obj3.equalsIgnoreCase(str)) {
                                                try {
                                                    MessageDigest instance2 = MessageDigest.getInstance("MD5");
                                                    instance2.update(obj3.getBytes());
                                                    byte[] digest = instance2.digest();
                                                    StringBuffer stringBuffer = new StringBuffer();
                                                    for (byte b10 : digest) {
                                                        stringBuffer.append(Integer.toHexString(b10 & 255));
                                                    }
                                                    obj3 = stringBuffer.toString();
                                                } catch (Throwable unused3) {
                                                    obj3 = str;
                                                }
                                            }
                                        } catch (Exception unused4) {
                                        }
                                    }
                                    jSONObject.putOpt("hostname", obj3);
                                    jSONObject.putOpt("sdk_version", "1.4.1");
                                    jSONObject.putOpt(ak.f45409o, context != null ? null : context.getPackageName());
                                    jSONObject.putOpt(ak.f45415u, "Android");
                                    SharedPreferences a11 = a.a(context);
                                    jSONObject.putOpt("uuid", a11 == null ? a11.getString("uuid", str) : str);
                                    jSONObject.putOpt("source_id", "umeng");
                                    obj4 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
                                    jSONObject.putOpt("app_version", obj4);
                                    obj5 = context.getResources().getString(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.labelRes);
                                    jSONObject.putOpt(NativeProtocol.BRIDGE_ARG_APP_NAME_STRING, obj5);
                                    obj6 = context.getResources().getConfiguration().locale.getCountry();
                                    jSONObject.putOpt("country", obj6);
                                    if (!(context == null || (a10 = a.a(context)) == null)) {
                                        obj7 = a10.getString("appkey", null);
                                    }
                                    jSONObject.putOpt("appkey", obj7);
                                    String str4 = DeviceConfig.UNKNOW;
                                    declaredMethod = DeviceConfig.class.getDeclaredMethod("getIdfa", Context.class);
                                    if (declaredMethod != null) {
                                        declaredMethod.setAccessible(true);
                                        Object invoke3 = declaredMethod.invoke(DeviceConfig.class, context);
                                        if (invoke3 != null && (invoke3 instanceof String)) {
                                            str = (String) invoke3;
                                        }
                                    }
                                    jSONObject.putOpt(VungleApiClient.GAID, str);
                                    return jSONObject;
                                }
                            }
                            obj2 = str;
                            jSONObject.putOpt("imei", obj2);
                            Method declaredMethod42 = Build.class.getDeclaredMethod("getString", String.class);
                            declaredMethod42.setAccessible(true);
                            obj3 = declaredMethod42.invoke(null, "net.hostname").toString();
                            if (obj3 != null) {
                            }
                            jSONObject.putOpt("hostname", obj3);
                            jSONObject.putOpt("sdk_version", "1.4.1");
                            jSONObject.putOpt(ak.f45409o, context != null ? null : context.getPackageName());
                            jSONObject.putOpt(ak.f45415u, "Android");
                            SharedPreferences a112 = a.a(context);
                            jSONObject.putOpt("uuid", a112 == null ? a112.getString("uuid", str) : str);
                            jSONObject.putOpt("source_id", "umeng");
                            obj4 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
                            jSONObject.putOpt("app_version", obj4);
                            obj5 = context.getResources().getString(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.labelRes);
                            jSONObject.putOpt(NativeProtocol.BRIDGE_ARG_APP_NAME_STRING, obj5);
                            obj6 = context.getResources().getConfiguration().locale.getCountry();
                            jSONObject.putOpt("country", obj6);
                            obj7 = a10.getString("appkey", null);
                            jSONObject.putOpt("appkey", obj7);
                            String str42 = DeviceConfig.UNKNOW;
                            declaredMethod = DeviceConfig.class.getDeclaredMethod("getIdfa", Context.class);
                            if (declaredMethod != null) {
                            }
                            jSONObject.putOpt(VungleApiClient.GAID, str);
                            return jSONObject;
                        }
                    }
                    i10 = 8;
                    jSONObject.putOpt(ak.M, Integer.valueOf(i10));
                    jSONObject.putOpt("model", Build.MODEL);
                    String str32 = DeviceConfig.UNKNOW;
                    declaredMethod2 = DeviceConfig.class.getDeclaredMethod("getImeiNew", Context.class);
                    if (declaredMethod2 != null) {
                    }
                    obj2 = str;
                    jSONObject.putOpt("imei", obj2);
                    Method declaredMethod422 = Build.class.getDeclaredMethod("getString", String.class);
                    declaredMethod422.setAccessible(true);
                    obj3 = declaredMethod422.invoke(null, "net.hostname").toString();
                    if (obj3 != null) {
                    }
                    jSONObject.putOpt("hostname", obj3);
                    jSONObject.putOpt("sdk_version", "1.4.1");
                    jSONObject.putOpt(ak.f45409o, context != null ? null : context.getPackageName());
                    jSONObject.putOpt(ak.f45415u, "Android");
                    SharedPreferences a1122 = a.a(context);
                    jSONObject.putOpt("uuid", a1122 == null ? a1122.getString("uuid", str) : str);
                    jSONObject.putOpt("source_id", "umeng");
                    obj4 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
                    jSONObject.putOpt("app_version", obj4);
                    obj5 = context.getResources().getString(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.labelRes);
                    jSONObject.putOpt(NativeProtocol.BRIDGE_ARG_APP_NAME_STRING, obj5);
                    obj6 = context.getResources().getConfiguration().locale.getCountry();
                    jSONObject.putOpt("country", obj6);
                    obj7 = a10.getString("appkey", null);
                    jSONObject.putOpt("appkey", obj7);
                    String str422 = DeviceConfig.UNKNOW;
                    declaredMethod = DeviceConfig.class.getDeclaredMethod("getIdfa", Context.class);
                    if (declaredMethod != null) {
                    }
                    jSONObject.putOpt(VungleApiClient.GAID, str);
                    return jSONObject;
                }
            }
        } catch (Throwable unused5) {
        }
        obj = str;
        jSONObject.putOpt(VungleApiClient.ANDROID_ID, obj);
        long j22 = 0;
        String externalStorageState2 = Environment.getExternalStorageState();
        j22 = Environment.getExternalStorageDirectory().getFreeSpace();
        jSONObject.putOpt("storage", Long.valueOf(j22));
        jSONObject.putOpt(ak.f45419y, Build.VERSION.RELEASE);
        Object obj72 = null;
        if (context != null) {
        }
        i10 = 8;
        jSONObject.putOpt(ak.M, Integer.valueOf(i10));
        jSONObject.putOpt("model", Build.MODEL);
        try {
            String str322 = DeviceConfig.UNKNOW;
            declaredMethod2 = DeviceConfig.class.getDeclaredMethod("getImeiNew", Context.class);
            if (declaredMethod2 != null) {
            }
        } catch (Throwable unused6) {
        }
        obj2 = str;
        jSONObject.putOpt("imei", obj2);
        Method declaredMethod4222 = Build.class.getDeclaredMethod("getString", String.class);
        declaredMethod4222.setAccessible(true);
        obj3 = declaredMethod4222.invoke(null, "net.hostname").toString();
        if (obj3 != null) {
        }
        jSONObject.putOpt("hostname", obj3);
        jSONObject.putOpt("sdk_version", "1.4.1");
        jSONObject.putOpt(ak.f45409o, context != null ? null : context.getPackageName());
        jSONObject.putOpt(ak.f45415u, "Android");
        SharedPreferences a11222 = a.a(context);
        jSONObject.putOpt("uuid", a11222 == null ? a11222.getString("uuid", str) : str);
        jSONObject.putOpt("source_id", "umeng");
        try {
            obj4 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (Exception e10) {
            e10.printStackTrace();
            obj4 = null;
        }
        jSONObject.putOpt("app_version", obj4);
        try {
            obj5 = context.getResources().getString(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.labelRes);
        } catch (Exception e11) {
            e11.printStackTrace();
            obj5 = null;
        }
        jSONObject.putOpt(NativeProtocol.BRIDGE_ARG_APP_NAME_STRING, obj5);
        try {
            obj6 = context.getResources().getConfiguration().locale.getCountry();
        } catch (Exception e12) {
            e12.printStackTrace();
            obj6 = null;
        }
        jSONObject.putOpt("country", obj6);
        obj72 = a10.getString("appkey", null);
        jSONObject.putOpt("appkey", obj72);
        try {
            String str4222 = DeviceConfig.UNKNOW;
            declaredMethod = DeviceConfig.class.getDeclaredMethod("getIdfa", Context.class);
            if (declaredMethod != null) {
            }
        } catch (Throwable unused7) {
        }
        jSONObject.putOpt(VungleApiClient.GAID, str);
        return jSONObject;
    }

    public synchronized String getZID(Context context) {
        if (context == null) {
            return "";
        }
        Context applicationContext = context.getApplicationContext();
        String a10 = c.a(applicationContext);
        if (!TextUtils.isEmpty(a10)) {
            return a10;
        }
        b.a(new c(applicationContext));
        return "";
    }

    public synchronized void init(Context context, String str, IZIDCompletionCallback iZIDCompletionCallback) {
        SharedPreferences a10;
        SharedPreferences.Editor edit;
        if (context == null) {
            if (iZIDCompletionCallback != null) {
                iZIDCompletionCallback.onFailure("1001", "传入参数Context为null");
            }
        } else if (TextUtils.isEmpty(str)) {
            if (iZIDCompletionCallback != null) {
                iZIDCompletionCallback.onFailure("1003", "传入参数appkey为空");
            }
        } else {
            Context applicationContext = context.getApplicationContext();
            if (!(applicationContext == null || str == null || TextUtils.isEmpty(str) || (a10 = a.a(applicationContext)) == null || (edit = a10.edit()) == null)) {
                edit.putString("appkey", str).commit();
            }
            String a11 = c.a(applicationContext);
            if (a11 == null || TextUtils.isEmpty(a11)) {
                b.a(new a(applicationContext, iZIDCompletionCallback));
            } else {
                b.a(new b(applicationContext));
                if (iZIDCompletionCallback != null) {
                    iZIDCompletionCallback.onSuccess(a11);
                }
            }
            String str2 = "";
            SharedPreferences a12 = a.a(context);
            if (a12 != null) {
                str2 = a12.getString("uuid", "");
            }
            if (TextUtils.isEmpty(str2)) {
                String str3 = "";
                SharedPreferences a13 = a.a(context);
                try {
                    str3 = UUID.randomUUID().toString();
                } catch (Throwable unused) {
                }
                if (a13 != null) {
                    a13.edit().putString("uuid", str3).commit();
                }
            }
        }
    }
}