package com.apiguard3.internal;

import X.4N2;
import X.8Kc;
import X.8r0;
import X.8r1;
import android.content.Context;
import android.util.Log;
import com.apiguard3.internal.setImportantForAutofill;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.abmock.SettingsManager;
import java.io.File;
import java.io.FilenameFilter;
import java.util.HashSet;
import java.util.Set;

public final class setContentCaptureSession {
    public static int getBody = 1;
    public static int getMethod;
    public setImportantForAutofill.getMethod AGRequest;
    public setImportantForAutofill.getBody getHeaders;
    public Set<String> getUrl;

    static {
        Covode.recordClassIndex(2485);
    }

    public setContentCaptureSession() {
        this(new setAccessibilityTraversalBefore(), new setAutofillId());
    }

    public static boolean INVOKEVIRTUAL_com_apiguard3_internal_setContentCaptureSession_com_ss_android_ugc_aweme_storage_FileLancet_delete(File file) {
        8r1 r3;
        MethodCollector.i(15457);
        try {
            if (8Kc.LIZIZ()) {
                r3 = (8r1) SettingsManager.LIZ().LIZ("storage_intercepter_key", 8r1.class, 4N2.LIZ);
            } else {
                r3 = 4N2.LIZ;
            }
            if (8r0.LIZIZ(file.getAbsolutePath(), r3)) {
                8r0.LIZ(file, new RuntimeException(), "exception_delete_log", 8r0.LIZ(r3));
            }
            if (8r0.LIZJ(file.getAbsolutePath(), r3)) {
                8r0.LIZ(file, new RuntimeException(), "exception_handle", 8r0.LIZ(r3));
                MethodCollector.o(15457);
                return false;
            }
        } catch (Throwable unused) {
        }
        boolean delete = file.delete();
        MethodCollector.o(15457);
        return delete;
    }

    public setContentCaptureSession(setImportantForAutofill.getBody getbody, setImportantForAutofill.getMethod getmethod) {
        this.getUrl = new HashSet();
        this.getHeaders = getbody;
        this.AGRequest = getmethod;
    }

    private void getHeaders(Context context, String str, String str2) {
        File dir = context.getDir("lib", 0);
        File method = getMethod(context, str, str2);
        final String body = this.getHeaders.getBody(str);
        File[] listFiles = dir.listFiles(new FilenameFilter() {
            public static int getBody = 1;
            public static int getMethod;

            static {
                Covode.recordClassIndex(2486);
            }

            public final boolean accept(File file, String str) {
                char c = 'E';
                int i = getBody + 69;
                getMethod = i % 128;
                if (i % 2 != 0) {
                    c = 'D';
                }
                boolean startsWith = str.startsWith(body);
                if (c != 'D') {
                    return startsWith;
                }
                throw new NullPointerException("hashCode");
            }
        });
        if (listFiles != null) {
            int length = listFiles.length;
            int i = 0;
            while (i < length) {
                int i2 = getMethod + 9;
                getBody = i2 % 128;
                int i3 = i2 % 2;
                File file = listFiles[i];
                if (!file.getAbsolutePath().equals(method.getAbsolutePath())) {
                    int i4 = getBody + 37;
                    getMethod = i4 % 128;
                    int i5 = i4 % 2;
                    INVOKEVIRTUAL_com_apiguard3_internal_setContentCaptureSession_com_ss_android_ugc_aweme_storage_FileLancet_delete(file);
                }
                i++;
                int i6 = getBody + 45;
                getMethod = i6 % 128;
                int i7 = i6 % 2;
            }
        }
    }

    private File getMethod(Context context, String str, String str2) {
        int i = getBody + 95;
        getMethod = i % 128;
        int i2 = i % 2;
        String body = this.getHeaders.getBody(str);
        if (setImportantForAutofill.getMethod(str2)) {
            return new File(context.getDir("lib", 0), body);
        }
        File dir = context.getDir("lib", 0);
        StringBuilder sb = new StringBuilder();
        sb.append(body);
        sb.append(".");
        sb.append(str2);
        File file = new File(dir, sb.toString());
        int i3 = getMethod + 73;
        getBody = i3 % 128;
        int i4 = i3 % 2;
        return file;
    }

    private void getUrl(Context context, String str, String str2) {
        boolean z;
        boolean z2 = false;
        if (!this.getUrl.contains(str)) {
            z = false;
        } else {
            z = true;
        }
        if (!z) {
            try {
                this.getHeaders.getHeaders(str);
                this.getUrl.add(str);
                Object[] objArr = new Object[2];
            } catch (UnsatisfiedLinkError e) {
                Object[] objArr2 = new Object[1];
                Log.getStackTraceString(e);
                Object[] objArr3 = new Object[2];
                Context context2 = context;
                File method = getMethod(context2, str, str2);
                if (!method.exists()) {
                    getHeaders(context2, str, str2);
                    this.AGRequest.getBody(context2, this.getHeaders.getHeaders(), this.getHeaders.getBody(str), method, this);
                }
                this.getHeaders.AGRequest(method.getAbsolutePath());
                this.getUrl.add(str);
                Object[] objArr4 = new Object[2];
                int i = getBody + 83;
                getMethod = i % 128;
                int i2 = i % 2;
            }
        } else {
            int i3 = getMethod + 39;
            getBody = i3 % 128;
            if (i3 % 2 == 0) {
                z2 = true;
            }
            Object[] objArr5 = new Object[1];
            if (z2) {
                objArr5[1] = str;
            }
        }
    }

    public static /* synthetic */ void getHeaders(setContentCaptureSession setcontentcapturesession, Context context, String str, String str2) {
        int i = getMethod + 41;
        getBody = i % 128;
        int i2 = i % 2;
        setcontentcapturesession.getUrl(context, str, str2);
        int i3 = getMethod + 59;
        getBody = i3 % 128;
        int i4 = i3 % 2;
    }

    public final void getMethod(Context context, String str, String str2, setImportantForAutofill.AGRequest aGRequest) {
        int i = getBody + 41;
        getMethod = i % 128;
        int i2 = i % 2;
        final Context context2 = context;
        if (context2 != null) {
            final String str3 = str;
            if (!setImportantForAutofill.getMethod(str3)) {
                Object[] objArr = new Object[1];
                final setImportantForAutofill.AGRequest aGRequest2 = aGRequest;
                if (aGRequest2 != null) {
                    new Thread(new Runnable((String) null) {
                        public static int method = 1;
                        public static int url;

                        static {
                            Covode.recordClassIndex(2487);
                        }

                        public final void run() {
                            int i = method + 39;
                            url = i % 128;
                            int i2 = i % 2;
                            try {
                                setContentCaptureSession.getHeaders(setContentCaptureSession.this, context2, str3, null);
                                aGRequest2.getUrl();
                                int i3 = url + 99;
                                method = i3 % 128;
                                int i4 = i3 % 2;
                            } catch (UnsatisfiedLinkError e) {
                                aGRequest2.AGRequest(e);
                            } catch (setRevealOnFocusHint e2) {
                                aGRequest2.AGRequest(e2);
                            }
                        }
                    }).start();
                    int i3 = getMethod + 107;
                    getBody = i3 % 128;
                    int i4 = i3 % 2;
                    return;
                }
                getUrl(context2, str3, (String) null);
                return;
            }
            throw new IllegalArgumentException("Given library is either null or empty");
        }
        throw new IllegalArgumentException("Given context is null");
    }
}
