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

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.google.android.gms.dynamite.descriptors.com.google.android.gms.ads.dynamite.ModuleDescriptor;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class rz extends vj1 {
    public final Context S;
    public final lv T;
    public final q7.a U;
    public final Executor W;

    @Nullable
    private SharedPreferences zzc;
    public final Object R = new Object();
    public final AtomicBoolean V = new AtomicBoolean(false);

    public rz(Context context, lv lvVar, q7.a aVar, Executor executor) {
        this.S = context.getApplicationContext();
        this.U = aVar;
        this.T = lvVar;
        this.W = executor;
    }

    public static JSONObject s(Context context, q7.a aVar) {
        JSONObject jSONObject = new JSONObject();
        try {
            if (((Boolean) op.f15139f.j()).booleanValue()) {
                jSONObject.put("package_name", context.getPackageName());
            }
            jSONObject.put("js", aVar.f32212a);
            jSONObject.put("mf", op.f15140g.j());
            jSONObject.put("cl", "839961582");
            jSONObject.put("rapid_rc", "dev");
            jSONObject.put("rapid_rollup", "HEAD");
            jSONObject.put("admob_module_version", 12451000);
            jSONObject.put("dynamite_local_version", ModuleDescriptor.MODULE_VERSION);
            jSONObject.put("dynamite_version", l8.c.d(context, ModuleDescriptor.MODULE_ID, false));
            jSONObject.put("container_version", 12451000);
        } catch (JSONException unused) {
        }
        return jSONObject;
    }

    @Override // com.google.android.gms.internal.ads.vj1
    public final com.google.common.util.concurrent.w a() {
        int i10;
        synchronized (this.R) {
            try {
                i10 = 0;
                if (this.zzc == null) {
                    this.zzc = this.S.getSharedPreferences("google_ads_flags_meta", 0);
                }
            } finally {
            }
        }
        SharedPreferences sharedPreferences = this.zzc;
        long j10 = sharedPreferences != null ? sharedPreferences.getLong("js_last_update", 0L) : 0L;
        m7.n.C.f30472k.getClass();
        if (System.currentTimeMillis() - j10 < ((Long) op.f15141h.j()).longValue()) {
            return ih1.k(null);
        }
        return ih1.h1(this.T.a(s(this.S, this.U)), new qz(this, i10), ((Boolean) op.f15146m.j()).booleanValue() ? this.W : b30.f9365g);
    }

    public final void t(JSONObject jSONObject) {
        tn tnVar = ao.f8762a;
        n7.y yVar = n7.y.f31093e;
        vn vnVar = yVar.f31095b;
        Context context = this.S;
        SharedPreferences sharedPreferencesZzb = vn.zzb(context);
        if (sharedPreferencesZzb == null) {
            return;
        }
        SharedPreferences.Editor editorEdit = sharedPreferencesZzb.edit();
        vu0 vu0Var = yVar.f31094a;
        Objects.requireNonNull(vu0Var);
        for (un unVar : (List) vu0Var.f17778b) {
            if (unVar.f17335a == 1) {
                Object objA = unVar.a(jSONObject);
                tn tnVar2 = (tn) unVar;
                int i10 = tnVar2.f16950e;
                String str = tnVar2.f17336b;
                switch (i10) {
                    case 0:
                        editorEdit.putBoolean(str, ((Boolean) objA).booleanValue());
                        break;
                    case 1:
                        editorEdit.putInt(str, ((Integer) objA).intValue());
                        break;
                    case 2:
                        editorEdit.putLong(str, ((Long) objA).longValue());
                        break;
                    case 3:
                        editorEdit.putFloat(str, ((Float) objA).floatValue());
                        break;
                    default:
                        editorEdit.putString(str, (String) objA);
                        break;
                }
            }
        }
        if (jSONObject != null) {
            editorEdit.putString("flag_configuration", jSONObject.toString());
        } else {
            q7.j.b("Flag Json is null.");
        }
        if (((Boolean) op.f15148o.j()).booleanValue() || ((Boolean) op.f15149p.j()).booleanValue()) {
            vn vnVar2 = n7.y.f31093e.f31095b;
            editorEdit.apply();
        } else {
            vn vnVar3 = n7.y.f31093e.f31095b;
            editorEdit.commit();
        }
        if (((Boolean) op.f15138e.j()).booleanValue() && !TextUtils.equals(context.getPackageName(), "com.google.android.gms")) {
            vn vnVar4 = n7.y.f31093e.f31095b;
            SharedPreferences sharedPreferencesZza = vn.zza(context);
            if (sharedPreferencesZza != null) {
                SharedPreferences.Editor editorEdit2 = sharedPreferencesZza.edit();
                JSONObject jSONObject2 = new JSONObject();
                Iterator<String> itKeys = jSONObject.keys();
                while (itKeys.hasNext()) {
                    String next = itKeys.next();
                    if (next.startsWith("adapter:")) {
                        try {
                            jSONObject2.put(next, jSONObject.get(next));
                        } catch (JSONException unused) {
                        }
                    }
                }
                editorEdit2.putString("flag_configuration", jSONObject2.toString());
                editorEdit2.apply();
            }
        }
        SharedPreferences sharedPreferences = this.zzc;
        if (sharedPreferences != null) {
            SharedPreferences.Editor editorEdit3 = sharedPreferences.edit();
            m7.n.C.f30472k.getClass();
            editorEdit3.putLong("js_last_update", System.currentTimeMillis()).apply();
        }
    }
}
