package com.google.android.gms.internal.ads;

import android.content.Context;
import android.graphics.Rect;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class ka0 implements iv {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f13193a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ij f13194b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final PowerManager f13195c;

    public ka0(Context context, ij ijVar) {
        this.f13193a = context;
        this.f13194b = ijVar;
        this.f13195c = (PowerManager) context.getSystemService("power");
    }

    @Override // com.google.android.gms.internal.ads.iv
    /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
    public final JSONObject zzb(ma0 ma0Var) throws JSONException {
        boolean z10;
        JSONObject jSONObject;
        JSONArray jSONArray = new JSONArray();
        JSONObject jSONObject2 = new JSONObject();
        jj jjVar = ma0Var.f14048e;
        if (jjVar == null) {
            jSONObject = new JSONObject();
        } else {
            ij ijVar = this.f13194b;
            if (ijVar.zzc() == null) {
                throw new JSONException("Active view Info cannot be null.");
            }
            JSONObject jSONObject3 = new JSONObject();
            JSONObject jSONObjectPut = jSONObject3.put("afmaVersion", ijVar.f12537c).put("activeViewJSON", ijVar.zzc()).put("timestamp", ma0Var.f14046c).put("adFormat", ijVar.f12535a).put("hashCode", ijVar.f12536b).put("isMraid", false).put("isStopped", false).put("isPaused", ma0Var.f14045b).put("isNative", ijVar.f12538d).put("isScreenOn", this.f13195c.isInteractive());
            p7.a aVar = m7.n.C.f30470i;
            synchronized (aVar) {
                z10 = aVar.f31643a;
            }
            JSONObject jSONObjectPut2 = jSONObjectPut.put("appMuted", z10).put("appVolume", r5.f30470i.a());
            Context context = this.f13193a;
            jSONObjectPut2.put("deviceVolume", p7.a.b(context.getApplicationContext()));
            DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
            JSONObject jSONObjectPut3 = jSONObject3.put("windowVisibility", jjVar.f12893b).put("isAttachedToWindow", jjVar.f12892a);
            JSONObject jSONObject4 = new JSONObject();
            Rect rect = jjVar.f12894c;
            JSONObject jSONObjectPut4 = jSONObjectPut3.put("viewBox", jSONObject4.put("top", rect.top).put("bottom", rect.bottom).put("left", rect.left).put("right", rect.right));
            JSONObject jSONObject5 = new JSONObject();
            Rect rect2 = jjVar.f12895d;
            JSONObject jSONObjectPut5 = jSONObjectPut4.put("adBox", jSONObject5.put("top", rect2.top).put("bottom", rect2.bottom).put("left", rect2.left).put("right", rect2.right));
            JSONObject jSONObject6 = new JSONObject();
            Rect rect3 = jjVar.f12896e;
            JSONObject jSONObjectPut6 = jSONObjectPut5.put("globalVisibleBox", jSONObject6.put("top", rect3.top).put("bottom", rect3.bottom).put("left", rect3.left).put("right", rect3.right)).put("globalVisibleBoxVisible", jjVar.f12897f);
            JSONObject jSONObject7 = new JSONObject();
            Rect rect4 = jjVar.f12898g;
            JSONObject jSONObjectPut7 = jSONObjectPut6.put("localVisibleBox", jSONObject7.put("top", rect4.top).put("bottom", rect4.bottom).put("left", rect4.left).put("right", rect4.right)).put("localVisibleBoxVisible", jjVar.f12899h);
            JSONObject jSONObject8 = new JSONObject();
            Rect rect5 = jjVar.f12900i;
            jSONObjectPut7.put("hitBox", jSONObject8.put("top", rect5.top).put("bottom", rect5.bottom).put("left", rect5.left).put("right", rect5.right)).put("screenDensity", displayMetrics.density);
            jSONObject3.put("isVisible", ma0Var.f14044a);
            if (((Boolean) n7.y.f31093e.f31096c.b(ao.N1)).booleanValue()) {
                JSONArray jSONArray2 = new JSONArray();
                List<Rect> list = jjVar.f12902k;
                if (list != null) {
                    for (Rect rect6 : list) {
                        jSONArray2.put(new JSONObject().put("top", rect6.top).put("bottom", rect6.bottom).put("left", rect6.left).put("right", rect6.right));
                    }
                }
                jSONObject3.put("scrollableContainerBoxes", jSONArray2);
            }
            if (!TextUtils.isEmpty(ma0Var.f14047d)) {
                jSONObject3.put("doneReasonCode", "u");
            }
            jSONObject = jSONObject3;
        }
        jSONArray.put(jSONObject);
        jSONObject2.put("units", jSONArray);
        return jSONObject2;
    }
}
