package p138.p176.p177.p242.p265.p266;

import android.content.SharedPreferences;
import android.os.Bundle;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import p000.p001.p002.p003.p004.C0567;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ބ.֏.ˠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C4822 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final String f14510;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final Bundle f14511;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public boolean f14512;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public Bundle f14513;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final /* synthetic */ C4874 f14514;

    public C4822(C4874 c4874, String str) {
        this.f14514 = c4874;
        C0567.m1926(str);
        this.f14510 = str;
        this.f14511 = new Bundle();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final Bundle m8090() {
        if (!this.f14512) {
            this.f14512 = true;
            String string = this.f14514.m8199().getString(this.f14510, null);
            if (string != null) {
                try {
                    Bundle bundle = new Bundle();
                    JSONArray jSONArray = new JSONArray(string);
                    for (int i = 0; i < jSONArray.length(); i++) {
                        try {
                            JSONObject jSONObject = jSONArray.getJSONObject(i);
                            String string2 = jSONObject.getString("n");
                            String string3 = jSONObject.getString("t");
                            byte b = -1;
                            int iHashCode = string3.hashCode();
                            if (iHashCode != 100) {
                                if (iHashCode != 108) {
                                    if (iHashCode == 115 && string3.equals("s")) {
                                        b = 0;
                                    }
                                } else if (string3.equals("l")) {
                                    b = 2;
                                }
                            } else if (string3.equals("d")) {
                                b = 1;
                            }
                            if (b == 0) {
                                bundle.putString(string2, jSONObject.getString("v"));
                            } else if (b == 1) {
                                bundle.putDouble(string2, Double.parseDouble(jSONObject.getString("v")));
                            } else if (b != 2) {
                                this.f14514.mo8165().f14444.m8035("Unrecognized persisted bundle type. Type", string3);
                            } else {
                                bundle.putLong(string2, Long.parseLong(jSONObject.getString("v")));
                            }
                        } catch (NumberFormatException | JSONException unused) {
                            this.f14514.mo8165().f14444.m8034("Error reading value from SharedPreferences. Value dropped");
                        }
                    }
                    this.f14513 = bundle;
                } catch (JSONException unused2) {
                    this.f14514.mo8165().f14444.m8034("Error loading bundle from SharedPreferences. Values will be lost");
                }
            }
            if (this.f14513 == null) {
                this.f14513 = this.f14511;
            }
        }
        return this.f14513;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m8091(Bundle bundle) {
        if (bundle == null) {
            bundle = new Bundle();
        }
        SharedPreferences.Editor editorEdit = this.f14514.m8199().edit();
        if (bundle.size() == 0) {
            editorEdit.remove(this.f14510);
        } else {
            String str = this.f14510;
            JSONArray jSONArray = new JSONArray();
            for (String str2 : bundle.keySet()) {
                Object obj = bundle.get(str2);
                if (obj != null) {
                    try {
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put("n", str2);
                        jSONObject.put("v", String.valueOf(obj));
                        if (obj instanceof String) {
                            jSONObject.put("t", "s");
                        } else if (obj instanceof Long) {
                            jSONObject.put("t", "l");
                        } else if (obj instanceof Double) {
                            jSONObject.put("t", "d");
                        } else {
                            this.f14514.mo8165().f14444.m8035("Cannot serialize bundle value to SharedPreferences. Type", obj.getClass());
                        }
                        jSONArray.put(jSONObject);
                    } catch (JSONException e) {
                        this.f14514.mo8165().f14444.m8035("Cannot serialize bundle value to SharedPreferences", e);
                    }
                }
            }
            editorEdit.putString(str, jSONArray.toString());
        }
        editorEdit.apply();
        this.f14513 = bundle;
    }
}
