package b0;

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import androidx.media3.session.legacy.PlaybackStateCompat;
import com.ifpdos.sdk.httpd.binder.aidl.RequestLine;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import n.AbstractC0637c;
import okhttp3.HttpUrl;

/* JADX INFO: loaded from: classes.dex */
public abstract class D {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final int f2965a = Build.VERSION.SDK_INT;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final String f2966b = Build.DEVICE;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final String f2967c = Build.MANUFACTURER;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final String f2968d = Build.MODEL;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final Pattern f2969e = Pattern.compile("(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)[Tt](\\d\\d):(\\d\\d):(\\d\\d)(\\.(\\d+))?([Zz]|((\\+|\\-)(\\d\\d):?(\\d\\d)))?");

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static final Pattern f2970f = Pattern.compile("^(-)?P(([0-9]*)Y)?(([0-9]*)M)?(([0-9]*)D)?(T(([0-9]*)H)?(([0-9]*)M)?(([0-9.]*)S)?)?$");

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static final Pattern f2971g = Pattern.compile("%([A-Fa-f0-9]{2})");

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private static final int[] f2972h = {0, 79764919, 159529838, 222504665, 319059676, 398814059, 445009330, 507990021, 638119352, 583659535, 797628118, 726387553, 890018660, 835552979, 1015980042, 944750013, 1276238704, 1221641927, 1167319070, 1095957929, 1595256236, 1540665371, 1452775106, 1381403509, 1780037320, 1859660671, 1671105958, 1733955601, 2031960084, 2111593891, 1889500026, 1952343757, -1742489888, -1662866601, -1851683442, -1788833735, -1960329156, -1880695413, -2103051438, -2040207643, -1104454824, -1159051537, -1213636554, -1284997759, -1389417084, -1444007885, -1532160278, -1603531939, -734892656, -789352409, -575645954, -646886583, -952755380, -1007220997, -827056094, -898286187, -231047128, -151282273, -71779514, -8804623, -515967244, -436212925, -390279782, -327299027, 881225847, 809987520, 1023691545, 969234094, 662832811, 591600412, 771767749, 717299826, 311336399, 374308984, 453813921, 533576470, 25881363, 88864420, 134795389, 214552010, 2023205639, 2086057648, 1897238633, 1976864222, 1804852699, 1867694188, 1645340341, 1724971778, 1587496639, 1516133128, 1461550545, 1406951526, 1302016099, 1230646740, 1142491917, 1087903418, -1398421865, -1469785312, -1524105735, -1578704818, -1079922613, -1151291908, -1239184603, -1293773166, -1968362705, -1905510760, -2094067647, -2014441994, -1716953613, -1654112188, -1876203875, -1796572374, -525066777, -462094256, -382327159, -302564546, -206542021, -143559028, -97365931, -17609246, -960696225, -1031934488, -817968335, -872425850, -709327229, -780559564, -600130067, -654598054, 1762451694, 1842216281, 1619975040, 1682949687, 2047383090, 2127137669, 1938468188, 2001449195, 1325665622, 1271206113, 1183200824, 1111960463, 1543535498, 1489069629, 1434599652, 1363369299, 622672798, 568075817, 748617968, 677256519, 907627842, 853037301, 1067152940, 995781531, 51762726, 131386257, 177728840, 240578815, 269590778, 349224269, 429104020, 491947555, -248556018, -168932423, -122852000, -60002089, -500490030, -420856475, -341238852, -278395381, -685261898, -739858943, -559578920, -630940305, -1004286614, -1058877219, -845023740, -916395085, -1119974018, -1174433591, -1262701040, -1333941337, -1371866206, -1426332139, -1481064244, -1552294533, -1690935098, -1611170447, -1833673816, -1770699233, -2009983462, -1930228819, -2119160460, -2056179517, 1569362073, 1498123566, 1409854455, 1355396672, 1317987909, 1246755826, 1192025387, 1137557660, 2072149281, 2135122070, 1912620623, 1992383480, 1753615357, 1816598090, 1627664531, 1707420964, 295390185, 358241886, 404320391, 483945776, 43990325, 106832002, 186451547, 266083308, 932423249, 861060070, 1041341759, 986742920, 613929101, 542559546, 756411363, 701822548, -978770311, -1050133554, -869589737, -924188512, -693284699, -764654318, -550540341, -605129092, -475935807, -413084042, -366743377, -287118056, -257573603, -194731862, -114850189, -35218492, -1984365303, -1921392450, -2143631769, -2063868976, -1698919467, -1635936670, -1824608069, -1744851700, -1347415887, -1418654458, -1506661409, -1561119128, -1129027987, -1200260134, -1254728445, -1309196108};

    class a implements ThreadFactory {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ String f2973a;

        a(String str) {
            this.f2973a = str;
        }

        @Override // java.util.concurrent.ThreadFactory
        public Thread newThread(Runnable runnable) {
            return new Thread(runnable, this.f2973a);
        }
    }

    public static a0.h A(a0.h hVar, int i2) {
        if (i2 == 0) {
            return hVar;
        }
        long j2 = hVar.f1944e;
        return new a0.h(hVar.f1940a, hVar.f1943d + ((long) i2), j2 != -1 ? 50000 + (j2 - ((long) i2)) : -1L, hVar.f1945f, hVar.f1946g);
    }

    public static int B(long j2) {
        return (int) (j2 >>> 32);
    }

    public static String C(Context context, String str) {
        String str2;
        try {
            str2 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException unused) {
            str2 = "?";
        }
        return str + "/" + str2 + " (Linux;Android " + Build.VERSION.RELEASE + ") ExoPlayerLib/1.5.15";
    }

    public static boolean D(Uri uri) {
        String scheme = uri.getScheme();
        return TextUtils.isEmpty(scheme) || scheme.equals("file");
    }

    public static void E(HttpURLConnection httpURLConnection, long j2) throws Throwable {
        int i2 = f2965a;
        if (i2 != 19 && i2 != 20) {
            return;
        }
        InputStream inputStream = null;
        try {
            InputStream inputStream2 = httpURLConnection.getInputStream();
            if (j2 == -1) {
                try {
                    try {
                        if (inputStream2.read() == -1) {
                            h(inputStream2);
                            return;
                        }
                    } catch (Throwable th) {
                        th = th;
                        inputStream = inputStream2;
                        h(inputStream);
                        throw th;
                    }
                } catch (IOException | Exception unused) {
                    inputStream = inputStream2;
                    h(inputStream);
                    return;
                }
            } else if (j2 <= PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH) {
                h(inputStream2);
                return;
            }
            String name = inputStream2.getClass().getName();
            if (name.equals("com.android.okhttp.internal.http.HttpTransport$ChunkedInputStream") || name.equals("com.android.okhttp.internal.http.HttpTransport$FixedLengthInputStream")) {
                Method declaredMethod = inputStream2.getClass().getSuperclass().getDeclaredMethod("unexpectedEndOfInput", null);
                declaredMethod.setAccessible(true);
                declaredMethod.invoke(inputStream2, null);
            }
            h(inputStream2);
        } catch (IOException | Exception unused2) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static ExecutorService F(String str) {
        return Executors.newSingleThreadExecutor(new a(str));
    }

    public static long G(String str) throws ParseException {
        Matcher matcher = f2969e.matcher(str);
        int i2 = 0;
        if (!matcher.matches()) {
            throw new ParseException("Invalid date/time format: " + str, 0);
        }
        if (matcher.group(9) != null && !matcher.group(9).equalsIgnoreCase("Z")) {
            i2 = (Integer.parseInt(matcher.group(12)) * 60) + Integer.parseInt(matcher.group(13));
            if (matcher.group(11).equals("-")) {
                i2 *= -1;
            }
        }
        GregorianCalendar gregorianCalendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gregorianCalendar.clear();
        gregorianCalendar.set(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1, Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4)), Integer.parseInt(matcher.group(5)), Integer.parseInt(matcher.group(6)));
        if (!TextUtils.isEmpty(matcher.group(8))) {
            gregorianCalendar.set(14, new BigDecimal("0." + matcher.group(8)).movePointRight(3).intValue());
        }
        long timeInMillis = gregorianCalendar.getTimeInMillis();
        return i2 != 0 ? timeInMillis - (((long) i2) * 60000) : timeInMillis;
    }

    public static long H(String str) {
        Matcher matcher = f2970f.matcher(str);
        if (!matcher.matches()) {
            return (long) (Double.parseDouble(str) * 3600.0d * 1000.0d);
        }
        boolean zIsEmpty = TextUtils.isEmpty(matcher.group(1));
        String strGroup = matcher.group(3);
        double d2 = com.jsyn.unitgen.u.FALSE;
        double d3 = strGroup != null ? Double.parseDouble(strGroup) * 3.1556908E7d : 0.0d;
        String strGroup2 = matcher.group(5);
        double d4 = d3 + (strGroup2 != null ? Double.parseDouble(strGroup2) * 2629739.0d : 0.0d);
        String strGroup3 = matcher.group(7);
        double d5 = d4 + (strGroup3 != null ? Double.parseDouble(strGroup3) * 86400.0d : 0.0d);
        String strGroup4 = matcher.group(10);
        double d6 = d5 + (strGroup4 != null ? Double.parseDouble(strGroup4) * 3600.0d : 0.0d);
        String strGroup5 = matcher.group(12);
        double d7 = d6 + (strGroup5 != null ? Double.parseDouble(strGroup5) * 60.0d : 0.0d);
        String strGroup6 = matcher.group(14);
        if (strGroup6 != null) {
            d2 = Double.parseDouble(strGroup6);
        }
        long j2 = (long) ((d7 + d2) * 1000.0d);
        return !zIsEmpty ? -j2 : j2;
    }

    public static long I(long j2, long j3, long j4) {
        if (j4 >= j3 && j4 % j3 == 0) {
            return j2 / (j4 / j3);
        }
        if (j4 < j3 && j3 % j4 == 0) {
            return j2 * (j3 / j4);
        }
        return (long) (j2 * (j3 / j4));
    }

    public static long[] J(List list, long j2, long j3) {
        int size = list.size();
        long[] jArr = new long[size];
        int i2 = 0;
        if (j3 >= j2 && j3 % j2 == 0) {
            long j4 = j3 / j2;
            while (i2 < size) {
                jArr[i2] = ((Long) list.get(i2)).longValue() / j4;
                i2++;
            }
        } else if (j3 >= j2 || j2 % j3 != 0) {
            double d2 = j2 / j3;
            while (i2 < size) {
                jArr[i2] = (long) (((Long) list.get(i2)).longValue() * d2);
                i2++;
            }
        } else {
            long j5 = j2 / j3;
            while (i2 < size) {
                jArr[i2] = ((Long) list.get(i2)).longValue() * j5;
                i2++;
            }
        }
        return jArr;
    }

    public static int[] K(List list) {
        if (list == null) {
            return null;
        }
        int size = list.size();
        int[] iArr = new int[size];
        for (int i2 = 0; i2 < size; i2++) {
            iArr[i2] = ((Integer) list.get(i2)).intValue();
        }
        return iArr;
    }

    public static byte[] L(InputStream inputStream) {
        byte[] bArr = new byte[4096];
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] byteArray = null;
        while (true) {
            try {
                int i2 = inputStream.read(bArr);
                if (i2 == -1) {
                    return byteArray;
                }
                try {
                    byteArrayOutputStream.write(bArr, 0, i2);
                    byteArray = byteArrayOutputStream.toByteArray();
                    h(byteArrayOutputStream);
                } finally {
                    h(byteArrayOutputStream);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public static String M(String str) {
        if (str == null) {
            return null;
        }
        return str.toLowerCase(Locale.US);
    }

    public static boolean a(Object obj, Object obj2) {
        return obj == null ? obj2 == null : obj.equals(obj2);
    }

    public static int b(long[] jArr, long j2, boolean z2, boolean z3) {
        int iBinarySearch = Arrays.binarySearch(jArr, j2);
        if (iBinarySearch < 0) {
            iBinarySearch = ~iBinarySearch;
        } else if (!z2) {
            iBinarySearch++;
        }
        return z3 ? Math.min(jArr.length - 1, iBinarySearch) : iBinarySearch;
    }

    public static int c(List list, Object obj, boolean z2, boolean z3) {
        int iBinarySearch = Collections.binarySearch(list, obj);
        if (iBinarySearch < 0) {
            iBinarySearch = -(iBinarySearch + 2);
        } else if (!z2) {
            iBinarySearch--;
        }
        return z3 ? Math.max(0, iBinarySearch) : iBinarySearch;
    }

    public static int d(long[] jArr, long j2, boolean z2, boolean z3) {
        int iBinarySearch = Arrays.binarySearch(jArr, j2);
        if (iBinarySearch < 0) {
            iBinarySearch = -(iBinarySearch + 2);
        } else if (!z2) {
            iBinarySearch--;
        }
        return z3 ? Math.max(0, iBinarySearch) : iBinarySearch;
    }

    public static int e(int i2, int i3) {
        return ((i2 + i3) - 1) / i3;
    }

    public static long f(long j2, long j3) {
        return ((j2 + j3) - 1) / j3;
    }

    public static void g(a0.f fVar) {
        if (fVar != null) {
            try {
                fVar.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void h(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException unused) {
            }
        }
    }

    public static boolean i(Object[] objArr, Object obj) {
        for (Object obj2 : objArr) {
            if (a(obj2, obj)) {
                return true;
            }
        }
        return false;
    }

    public static int j(byte[] bArr, int i2, int i3, int i4) {
        while (i2 < i3) {
            i4 = f2972h[((i4 >>> 24) ^ (bArr[i2] & 255)) & 255] ^ (i4 << 8);
            i2++;
        }
        return i4;
    }

    public static byte[] k(String str, byte[] bArr, Map map) throws Throwable {
        InputStream inputStream;
        HttpURLConnection httpURLConnection = null;
        try {
            HttpURLConnection httpURLConnection2 = (HttpURLConnection) new URL(str).openConnection();
            try {
                httpURLConnection2.setRequestMethod(RequestLine.METHOD_POST);
                httpURLConnection2.setDoOutput(bArr != null);
                httpURLConnection2.setDoInput(true);
                if (map != null) {
                    for (Map.Entry entry : map.entrySet()) {
                        httpURLConnection2.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
                    }
                }
                if (bArr != null) {
                    OutputStream outputStream = httpURLConnection2.getOutputStream();
                    try {
                        outputStream.write(bArr);
                        outputStream.close();
                    } catch (Throwable th) {
                        outputStream.close();
                        throw th;
                    }
                }
                try {
                    inputStream = httpURLConnection2.getInputStream();
                } catch (Throwable unused) {
                    inputStream = null;
                }
                try {
                    byte[] bArrL = L(inputStream);
                    h(inputStream);
                    httpURLConnection2.disconnect();
                    return bArrL;
                } catch (Throwable unused2) {
                    h(inputStream);
                    httpURLConnection2.disconnect();
                    return null;
                }
            } catch (Throwable th2) {
                th = th2;
                httpURLConnection = httpURLConnection2;
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
        }
    }

    public static int[] l(int i2) {
        int[] iArr = new int[i2];
        for (int i3 = 0; i3 < i2; i3++) {
            iArr[i3] = i3;
        }
        return iArr;
    }

    public static int m(ByteBuffer byteBuffer, int i2) {
        int i3 = byteBuffer.getInt(i2);
        return byteBuffer.order() == ByteOrder.BIG_ENDIAN ? i3 : Integer.reverseBytes(i3);
    }

    public static int n(long j2) {
        return (int) j2;
    }

    public static byte[] o(String str) {
        int length = str.length() / 2;
        byte[] bArr = new byte[length];
        for (int i2 = 0; i2 < length; i2++) {
            int i3 = i2 * 2;
            bArr[i2] = (byte) ((Character.digit(str.charAt(i3), 16) << 4) + Character.digit(str.charAt(i3 + 1), 16));
        }
        return bArr;
    }

    public static String p(Object[] objArr) {
        StringBuilder sb = new StringBuilder();
        for (int i2 = 0; i2 < objArr.length; i2++) {
            sb.append(objArr[i2].getClass().getSimpleName());
            if (i2 < objArr.length - 1) {
                sb.append(", ");
            }
        }
        return sb.toString();
    }

    private static void q(Display display, Point point) {
        display.getSize(point);
    }

    private static void r(Display display, Point point) {
        display.getRealSize(point);
    }

    private static void s(Display display, Point point) {
        Display.Mode mode = display.getMode();
        point.x = mode.getPhysicalWidth();
        point.y = mode.getPhysicalHeight();
    }

    private static void t(Display display, Point point) {
        point.x = display.getWidth();
        point.y = display.getHeight();
    }

    public static int u(String str) {
        int length = str.length();
        AbstractC0399d.a(length <= 4);
        int iCharAt = 0;
        for (int i2 = 0; i2 < length; i2++) {
            iCharAt = (iCharAt << 8) | str.charAt(i2);
        }
        return iCharAt;
    }

    public static long v(int i2, int i3) {
        return (((long) i3) & 4294967295L) | (((long) i2) << 32);
    }

    public static int w(int i2) {
        if (i2 == 8) {
            return 3;
        }
        if (i2 == 16) {
            return 2;
        }
        if (i2 == 24) {
            return AbstractC0637c.f5494a;
        }
        if (i2 != 32) {
            return 0;
        }
        return AbstractC0637c.f5495b;
    }

    public static Point x(Context context) {
        String str;
        String str2;
        String str3;
        if (f2965a < 25) {
            String str4 = f2967c;
            if ("Sony".equals(str4) && (str3 = f2968d) != null && str3.startsWith("BRAVIA") && context.getPackageManager().hasSystemFeature("com.sony.dtv.hardware.panel.qfhd")) {
                return new Point(3840, 2160);
            }
            if ("NVIDIA".equals(str4) && (str = f2968d) != null && str.contains("SHIELD")) {
                try {
                    Class<?> cls = Class.forName("android.os.SystemProperties");
                    str2 = (String) cls.getMethod("get", String.class).invoke(cls, "sys.display-size");
                } catch (Exception e2) {
                    Log.e("Util", "Failed to read sys.display-size", e2);
                    str2 = null;
                }
                if (!TextUtils.isEmpty(str2)) {
                    try {
                        String[] strArrSplit = str2.trim().split("x");
                        if (strArrSplit.length == 2) {
                            int i2 = Integer.parseInt(strArrSplit[0]);
                            int i3 = Integer.parseInt(strArrSplit[1]);
                            if (i2 > 0 && i3 > 0) {
                                return new Point(i2, i3);
                            }
                        }
                    } catch (NumberFormatException unused) {
                    }
                    Log.e("Util", "Invalid sys.display-size: " + str2);
                }
            }
        }
        Display defaultDisplay = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
        Point point = new Point();
        int i4 = f2965a;
        if (i4 >= 23) {
            s(defaultDisplay, point);
        } else if (i4 >= 17) {
            r(defaultDisplay, point);
        } else if (i4 >= 16) {
            q(defaultDisplay, point);
        } else {
            t(defaultDisplay, point);
        }
        return point;
    }

    public static String y(String str, String str2) {
        String str3;
        try {
            str3 = (String) Class.forName("android.os.SystemProperties").getMethod("get", String.class, String.class).invoke(null, str, str2);
        } catch (Exception e2) {
            Log.e("Util", "getprop exception: " + e2.toString());
            str3 = HttpUrl.FRAGMENT_ENCODE_SET;
        }
        Log.d("Util", "getProp: key=" + str + ", value=" + str3);
        return str3;
    }

    public static a0.h z(a0.h hVar, int i2) {
        if (i2 == 0) {
            return hVar;
        }
        long j2 = hVar.f1944e;
        return new a0.h(hVar.f1940a, hVar.f1943d + ((long) i2), j2 != -1 ? j2 - ((long) i2) : -1L, hVar.f1945f, hVar.f1946g);
    }
}
