package IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9;

import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.X6FRs_4;
import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0;
import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.PGPF6hQ_2;
import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.IMuAHx_6;
import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.Xgtqvk_8;
import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.StatFs;
import android.util.Log;
import androidx.recyclerview.widget.RecyclerView;
import com.wang.avi.BuildConfig;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* compiled from: Util.java */
/* loaded from: classes.dex */
public class PGPF6hQ_2 {
    public static InterfaceC0010PGPF6hQ_2 KQgRr5e_0 = new QxJ9d_1();

    /* compiled from: Util.java */
    /* loaded from: classes.dex */
    public static class KQgRr5e_0 implements ThreadFactory {
        public final /* synthetic */ String KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final /* synthetic */ boolean f162KQgRr5e_0;

        public KQgRr5e_0(String str, boolean z) {
            this.KQgRr5e_0 = str;
            this.f162KQgRr5e_0 = z;
        }

        @Override // java.util.concurrent.ThreadFactory
        public Thread newThread(Runnable runnable) {
            Thread thread = new Thread(runnable, this.KQgRr5e_0);
            thread.setDaemon(this.f162KQgRr5e_0);
            return thread;
        }
    }

    /* compiled from: Util.java */
    /* renamed from: IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2$PGPF6hQ_2  reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public interface InterfaceC0010PGPF6hQ_2 {
        void KQgRr5e_0(String str, String str2);

        void QxJ9d_1(String str, String str2);
    }

    /* compiled from: Util.java */
    /* loaded from: classes.dex */
    public static class QxJ9d_1 implements InterfaceC0010PGPF6hQ_2 {
        @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.InterfaceC0010PGPF6hQ_2
        public void KQgRr5e_0(String str, String str2) {
        }

        @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.InterfaceC0010PGPF6hQ_2
        public void QxJ9d_1(String str, String str2) {
        }
    }

    public static void KQgRr5e_0(String str, String str2) {
        InterfaceC0010PGPF6hQ_2 interfaceC0010PGPF6hQ_2 = KQgRr5e_0;
        if (interfaceC0010PGPF6hQ_2 != null) {
            interfaceC0010PGPF6hQ_2.QxJ9d_1(str, str2);
        } else {
            Log.d(str, str2);
        }
    }

    public static boolean KQgRr5e_0(long j, long j2) {
        return j == j2;
    }

    public static void QxJ9d_1(String str, String str2) {
        InterfaceC0010PGPF6hQ_2 interfaceC0010PGPF6hQ_2 = KQgRr5e_0;
        if (interfaceC0010PGPF6hQ_2 != null) {
            interfaceC0010PGPF6hQ_2.KQgRr5e_0(str, str2);
        } else {
            Log.w(str, str2);
        }
    }

    public static boolean KQgRr5e_0(CharSequence charSequence) {
        return charSequence == null || charSequence.length() == 0;
    }

    public static boolean QxJ9d_1(ConnectivityManager connectivityManager) {
        if (connectivityManager == null) {
            QxJ9d_1("Util", "failed to get connectivity manager!");
            return true;
        }
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo == null || activeNetworkInfo.getType() != 1;
    }

    public static ThreadFactory KQgRr5e_0(String str, boolean z) {
        return new KQgRr5e_0(str, z);
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static String m104KQgRr5e_0(String str) {
        byte[] bArr;
        try {
            bArr = MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException | NoSuchAlgorithmException unused) {
            bArr = null;
        }
        if (bArr != null) {
            StringBuilder sb = new StringBuilder(bArr.length * 2);
            for (byte b : bArr) {
                int i = b & 255;
                if (i < 16) {
                    sb.append('0');
                }
                sb.append(Integer.toHexString(i));
            }
            return sb.toString();
        }
        return null;
    }

    public static long QxJ9d_1(String str) {
        if (str != null && str.length() != 0) {
            try {
                Matcher matcher = Pattern.compile("bytes (\\d+)-(\\d+)/\\d+").matcher(str);
                if (matcher.find()) {
                    return (Long.parseLong(matcher.group(2)) - Long.parseLong(matcher.group(1))) + 1;
                }
            } catch (Exception e) {
                QxJ9d_1("Util", "parse content-length from content-range failed " + e);
            }
        }
        return -1L;
    }

    public static void KQgRr5e_0(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.KQgRr5e_0 kQgRr5e_0) {
        boolean z = true;
        if (kQgRr5e_0.QxJ9d_1() >= 0 && kQgRr5e_0.QxJ9d_1() <= kQgRr5e_0.KQgRr5e_0()) {
            z = false;
        }
        if (z) {
            QxJ9d_1("resetBlockIfDirty", "block is dirty so have to reset: " + kQgRr5e_0);
            kQgRr5e_0.m86KQgRr5e_0();
        }
    }

    public static boolean QxJ9d_1(Uri uri) {
        return uri.getScheme().equals("file");
    }

    public static void QxJ9d_1(Map<String, List<String>> map, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0 kQgRr5e_0) throws IOException {
        KQgRr5e_0(map);
        KQgRr5e_0(map, kQgRr5e_0);
    }

    public static long KQgRr5e_0(StatFs statFs) {
        if (Build.VERSION.SDK_INT >= 18) {
            return statFs.getAvailableBytes();
        }
        return statFs.getAvailableBlocks() * statFs.getBlockSize();
    }

    public static String KQgRr5e_0(long j, boolean z) {
        int i = z ? 1000 : RecyclerView.WGk6X_27.FLAG_ADAPTER_FULLUPDATE;
        if (j < i) {
            return j + " B";
        }
        double d = j;
        double d2 = i;
        int log = (int) (Math.log(d) / Math.log(d2));
        StringBuilder sb = new StringBuilder();
        sb.append((z ? "kMGTPE" : "KMGTPE").charAt(log - 1));
        sb.append(z ? BuildConfig.FLAVOR : "i");
        String sb2 = sb.toString();
        Locale locale = Locale.ENGLISH;
        double pow = Math.pow(d2, log);
        Double.isNaN(d);
        return String.format(locale, "%.1f %sB", Double.valueOf(d / pow), sb2);
    }

    public static Xgtqvk_8 KQgRr5e_0(Context context) {
        try {
            return (Xgtqvk_8) Class.forName("IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.FSaI4_7").getDeclaredConstructor(Context.class).newInstance(context);
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException unused) {
            return new IMuAHx_6();
        }
    }

    public static Xgtqvk_8 KQgRr5e_0(Xgtqvk_8 xgtqvk_8) {
        try {
            xgtqvk_8 = (Xgtqvk_8) xgtqvk_8.getClass().getMethod("createRemitSelf", new Class[0]).invoke(xgtqvk_8, new Object[0]);
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException unused) {
        }
        KQgRr5e_0("Util", "Get final download store is " + xgtqvk_8);
        return xgtqvk_8;
    }

    public static KQgRr5e_0.QxJ9d_1 KQgRr5e_0() {
        try {
            return (KQgRr5e_0.QxJ9d_1) Class.forName("IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.QxJ9d_1$KQgRr5e_0").getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException unused) {
            return new PGPF6hQ_2.QxJ9d_1();
        }
    }

    public static void KQgRr5e_0(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.PGPF6hQ_2 pGPF6hQ_2, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.PGPF6hQ_2 pGPF6hQ_22, long j, boolean z) {
        int KQgRr5e_02 = X6FRs_4.KQgRr5e_0().m24KQgRr5e_0().KQgRr5e_0(z) ? X6FRs_4.KQgRr5e_0().m24KQgRr5e_0().KQgRr5e_0(pGPF6hQ_2, j) : 1;
        pGPF6hQ_22.m92KQgRr5e_0();
        long j2 = KQgRr5e_02;
        long j3 = j / j2;
        int i = 0;
        long j4 = 0;
        long j5 = 0;
        while (i < KQgRr5e_02) {
            j4 += j5;
            j5 = i == 0 ? (j % j2) + j3 : j3;
            pGPF6hQ_22.KQgRr5e_0(new IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.Mqv2r_3.KQgRr5e_0(j4, j5));
            i++;
        }
    }

    public static long KQgRr5e_0(String str) {
        if (str == null) {
            return -1L;
        }
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException unused) {
            KQgRr5e_0("Util", "parseContentLength failed parse for '" + str + "'");
            return -1L;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static boolean m106KQgRr5e_0(String str) {
        return X6FRs_4.KQgRr5e_0().m31KQgRr5e_0().checkCallingOrSelfPermission(str) == 0;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static boolean m105KQgRr5e_0(Uri uri) {
        return uri.getScheme().equals("content");
    }

    @SuppressFBWarnings({"DMI"})
    public static File KQgRr5e_0(File file) {
        File parentFile = file.getParentFile();
        return parentFile == null ? new File("/") : parentFile;
    }

    public static long KQgRr5e_0(Uri uri) {
        Cursor query = X6FRs_4.KQgRr5e_0().m31KQgRr5e_0().getContentResolver().query(uri, null, null, null, null);
        if (query != null) {
            try {
                query.moveToFirst();
                return query.getLong(query.getColumnIndex("_size"));
            } finally {
                query.close();
            }
        }
        return 0L;
    }

    public static boolean KQgRr5e_0(ConnectivityManager connectivityManager) {
        if (connectivityManager == null) {
            QxJ9d_1("Util", "failed to get connectivity manager!");
            return true;
        }
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    public static void KQgRr5e_0(Map<String, List<String>> map) throws IOException {
        if (map.containsKey("If-Match") || map.containsKey("Range")) {
            throw new IOException("If-Match and Range only can be handle by internal!");
        }
    }

    public static void KQgRr5e_0(Map<String, List<String>> map, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0 kQgRr5e_0) {
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
            String key = entry.getKey();
            for (String str : entry.getValue()) {
                kQgRr5e_0.KQgRr5e_0(key, str);
            }
        }
    }

    public static void KQgRr5e_0(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0 kQgRr5e_0) {
        kQgRr5e_0.KQgRr5e_0("User-Agent", "OkDownload/1.0.7");
    }
}
