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

import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class sn implements SharedPreferences.OnSharedPreferenceChangeListener {

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

    @Nullable
    private SharedPreferences zzb = null;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public JSONObject f16505b = new JSONObject();

    private final void zzg(@Nullable SharedPreferences sharedPreferences) {
        if (sharedPreferences != null) {
            try {
                this.f16505b = new JSONObject((String) ni.b(new rn(sharedPreferences, 0)));
            } catch (JSONException unused) {
            }
        }
    }

    public final void a(Context context) {
        SharedPreferences sharedPreferences;
        synchronized (this.f16504a) {
            try {
                if (this.zzb != null) {
                    return;
                }
                if (context.getApplicationContext() != null) {
                    context = context.getApplicationContext();
                }
                vn vnVar = n7.y.f31093e.f31095b;
                SharedPreferences sharedPreferencesZza = vn.zza(context);
                this.zzb = sharedPreferencesZza;
                zzg(sharedPreferencesZza);
                if (!((Boolean) op.f15135b.j()).booleanValue() && (sharedPreferences = this.zzb) != null) {
                    sharedPreferences.registerOnSharedPreferenceChangeListener(this);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // android.content.SharedPreferences.OnSharedPreferenceChangeListener
    public final void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @Nullable String str) {
        if ("flag_configuration".equals(str)) {
            zzg(sharedPreferences);
        }
    }
}
