package ඓ.ⁱ.K.K;

import androidx.recyclerview.widget.RecyclerView;
import com.facebook.GraphRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import ඓ.ⁱ.K.ʬ.C1229;
import ඓ.ⁱ.K.㸾.C1276;
import ඓ.K.K.K.C1293;
import 㿎.AbstractC2651;
import 㿎.C2625;
import 㿎.C2628;
import 㿎.C2642;
import 㿎.C2644;
import 㿎.C2671;

/* renamed from: ඓ.ⁱ.K.K.ῲ  reason: contains not printable characters */
/* compiled from: UploadInfoCollector */
public final class C1260 {

    /* renamed from: ඓ  reason: contains not printable characters */
    public static ExecutorService f4950;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static C1260 f4951;

    /* renamed from: 㴹  reason: contains not printable characters */
    public static C2625 f4952;

    /* renamed from: ʬ  reason: contains not printable characters */
    public File f4953 = null;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final String f4954;

    /* renamed from: K  reason: contains not printable characters */
    public final String f4955;

    /* renamed from: 㸾  reason: contains not printable characters */
    public long f4956;

    /* renamed from: ඓ.ⁱ.K.K.ῲ$ʬ  reason: contains not printable characters */
    /* compiled from: UploadInfoCollector */
    public static abstract class AbstractC1261 {
        /* renamed from: K  reason: contains not printable characters */
        public abstract String m3374();
    }

    /* renamed from: ඓ.ⁱ.K.K.ῲ$ῲ  reason: contains not printable characters */
    /* compiled from: UploadInfoCollector */
    public class RunnableC1262 implements Runnable {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ C1276 f4958;

        public RunnableC1262(C1276 r2) {
            this.f4958 = r2;
        }

        public void run() {
            try {
                C1260.this.m3372(this.f4958, C1260.this.f4953);
            } catch (Throwable unused) {
            }
        }
    }

    /* renamed from: ඓ.ⁱ.K.K.ῲ$K  reason: contains not printable characters */
    /* compiled from: UploadInfoCollector */
    public class RunnableC1263 implements Runnable {

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ AbstractC1261 f4960;

        public RunnableC1263(AbstractC1261 r2) {
            this.f4960 = r2;
        }

        public void run() {
            try {
                C1260.this.m3371(this.f4960.m3374(), C1260.this.f4953);
            } catch (Throwable unused) {
            }
        }
    }

    public C1260(String str, String str2) {
        this.f4954 = str;
        this.f4955 = str2;
        try {
            m3370();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static void m3368(C1276 r3, AbstractC1261 r4) {
        try {
            if (f4951 == null) {
                f4951 = new C1260("_qiniu_record_file_hs5z9lo7anx03", "https://uplog.qbox.me/log/3");
            }
            f4951.m3373(r3, r4);
        } catch (Throwable unused) {
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:25:0x0039 A[SYNTHETIC, Splitter:B:25:0x0039] */
    /* JADX WARNING: Removed duplicated region for block: B:30:? A[RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:32:? A[RETURN, SYNTHETIC] */
    /* renamed from: K  reason: contains not printable characters */
    public static void m3369(File file, String str, boolean z) {
        Throwable th;
        FileNotFoundException e;
        IOException e2;
        FileOutputStream fileOutputStream = null;
        try {
            FileOutputStream fileOutputStream2 = new FileOutputStream(file, z);
            try {
                fileOutputStream2.write(str.getBytes(Charset.forName("UTF-8")));
                fileOutputStream2.flush();
                try {
                    fileOutputStream2.close();
                } catch (IOException unused) {
                }
            } catch (FileNotFoundException e3) {
                e = e3;
                fileOutputStream = fileOutputStream2;
                e.printStackTrace();
                if (fileOutputStream == null) {
                    return;
                }
                fileOutputStream.close();
            } catch (IOException e4) {
                e2 = e4;
                fileOutputStream = fileOutputStream2;
                try {
                    e2.printStackTrace();
                    if (fileOutputStream == null) {
                        return;
                    }
                    fileOutputStream.close();
                } catch (Throwable th2) {
                    th = th2;
                    fileOutputStream2 = fileOutputStream;
                    if (fileOutputStream2 != null) {
                        try {
                            fileOutputStream2.close();
                        } catch (IOException unused2) {
                        }
                    }
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                if (fileOutputStream2 != null) {
                }
                throw th;
            }
        } catch (FileNotFoundException e5) {
            e = e5;
            e.printStackTrace();
            if (fileOutputStream == null) {
            }
            fileOutputStream.close();
        } catch (IOException e6) {
            e2 = e6;
            e2.printStackTrace();
            if (fileOutputStream == null) {
            }
            fileOutputStream.close();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3370() throws IOException {
        File file = new File(C1264.f4961);
        if (!file.exists()) {
            if (!file.mkdirs()) {
                StringBuilder r2 = C1293.m3416("mkdir failed: ");
                r2.append(file.getAbsolutePath());
                throw new IOException(r2.toString());
            }
        } else if (file.isDirectory()) {
            this.f4953 = new File(file, this.f4954);
        } else {
            throw new IOException(file.getAbsolutePath() + " is not a dir");
        }
        ExecutorService executorService = f4950;
        if (executorService == null || executorService.isShutdown()) {
            f4950 = Executors.newSingleThreadExecutor();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3373(C1276 r2, AbstractC1261 r3) {
        ExecutorService executorService = f4950;
        if (executorService != null && !executorService.isShutdown()) {
            f4950.submit(new RunnableC1263(r3));
            if (r2 != C1276.f4987) {
                f4950.submit(new RunnableC1262(r2));
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3371(String str, File file) {
        if (file.length() < ((long) 2097152)) {
            m3369(file, str + "\n", true);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:31:0x00c5  */
    /* JADX WARNING: Removed duplicated region for block: B:35:? A[RETURN, SYNTHETIC] */
    /* renamed from: K  reason: contains not printable characters */
    public final void m3372(C1276 r8, File file) {
        boolean z;
        if (file.length() > ((long) RecyclerView.AbstractC0269.FLAG_APPEARED_IN_PRE_LAYOUT)) {
            long time = new Date().getTime();
            if (time > this.f4956 + ((long) 600000)) {
                this.f4956 = time;
                try {
                    if (f4952 == null) {
                        C2625.C2626 r1 = new C2625.C2626();
                        r1.m6924(10, TimeUnit.SECONDS);
                        r1.m6923(15, TimeUnit.SECONDS);
                        r1.m6922((long) 350, TimeUnit.SECONDS);
                        f4952 = new C2625(r1);
                    }
                    C2625 r12 = f4952;
                    AbstractC2651 create = AbstractC2651.create(C2628.m6936("text/plain"), file);
                    C2644.C2645 k = new C2644.C2645();
                    k.m6965(this.f4955);
                    k.f8988.m7002("Authorization", "UpToken " + r8.f4990);
                    k.f8988.m7002(GraphRequest.USER_AGENT_HEADER, C1229.f4859.m3303(r8.f4989));
                    k.m6967("POST", create);
                    C2671 r82 = ((C2642) r12.m6920(k.m6970())).m6955();
                    try {
                        if (r82.m7006()) {
                            String r13 = r82.f9088.m6996("X-Reqid");
                            if (r13 == null) {
                                r13 = null;
                            }
                            if (r13 != null) {
                                z = true;
                                if (!z) {
                                    m3369(file, "", false);
                                    m3369(file, "", false);
                                    return;
                                }
                                return;
                            }
                        }
                        z = false;
                    } finally {
                        try {
                            r82.f9093.close();
                        } catch (Exception unused) {
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    z = false;
                }
                if (!z) {
                }
            }
        }
    }
}
