package p7;

import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.kq1;
import com.google.android.gms.internal.ads.rq1;
import com.google.android.gms.internal.ads.ru;
import com.google.android.gms.internal.ads.tn;
import com.google.android.gms.internal.ads.wa1;
import com.google.android.gms.internal.ads.yn;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import javax.annotation.Nonnull;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public abstract class z {
    public static boolean a(int i10) {
        tn tnVar = ao.g4;
        n7.y yVar = n7.y.f31093e;
        if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
            return ((Boolean) yVar.f31096c.b(ao.f8883h4)).booleanValue() || i10 <= 15299999;
        }
        return true;
    }

    public static boolean b(Context context, wa1 wa1Var) {
        if (!wa1Var.K) {
            return false;
        }
        tn tnVar = ao.f8821d9;
        n7.y yVar = n7.y.f31093e;
        boolean zBooleanValue = ((Boolean) yVar.f31096c.b(tnVar)).booleanValue();
        yn ynVar = yVar.f31096c;
        if (zBooleanValue) {
            return ((Boolean) ynVar.b(ao.f8871g9)).booleanValue();
        }
        String str = (String) ynVar.b(ao.f8838e9);
        if (!str.isEmpty() && context != null) {
            String packageName = context.getPackageName();
            Iterator it = new rq1(ru.c(new kq1(';')), str).iterator();
            while (it.hasNext()) {
                if (((String) it.next()).equals(packageName)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static WindowManager.LayoutParams c() {
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(-2, -2, 0, 0, -2);
        layoutParams.flags = ((Integer) n7.y.f31093e.f31096c.b(ao.f8855f9)).intValue();
        layoutParams.type = 2;
        layoutParams.gravity = 8388659;
        return layoutParams;
    }

    public static JSONObject d(Context context, Rect rect) throws JSONException {
        JSONObject jSONObject = new JSONObject();
        int i10 = rect.right - rect.left;
        n7.x xVar = n7.x.f31085g;
        jSONObject.put("width", xVar.f31086a.b(context, i10));
        int i11 = rect.bottom - rect.top;
        q7.e eVar = xVar.f31086a;
        jSONObject.put("height", eVar.b(context, i11));
        jSONObject.put("x", eVar.b(context, rect.left));
        jSONObject.put("y", eVar.b(context, rect.top));
        jSONObject.put("relative_to", "self");
        return jSONObject;
    }

    public static int e(int i10) {
        if (i10 != -2) {
            return i10 != -1 ? 2 : 3;
        }
        return 4;
    }

    /* JADX WARN: Removed duplicated region for block: B:28:0x0110  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0120  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x012a  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x012f  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x013b A[Catch: JSONException -> 0x013f, TRY_LEAVE, TryCatch #3 {JSONException -> 0x013f, blocks: (B:25:0x0107, B:42:0x0132, B:43:0x0136, B:44:0x013b), top: B:64:0x0107 }] */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0151 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0185 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static JSONObject zzb(Context context, @Nullable View view) {
        String str;
        int iHashCode;
        byte b10;
        JSONObject jSONObjectD;
        JSONObject jSONObject = new JSONObject();
        if (view != null) {
            try {
                int[] iArrZzg = zzg(view);
                int[] iArr = {view.getMeasuredWidth(), view.getMeasuredHeight()};
                for (ViewParent parent = view.getParent(); parent instanceof ViewGroup; parent = parent.getParent()) {
                    ViewGroup viewGroup = (ViewGroup) parent;
                    iArr[0] = Math.min(viewGroup.getMeasuredWidth(), iArr[0]);
                    iArr[1] = Math.min(viewGroup.getMeasuredHeight(), iArr[1]);
                }
                JSONObject jSONObject2 = new JSONObject();
                int measuredWidth = view.getMeasuredWidth();
                n7.x xVar = n7.x.f31085g;
                q7.e eVar = xVar.f31086a;
                q7.e eVar2 = xVar.f31086a;
                jSONObject2.put("width", eVar.b(context, measuredWidth));
                jSONObject2.put("height", eVar2.b(context, view.getMeasuredHeight()));
                jSONObject2.put("x", eVar2.b(context, iArrZzg[0]));
                jSONObject2.put("y", eVar2.b(context, iArrZzg[1]));
                jSONObject2.put("maximum_visible_width", eVar2.b(context, iArr[0]));
                jSONObject2.put("maximum_visible_height", eVar2.b(context, iArr[1]));
                jSONObject2.put("relative_to", "window");
                jSONObject.put("frame", jSONObject2);
                Rect rect = new Rect();
                if (view.getGlobalVisibleRect(rect)) {
                    jSONObjectD = d(context, rect);
                } else {
                    JSONObject jSONObject3 = new JSONObject();
                    jSONObject3.put("width", 0);
                    jSONObject3.put("height", 0);
                    jSONObject3.put("x", eVar2.b(context, iArrZzg[0]));
                    jSONObject3.put("y", eVar2.b(context, iArrZzg[1]));
                    jSONObject3.put("relative_to", "window");
                    jSONObjectD = jSONObject3;
                }
                jSONObject.put("visible_bounds", jSONObjectD);
            } catch (Exception unused) {
                q7.j.d("Unable to get native ad view bounding box");
            }
            ViewParent parent2 = view.getParent();
            if (parent2 != null) {
                try {
                    str = (String) parent2.getClass().getMethod("getTemplateTypeName", new Class[0]).invoke(parent2, new Object[0]);
                } catch (IllegalAccessException | NoSuchMethodException | SecurityException | InvocationTargetException unused2) {
                    str = "";
                }
                try {
                    iHashCode = str.hashCode();
                } catch (JSONException unused3) {
                }
                if (iHashCode == -2066603854) {
                    b10 = (iHashCode == 2019754500 && str.equals("medium_template")) ? (byte) 1 : (byte) -1;
                    if (b10 != 0) {
                        jSONObject.put("native_template_type", 1);
                    } else if (b10 != 1) {
                        jSONObject.put("native_template_type", 0);
                    } else {
                        jSONObject.put("native_template_type", 2);
                    }
                    if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8771a9)).booleanValue()) {
                        try {
                            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                            jSONObject.put("view_width_layout_type", e(layoutParams.width) - 1);
                            jSONObject.put("view_height_layout_type", e(layoutParams.height) - 1);
                        } catch (Exception unused4) {
                            l0.g("Unable to get native ad view layout types");
                        }
                    }
                    if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8804c9)).booleanValue()) {
                        try {
                            jSONObject.put("alpha", view.getAlpha());
                        } catch (JSONException unused5) {
                        }
                    }
                } else {
                    if (str.equals("small_template")) {
                        b10 = 0;
                    }
                    if (b10 != 0) {
                    }
                    if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8771a9)).booleanValue()) {
                    }
                    if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8804c9)).booleanValue()) {
                    }
                }
            } else {
                str = "";
                iHashCode = str.hashCode();
                if (iHashCode == -2066603854) {
                }
            }
        }
        return jSONObject;
    }

    public static JSONObject zzc(@Nullable View view) {
        JSONObject jSONObject = new JSONObject();
        if (view != null) {
            try {
                tn tnVar = ao.W8;
                n7.y yVar = n7.y.f31093e;
                yn ynVar = yVar.f31096c;
                yn ynVar2 = yVar.f31096c;
                boolean zBooleanValue = ((Boolean) ynVar.b(tnVar)).booleanValue();
                if (zBooleanValue) {
                    if (((Boolean) ynVar2.b(ao.X8)).booleanValue()) {
                        r0 r0Var = m7.n.C.f30464c;
                        jSONObject.put("contained_in_scroll_view", r0.zzC(view) != 0);
                    }
                    if (((Boolean) ynVar2.b(ao.Y8)).booleanValue()) {
                        r0 r0Var2 = m7.n.C.f30464c;
                        jSONObject.put("scroll_view_type", r0.zzC(view));
                    }
                } else {
                    r0 r0Var3 = m7.n.C.f30464c;
                    ViewParent parent = view.getParent();
                    while (parent != null && !(parent instanceof AdapterView)) {
                        parent = parent.getParent();
                    }
                    if (parent != null && ((AdapterView) parent).getPositionForView(view) != -1) {
                        z = true;
                    }
                    jSONObject.put("contained_in_scroll_view", z);
                }
            } catch (Exception unused) {
            }
        }
        return jSONObject;
    }

    public static JSONObject zzd(Context context, @Nullable View view) {
        JSONObject jSONObject = new JSONObject();
        if (view != null) {
            try {
                m7.n nVar = m7.n.C;
                r0 r0Var = nVar.f30464c;
                jSONObject.put("can_show_on_lock_screen", r0.H(view));
                r0 r0Var2 = nVar.f30464c;
                jSONObject.put("is_keyguard_locked", r0.d(context));
            } catch (JSONException unused) {
                q7.j.d("Unable to get lock screen information");
            }
        }
        return jSONObject;
    }

    public static JSONObject zze(Context context, @Nullable Map map, @Nullable Map map2, @Nullable View view, @Nullable ImageView.ScaleType scaleType) {
        String str;
        String str2;
        JSONObject jSONObject;
        boolean z10;
        JSONObject jSONObjectD;
        String str3 = "ad_view";
        String str4 = "relative_to";
        JSONObject jSONObject2 = new JSONObject();
        if (map != null && view != null) {
            int[] iArrZzg = zzg(view);
            Iterator it = map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                View view2 = (View) ((WeakReference) entry.getValue()).get();
                if (view2 != null) {
                    int[] iArrZzg2 = zzg(view2);
                    JSONObject jSONObject3 = new JSONObject();
                    JSONObject jSONObject4 = new JSONObject();
                    Iterator it2 = it;
                    try {
                        int measuredWidth = view2.getMeasuredWidth();
                        JSONObject jSONObject5 = jSONObject2;
                        try {
                            n7.x xVar = n7.x.f31085g;
                            q7.e eVar = xVar.f31086a;
                            q7.e eVar2 = xVar.f31086a;
                            jSONObject4.put("width", eVar.b(context, measuredWidth));
                            jSONObject4.put("height", eVar2.b(context, view2.getMeasuredHeight()));
                            jSONObject4.put("x", eVar2.b(context, iArrZzg2[0] - iArrZzg[0]));
                            jSONObject4.put("y", eVar2.b(context, iArrZzg2[1] - iArrZzg[1]));
                            jSONObject4.put(str4, str3);
                            jSONObject3.put("frame", jSONObject4);
                            Rect rect = new Rect();
                            if (view2.getLocalVisibleRect(rect)) {
                                jSONObjectD = d(context, rect);
                                z10 = true;
                            } else {
                                JSONObject jSONObject6 = new JSONObject();
                                jSONObject6.put("width", 0);
                                jSONObject6.put("height", 0);
                                jSONObject6.put("x", eVar2.b(context, iArrZzg2[0] - iArrZzg[0]));
                                z10 = true;
                                jSONObject6.put("y", eVar2.b(context, iArrZzg2[1] - iArrZzg[1]));
                                jSONObject6.put(str4, str3);
                                jSONObjectD = jSONObject6;
                            }
                            jSONObject3.put("visible_bounds", jSONObjectD);
                            if (((String) entry.getKey()).equals("3010")) {
                                tn tnVar = ao.Z8;
                                n7.y yVar = n7.y.f31093e;
                                yn ynVar = yVar.f31096c;
                                yn ynVar2 = yVar.f31096c;
                                if (((Boolean) ynVar.b(tnVar)).booleanValue()) {
                                    jSONObject3.put("mediaview_graphics_matrix", view2.getMatrix().toShortString());
                                }
                                if (((Boolean) ynVar2.b(ao.f8771a9)).booleanValue()) {
                                    ViewGroup.LayoutParams layoutParams = view2.getLayoutParams();
                                    jSONObject3.put("view_width_layout_type", e(layoutParams.width) - 1);
                                    jSONObject3.put("view_height_layout_type", e(layoutParams.height) - 1);
                                }
                                if (((Boolean) ynVar2.b(ao.f8788b9)).booleanValue()) {
                                    ArrayList arrayList = new ArrayList();
                                    arrayList.add(Integer.valueOf(view2.getId()));
                                    for (ViewParent parent = view2.getParent(); parent instanceof View; parent = parent.getParent()) {
                                        arrayList.add(Integer.valueOf(((View) parent).getId()));
                                    }
                                    jSONObject3.put("view_path", TextUtils.join("/", arrayList));
                                }
                                if (scaleType != null) {
                                    jSONObject3.put("mediaview_scale_type", scaleType.ordinal());
                                }
                            }
                            if (view2 instanceof TextView) {
                                TextView textView = (TextView) view2;
                                jSONObject3.put("text_color", textView.getCurrentTextColor());
                                str = str3;
                                str2 = str4;
                                try {
                                    jSONObject3.put("font_size", textView.getTextSize());
                                    jSONObject3.put(MimeTypes.BASE_TYPE_TEXT, textView.getText());
                                } catch (JSONException unused) {
                                    jSONObject = jSONObject5;
                                    q7.j.d("Unable to get asset views information");
                                    it = it2;
                                    jSONObject2 = jSONObject;
                                    str3 = str;
                                    str4 = str2;
                                }
                            } else {
                                str = str3;
                                str2 = str4;
                            }
                            if (map2 == null || !map2.containsKey(entry.getKey()) || !view2.isClickable()) {
                                z10 = false;
                            }
                            jSONObject3.put("is_clickable", z10);
                            if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8804c9)).booleanValue()) {
                                jSONObject3.put("alpha", view2.getAlpha());
                            }
                            jSONObject = jSONObject5;
                        } catch (JSONException unused2) {
                            str = str3;
                            str2 = str4;
                        }
                    } catch (JSONException unused3) {
                        str = str3;
                        str2 = str4;
                        jSONObject = jSONObject2;
                    }
                    try {
                        jSONObject.put((String) entry.getKey(), jSONObject3);
                    } catch (JSONException unused4) {
                        q7.j.d("Unable to get asset views information");
                    }
                    it = it2;
                    jSONObject2 = jSONObject;
                    str3 = str;
                    str4 = str2;
                }
            }
        }
        return jSONObject2;
    }

    public static JSONObject zzf(@Nullable String str, Context context, Point point, Point point2) {
        JSONObject jSONObject;
        JSONObject jSONObject2 = null;
        try {
            jSONObject = new JSONObject();
        } catch (Exception unused) {
        }
        try {
            JSONObject jSONObject3 = new JSONObject();
            try {
                int i10 = point2.x;
                n7.x xVar = n7.x.f31085g;
                jSONObject3.put("x", xVar.f31086a.b(context, i10));
                jSONObject3.put("y", xVar.f31086a.b(context, point2.y));
                jSONObject3.put("start_x", xVar.f31086a.b(context, point.x));
                jSONObject3.put("start_y", xVar.f31086a.b(context, point.y));
                jSONObject2 = jSONObject3;
            } catch (JSONException unused2) {
            }
            jSONObject.put("click_point", jSONObject2);
            jSONObject.put("asset_id", str);
            return jSONObject;
        } catch (Exception unused3) {
            jSONObject2 = jSONObject;
            return jSONObject2;
        }
    }

    public static int[] zzg(@Nullable View view) {
        int[] iArr = new int[2];
        if (view != null) {
            view.getLocationOnScreen(iArr);
        }
        return iArr;
    }

    public static Point zzh(MotionEvent motionEvent, @Nullable View view) {
        int[] iArrZzg = zzg(view);
        return new Point(((int) motionEvent.getRawX()) - iArrZzg[0], ((int) motionEvent.getRawY()) - iArrZzg[1]);
    }

    @Nullable
    public static JSONObject zzj(@Nonnull Context context) {
        JSONObject jSONObject = new JSONObject();
        r0 r0Var = m7.n.C.f30464c;
        WindowManager windowManager = (WindowManager) context.getSystemService("window");
        DisplayMetrics displayMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(displayMetrics);
        try {
            int i10 = displayMetrics.widthPixels;
            n7.x xVar = n7.x.f31085g;
            jSONObject.put("width", xVar.f31086a.b(context, i10));
            jSONObject.put("height", xVar.f31086a.b(context, displayMetrics.heightPixels));
            return jSONObject;
        } catch (JSONException unused) {
            return null;
        }
    }
}
