package com.parse;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.locks.ReentrantLock;
import org.json.JSONException;
import org.json.JSONObject;
import p137.C2742;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;

/* JADX INFO: loaded from: classes.dex */
public class ParseConfig {
    public final Map<String, Object> params;

    static {
        new ReentrantLock();
    }

    public ParseConfig() {
        this.params = Collections.unmodifiableMap(new HashMap());
    }

    public ParseConfig(Map<String, Object> map) {
        this.params = Collections.unmodifiableMap(map);
    }

    public static ParseConfig decode(JSONObject jSONObject, ParseDecoder parseDecoder) {
        Map map = (Map) ((Map) parseDecoder.decode(jSONObject)).get("params");
        if (map != null) {
            return new ParseConfig(map);
        }
        throw new RuntimeException("Object did not contain the 'params' key.");
    }

    public static ParseConfigController getConfigController() {
        ParseCorePlugins parseCorePlugins = ParseCorePlugins.INSTANCE;
        if (parseCorePlugins.configController.get() == null) {
            parseCorePlugins.configController.compareAndSet(null, new ParseConfigController(ParsePlugins.get().restClient(), new ParseCurrentConfigController(new File(ParsePlugins.get().getParseDir(), "currentConfig"))));
        }
        return parseCorePlugins.configController.get();
    }

    public static ParseConfig getCurrentConfig() {
        try {
            final ParseCurrentConfigController parseCurrentConfigController = getConfigController().currentConfigController;
            if (parseCurrentConfigController != null) {
                return (ParseConfig) C4303.wait(C2742.m4802(new Callable<ParseConfig>() { // from class: com.parse.ParseCurrentConfigController.2
                    public AnonymousClass2() {
                    }

                    @Override // java.util.concurrent.Callable
                    public ParseConfig call() {
                        synchronized (ParseCurrentConfigController.this.currentConfigMutex) {
                            if (ParseCurrentConfigController.this.currentConfig == null) {
                                ParseCurrentConfigController parseCurrentConfigController2 = ParseCurrentConfigController.this;
                                ParseConfig parseConfig = null;
                                if (parseCurrentConfigController2 == null) {
                                    throw null;
                                }
                                try {
                                    parseConfig = ParseConfig.decode(C4303.readFileToJSONObject(parseCurrentConfigController2.currentConfigFile), ParseDecoder.INSTANCE);
                                } catch (IOException | JSONException unused) {
                                }
                                ParseCurrentConfigController parseCurrentConfigController3 = ParseCurrentConfigController.this;
                                if (parseConfig == null) {
                                    parseConfig = new ParseConfig();
                                }
                                parseCurrentConfigController3.currentConfig = parseConfig;
                            }
                        }
                        return ParseCurrentConfigController.this.currentConfig;
                    }
                }, ParseExecutors.io()));
            }
            throw null;
        } catch (ParseException unused) {
            return new ParseConfig();
        }
    }

    public String toString() {
        StringBuilder sbM4889 = C2803.m4889("ParseConfig[");
        sbM4889.append(this.params.toString());
        sbM4889.append("]");
        return sbM4889.toString();
    }
}
