package io.flutter.plugins.sharedpreferences;

import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/* JADX INFO: loaded from: classes.dex */
public class a implements ad.c, d {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public SharedPreferences f28279a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final i f28280b = new androidx.datastore.preferences.protobuf.h(0);

    @NonNull
    private Map<String, Object> getAllPrefs(@NonNull String str, @Nullable Set<String> set) throws ClassNotFoundException, IOException, RuntimeException {
        Object bigInteger;
        Object objValueOf;
        Map<String, ?> all = this.f28279a.getAll();
        HashMap map = new HashMap();
        for (String str2 : all.keySet()) {
            if (str2.startsWith(str) && (set == null || set.contains(str2))) {
                Object obj = all.get(str2);
                Objects.requireNonNull(obj);
                boolean z10 = obj instanceof String;
                i iVar = this.f28280b;
                if (z10) {
                    String str3 = (String) obj;
                    if (str3.startsWith("VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu")) {
                        objValueOf = obj;
                        if (!str3.startsWith("VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu!")) {
                            objValueOf = ((androidx.datastore.preferences.protobuf.h) iVar).a(str3.substring(40));
                        }
                    } else if (str3.startsWith("VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy")) {
                        bigInteger = new BigInteger(str3.substring(44), 36);
                        objValueOf = bigInteger;
                    } else {
                        objValueOf = obj;
                        if (str3.startsWith("VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu")) {
                            objValueOf = Double.valueOf(str3.substring(40));
                        }
                    }
                    map.put(str2, objValueOf);
                } else {
                    boolean z11 = obj instanceof Set;
                    objValueOf = obj;
                    if (z11) {
                        ArrayList arrayList = new ArrayList((Set) obj);
                        this.f28279a.edit().remove(str2).putString(str2, "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu" + ((androidx.datastore.preferences.protobuf.h) iVar).b(arrayList)).apply();
                        bigInteger = arrayList;
                        objValueOf = bigInteger;
                    }
                    map.put(str2, objValueOf);
                }
            }
        }
        return map;
    }

    public final Boolean a(String str, String str2) {
        if (str2.startsWith("VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu") || str2.startsWith("VGhpcyBpcyB0aGUgcHJlZml4IGZvciBCaWdJbnRlZ2Vy") || str2.startsWith("VGhpcyBpcyB0aGUgcHJlZml4IGZvciBEb3VibGUu")) {
            throw new RuntimeException("StorageError: This string cannot be stored as it clashes with special identifier prefixes");
        }
        return Boolean.valueOf(this.f28279a.edit().putString(str, str2).commit());
    }

    @Override // io.flutter.plugins.sharedpreferences.d
    @NonNull
    public Boolean clear(@NonNull String str, @Nullable List<String> list) throws RuntimeException {
        SharedPreferences.Editor editorEdit = this.f28279a.edit();
        Map<String, ?> all = this.f28279a.getAll();
        ArrayList arrayList = new ArrayList();
        for (String str2 : all.keySet()) {
            if (str2.startsWith(str) && (list == null || list.contains(str2))) {
                arrayList.add(str2);
            }
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            editorEdit.remove((String) it.next());
        }
        return Boolean.valueOf(editorEdit.commit());
    }

    @Override // io.flutter.plugins.sharedpreferences.d
    @NonNull
    public Map<String, Object> getAll(@NonNull String str, @Nullable List<String> list) throws RuntimeException {
        return getAllPrefs(str, list == null ? null : new HashSet(list));
    }

    @Override // ad.c
    public final void onAttachedToEngine(ad.b bVar) {
        ed.i iVar = bVar.f443b;
        this.f28279a = bVar.f442a.getSharedPreferences("FlutterSharedPreferences", 0);
        try {
            d.setUp(iVar, this);
        } catch (Exception unused) {
        }
    }

    @Override // ad.c
    public final void onDetachedFromEngine(ad.b bVar) {
        d.setUp(bVar.f443b, null);
    }
}
