package p7;

import android.R;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.KeyguardManager;
import android.app.LocaleManager;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.os.PowerManager;
import android.os.Process;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.widget.AbsListView;
import android.widget.HorizontalScrollView;
import android.widget.ScrollView;
import androidx.annotation.Nullable;
import androidx.media3.exoplayer.offline.DownloadService;
import androidx.media3.exoplayer.rtsp.RtspHeaders;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import androidx.media3.exoplayer.upstream.CmcdData;
import com.google.android.gms.ads.formats.zzh;
import com.google.android.gms.ads.nativead.NativeAdView;
import com.google.android.gms.internal.ads.a70;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.br0;
import com.google.android.gms.internal.ads.c00;
import com.google.android.gms.internal.ads.cr0;
import com.google.android.gms.internal.ads.kq1;
import com.google.android.gms.internal.ads.n60;
import com.google.android.gms.internal.ads.rq1;
import com.google.android.gms.internal.ads.ru;
import com.google.android.gms.internal.ads.s50;
import com.google.android.gms.internal.ads.tn;
import com.google.android.gms.internal.ads.uo;
import com.google.android.gms.internal.ads.vj1;
import com.google.android.gms.internal.ads.wa1;
import com.google.android.gms.internal.ads.yn;
import com.google.android.gms.internal.ads.za1;
import com.google.android.gms.internal.ads.zzduy;
import com.google.firebase.messaging.Constants$ScionAnalytics$MessageType;
import java.io.ByteArrayInputStream;
import java.net.HttpURLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class r0 {

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static final m0 f31763l = new m0(Looper.getMainLooper(), 0);

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public String f31770g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public volatile String f31771h;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final AtomicReference f31764a = new AtomicReference(null);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final AtomicReference f31765b = new AtomicReference(null);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final AtomicReference f31766c = new AtomicReference(new Bundle());

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final AtomicBoolean f31767d = new AtomicBoolean();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f31768e = true;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Object f31769f = new Object();

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public boolean f31772i = false;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f31773j = false;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final ExecutorService f31774k = Executors.newSingleThreadExecutor();

    public static ArrayList D() {
        tn tnVar = ao.f8762a;
        List listB = n7.y.f31093e.f31094a.B();
        ArrayList arrayList = new ArrayList();
        for (String str : (ArrayList) listB) {
            ru ruVarC = ru.c(new kq1(','));
            str.getClass();
            Iterator it = new rq1(ruVarC, str).iterator();
            while (it.hasNext()) {
                try {
                    arrayList.add(Long.valueOf((String) it.next()));
                } catch (NumberFormatException unused) {
                    l0.g("Experiment ID is not a number");
                }
            }
        }
        return arrayList;
    }

    public static String E(String str, String str2) {
        char[] charArray = str.toCharArray();
        for (int i10 = 0; i10 < charArray.length; i10++) {
            charArray[i10] = (char) (charArray[i10] ^ str2.charAt(i10 % str2.length()));
        }
        return new String(charArray);
    }

    public static r F(Context context) {
        r rVar = new r(Locale.getDefault().getLanguage(), Locale.getDefault().getCountry());
        if (Build.VERSION.SDK_INT < 33) {
            Locale locale = context.getResources().getConfiguration().getLocales().get(0);
            return new r(locale.getLanguage(), locale.getCountry());
        }
        LocaleManager localeManagerA = io.flutter.embedding.android.d.a(context.getSystemService(io.flutter.embedding.android.d.j()));
        if (localeManagerA == null || localeManagerA.getSystemLocales().isEmpty()) {
            return rVar;
        }
        Locale locale2 = localeManagerA.getSystemLocales().get(0);
        return new r(locale2.getLanguage(), locale2.getCountry());
    }

    public static int G(Context context, Uri uri, Bundle bundle) {
        if (context == null) {
            l0.g("Trying to open chrome custom tab on a null context");
            return 3;
        }
        if (!(context instanceof Activity)) {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setData(uri);
            intent.addFlags(268435456);
            context.startActivity(intent);
            return 2;
        }
        tn tnVar = ao.f9033q5;
        n7.y yVar = n7.y.f31093e;
        boolean zBooleanValue = ((Boolean) yVar.f31096c.b(tnVar)).booleanValue();
        yn ynVar = yVar.f31096c;
        if (zBooleanValue) {
            androidx.browser.customtabs.q qVar = new androidx.browser.customtabs.q(m7.n.C.f30475n.zzb());
            v(qVar, bundle);
            androidx.browser.customtabs.r rVarB = qVar.b();
            if (((Boolean) ynVar.b(ao.D5)).booleanValue()) {
                q7.e eVar = n7.x.f31085g.f31086a;
                if (q7.e.h()) {
                    return 5;
                }
            }
            rVarB.f884a.setPackage(vj1.c(context));
            rVarB.a(context, uri);
            return 5;
        }
        if (!((Boolean) ynVar.b(ao.f8999o5)).booleanValue()) {
            Intent intent2 = new Intent("android.intent.action.VIEW");
            intent2.setData(uri);
            intent2.addFlags(268435456);
            context.startActivity(intent2);
            return 9;
        }
        uo uoVar = new uo();
        u.e eVar2 = new u.e();
        eVar2.f33125a = uoVar;
        eVar2.f33126b = bundle;
        eVar2.f33127c = context;
        eVar2.f33128d = uri;
        uoVar.c(eVar2);
        uoVar.d((Activity) context);
        return 5;
    }

    /* JADX WARN: Removed duplicated region for block: B:4:0x0007  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final boolean H(View view) {
        Activity activity;
        View rootView = view.getRootView();
        if (rootView == null) {
            activity = null;
        } else {
            Context context = rootView.getContext();
            if (context instanceof Activity) {
                activity = (Activity) context;
            }
        }
        if (activity == null) {
            return false;
        }
        Window window = activity.getWindow();
        WindowManager.LayoutParams attributes = window != null ? window.getAttributes() : null;
        return (attributes == null || (attributes.flags & 524288) == 0) ? false : true;
    }

    public static final void I(Context context, Intent intent) {
        if (intent == null) {
            return;
        }
        Bundle extras = intent.getExtras() != null ? intent.getExtras() : new Bundle();
        extras.putBinder("android.support.customtabs.extra.SESSION", null);
        extras.putString("com.android.browser.application_id", context.getPackageName());
        intent.putExtras(extras);
    }

    public static final String J(Context context) {
        if (context.getApplicationContext() != null) {
            context = context.getApplicationContext();
        }
        return u(zzai(context));
    }

    public static final String K() {
        StringBuilder sb = new StringBuilder(256);
        sb.append("Mozilla/5.0 (Linux; U; Android");
        String str = Build.VERSION.RELEASE;
        if (str != null) {
            sb.append(" ");
            sb.append(str);
        }
        sb.append("; ");
        sb.append(Locale.getDefault());
        String str2 = Build.DEVICE;
        if (str2 != null) {
            sb.append("; ");
            sb.append(str2);
            String str3 = Build.DISPLAY;
            if (str3 != null) {
                sb.append(" Build/");
                sb.append(str3);
            }
        }
        sb.append(") AppleWebKit/533 Version/4.0 Safari/533");
        return sb.toString();
    }

    public static final String L() {
        String str = Build.MANUFACTURER;
        String str2 = Build.MODEL;
        return str2.startsWith(str) ? str2 : defpackage.e.p(new StringBuilder(String.valueOf(str).length() + 1 + str2.length()), str, " ", str2);
    }

    public static final HashMap M(String str) {
        HashMap map = new HashMap();
        try {
            JSONObject jSONObject = new JSONObject(str);
            Iterator<String> itKeys = jSONObject.keys();
            while (itKeys.hasNext()) {
                String next = itKeys.next();
                HashSet hashSet = new HashSet();
                JSONArray jSONArrayOptJSONArray = jSONObject.optJSONArray(next);
                if (jSONArrayOptJSONArray != null) {
                    for (int i10 = 0; i10 < jSONArrayOptJSONArray.length(); i10++) {
                        String strOptString = jSONArrayOptJSONArray.optString(i10);
                        if (strOptString != null) {
                            hashSet.add(strOptString);
                        }
                    }
                    map.put(next, hashSet);
                }
            }
            return map;
        } catch (JSONException e10) {
            m7.n.C.f30469h.d("AdUtil.getMapOfFileNamesToKeysFromJsonString", e10);
            return map;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r3v0, types: [android.view.View] */
    /* JADX WARN: Type inference failed for: r3v1 */
    /* JADX WARN: Type inference failed for: r3v6, types: [android.view.ViewParent] */
    public static final long a(View view) {
        float fMin = Float.MAX_VALUE;
        do {
            if (!(view instanceof View)) {
                break;
            }
            View view2 = (View) view;
            fMin = Math.min(fMin, view2.getAlpha());
            view = view2.getParent();
        } while (fMin > 0.0f);
        return Math.round((fMin >= 0.0f ? fMin : 0.0f) * 100.0f);
    }

    public static final boolean b(Context context, String str) {
        int i10 = c00.f9688a;
        Context applicationContext = context.getApplicationContext();
        if (applicationContext != null) {
            context = applicationContext;
        }
        return j8.e.a(context).f28722a.getPackageManager().checkPermission(str, context.getPackageName()) == 0;
    }

    public static final boolean c(String str) {
        if (!q7.g.b()) {
            return false;
        }
        tn tnVar = ao.W5;
        n7.y yVar = n7.y.f31093e;
        if (!((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
            return false;
        }
        String str2 = (String) yVar.f31096c.b(ao.Y5);
        if (!str2.isEmpty()) {
            for (String str3 : str2.split(";")) {
                if (str3.equals(str)) {
                    return false;
                }
            }
        }
        String str4 = (String) n7.y.f31093e.f31096c.b(ao.X5);
        if (str4.isEmpty()) {
            return true;
        }
        for (String str5 : str4.split(";")) {
            if (str5.equals(str)) {
                return true;
            }
        }
        return false;
    }

    public static final boolean d(Context context) {
        KeyguardManager keyguardManagerZzaf;
        return (context == null || (keyguardManagerZzaf = zzaf(context)) == null || !keyguardManagerZzaf.isKeyguardLocked()) ? false : true;
    }

    public static final boolean e(Context context) {
        try {
            context.getClassLoader().loadClass("com.google.android.gms.ads.internal.ClientApi");
            return false;
        } catch (ClassNotFoundException unused) {
            return true;
        } catch (Throwable th) {
            m7.n.C.f30469h.d("AdUtil.isLiteSdk", th);
            return false;
        }
    }

    public static final boolean f(Context context) {
        List<ActivityManager.RunningAppProcessInfo> runningAppProcesses;
        PowerManager powerManager;
        try {
            ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
            KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService("keyguard");
            if (activityManager == null || keyguardManager == null || (runningAppProcesses = activityManager.getRunningAppProcesses()) == null) {
                return false;
            }
            for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
                if (Process.myPid() == runningAppProcessInfo.pid) {
                    if (runningAppProcessInfo.importance == 100 && !keyguardManager.inKeyguardRestrictedInputMode() && (powerManager = (PowerManager) context.getSystemService("power")) != null) {
                        return !powerManager.isScreenOn();
                    }
                    return true;
                }
            }
            return true;
        } catch (Throwable unused) {
        }
        return false;
    }

    public static final boolean g(Context context) {
        try {
            Bundle bundleZzai = zzai(context);
            String string = bundleZzai.getString("com.google.android.gms.ads.INTEGRATION_MANAGER");
            if (TextUtils.isEmpty(u(bundleZzai))) {
                if (!TextUtils.isEmpty(string)) {
                    return true;
                }
            }
        } catch (RemoteException unused) {
        }
        return false;
    }

    public static final boolean h(Context context) {
        Window window;
        if ((context instanceof Activity) && (window = ((Activity) context).getWindow()) != null && window.getDecorView() != null) {
            Rect rect = new Rect();
            Rect rect2 = new Rect();
            window.getDecorView().getGlobalVisibleRect(rect, null);
            window.getDecorView().getWindowVisibleDisplayFrame(rect2);
            if (rect.bottom != 0 && rect2.bottom != 0 && rect.top == rect2.top) {
                return true;
            }
        }
        return false;
    }

    public static final void i(View view, int i10) {
        String strA;
        int i11;
        int iHeight;
        int iWidth;
        String str;
        wa1 wa1VarZzC;
        za1 za1VarZzaC;
        View childAt = view;
        int[] iArr = new int[2];
        Rect rect = new Rect();
        try {
            String packageName = view.getContext().getPackageName();
            if (childAt instanceof zzduy) {
                childAt = ((zzduy) childAt).getChildAt(0);
            }
            if ((childAt instanceof zzh) || (childAt instanceof NativeAdView)) {
                strA = "NATIVE";
                i11 = 1;
            } else {
                strA = "UNKNOWN";
                i11 = 0;
            }
            if (childAt.getLocalVisibleRect(rect)) {
                iWidth = rect.width();
                iHeight = rect.height();
            } else {
                iHeight = 0;
                iWidth = 0;
            }
            r0 r0Var = m7.n.C.f30464c;
            long jA = a(childAt);
            childAt.getLocationOnScreen(iArr);
            int i12 = iArr[0];
            int i13 = iArr[1];
            String str2 = "none";
            if (!(childAt instanceof n60) || (za1VarZzaC = ((n60) childAt).zzaC()) == null) {
                str = "none";
            } else {
                str = za1VarZzaC.f19181b;
                int iHashCode = childAt.hashCode();
                StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 1 + String.valueOf(iHashCode).length());
                sb.append(str);
                sb.append(":");
                sb.append(iHashCode);
                childAt.setContentDescription(sb.toString());
            }
            if ((childAt instanceof s50) && (wa1VarZzC = ((s50) childAt).zzC()) != null) {
                strA = wa1.a(wa1VarZzC.f17973b);
                i11 = wa1VarZzC.f17979e;
                str2 = wa1VarZzC.B;
            }
            q7.j.c(String.format(Locale.US, "<Ad hashCode=%d, package=%s, adNetCls=%s, gwsQueryId=%s, format=%s, impType=%d, class=%s, x=%d, y=%d, width=%d, height=%d, vWidth=%d, vHeight=%d, alpha=%d, state=%s>", Integer.valueOf(childAt.hashCode()), packageName, str2, str, strA, Integer.valueOf(i11), childAt.getClass().getName(), Integer.valueOf(i12), Integer.valueOf(i13), Integer.valueOf(childAt.getWidth()), Integer.valueOf(childAt.getHeight()), Integer.valueOf(iWidth), Integer.valueOf(iHeight), Long.valueOf(jA), Integer.toString(i10, 2)));
        } catch (Exception unused) {
        }
    }

    public static final AlertDialog.Builder j(Context context) {
        t0 t0Var = m7.n.C.f30467f;
        return new AlertDialog.Builder(context, R.style.Theme.Material.Dialog.Alert);
    }

    public static final void k(Context context, wa1 wa1Var, cr0 cr0Var) {
        br0 br0VarA = cr0Var.a();
        br0VarA.zzc("action", "can_show");
        m7.n nVar = m7.n.C;
        r0 r0Var = nVar.f30464c;
        boolean zF = f(context);
        String str = SessionDescription.SUPPORTED_SDP_VERSION;
        br0VarA.zzc(DownloadService.KEY_FOREGROUND, true != zF ? "1" : SessionDescription.SUPPORTED_SDP_VERSION);
        if (true == nVar.f30468g.d()) {
            str = "1";
        }
        br0VarA.zzc("fg_al", str);
        if (wa1Var != null) {
            List list = wa1Var.f18005r;
            if (!list.isEmpty()) {
                br0VarA.zzc("ancn", (String) list.get(0));
            }
            br0VarA.zzc("ad_format", wa1.a(wa1Var.f17973b));
        }
        br0VarA.b();
    }

    public static final int l(String str) {
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException e10) {
            q7.j.d("Could not parse value:".concat(e10.toString()));
            return 0;
        }
    }

    public static final int[] m(Activity activity) {
        View viewFindViewById;
        Window window = activity.getWindow();
        return (window == null || (viewFindViewById = window.findViewById(R.id.content)) == null) ? new int[]{0, 0} : new int[]{viewFindViewById.getWidth(), viewFindViewById.getHeight()};
    }

    public static final int[] n(Activity activity) {
        View viewFindViewById;
        Window window = activity.getWindow();
        int[] iArr = (window == null || (viewFindViewById = window.findViewById(R.id.content)) == null) ? new int[]{0, 0} : new int[]{viewFindViewById.getTop(), viewFindViewById.getBottom()};
        n7.x xVar = n7.x.f31085g;
        return new int[]{xVar.f31086a.b(activity, iArr[0]), xVar.f31086a.b(activity, iArr[1])};
    }

    public static final boolean o(View view, PowerManager powerManager, KeyguardManager keyguardManager) {
        boolean z10 = m7.n.C.f30464c.f31768e || keyguardManager == null || !keyguardManager.inKeyguardRestrictedInputMode() || H(view);
        long jA = a(view);
        if (view.getVisibility() == 0 && view.isShown() && ((powerManager == null || powerManager.isScreenOn()) && z10)) {
            tn tnVar = ao.J1;
            n7.y yVar = n7.y.f31093e;
            if (!((Boolean) yVar.f31096c.b(tnVar)).booleanValue() || view.getLocalVisibleRect(new Rect()) || view.getGlobalVisibleRect(new Rect())) {
                tn tnVar2 = ao.Ob;
                if (!((Boolean) yVar.f31096c.b(tnVar2)).booleanValue() || jA >= ((Integer) r6.b(ao.Qb)).intValue()) {
                    return true;
                }
            }
        }
        return false;
    }

    public static int p(int i10) {
        if (i10 >= 5000) {
            return i10;
        }
        if (i10 <= 0) {
            return 60000;
        }
        StringBuilder sb = new StringBuilder(String.valueOf(i10).length() + 86);
        sb.append("HTTP timeout too low: ");
        sb.append(i10);
        sb.append(" milliseconds. Reverting to default timeout: 60000 milliseconds.");
        q7.j.d(sb.toString());
        return 60000;
    }

    public static final void q(Context context, Intent intent) {
        if (!((Boolean) n7.y.f31093e.f31096c.b(ao.f8955lc)).booleanValue()) {
            try {
                context.startActivity(intent);
                return;
            } catch (Throwable unused) {
                intent.addFlags(268435456);
                context.startActivity(intent);
                return;
            }
        }
        try {
            try {
                context.startActivity(intent);
            } catch (Throwable unused2) {
                intent.addFlags(268435456);
                context.startActivity(intent);
            }
        } catch (SecurityException e10) {
            m7.n.C.f30469h.d("AdUtil.startActivityWithUnknownContext", e10);
        }
    }

    public static final void r(Context context, Uri uri) {
        try {
            Intent intent = new Intent("android.intent.action.VIEW", uri);
            Bundle bundle = new Bundle();
            intent.putExtras(bundle);
            I(context, intent);
            bundle.putString("com.android.browser.application_id", context.getPackageName());
            context.startActivity(intent);
            String string = uri.toString();
            StringBuilder sb = new StringBuilder(String.valueOf(string).length() + 26);
            sb.append("Opening ");
            sb.append(string);
            sb.append(" in a new browser.");
            q7.j.a(sb.toString());
        } catch (ActivityNotFoundException unused) {
        }
    }

    public static final boolean s(Context context, View view) {
        Context applicationContext = context.getApplicationContext();
        return o(view, applicationContext != null ? (PowerManager) applicationContext.getSystemService("power") : null, zzaf(context));
    }

    public static boolean t(String str, AtomicReference atomicReference, String str2) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        try {
            Pattern patternCompile = (Pattern) atomicReference.get();
            if (patternCompile == null || !str2.equals(patternCompile.pattern())) {
                patternCompile = Pattern.compile(str2);
                atomicReference.set(patternCompile);
            }
            return patternCompile.matcher(str).matches();
        } catch (PatternSyntaxException unused) {
            return false;
        }
    }

    public static String u(Bundle bundle) {
        if (bundle == null) {
            return "";
        }
        String string = bundle.getString("com.google.android.gms.ads.APPLICATION_ID");
        return !TextUtils.isEmpty(string) ? (string.matches("^ca-app-pub-[0-9]{16}~[0-9]{10}$") || string.matches("^/\\d+~.+$")) ? string : "" : "";
    }

    public static final void v(androidx.browser.customtabs.q qVar, Bundle bundle) {
        if (bundle.isEmpty()) {
            return;
        }
        int i10 = bundle.getInt(CmcdData.STREAMING_FORMAT_HLS, -1);
        Intent intent = qVar.f880a;
        if (i10 >= 0) {
            if (i10 <= 0) {
                throw new IllegalArgumentException("Invalid value for the initialHeightPx argument");
            }
            intent.putExtra("androidx.browser.customtabs.extra.INITIAL_ACTIVITY_HEIGHT_PX", i10);
            intent.putExtra("androidx.browser.customtabs.extra.ACTIVITY_HEIGHT_RESIZE_BEHAVIOR", 0);
        }
        int i11 = bundle.getInt("cbp", -1);
        if (i11 < 0 || i11 > 2) {
            return;
        }
        if (i11 < 0 || i11 > 2) {
            throw new IllegalArgumentException("Invalid value for the position argument");
        }
        intent.putExtra("androidx.browser.customtabs.extra.CLOSE_BUTTON_POSITION", i11);
    }

    public static final String w(Context context, String str) {
        String strK;
        if (str == null) {
            return K();
        }
        try {
            if (androidx.emoji2.text.b0.f2209b == null) {
                androidx.emoji2.text.b0.f2209b = new androidx.emoji2.text.b0();
            }
            androidx.emoji2.text.b0 b0Var = androidx.emoji2.text.b0.f2209b;
            if (TextUtils.isEmpty(b0Var.f2210a)) {
                b0Var.f2210a = (String) hb.a.L0(context, new h0(e8.g.getRemoteContext(context), context));
            }
            strK = b0Var.f2210a;
        } catch (Exception unused) {
            strK = null;
        }
        if (TextUtils.isEmpty(strK)) {
            strK = WebSettings.getDefaultUserAgent(context);
        }
        if (TextUtils.isEmpty(strK)) {
            strK = K();
        }
        String strP = defpackage.e.p(new StringBuilder(String.valueOf(strK).length() + 10 + str.length()), strK, " (Mobile; ", str);
        try {
            if (j8.e.a(context).c()) {
                StringBuilder sb = new StringBuilder(strP.length() + 4);
                sb.append(strP);
                sb.append(";aia");
                strP = sb.toString();
            }
        } catch (Exception e10) {
            m7.n.C.f30469h.d("AdUtil.getUserAgent", e10);
        }
        return strP.concat(")");
    }

    @Nullable
    public static final WebResourceResponse zzB(Context context, String str, String str2) {
        try {
            HashMap map = new HashMap();
            map.put(RtspHeaders.USER_AGENT, m7.n.C.f30464c.A(context, str));
            map.put(RtspHeaders.CACHE_CONTROL, "max-stale=3600");
            String str3 = (String) new v(context).zzb(0, str2, map, null).get(60L, TimeUnit.SECONDS);
            if (str3 != null) {
                return new WebResourceResponse("application/javascript", "UTF-8", new ByteArrayInputStream(str3.getBytes(StandardCharsets.UTF_8)));
            }
        } catch (InterruptedException | ExecutionException | TimeoutException unused) {
        }
        return null;
    }

    public static final int zzC(@Nullable View view) {
        for (ViewParent parent = view.getParent(); parent != null; parent = parent.getParent()) {
            if (parent instanceof ScrollView) {
                return 1;
            }
            if (parent instanceof AbsListView) {
                return 2;
            }
            if (parent instanceof HorizontalScrollView) {
                return 3;
            }
            if (parent instanceof androidx.core.view.q0) {
                return 4;
            }
        }
        return 0;
    }

    @Nullable
    public static final x zzE(Context context) {
        try {
            Object objNewInstance = context.getClassLoader().loadClass("com.google.android.gms.ads.internal.util.WorkManagerUtil").getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
            if (!(objNewInstance instanceof IBinder)) {
                q7.j.b("Instantiated WorkManagerUtil not instance of IBinder.");
                return null;
            }
            IBinder iBinder = (IBinder) objNewInstance;
            if (iBinder == null) {
                return null;
            }
            IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.gms.ads.internal.util.IWorkManagerUtil");
            return iInterfaceQueryLocalInterface instanceof x ? (x) iInterfaceQueryLocalInterface : new w(iBinder, "com.google.android.gms.ads.internal.util.IWorkManagerUtil", 0);
        } catch (Exception e10) {
            m7.n.C.f30469h.d("Failed to instantiate WorkManagerUtil", e10);
            return null;
        }
    }

    public static final boolean zzT(@Nullable wa1 wa1Var) {
        return ((Boolean) n7.y.f31093e.f31096c.b(ao.Le)).booleanValue() && wa1Var != null && wa1Var.f17979e == 4;
    }

    @Nullable
    public static final Map zzV(Uri uri) {
        String encodedQuery;
        if (uri == null) {
            return null;
        }
        if (!((Boolean) n7.y.f31093e.f31096c.b(ao.f9076t)).booleanValue()) {
            HashMap map = new HashMap();
            for (String str : uri.getQueryParameterNames()) {
                if (!TextUtils.isEmpty(str)) {
                    map.put(str, uri.getQueryParameter(str));
                }
            }
            return map;
        }
        HashMap map2 = new HashMap();
        if (!uri.isOpaque() && (encodedQuery = uri.getEncodedQuery()) != null) {
            int i10 = 0;
            while (true) {
                int iIndexOf = encodedQuery.indexOf(38, i10);
                int length = encodedQuery.length();
                if (iIndexOf != -1) {
                    length = iIndexOf;
                }
                int iIndexOf2 = encodedQuery.indexOf(61, i10);
                if (iIndexOf2 > length || iIndexOf2 == -1) {
                    iIndexOf2 = length;
                }
                map2.put(Uri.decode(encodedQuery.substring(i10, iIndexOf2)), iIndexOf2 == length ? "" : Uri.decode(encodedQuery.substring(iIndexOf2 + 1, length)));
                if (iIndexOf == -1) {
                    break;
                }
                i10 = iIndexOf + 1;
            }
        }
        return map2;
    }

    public static final void zzae(Context context, Intent intent, @Nullable cr0 cr0Var, String str) {
        tn tnVar = ao.f9042qe;
        n7.y yVar = n7.y.f31093e;
        yn ynVar = yVar.f31096c;
        yn ynVar2 = yVar.f31096c;
        if (!((Boolean) ynVar.b(tnVar)).booleanValue() || !(context instanceof a70)) {
            q(context, intent);
            return;
        }
        try {
            Uri data = intent.getData();
            if (data == null || data.toString() == null || !data.toString().matches((String) ynVar2.b(ao.f9074se))) {
                q(context, intent);
                return;
            }
            ((a70) context).a(intent);
            if (!((Boolean) ynVar2.b(ao.f9058re)).booleanValue() || cr0Var == null) {
                return;
            }
            br0 br0VarA = cr0Var.a();
            br0VarA.zzc("action", "hila");
            if (str == null) {
                str = "";
            }
            br0VarA.zzc("gqi", str);
            br0VarA.d();
        } catch (ActivityNotFoundException e10) {
            e = e10;
            m7.n.C.f30469h.d("AdUtil.startActivityForResult", e);
            q(context, intent);
        } catch (SecurityException e11) {
            e = e11;
            m7.n.C.f30469h.d("AdUtil.startActivityForResult", e);
            q(context, intent);
        } catch (Exception e12) {
            m7.n.C.f30469h.d("AdUtil.startActivityForResult", e12);
            q(context, intent);
        }
    }

    @Nullable
    private static KeyguardManager zzaf(Context context) {
        Object systemService = context.getSystemService("keyguard");
        if (systemService == null || !(systemService instanceof KeyguardManager)) {
            return null;
        }
        return (KeyguardManager) systemService;
    }

    @Nullable
    private static Bundle zzai(Context context) throws RemoteException {
        try {
            return j8.e.a(context).a(128, context.getPackageName()).metaData;
        } catch (PackageManager.NameNotFoundException | NullPointerException unused) {
            l0.h();
            return null;
        }
    }

    @Nullable
    public static final Integer zzw(Context context) {
        Object systemService = context.getSystemService(Constants$ScionAnalytics$MessageType.DISPLAY_NOTIFICATION);
        if (systemService instanceof DisplayManager) {
            return Integer.valueOf(((DisplayManager) systemService).getDisplays().length);
        }
        return null;
    }

    public final String A(Context context, String str) {
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9156xc)).booleanValue()) {
            if (this.f31771h != null) {
                return this.f31771h;
            }
            this.f31771h = w(context, str);
            return this.f31771h;
        }
        synchronized (this.f31769f) {
            try {
                String str2 = this.f31770g;
                if (str2 != null) {
                    return str2;
                }
                String strW = w(context, str);
                this.f31770g = strW;
                return strW;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final boolean B(String str) {
        return t(str, this.f31764a, (String) n7.y.f31093e.f31096c.b(ao.D0));
    }

    public final boolean C(String str) {
        return t(str, this.f31765b, (String) n7.y.f31093e.f31096c.b(ao.E0));
    }

    public final void x(Context context, String str, HttpURLConnection httpURLConnection, int i10) {
        int iP = p(i10);
        StringBuilder sb = new StringBuilder(String.valueOf(iP).length() + 28);
        sb.append("HTTP timeout: ");
        sb.append(iP);
        sb.append(" milliseconds.");
        q7.j.c(sb.toString());
        httpURLConnection.setConnectTimeout(iP);
        httpURLConnection.setInstanceFollowRedirects(false);
        httpURLConnection.setReadTimeout(iP);
        if (TextUtils.isEmpty(httpURLConnection.getRequestProperty(RtspHeaders.USER_AGENT))) {
            httpURLConnection.setRequestProperty(RtspHeaders.USER_AGENT, A(context, str));
        }
        httpURLConnection.setUseCaches(false);
    }

    public final void y(Context context) {
        if (this.f31772i) {
            return;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.USER_PRESENT");
        intentFilter.addAction("android.intent.action.SCREEN_OFF");
        ao.a(context);
        if (!((Boolean) n7.y.f31093e.f31096c.b(ao.f8938kc)).booleanValue() || Build.VERSION.SDK_INT < 33) {
            context.getApplicationContext().registerReceiver(new e.i0(this), intentFilter);
        } else {
            context.getApplicationContext().registerReceiver(new e.i0(this), intentFilter, 4);
        }
        this.f31772i = true;
    }

    public final void z(Context context) {
        if (this.f31773j) {
            return;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.google.android.ads.intent.DEBUG_LOGGING_ENABLEMENT_CHANGED");
        ao.a(context);
        if (!((Boolean) n7.y.f31093e.f31096c.b(ao.f8938kc)).booleanValue() || Build.VERSION.SDK_INT < 33) {
            context.getApplicationContext().registerReceiver(new q0(this), intentFilter);
        } else {
            context.getApplicationContext().registerReceiver(new q0(this), intentFilter, 4);
        }
        this.f31773j = true;
    }

    public final void zzg(final Context context, @Nullable String str, String str2, Bundle bundle, boolean z10) {
        Bundle bundleJ;
        r0 r0Var = m7.n.C.f30464c;
        bundle.putString("device", L());
        tn tnVar = ao.f8762a;
        n7.y yVar = n7.y.f31093e;
        bundle.putString("eids", TextUtils.join(",", yVar.f31094a.A()));
        if (bundle.isEmpty()) {
            q7.j.a("Empty or null bundle.");
        } else {
            final String str3 = (String) yVar.f31096c.b(ao.Mb);
            boolean andSet = this.f31767d.getAndSet(true);
            AtomicReference atomicReference = this.f31766c;
            if (!andSet) {
                SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() { // from class: p7.p0
                    @Override // android.content.SharedPreferences.OnSharedPreferenceChangeListener
                    public final /* synthetic */ void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str4) {
                        this.f31752a.f31766c.set(com.bumptech.glide.g.J(context, str3));
                    }
                };
                if (TextUtils.isEmpty(str3)) {
                    bundleJ = Bundle.EMPTY;
                } else {
                    PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
                    bundleJ = com.bumptech.glide.g.J(context, str3);
                }
                atomicReference.set(bundleJ);
            }
            bundle.putAll((Bundle) atomicReference.get());
        }
        q7.e eVar = n7.x.f31085g.f31086a;
        q7.e.zzB(context, str, "gmob-apps", bundle, true, new r(context, str));
    }
}
