package com.bytedance.sdk.openadsdk.core.settings;

import android.os.SystemClock;
import com.bytedance.sdk.openadsdk.core.lG;
import com.bytedance.sdk.openadsdk.core.settings.wN;
import com.bytedance.sdk.openadsdk.utils.mn;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
public abstract class EH implements wN {
    private final String DSW;
    private YFl nc;
    private final ConcurrentHashMap<String, Object> tN = new ConcurrentHashMap<>();
    private final Object AlY = new Object();
    private final Object wN = new Object();
    private final CountDownLatch vc = new CountDownLatch(1);
    private Properties qsH = new Properties();
    private volatile boolean NjR = false;

    /* loaded from: classes2.dex */
    public interface YFl {
        void Sg();

        void YFl();
    }

    public boolean Sg() {
        return this.NjR;
    }

    public EH(String str, YFl yFl) {
        this.DSW = str;
        this.nc = yFl;
        mn.YFl(new com.bytedance.sdk.component.qsH.qsH("SetL_".concat(String.valueOf(str))) { // from class: com.bytedance.sdk.openadsdk.core.settings.EH.1
            @Override // java.lang.Runnable
            public void run() {
                EH.this.YFl(false);
            }
        });
    }

    public String YFl(String str, String str2) {
        if (str == null || str.isEmpty()) {
            return str2;
        }
        wN();
        return this.qsH.getProperty(str, str2);
    }

    private void wN() {
        if (this.NjR) {
            return;
        }
        try {
            SystemClock.elapsedRealtime();
            this.vc.await(mn.wN() ? 4 : 8, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            com.bytedance.sdk.component.utils.YoT.YFl("SdkSettings.Prop", "awaitLoadedLocked: ", e);
        }
    }

    public int YFl(String str, int i) {
        if (str != null && !str.isEmpty()) {
            wN();
            try {
                return Integer.parseInt(this.qsH.getProperty(str, String.valueOf(i)));
            } catch (NumberFormatException e) {
                com.bytedance.sdk.component.utils.YoT.YFl("SdkSettings.Prop", "", e);
            }
        }
        return i;
    }

    public long YFl(String str, long j) {
        if (str != null && !str.isEmpty()) {
            wN();
            try {
                return Long.parseLong(this.qsH.getProperty(str, String.valueOf(j)));
            } catch (NumberFormatException e) {
                com.bytedance.sdk.component.utils.YoT.YFl("SdkSettings.Prop", "", e);
            }
        }
        return j;
    }

    public float YFl(String str, float f) {
        if (str != null && !str.isEmpty()) {
            wN();
            try {
                return Float.parseFloat(this.qsH.getProperty(str, String.valueOf(f)));
            } catch (NumberFormatException e) {
                com.bytedance.sdk.component.utils.YoT.YFl("SdkSettings.Prop", "", e);
            }
        }
        return f;
    }

    public boolean YFl(String str, boolean z) {
        if (str != null && !str.isEmpty()) {
            wN();
            try {
                return Boolean.parseBoolean(this.qsH.getProperty(str, String.valueOf(z)));
            } catch (Exception e) {
                com.bytedance.sdk.component.utils.YoT.YFl("SdkSettings.Prop", "", e);
            }
        }
        return z;
    }

    /* JADX WARN: Removed duplicated region for block: B:62:0x0103 A[Catch: all -> 0x0113, TryCatch #2 {, blocks: (B:4:0x0003, B:7:0x0009, B:9:0x000b, B:11:0x0016, B:17:0x004d, B:18:0x0052, B:60:0x00ff, B:62:0x0103, B:64:0x0107, B:65:0x010a, B:66:0x0111, B:26:0x0066, B:27:0x0069, B:36:0x007c, B:37:0x007f, B:42:0x008d, B:44:0x0097, B:46:0x00a1, B:48:0x00b6, B:49:0x00c6, B:51:0x00cc, B:53:0x00de, B:56:0x00e6, B:58:0x00f1, B:59:0x00f4, B:24:0x005d, B:34:0x0073), top: B:75:0x0003 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void YFl(boolean r9) {
        /*
            Method dump skipped, instructions count: 278
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.sdk.openadsdk.core.settings.EH.YFl(boolean):void");
    }

    private File vc() {
        return new File(lG.YFl().getFilesDir(), this.DSW);
    }

    public wN.YFl YFl() {
        return new Sg();
    }

    public <T> T YFl(String str, T t, wN.Sg<T> sg) {
        T Sg2;
        if (str != null && !str.isEmpty()) {
            if (this.tN.containsKey(str)) {
                try {
                    return (T) this.tN.get(str);
                } catch (Exception e) {
                    com.bytedance.sdk.component.utils.YoT.YFl("SdkSettings.Prop", "", e);
                    return t;
                }
            }
            wN();
            String property = this.qsH.getProperty(str, null);
            if (property != null && sg != null && (Sg2 = sg.Sg(property)) != null) {
                this.tN.put(str, Sg2);
                return Sg2;
            }
        }
        return t;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void YFl(Properties properties) {
        FileOutputStream fileOutputStream;
        synchronized (this.wN) {
            File vc = vc();
            FileOutputStream fileOutputStream2 = null;
            try {
                try {
                    fileOutputStream = new FileOutputStream(vc);
                } catch (Throwable th) {
                    th = th;
                }
            } catch (Exception e) {
                e = e;
            }
            try {
                properties.store(fileOutputStream, (String) null);
                Object[] objArr = new Object[3];
                vc.getAbsolutePath();
                com.bytedance.sdk.openadsdk.utils.nc.YFl(fileOutputStream);
            } catch (Exception e2) {
                e = e2;
                fileOutputStream2 = fileOutputStream;
                com.bytedance.sdk.component.utils.YoT.YFl("SdkSettings.Prop", "saveToLocal: ", e);
                if (fileOutputStream2 != null) {
                    com.bytedance.sdk.openadsdk.utils.nc.YFl(fileOutputStream2);
                }
                rkt.wqc();
            } catch (Throwable th2) {
                th = th2;
                fileOutputStream2 = fileOutputStream;
                if (fileOutputStream2 != null) {
                    com.bytedance.sdk.openadsdk.utils.nc.YFl(fileOutputStream2);
                }
                throw th;
            }
        }
        rkt.wqc();
    }

    public void tN() {
        File vc = vc();
        if (vc.exists()) {
            vc.delete();
        }
    }

    /* loaded from: classes2.dex */
    public class Sg implements wN.YFl {
        private final Map<String, Object> Sg = new HashMap();
        private final Object tN = new Object();

        public Sg() {
        }

        @Override // com.bytedance.sdk.openadsdk.core.settings.wN.YFl
        public void YFl() {
            Object obj;
            new Object[]{"commit: ", this.Sg};
            Properties properties = new Properties();
            synchronized (this.tN) {
                properties.putAll(EH.this.qsH);
                boolean z = false;
                for (Map.Entry<String, Object> entry : this.Sg.entrySet()) {
                    String key = entry.getKey();
                    Object value = entry.getValue();
                    if (value != this && value != null) {
                        if (!properties.containsKey(key) || (obj = properties.get(key)) == null || !obj.equals(value)) {
                            properties.put(key, String.valueOf(value));
                            z = true;
                        }
                    }
                    if (properties.containsKey(key)) {
                        properties.remove(key);
                        z = true;
                    }
                }
                this.Sg.clear();
                if (z) {
                    EH.this.YFl(properties);
                    EH.this.qsH = properties;
                    EH.this.tN.clear();
                }
            }
        }

        @Override // com.bytedance.sdk.openadsdk.core.settings.wN.YFl
        public wN.YFl YFl(String str, String str2) {
            synchronized (this.tN) {
                this.Sg.put(str, str2);
            }
            return this;
        }

        @Override // com.bytedance.sdk.openadsdk.core.settings.wN.YFl
        public wN.YFl YFl(String str, int i) {
            synchronized (this.tN) {
                this.Sg.put(str, Integer.valueOf(i));
            }
            return this;
        }

        @Override // com.bytedance.sdk.openadsdk.core.settings.wN.YFl
        public wN.YFl YFl(String str, long j) {
            synchronized (this.tN) {
                this.Sg.put(str, Long.valueOf(j));
            }
            return this;
        }

        @Override // com.bytedance.sdk.openadsdk.core.settings.wN.YFl
        public wN.YFl YFl(String str) {
            synchronized (this.tN) {
                this.Sg.put(str, this);
            }
            return this;
        }

        @Override // com.bytedance.sdk.openadsdk.core.settings.wN.YFl
        public wN.YFl YFl(String str, float f) {
            synchronized (this.tN) {
                this.Sg.put(str, Float.valueOf(f));
            }
            return this;
        }

        @Override // com.bytedance.sdk.openadsdk.core.settings.wN.YFl
        public wN.YFl YFl(String str, boolean z) {
            synchronized (this.tN) {
                this.Sg.put(str, Boolean.valueOf(z));
            }
            return this;
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void AlY() {
        YFl yFl = this.nc;
        if (yFl != null) {
            yFl.Sg();
        }
    }
}
