package com.appsflyer;

import android.os.Bundle;
import android.util.Base64;
import com.facebook.applinks.AppLinkData;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class AFFacebookDeferredDeeplink {

    /* renamed from: ˋ  reason: contains not printable characters */
    public String f1854;

    /* renamed from: ˎ  reason: contains not printable characters */
    public byte[] f1855;

    /* renamed from: ˏ  reason: contains not printable characters */
    public String f1856;

    /* renamed from: ॱ  reason: contains not printable characters */
    public String f1857;

    /* renamed from: com.appsflyer.AFFacebookDeferredDeeplink$3  reason: invalid class name */
    public static class AnonymousClass3 implements InvocationHandler {

        /* renamed from: ˊ  reason: contains not printable characters */
        public static String f1858;

        /* renamed from: ˎ  reason: contains not printable characters */
        public static String f1859;

        /* renamed from: ˋ  reason: contains not printable characters */
        public /* synthetic */ AppLinkFetchEvents f1860;

        /* renamed from: ˏ  reason: contains not printable characters */
        public /* synthetic */ Class f1861;

        public AnonymousClass3(Class cls, AppLinkFetchEvents appLinkFetchEvents) {
            this.f1861 = cls;
            this.f1860 = appLinkFetchEvents;
        }

        /* renamed from: ˋ  reason: contains not printable characters */
        public static void m1074(String str) {
            f1859 = str;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < str.length(); i++) {
                if (i == 0 || i == str.length() - 1) {
                    sb.append(str.charAt(i));
                } else {
                    sb.append("*");
                }
            }
            f1858 = sb.toString();
        }

        /* renamed from: ॱ  reason: contains not printable characters */
        public static void m1075(String str) {
            if (f1859 == null) {
                m1074(AppsFlyerProperties.getInstance().getString(AppsFlyerProperties.AF_KEY));
            }
            String str2 = f1859;
            if (str2 != null && str.contains(str2)) {
                AFLogger.afInfoLog(str.replace(f1859, f1858));
            }
        }

        @Override // java.lang.reflect.InvocationHandler
        public final Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
            String str;
            String str2;
            String str3;
            Bundle bundle;
            if (method.getName().equals("onDeferredAppLinkDataFetched")) {
                if (objArr[0] != null) {
                    Bundle bundle2 = (Bundle) Bundle.class.cast(this.f1861.getMethod("getArgumentBundle", new Class[0]).invoke(this.f1861.cast(objArr[0]), new Object[0]));
                    if (bundle2 != null) {
                        str = bundle2.getString(AppLinkData.ARGUMENTS_NATIVE_URL);
                        str3 = bundle2.getString(AppLinkData.METHOD_ARGS_TARGET_URL_KEY);
                        Bundle bundle3 = bundle2.getBundle(AppLinkData.ARGUMENTS_EXTRAS_KEY);
                        str2 = (bundle3 == null || (bundle = bundle3.getBundle("deeplink_context")) == null) ? null : bundle.getString("promo_code");
                    } else {
                        str2 = null;
                        str = null;
                        str3 = null;
                    }
                    AppLinkFetchEvents appLinkFetchEvents = this.f1860;
                    if (appLinkFetchEvents != null) {
                        appLinkFetchEvents.onAppLinkFetchFinished(str, str3, str2);
                    }
                } else {
                    AppLinkFetchEvents appLinkFetchEvents2 = this.f1860;
                    if (appLinkFetchEvents2 != null) {
                        appLinkFetchEvents2.onAppLinkFetchFinished(null, null, null);
                    }
                }
                return null;
            }
            AppLinkFetchEvents appLinkFetchEvents3 = this.f1860;
            if (appLinkFetchEvents3 != null) {
                appLinkFetchEvents3.onAppLinkFetchFailed("onDeferredAppLinkDataFetched invocation failed");
            }
            return null;
        }

        public AnonymousClass3() {
        }
    }

    public interface AppLinkFetchEvents {
        void onAppLinkFetchFailed(String str);

        void onAppLinkFetchFinished(String str, String str2, String str3);
    }

    public AFFacebookDeferredDeeplink() {
    }

    public AFFacebookDeferredDeeplink(String str, byte[] bArr, String str2) {
        this.f1854 = str;
        this.f1855 = bArr;
        this.f1857 = str2;
    }

    public AFFacebookDeferredDeeplink(char[] cArr) {
        Scanner scanner = new Scanner(new String(cArr));
        int i = 0;
        int i2 = 0;
        while (scanner.hasNextLine()) {
            String nextLine = scanner.nextLine();
            if (nextLine.startsWith("url=")) {
                this.f1854 = nextLine.substring(4).trim();
            } else if (nextLine.startsWith("version=")) {
                this.f1857 = nextLine.substring(8).trim();
                Matcher matcher = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$").matcher(this.f1857);
                if (matcher.matches()) {
                    i = Integer.parseInt(matcher.group(1));
                    i2 = Integer.parseInt(matcher.group(2));
                }
            } else if (nextLine.startsWith("data=")) {
                String trim = nextLine.substring(5).trim();
                this.f1855 = (i > 4 || i2 >= 11) ? Base64.decode(trim, 2) : trim.getBytes();
            }
        }
        scanner.close();
    }
}
