package com.ss.android.ugc.aweme.legoImp.task;

import X.0Gp;
import X.2HX;
import X.2UX;
import X.2nK;
import X.3GY;
import X.8Zd;
import X.8Ze;
import X.8eL;
import X.8ec;
import X.8n2;
import X.8uQ;
import X.9EH;
import X.9Ft;
import X.9Fx;
import X.C0755RTb;
import X.C0767RTn;
import X.C0806RVa;
import X.C0807RVb;
import X.C0810RVe;
import X.C0813RVh;
import X.M12;
import X.RVX;
import X.RXQ;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.CancellationSignal;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import com.android.installreferrer.api.InstallReferrerClient;
import com.appsflyer.AppsFlyerLib;
import com.bytedance.bpea.basics.Cert;
import com.bytedance.bpea.cert.token.TokenCert;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.compliance.api.a;
import java.lang.reflect.Method;
import java.util.List;

public class InitAppsFlyer implements 8Ze {
    public static final String LIZ = "XY8Lpakui8g4kBcposRgxA";
    public static boolean LIZIZ = false;
    public static boolean LIZJ = false;
    public static boolean LIZLLL = false;

    public static Cursor LIZ(ContentResolver contentResolver, Uri uri) {
        MethodCollector.i(5734);
        3GY.LIZ(240004);
        Uri uri2 = uri;
        ContentResolver contentResolver2 = contentResolver;
        Pair LIZ2 = 3GY.LIZ((Object) null, contentResolver2, new Object[]{uri2, null, null, null, null, null}, 240004, "android.database.Cursor", false, -849321744, 2);
        Cursor query = ((Boolean) LIZ2.first).booleanValue() ? (Cursor) LIZ2.second : contentResolver2.query(uri2, (String[]) null, (String) null, (String[]) null, (String) null, (CancellationSignal) null);
        MethodCollector.o(5734);
        return query;
    }

    public boolean meetTrigger() {
        return true;
    }

    public String prefix() {
        return "task_";
    }

    public boolean serialExecute() {
        return false;
    }

    public int targetProcess() {
        return 1;
    }

    public List triggerOtherLegoComponents() {
        return null;
    }

    public 9Ft triggerType() {
        return 8Zd.LIZ(this);
    }

    public 9Fx scenesType() {
        return 9Fx.DEFAULT;
    }

    public 8ec type() {
        return 8ec.MAIN;
    }

    public String key() {
        return getClass().getSimpleName();
    }

    static {
        Covode.recordClassIndex(90453);
    }

    public static boolean LIZIZ() {
        String str = Build.BRAND;
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        if (str.equalsIgnoreCase("xiaomi") || str.equalsIgnoreCase("redmi")) {
            return true;
        }
        return false;
    }

    public static boolean LIZJ() {
        String str = Build.BRAND;
        if (!TextUtils.isEmpty(str)) {
            return "samsung".equalsIgnoreCase(str);
        }
        return false;
    }

    public static void LJ() {
        try {
            String str = (String) Class.forName("android.os.SystemProperties").getMethod("get", new Class[]{String.class, String.class}).invoke((Object) null, new Object[]{"ro.product.tiktok.partnerid", ""});
            if (!TextUtils.isEmpty(str)) {
                C0755RTb.LIZ.LIZ(str, (String) null, (String) null, (Cert) TokenCert.with("bpea-appsflyer_androidsdk_1982"));
            }
        } catch (Exception unused) {
        }
    }

    public static void LIZLLL() {
        try {
            Method method = Class.forName("android.os.SystemProperties").getMethod("get", new Class[]{String.class, String.class});
            String str = (String) method.invoke((Object) null, new Object[]{"ro.channelId." + 9EH.LJJIFFI.LIZ().getPackageName(), ""});
            if (!TextUtils.isEmpty(str)) {
                C0755RTb.LIZ.LIZ(str, (String) null, (String) null, (Cert) TokenCert.with("bpea-appsflyer_androidsdk_1981"));
            }
        } catch (Exception unused) {
        }
    }

    public static boolean LIZ() {
        boolean z;
        if (C0813RVh.LJFF.LIZJ() && LIZJ) {
            return LIZLLL;
        }
        String packageName = 9EH.LJJIFFI.LIZ().getPackageName();
        if (!LIZIZ() || LIZ(packageName)) {
            z = true;
        } else {
            z = false;
        }
        LIZLLL = z;
        LIZJ = true;
        return z;
    }

    public static boolean LIZJ(Context context) {
        try {
            SharedPreferences LIZ2 = 8uQ.LIZ(context, "preinsatll_appflyer", 0);
            if (LIZ2.contains("is_microsoft_dou")) {
                return LIZ2.getBoolean("is_microsoft_dou", false);
            }
            PackageManager packageManager = context.getPackageManager();
            if (packageManager != null) {
                boolean hasSystemFeature = packageManager.hasSystemFeature("com.microsoft.device.display.displaymask");
                LIZ2.edit().putBoolean("is_microsoft_dou", hasSystemFeature).apply();
                return hasSystemFeature;
            }
            LIZ2.edit().putBoolean("is_microsoft_dou", false).apply();
            return false;
        } catch (Exception unused) {
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:29:0x00ab, code lost:
        if (0 != 0) goto L_0x0043;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static void LIZ(android.content.Context r8) {
        /*
            X.RVh r0 = X.C0813RVh.LJFF
            boolean r0 = r0.LIZLLL()
            if (r0 == 0) goto L_0x000d
            boolean r0 = LIZIZ
            if (r0 == 0) goto L_0x000d
            return
        L_0x000d:
            java.lang.String r0 = "preinsatll_appflyer"
            r4 = 0
            android.content.SharedPreferences r1 = X.8uQ.LIZ(r8, r0, r4)
            r7 = 1
            java.lang.String r6 = ""
            if (r1 == 0) goto L_0x0049
            java.lang.String r0 = "preinsatll_channel"
            java.lang.String r5 = r1.getString(r0, r6)
            java.lang.String r0 = "preinsatll_campaign"
            java.lang.String r3 = r1.getString(r0, r6)
            java.lang.String r0 = "preinsatll_site_id"
            java.lang.String r2 = r1.getString(r0, r6)
            boolean r0 = android.text.TextUtils.isEmpty(r5)
            if (r0 != 0) goto L_0x0049
            boolean r0 = LIZ()
            if (r0 == 0) goto L_0x0049
            X.RTb r1 = X.C0755RTb.LIZ
            java.lang.String r0 = "bpea-appsflyer_androidsdk_1979"
            com.bytedance.bpea.cert.token.TokenCert r0 = com.bytedance.bpea.cert.token.TokenCert.with(r0)
            r1.LIZ((java.lang.String) r5, (java.lang.String) r3, (java.lang.String) r2, (com.bytedance.bpea.basics.Cert) r0)
            r0 = 1
        L_0x0043:
            LIZIZ(r8)
            LIZIZ = r7
            return
        L_0x0049:
            boolean r0 = LIZ()
            if (r0 == 0) goto L_0x00ad
            android.content.pm.PackageManager r1 = r8.getPackageManager()     // Catch:{ all -> 0x00ab }
            java.lang.String r0 = r8.getPackageName()     // Catch:{ all -> 0x00ab }
            android.content.pm.ApplicationInfo r2 = LIZ((android.content.pm.PackageManager) r1, (java.lang.String) r0)     // Catch:{ all -> 0x00ab }
            android.os.Bundle r1 = r2.metaData     // Catch:{ all -> 0x00ab }
            java.lang.String r0 = "AF_PRE_INSTALL_NAME"
            java.lang.String r3 = r1.getString(r0)     // Catch:{ all -> 0x00ab }
            android.os.Bundle r1 = r2.metaData     // Catch:{ all -> 0x00ab }
            java.lang.String r0 = "AF_PRE_INSTALL_CAMPAIGN"
            java.lang.String r5 = r1.getString(r0, r6)     // Catch:{ all -> 0x00ab }
            android.os.Bundle r1 = r2.metaData     // Catch:{ all -> 0x00ab }
            java.lang.String r0 = "AF_PRE_INSTALL_SITE_ID"
            java.lang.String r2 = r1.getString(r0, r6)     // Catch:{ all -> 0x00ab }
            boolean r0 = android.text.TextUtils.isEmpty(r3)     // Catch:{ all -> 0x00ab }
            if (r0 != 0) goto L_0x0091
            boolean r0 = android.text.TextUtils.isEmpty(r5)     // Catch:{ all -> 0x00ab }
            if (r0 == 0) goto L_0x0085
            boolean r0 = android.text.TextUtils.isEmpty(r2)     // Catch:{ all -> 0x00ab }
            if (r0 != 0) goto L_0x0091
        L_0x0085:
            X.RTb r1 = X.C0755RTb.LIZ     // Catch:{ all -> 0x00ab }
            java.lang.String r0 = "bpea-appsflyer_androidsdk_1980"
            com.bytedance.bpea.cert.token.TokenCert r0 = com.bytedance.bpea.cert.token.TokenCert.with(r0)     // Catch:{ all -> 0x00ab }
            r1.LIZ((java.lang.String) r3, (java.lang.String) r5, (java.lang.String) r2, (com.bytedance.bpea.basics.Cert) r0)     // Catch:{ all -> 0x00ab }
            goto L_0x00ad
        L_0x0091:
            boolean r0 = android.text.TextUtils.isEmpty(r3)     // Catch:{ all -> 0x00ab }
            if (r0 != 0) goto L_0x00ad
            java.lang.String r0 = "googleplay"
            boolean r0 = android.text.TextUtils.equals(r3, r0)     // Catch:{ all -> 0x00ab }
            if (r0 != 0) goto L_0x00ad
            X.RTb r1 = X.C0755RTb.LIZ     // Catch:{ all -> 0x00ab }
            java.lang.String r0 = "bpea-appsflyer_androidsdk_1977"
            com.bytedance.bpea.cert.token.TokenCert r0 = com.bytedance.bpea.cert.token.TokenCert.with(r0)     // Catch:{ all -> 0x00ab }
            r1.LIZ((java.lang.String) r3, (com.bytedance.bpea.basics.Cert) r0)     // Catch:{ all -> 0x00ab }
            goto L_0x00ad
        L_0x00ab:
            if (r4 != 0) goto L_0x0043
        L_0x00ad:
            boolean r0 = LIZJ()
            if (r0 == 0) goto L_0x00b6
            LIZLLL()
        L_0x00b6:
            boolean r0 = LIZJ(r8)
            if (r0 == 0) goto L_0x0043
            LJ()
            goto L_0x0043
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.legoImp.task.InitAppsFlyer.LIZ(android.content.Context):void");
    }

    public static void LIZIZ(Context context) {
        String str;
        SharedPreferences LIZ2 = 8uQ.LIZ(context, "preinsatll_appflyer", 0);
        int i = LIZ2.getInt("check_times", 0);
        if (!LIZ2.contains("is_orange_preinstall")) {
            try {
                ContentResolver contentResolver = context.getContentResolver();
                Cursor LIZ3 = LIZ(contentResolver, Uri.parse("content://com.orange.update.provider.attributionprovider/" + context.getPackageName()));
                if (LIZ3 == null || LIZ3.getCount() <= 0) {
                    LIZ2.edit().putBoolean("is_orange_preinstall", false).apply();
                    if (LIZ3 == null) {
                        return;
                    }
                } else {
                    while (LIZ3.moveToNext()) {
                        String string = LIZ3.getString(LIZ3.getColumnIndex("package_name"));
                        String string2 = LIZ3.getString(LIZ3.getColumnIndex("preinstalled_version"));
                        if (LIZ3.getInt(LIZ3.getColumnIndex("is_virtual_preload")) == 1) {
                            str = "virtualpreload";
                        } else {
                            str = "appcenterstore";
                        }
                        C0755RTb.LIZ.LIZ("orange_int", str, (String) null, (Cert) TokenCert.with("bpea-appsflyer_androidsdk_2019"));
                        2UX r1 = new 2UX();
                        r1.LIZ("package_name", string);
                        r1.LIZ("preinstalled_version", string2);
                        r1.LIZ("campaign", str);
                        2nK.LIZ("orange_preinstall", r1.LIZ);
                        SharedPreferences.Editor edit = LIZ2.edit();
                        edit.putBoolean("is_orange_preinstall", true);
                        edit.putString("orange_campaign", str);
                        edit.apply();
                    }
                }
                LIZ3.close();
            } catch (Exception unused) {
                LIZ2.edit().putBoolean("is_orange_preinstall", false).apply();
            }
        } else if (LIZ2.getBoolean("is_orange_preinstall", false) && i < 2) {
            C0755RTb.LIZ.LIZ("orange_int", LIZ2.getString("orange_campaign", ""), (String) null, (Cert) TokenCert.with("bpea-appsflyer_androidsdk_2018"));
            LIZ2.edit().putInt("check_times", i + 1).apply();
        }
    }

    public void run(final Context context) {
        2HX.LIZ.LIZ("method_app_flyer_duration", false);
        if (RXQ.LIZIZ.LIZLLL()) {
            8eL.LIZIZ().execute(new Runnable() {
                static {
                    Covode.recordClassIndex(90454);
                }

                public final void run() {
                    if (!C0807RVb.LIZ.LIZ(context)) {
                        2nK.onEventV3("af_task_start");
                    }
                }
            });
        } else if (!C0807RVb.LIZ.LIZ(context)) {
            2nK.onEventV3("af_task_start");
        }
        LIZ(context);
        2 r4 = new 2(this, SystemClock.uptimeMillis());
        if (Build.VERSION.SDK_INT <= 28) {
            LIZ(context, (C0767RTn) r4);
            C0807RVb rVb = C0807RVb.LIZ;
            M12.LIZ(context);
            if (!rVb.LIZ(context)) {
                if (!C0813RVh.LJFF.LIZIZ()) {
                    2nK.onEventV3("google_install_referrer_start");
                }
                0Gp.LIZ(new C0806RVa(context));
            }
        } else if (C0807RVb.LIZ.LIZ(context)) {
            LIZ(context, (C0767RTn) r4);
        } else {
            0Gp.LIZ(new C0810RVe(this, InstallReferrerClient.newBuilder(context).build(), context, r4));
        }
        2HX.LIZ.LIZIZ("method_app_flyer_duration", false);
    }

    public static boolean LIZ(String str) {
        try {
            return ((Boolean) Class.forName("miui.os.MiuiInit").getMethod("isPreinstalledPackage", new Class[]{String.class}).invoke((Object) null, new Object[]{str})).booleanValue();
        } catch (Exception unused) {
            return false;
        }
    }

    public static ApplicationInfo LIZ(PackageManager packageManager, String str) {
        Context LIZ2 = 9EH.LJJIFFI.LIZ();
        if (!8n2.LJIIIZ || !TextUtils.equals(str, LIZ2.getPackageName())) {
            if (8n2.LJIIIZ) {
                TextUtils.equals(str, LIZ2.getPackageName());
            }
            return packageManager.getApplicationInfo(str, 128);
        }
        if (8n2.LIZ == null) {
            8n2.LIZ = packageManager.getApplicationInfo(str, 128);
        }
        return 8n2.LIZ;
    }

    public final void LIZ(Context context, C0767RTn rTn) {
        C0755RTb.LIZ.LIZ(LIZ, rTn, context, (Cert) TokenCert.with("bpea-appsflyer_androidsdk_1960"));
        if (C0813RVh.LJFF.LIZJ()) {
            8eL.LIZIZ().execute(new Runnable() {
                static {
                    Covode.recordClassIndex(90457);
                }

                public final void run() {
                    2nK.onEventV3("af_start_init");
                }
            });
        } else {
            2nK.onEventV3("af_start_init");
        }
        try {
            C0755RTb.LIZ.LIZ(TokenCert.with("bpea-appsflyer_androidsdk_1973"));
            C0755RTb.LIZ.LIZIZ(TokenCert.with("bpea-appsflyer_androidsdk_1975"));
            if (a.LIZLLL().LJI()) {
                AppsFlyerLib.getInstance().setSharingFilterForAllPartners();
            }
            RVX.LIZ();
        } catch (Exception unused) {
        }
    }
}
