package com.bytedance.apm.config;

import X.2p5;
import X.AnonymousClass956;
import X.AnonymousClass9M7;
import X.AnonymousClass9MA;
import X.AnonymousClass9MG;
import X.C29868ld;
import X.C30268mH;
import X.C30308mL;
import X.C30488md;
import X.C398694f;
import android.content.IntentFilter;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.services.slardar.config.IConfigManager;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.json.JSONObject;

public class SlardarConfigManagerImpl implements IConfigManager {
    public AnonymousClass9M7 mSlardarConfigFetcher = new AnonymousClass9M7();

    static {
        Covode.recordClassIndex(23255);
    }

    public JSONObject getConfig() {
        return this.mSlardarConfigFetcher.LJI;
    }

    public boolean isConfigReady() {
        return this.mSlardarConfigFetcher.LIZ;
    }

    public String queryConfig() {
        return this.mSlardarConfigFetcher.LIZLLL();
    }

    public void fetchConfig() {
        AnonymousClass9M7 r6 = this.mSlardarConfigFetcher;
        boolean LIZ = r6.LIZ();
        if (C30268mH.LIZJ()) {
            if (r6.LJIIIIZZ > System.currentTimeMillis()) {
                LIZ = true;
            }
            r6.LIZ(LIZ);
        }
    }

    public JSONObject getConfigJSON(String str) {
        return this.mSlardarConfigFetcher.LIZIZ(str);
    }

    public boolean getServiceSwitch(String str) {
        return this.mSlardarConfigFetcher.LIZ(str);
    }

    public void unregisterConfigListener(AnonymousClass9MG r3) {
        AnonymousClass9M7 r1 = this.mSlardarConfigFetcher;
        if (r3 != null && r1.LJIIL != null) {
            r1.LJIIL.remove(r3);
        }
    }

    public void unregisterResponseConfigListener(C398694f r2) {
        if (r2 != null && C30488md.LIZ != null) {
            C30488md.LIZ.remove(r2);
        }
    }

    public boolean getMetricTypeSwitch(String str) {
        AnonymousClass9M7 r1 = this.mSlardarConfigFetcher;
        if (r1.LIZLLL == null || TextUtils.isEmpty(str) || r1.LIZLLL.optInt(str) != 1) {
            return false;
        }
        return true;
    }

    public boolean getSwitch(String str) {
        AnonymousClass9M7 r1 = this.mSlardarConfigFetcher;
        if (TextUtils.isEmpty(str) || r1.LJI == null) {
            return false;
        }
        return r1.LJI.optBoolean(str);
    }

    public void registerResponseConfigListener(C398694f r2) {
        if (r2 != null) {
            if (C30488md.LIZ == null) {
                C30488md.LIZ = new CopyOnWriteArrayList();
            }
            if (!C30488md.LIZ.contains(r2)) {
                C30488md.LIZ.add(r2);
            }
        }
    }

    public boolean getLogTypeSwitch(String str) {
        AnonymousClass9M7 r1 = this.mSlardarConfigFetcher;
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        if (TextUtils.equals(str, "block_monitor")) {
            str = "caton_monitor";
        }
        if (TextUtils.equals(str, "core_exception_monitor")) {
            return r1.LIZIZ;
        }
        if (r1.LIZJ == null || r1.LIZJ.optInt(str) != 1) {
            return false;
        }
        return true;
    }

    public void registerConfigListener(AnonymousClass9MG r4) {
        AnonymousClass9M7 r2 = this.mSlardarConfigFetcher;
        if (r4 != null) {
            if (r2.LJIIL == null) {
                r2.LJIIL = new CopyOnWriteArrayList();
            }
            if (!r2.LJIIL.contains(r4)) {
                r2.LJIIL.add(r4);
            }
            if (C30268mH.LJFF()) {
                String[] strArr = new String[1];
                "addConfigListener, mReady=" + r2.LIZ;
            }
            if (r2.LIZ) {
                r4.LIZ(r2.LJI, r2.LJII);
                r4.LIZLLL();
            }
        }
    }

    public void forceUpdateFromRemote(C30308mL r3, List<String> list) {
        AnonymousClass9M7 r1 = this.mSlardarConfigFetcher;
        r1.LIZIZ();
        if (r3 != null) {
            r1.LJFF = r3;
        }
        if (!C29868ld.LIZ((List<?>) list)) {
            r1.LJ = new ArrayList(list);
        }
        r1.LIZ(true);
    }

    public int getConfigInt(String str, int i) {
        AnonymousClass9M7 r1 = this.mSlardarConfigFetcher;
        if (TextUtils.isEmpty(str) || r1.LJI == null) {
            return i;
        }
        return r1.LJI.optInt(str, i);
    }

    public void initParams(boolean z, C30308mL r6, List<String> list) {
        AnonymousClass9M7 r3 = this.mSlardarConfigFetcher;
        r3.LJIIJ = z;
        r3.LJIIJJI = C30268mH.LIZJ();
        r3.LIZIZ();
        r3.LJFF = r6;
        if (!C29868ld.LIZ((List<?>) list)) {
            r3.LJ = r3.LIZ(list);
        }
        if (!r3.LJIIIZ) {
            r3.LJIIIZ = true;
            if (r3.LIZJ()) {
                2p5.LIZ.LIZ((AnonymousClass956) r3);
            }
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("com.apm.setting.update.action");
            AnonymousClass9MA r1 = new AnonymousClass9MA(r3);
            if (C30268mH.LIZ != null) {
                AnonymousClass9M7.LIZ(C30268mH.LIZ, r1, intentFilter);
            }
        }
    }
}
