package w5; import android.content.Context; import android.content.res.Resources; import android.graphics.Point; import android.view.WindowManager; import com.google.android.gms.ads.RequestConfiguration; import java.util.Iterator; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import z5.b; /* loaded from: classes2.dex */ public abstract class b { /* renamed from: a, reason: collision with root package name */ private static WindowManager f15155a; /* renamed from: b, reason: collision with root package name */ private static String[] f15156b = {"x", "y", "width", "height"}; /* renamed from: c, reason: collision with root package name */ static float f15157c = Resources.getSystem().getDisplayMetrics().density; private static class a { /* renamed from: a, reason: collision with root package name */ final float f15158a; /* renamed from: b, reason: collision with root package name */ final float f15159b; a(float f10, float f11) { this.f15158a = f10; this.f15159b = f11; } } static float a(int i10) { return i10 / f15157c; } public static JSONObject b(int i10, int i11, int i12, int i13) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("x", a(i10)); jSONObject.put("y", a(i11)); jSONObject.put("width", a(i12)); jSONObject.put("height", a(i13)); } catch (JSONException e10) { c.b("Error with creating viewStateObject", e10); } return jSONObject; } public static void c(Context context) { if (context != null) { f15157c = context.getResources().getDisplayMetrics().density; f15155a = (WindowManager) context.getSystemService("window"); } } public static void d(JSONObject jSONObject) { a j10 = j(jSONObject); try { jSONObject.put("width", j10.f15158a); jSONObject.put("height", j10.f15159b); } catch (JSONException e10) { e10.printStackTrace(); } } public static void e(JSONObject jSONObject, String str) { try { jSONObject.put("adSessionId", str); } catch (JSONException e10) { c.b("Error with setting ad session id", e10); } } public static void f(JSONObject jSONObject, String str, Object obj) { try { jSONObject.put(str, obj); } catch (JSONException e10) { c.b("JSONException during JSONObject.put for name [" + str + "]", e10); } } public static void g(JSONObject jSONObject, JSONObject jSONObject2) { try { JSONArray optJSONArray = jSONObject.optJSONArray("childViews"); if (optJSONArray == null) { optJSONArray = new JSONArray(); jSONObject.put("childViews", optJSONArray); } optJSONArray.put(jSONObject2); } catch (JSONException e10) { e10.printStackTrace(); } } public static void h(JSONObject jSONObject, b.a aVar) { aVar.a(); JSONArray jSONArray = new JSONArray(); Iterator it = aVar.b().iterator(); while (it.hasNext()) { jSONArray.put((String) it.next()); } try { jSONObject.put("isFriendlyObstructionFor", jSONArray); throw null; } catch (JSONException e10) { c.b("Error with setting friendly obstruction", e10); } } private static boolean i(JSONArray jSONArray, JSONArray jSONArray2) { if (jSONArray == null && jSONArray2 == null) { return true; } return (jSONArray == null || jSONArray2 == null || jSONArray.length() != jSONArray2.length()) ? false : true; } private static a j(JSONObject jSONObject) { float f10; float f11; if (f15155a != null) { Point point = new Point(0, 0); f15155a.getDefaultDisplay().getRealSize(point); f10 = a(point.x); f11 = a(point.y); } else { f10 = 0.0f; f11 = 0.0f; } return new a(f10, f11); } public static void k(JSONObject jSONObject, String str) { try { jSONObject.put("notVisibleReason", str); } catch (JSONException e10) { c.b("Error with setting not visible reason", e10); } } public static boolean l(JSONObject jSONObject, JSONObject jSONObject2) { if (jSONObject == null && jSONObject2 == null) { return true; } return jSONObject != null && jSONObject2 != null && m(jSONObject, jSONObject2) && n(jSONObject, jSONObject2) && o(jSONObject, jSONObject2) && p(jSONObject, jSONObject2); } private static boolean m(JSONObject jSONObject, JSONObject jSONObject2) { for (String str : f15156b) { if (jSONObject.optDouble(str) != jSONObject2.optDouble(str)) { return false; } } return true; } private static boolean n(JSONObject jSONObject, JSONObject jSONObject2) { return jSONObject.optString("adSessionId", RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED).equals(jSONObject2.optString("adSessionId", RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED)); } private static boolean o(JSONObject jSONObject, JSONObject jSONObject2) { JSONArray optJSONArray = jSONObject.optJSONArray("isFriendlyObstructionFor"); JSONArray optJSONArray2 = jSONObject2.optJSONArray("isFriendlyObstructionFor"); if (optJSONArray == null && optJSONArray2 == null) { return true; } if (!i(optJSONArray, optJSONArray2)) { return false; } for (int i10 = 0; i10 < optJSONArray.length(); i10++) { if (!optJSONArray.optString(i10, RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED).equals(optJSONArray2.optString(i10, RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED))) { return false; } } return true; } private static boolean p(JSONObject jSONObject, JSONObject jSONObject2) { JSONArray optJSONArray = jSONObject.optJSONArray("childViews"); JSONArray optJSONArray2 = jSONObject2.optJSONArray("childViews"); if (optJSONArray == null && optJSONArray2 == null) { return true; } if (!i(optJSONArray, optJSONArray2)) { return false; } for (int i10 = 0; i10 < optJSONArray.length(); i10++) { if (!l(optJSONArray.optJSONObject(i10), optJSONArray2.optJSONObject(i10))) { return false; } } return true; } }