package d3;

import android.content.SharedPreferences;
import android.text.TextUtils;

/* JADX INFO: loaded from: classes.dex */
public abstract class D1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final C3.W f11445a = C3.G.t("Version", "GoogleConsent", "VendorConsent", "VendorLegitimateInterest", "gdprApplies", "EnableAdvertiserConsentMode", "PolicyVersion", "PurposeConsents", "PurposeOneTreatment", "Purpose1", "Purpose3", "Purpose4", "Purpose7", "CmpSdkID", "PublisherCC", "PublisherRestrictions1", "PublisherRestrictions3", "PublisherRestrictions4", "PublisherRestrictions7", "AuthorizePurpose1", "AuthorizePurpose3", "AuthorizePurpose4", "AuthorizePurpose7", "PurposeDiagnostics");

    public static int a(SharedPreferences sharedPreferences, String str) {
        try {
            return sharedPreferences.getInt(str, -1);
        } catch (ClassCastException unused) {
            return -1;
        }
    }

    public static String b(SharedPreferences sharedPreferences, String str) {
        try {
            return sharedPreferences.getString(str, "");
        } catch (ClassCastException unused) {
            return "";
        }
    }

    public static final boolean c(com.google.android.gms.internal.measurement.K1 k12, C3.b0 b0Var, C3.b0 b0Var2, C3.i0 i0Var, char[] cArr, int i, int i5, int i8, String str, String str2, String str3, boolean z8, boolean z9) {
        C1 c12;
        char c3;
        int iD = d(k12);
        if (iD > 0 && (i5 != 1 || i != 1)) {
            cArr[iD] = '2';
        }
        if (e(k12, b0Var2) == com.google.android.gms.internal.measurement.L1.f9635r) {
            c3 = '3';
        } else {
            if (k12 == com.google.android.gms.internal.measurement.K1.f9623r && i8 == 1 && i0Var.f1276t.equals(str)) {
                if (iD > 0 && cArr[iD] != '2') {
                    cArr[iD] = '1';
                }
                return true;
            }
            if (b0Var.containsKey(k12) && (c12 = (C1) b0Var.get(k12)) != null) {
                int iOrdinal = c12.ordinal();
                com.google.android.gms.internal.measurement.L1 l12 = com.google.android.gms.internal.measurement.L1.f9637t;
                if (iOrdinal != 0) {
                    com.google.android.gms.internal.measurement.L1 l13 = com.google.android.gms.internal.measurement.L1.f9636s;
                    if (iOrdinal != 1) {
                        if (iOrdinal == 2) {
                            return e(k12, b0Var2) == l12 ? h(k12, cArr, str3, z9) : g(k12, cArr, str2, z8);
                        }
                        if (iOrdinal == 3) {
                            return e(k12, b0Var2) == l13 ? g(k12, cArr, str2, z8) : h(k12, cArr, str3, z9);
                        }
                        c3 = '0';
                    } else if (e(k12, b0Var2) != l13) {
                        return h(k12, cArr, str3, z9);
                    }
                } else if (e(k12, b0Var2) != l12) {
                    return g(k12, cArr, str2, z8);
                }
                c3 = '8';
            } else {
                c3 = '0';
            }
        }
        if (iD <= 0 || cArr[iD] == '2') {
            return false;
        }
        cArr[iD] = c3;
        return false;
    }

    public static final int d(com.google.android.gms.internal.measurement.K1 k12) {
        if (k12 == com.google.android.gms.internal.measurement.K1.f9623r) {
            return 1;
        }
        if (k12 == com.google.android.gms.internal.measurement.K1.f9625t) {
            return 2;
        }
        if (k12 == com.google.android.gms.internal.measurement.K1.f9626u) {
            return 3;
        }
        return k12 == com.google.android.gms.internal.measurement.K1.f9627v ? 4 : -1;
    }

    public static final com.google.android.gms.internal.measurement.L1 e(com.google.android.gms.internal.measurement.K1 k12, C3.b0 b0Var) {
        Object obj = com.google.android.gms.internal.measurement.L1.f9638u;
        Object obj2 = b0Var.get(k12);
        if (obj2 != null) {
            obj = obj2;
        }
        return (com.google.android.gms.internal.measurement.L1) obj;
    }

    public static final String f(com.google.android.gms.internal.measurement.K1 k12, String str, String str2) {
        String strValueOf = "0";
        String strValueOf2 = (TextUtils.isEmpty(str) || str.length() < k12.a()) ? "0" : String.valueOf(str.charAt(k12.a() - 1));
        if (!TextUtils.isEmpty(str2) && str2.length() >= k12.a()) {
            strValueOf = String.valueOf(str2.charAt(k12.a() - 1));
        }
        return String.valueOf(strValueOf2).concat(String.valueOf(strValueOf));
    }

    public static final boolean g(com.google.android.gms.internal.measurement.K1 k12, char[] cArr, String str, boolean z8) {
        char c3;
        int iD = d(k12);
        if (!z8) {
            c3 = '4';
        } else {
            if (str.length() >= k12.a()) {
                char cCharAt = str.charAt(k12.a() - 1);
                boolean z9 = cCharAt == '1';
                if (iD > 0 && cArr[iD] != '2') {
                    cArr[iD] = cCharAt != '1' ? '6' : '1';
                }
                return z9;
            }
            c3 = '0';
        }
        if (iD > 0 && cArr[iD] != '2') {
            cArr[iD] = c3;
        }
        return false;
    }

    public static final boolean h(com.google.android.gms.internal.measurement.K1 k12, char[] cArr, String str, boolean z8) {
        char c3;
        int iD = d(k12);
        if (!z8) {
            c3 = '5';
        } else {
            if (str.length() >= k12.a()) {
                char cCharAt = str.charAt(k12.a() - 1);
                boolean z9 = cCharAt == '1';
                if (iD > 0 && cArr[iD] != '2') {
                    cArr[iD] = cCharAt != '1' ? '7' : '1';
                }
                return z9;
            }
            c3 = '0';
        }
        if (iD > 0 && cArr[iD] != '2') {
            cArr[iD] = c3;
        }
        return false;
    }
}
