Rabbit-R1/original r1/java/sources/androidx/media3/common/util/Util.java
2024-05-21 17:08:36 -04:00

1913 lines
70 KiB
Java

package androidx.media3.common.util;
import android.app.Activity;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcel;
import android.security.NetworkSecurityPolicy;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Base64;
import android.util.SparseLongArray;
import android.view.Display;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.autofill.HintConstants;
import androidx.compose.material3.MenuKt;
import androidx.compose.runtime.ComposerKt;
import androidx.core.location.LocationRequestCompat;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.ParserException;
import androidx.media3.common.Player;
import androidx.media3.exoplayer.upstream.CmcdHeadersFactory;
import androidx.recyclerview.widget.ItemTouchHelper;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.google.common.base.Ascii;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import io.flutter.embedding.android.KeyboardMap;
import io.sentry.protocol.User;
import io.sentry.protocol.ViewHierarchyNode;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.Formatter;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.NoSuchElementException;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.DataFormatException;
import java.util.zip.GZIPOutputStream;
import java.util.zip.Inflater;
import okhttp3.internal.ws.WebSocketProtocol;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import tech.rabbit.r1launcher.BuildConfig;
/* loaded from: classes2.dex */
public final class Util {
private static final int[] CRC32_BYTES_MSBF;
private static final int[] CRC8_BYTES_MSBF;
public static final String DEVICE;
public static final String DEVICE_DEBUG_INFO;
public static final byte[] EMPTY_BYTE_ARRAY;
private static final Pattern ESCAPED_CHARACTER_PATTERN;
private static final String ISM_DASH_FORMAT_EXTENSION = "format=mpd-time-csf";
private static final String ISM_HLS_FORMAT_EXTENSION = "format=m3u8-aapl";
private static final Pattern ISM_PATH_PATTERN;
public static final String MANUFACTURER;
public static final String MODEL;
public static final int SDK_INT;
private static final String TAG = "Util";
private static final Pattern XS_DATE_TIME_PATTERN;
private static final Pattern XS_DURATION_PATTERN;
private static final String[] additionalIsoLanguageReplacements;
private static final String[] isoLegacyTagReplacements;
private static HashMap<String, String> languageTagReplacementMap;
public static long addWithOverflowDefault(long j, long j2, long j3) {
long j4 = j + j2;
return ((j ^ j4) & (j2 ^ j4)) < 0 ? j3 : j4;
}
@EnsuresNonNull({"#1"})
public static <T> T castNonNull(T t) {
return t;
}
@EnsuresNonNull({"#1"})
public static <T> T[] castNonNullTypeArray(T[] tArr) {
return tArr;
}
public static int compareLong(long j, long j2) {
if (j < j2) {
return -1;
}
return j == j2 ? 0 : 1;
}
public static String getAdaptiveMimeTypeForContentType(int i) {
if (i == 0) {
return "application/dash+xml";
}
if (i == 1) {
return "application/vnd.ms-sstr+xml";
}
if (i != 2) {
return null;
}
return "application/x-mpegURL";
}
public static int getAudioContentTypeForStreamType(int i) {
if (i != 0) {
return (i == 1 || i == 2 || i == 4 || i == 5 || i == 8) ? 4 : 2;
}
return 1;
}
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
/* JADX WARN: Failed to find 'out' block for switch in B:2:0x0002. Please report as an issue. */
/* JADX WARN: Removed duplicated region for block: B:9:0x0015 A[RETURN] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static int getAudioTrackChannelConfig(int r2) {
/*
r0 = 6396(0x18fc, float:8.963E-42)
switch(r2) {
case 1: goto L28;
case 2: goto L25;
case 3: goto L22;
case 4: goto L1f;
case 5: goto L1c;
case 6: goto L19;
case 7: goto L16;
case 8: goto L15;
case 9: goto L5;
case 10: goto Lb;
case 11: goto L5;
case 12: goto L7;
default: goto L5;
}
L5:
r2 = 0
return r2
L7:
r2 = 743676(0xb58fc, float:1.042112E-39)
return r2
Lb:
int r2 = androidx.media3.common.util.Util.SDK_INT
r1 = 32
if (r2 < r1) goto L15
r2 = 737532(0xb40fc, float:1.033502E-39)
return r2
L15:
return r0
L16:
r2 = 1276(0x4fc, float:1.788E-42)
return r2
L19:
r2 = 252(0xfc, float:3.53E-43)
return r2
L1c:
r2 = 220(0xdc, float:3.08E-43)
return r2
L1f:
r2 = 204(0xcc, float:2.86E-43)
return r2
L22:
r2 = 28
return r2
L25:
r2 = 12
return r2
L28:
r2 = 4
return r2
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.media3.common.util.Util.getAudioTrackChannelConfig(int):int");
}
public static int getAudioUsageForStreamType(int i) {
if (i == 0) {
return 2;
}
if (i == 1) {
return 13;
}
if (i == 2) {
return 6;
}
int i2 = 4;
if (i != 4) {
i2 = 5;
if (i != 5) {
return i != 8 ? 1 : 3;
}
}
return i2;
}
public static int getErrorCodeForMediaDrmErrorCode(int i) {
if (i == 2 || i == 4) {
return 6005;
}
if (i == 10) {
return 6004;
}
if (i == 7) {
return 6005;
}
if (i == 8) {
return 6003;
}
switch (i) {
case 15:
return 6003;
case 16:
case 18:
return 6005;
case 17:
case 19:
case 20:
case 21:
case 22:
return 6004;
default:
switch (i) {
case 24:
case 25:
case 26:
case 27:
case 28:
return 6002;
default:
return 6006;
}
}
}
public static int getPcmEncoding(int i) {
if (i == 8) {
return 3;
}
if (i == 16) {
return 2;
}
if (i != 24) {
return i != 32 ? 0 : 805306368;
}
return 536870912;
}
public static int getStreamTypeForAudioUsage(int i) {
if (i == 13) {
return 1;
}
switch (i) {
case 2:
return 0;
case 3:
return 8;
case 4:
return 4;
case 5:
case 7:
case 8:
case 9:
case 10:
return 5;
case 6:
return 2;
default:
return 3;
}
}
public static boolean isEncodingHighResolutionPcm(int i) {
return i == 536870912 || i == 805306368 || i == 4;
}
public static boolean isEncodingLinearPcm(int i) {
return i == 3 || i == 2 || i == 268435456 || i == 536870912 || i == 805306368 || i == 4;
}
public static boolean isLinebreak(int i) {
return i == 10 || i == 13;
}
public static long msToUs(long j) {
return (j == -9223372036854775807L || j == Long.MIN_VALUE) ? j : j * 1000;
}
private static boolean shouldEscapeCharacter(char c) {
return c == '\"' || c == '%' || c == '*' || c == '/' || c == ':' || c == '<' || c == '\\' || c == '|' || c == '>' || c == '?';
}
public static long subtractWithOverflowDefault(long j, long j2, long j3) {
long j4 = j - j2;
return ((j ^ j4) & (j2 ^ j)) < 0 ? j3 : j4;
}
public static byte[] toByteArray(int i) {
return new byte[]{(byte) (i >> 24), (byte) (i >> 16), (byte) (i >> 8), (byte) i};
}
public static long toUnsignedLong(int i) {
return i & KeyboardMap.kValueMask;
}
static {
int i = Build.VERSION.SDK_INT;
SDK_INT = i;
String str = Build.DEVICE;
DEVICE = str;
String str2 = Build.MANUFACTURER;
MANUFACTURER = str2;
String str3 = Build.MODEL;
MODEL = str3;
DEVICE_DEBUG_INFO = str + ", " + str3 + ", " + str2 + ", " + i;
EMPTY_BYTE_ARRAY = new byte[0];
XS_DATE_TIME_PATTERN = Pattern.compile("(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)[Tt](\\d\\d):(\\d\\d):(\\d\\d)([\\.,](\\d+))?([Zz]|((\\+|\\-)(\\d?\\d):?(\\d\\d)))?");
XS_DURATION_PATTERN = Pattern.compile("^(-)?P(([0-9]*)Y)?(([0-9]*)M)?(([0-9]*)D)?(T(([0-9]*)H)?(([0-9]*)M)?(([0-9.]*)S)?)?$");
ESCAPED_CHARACTER_PATTERN = Pattern.compile("%([A-Fa-f0-9]{2})");
ISM_PATH_PATTERN = Pattern.compile("(?:.*\\.)?isml?(?:/(manifest(.*))?)?", 2);
additionalIsoLanguageReplacements = new String[]{"alb", "sq", "arm", "hy", "baq", "eu", "bur", "my", "tib", "bo", "chi", "zh", "cze", "cs", "dut", "nl", "ger", "de", "gre", "el", "fre", "fr", User.JsonKeys.GEO, "ka", "ice", "is", "mac", "mk", "mao", "mi", "may", "ms", "per", "fa", "rum", "ro", "scc", "hbs-srp", "slo", "sk", "wel", "cy", "id", "ms-ind", "iw", "he", "heb", "he", "ji", "yi", "arb", "ar-arb", "in", "ms-ind", "ind", "ms-ind", "nb", "no-nob", "nob", "no-nob", "nn", "no-nno", "nno", "no-nno", "tw", "ak-twi", "twi", "ak-twi", "bs", "hbs-bos", "bos", "hbs-bos", "hr", "hbs-hrv", "hrv", "hbs-hrv", "sr", "hbs-srp", "srp", "hbs-srp", "cmn", "zh-cmn", "hak", "zh-hak", "nan", "zh-nan", "hsn", "zh-hsn"};
isoLegacyTagReplacements = new String[]{"i-lux", "lb", "i-hak", "zh-hak", "i-navajo", "nv", "no-bok", "no-nob", "no-nyn", "no-nno", "zh-guoyu", "zh-cmn", "zh-hakka", "zh-hak", "zh-min-nan", "zh-nan", "zh-xiang", "zh-hsn"};
CRC32_BYTES_MSBF = new int[]{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};
CRC8_BYTES_MSBF = new int[]{0, 7, 14, 9, 28, 27, 18, 21, 56, 63, 54, 49, 36, 35, 42, 45, 112, 119, WebSocketProtocol.PAYLOAD_SHORT, 121, AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR, 107, 98, 101, 72, 79, 70, 65, 84, 83, 90, 93, 224, 231, 238, 233, 252, 251, 242, 245, 216, 223, 214, 209, 196, 195, ComposerKt.compositionLocalMapKey, 205, 144, 151, 158, 153, 140, 139, 130, 133, 168, 175, 166, 161, SubsamplingScaleImageView.ORIENTATION_180, 179, 186, 189, 199, 192, ComposerKt.providerKey, ComposerKt.referenceKey, 219, 220, 213, 210, 255, 248, 241, 246, 227, 228, 237, 234, 183, 176, 185, 190, 171, 172, 165, 162, 143, 136, 129, 134, 147, 148, 157, 154, 39, 32, 41, 46, 59, 60, 53, 50, 31, 24, 17, 22, 3, 4, 13, 10, 87, 80, 89, 94, 75, 76, 69, 66, 111, LocationRequestCompat.QUALITY_LOW_POWER, 97, LocationRequestCompat.QUALITY_BALANCED_POWER_ACCURACY, 115, 116, 125, 122, 137, 142, 135, 128, 149, 146, 155, 156, 177, 182, 191, 184, 173, 170, 163, 164, 249, 254, 247, 240, 229, 226, 235, 236, 193, 198, ComposerKt.reuseKey, 200, 221, 218, 211, 212, 105, 110, 103, 96, 117, 114, 123, 124, 81, 86, 95, 88, 77, 74, 67, 68, 25, 30, 23, 16, 5, 2, 11, 12, 33, 38, 47, 40, 61, 58, 51, 52, 78, 73, 64, 71, 82, 85, 92, 91, 118, 113, MenuKt.InTransitionDuration, 127, 106, AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR_OVERLAY, 100, 99, 62, 57, 48, 55, 34, 37, 44, 43, 6, 1, 8, 15, 26, 29, 20, 19, 174, 169, 160, 167, 178, 181, 188, 187, 150, 145, 152, 159, 138, 141, 132, 131, 222, 217, 208, 215, 194, 197, ComposerKt.providerMapsKey, ComposerKt.providerValuesKey, 230, 225, 232, 239, ItemTouchHelper.Callback.DEFAULT_SWIPE_ANIMATION_DURATION, 253, 244, 243};
}
private Util() {
}
public static byte[] toByteArray(InputStream inputStream) throws IOException {
byte[] bArr = new byte[4096];
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
byteArrayOutputStream.write(bArr, 0, read);
} else {
return byteArrayOutputStream.toByteArray();
}
}
}
public static byte[] toByteArray(int... iArr) {
byte[] bArr = new byte[iArr.length * 4];
int i = 0;
for (int i2 : iArr) {
byte[] byteArray = toByteArray(i2);
bArr[i] = byteArray[0];
bArr[i + 1] = byteArray[1];
int i3 = i + 3;
bArr[i + 2] = byteArray[2];
i += 4;
bArr[i3] = byteArray[3];
}
return bArr;
}
public static byte[] toByteArray(float f) {
return toByteArray(Float.floatToIntBits(f));
}
public static float toFloat(byte[] bArr) {
Assertions.checkArgument(bArr.length == 4);
return Float.intBitsToFloat((bArr[3] & 255) | (bArr[0] << Ascii.CAN) | ((bArr[1] & 255) << 16) | ((bArr[2] & 255) << 8));
}
public static int toInteger(byte[] bArr) {
Assertions.checkArgument(bArr.length == 4);
return bArr[3] | (bArr[0] << Ascii.CAN) | (bArr[1] << Ascii.DLE) | (bArr[2] << 8);
}
public static Intent registerReceiverNotExported(Context context, BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) {
if (SDK_INT < 33) {
return context.registerReceiver(broadcastReceiver, intentFilter);
}
return context.registerReceiver(broadcastReceiver, intentFilter, 4);
}
public static ComponentName startForegroundService(Context context, Intent intent) {
if (SDK_INT >= 26) {
return context.startForegroundService(intent);
}
return context.startService(intent);
}
public static boolean maybeRequestReadExternalStoragePermission(Activity activity, Uri... uriArr) {
if (SDK_INT < 23) {
return false;
}
for (Uri uri : uriArr) {
if (maybeRequestReadExternalStoragePermission(activity, uri)) {
return true;
}
}
return false;
}
public static boolean maybeRequestReadExternalStoragePermission(Activity activity, MediaItem... mediaItemArr) {
if (SDK_INT < 23) {
return false;
}
for (MediaItem mediaItem : mediaItemArr) {
if (mediaItem.localConfiguration != null) {
if (maybeRequestReadExternalStoragePermission(activity, mediaItem.localConfiguration.uri)) {
return true;
}
ImmutableList<MediaItem.SubtitleConfiguration> immutableList = mediaItem.localConfiguration.subtitleConfigurations;
for (int i = 0; i < immutableList.size(); i++) {
if (maybeRequestReadExternalStoragePermission(activity, immutableList.get(i).uri)) {
return true;
}
}
}
}
return false;
}
private static boolean maybeRequestReadExternalStoragePermission(Activity activity, Uri uri) {
return SDK_INT >= 23 && (isLocalFileUri(uri) || isMediaStoreExternalContentUri(uri)) && requestExternalStoragePermission(activity);
}
private static boolean isMediaStoreExternalContentUri(Uri uri) {
if (!"content".equals(uri.getScheme()) || !"media".equals(uri.getAuthority())) {
return false;
}
List<String> pathSegments = uri.getPathSegments();
if (pathSegments.isEmpty()) {
return false;
}
String str = pathSegments.get(0);
return "external".equals(str) || "external_primary".equals(str);
}
public static boolean checkCleartextTrafficPermitted(MediaItem... mediaItemArr) {
if (SDK_INT < 24) {
return true;
}
for (MediaItem mediaItem : mediaItemArr) {
if (mediaItem.localConfiguration != null) {
if (isTrafficRestricted(mediaItem.localConfiguration.uri)) {
return false;
}
for (int i = 0; i < mediaItem.localConfiguration.subtitleConfigurations.size(); i++) {
if (isTrafficRestricted(mediaItem.localConfiguration.subtitleConfigurations.get(i).uri)) {
return false;
}
}
}
}
return true;
}
public static boolean isLocalFileUri(Uri uri) {
String scheme = uri.getScheme();
return TextUtils.isEmpty(scheme) || "file".equals(scheme);
}
public static boolean areEqual(Object obj, Object obj2) {
if (obj == null) {
return obj2 == null;
}
return obj.equals(obj2);
}
public static boolean contains(Object[] objArr, Object obj) {
for (Object obj2 : objArr) {
if (areEqual(obj2, obj)) {
return true;
}
}
return false;
}
public static <T> void removeRange(List<T> list, int i, int i2) {
if (i < 0 || i2 > list.size() || i > i2) {
throw new IllegalArgumentException();
}
if (i != i2) {
list.subList(i, i2).clear();
}
}
public static <T> T[] nullSafeArrayCopy(T[] tArr, int i) {
Assertions.checkArgument(i <= tArr.length);
return (T[]) Arrays.copyOf(tArr, i);
}
public static <T> T[] nullSafeArrayCopyOfRange(T[] tArr, int i, int i2) {
Assertions.checkArgument(i >= 0);
Assertions.checkArgument(i2 <= tArr.length);
return (T[]) Arrays.copyOfRange(tArr, i, i2);
}
public static <T> T[] nullSafeArrayAppend(T[] tArr, T t) {
Object[] copyOf = Arrays.copyOf(tArr, tArr.length + 1);
copyOf[tArr.length] = t;
return (T[]) castNonNullTypeArray(copyOf);
}
public static <T> T[] nullSafeArrayConcatenation(T[] tArr, T[] tArr2) {
T[] tArr3 = (T[]) Arrays.copyOf(tArr, tArr.length + tArr2.length);
System.arraycopy(tArr2, 0, tArr3, tArr.length, tArr2.length);
return tArr3;
}
public static <T> void nullSafeListToArray(List<T> list, T[] tArr) {
Assertions.checkState(list.size() == tArr.length);
list.toArray(tArr);
}
public static Handler createHandlerForCurrentLooper() {
return createHandlerForCurrentLooper(null);
}
public static Handler createHandlerForCurrentLooper(Handler.Callback callback) {
return createHandler((Looper) Assertions.checkStateNotNull(Looper.myLooper()), callback);
}
public static Handler createHandlerForCurrentOrMainLooper() {
return createHandlerForCurrentOrMainLooper(null);
}
public static Handler createHandlerForCurrentOrMainLooper(Handler.Callback callback) {
return createHandler(getCurrentOrMainLooper(), callback);
}
public static Handler createHandler(Looper looper, Handler.Callback callback) {
return new Handler(looper, callback);
}
public static boolean postOrRun(Handler handler, Runnable runnable) {
if (!handler.getLooper().getThread().isAlive()) {
return false;
}
if (handler.getLooper() == Looper.myLooper()) {
runnable.run();
return true;
}
return handler.post(runnable);
}
public static <T> ListenableFuture<T> postOrRunWithCompletion(Handler handler, final Runnable runnable, final T t) {
final SettableFuture create = SettableFuture.create();
postOrRun(handler, new Runnable() { // from class: androidx.media3.common.util.Util$$ExternalSyntheticLambda0
@Override // java.lang.Runnable
public final void run() {
Util.lambda$postOrRunWithCompletion$0(SettableFuture.this, runnable, t);
}
});
return create;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static /* synthetic */ void lambda$postOrRunWithCompletion$0(SettableFuture settableFuture, Runnable runnable, Object obj) {
try {
if (settableFuture.isCancelled()) {
return;
}
runnable.run();
settableFuture.set(obj);
} catch (Throwable th) {
settableFuture.setException(th);
}
}
public static <T, U> ListenableFuture<T> transformFutureAsync(final ListenableFuture<U> listenableFuture, final AsyncFunction<U, T> asyncFunction) {
final SettableFuture create = SettableFuture.create();
create.addListener(new Runnable() { // from class: androidx.media3.common.util.Util$$ExternalSyntheticLambda1
@Override // java.lang.Runnable
public final void run() {
Util.lambda$transformFutureAsync$1(SettableFuture.this, listenableFuture);
}
}, MoreExecutors.directExecutor());
listenableFuture.addListener(new Runnable() { // from class: androidx.media3.common.util.Util$$ExternalSyntheticLambda2
@Override // java.lang.Runnable
public final void run() {
Util.lambda$transformFutureAsync$2(ListenableFuture.this, create, asyncFunction);
}
}, MoreExecutors.directExecutor());
return create;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static /* synthetic */ void lambda$transformFutureAsync$1(SettableFuture settableFuture, ListenableFuture listenableFuture) {
if (settableFuture.isCancelled()) {
listenableFuture.cancel(false);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static /* synthetic */ void lambda$transformFutureAsync$2(ListenableFuture listenableFuture, SettableFuture settableFuture, AsyncFunction asyncFunction) {
try {
try {
settableFuture.setFuture(asyncFunction.apply(Futures.getDone(listenableFuture)));
} catch (Throwable th) {
settableFuture.setException(th);
}
} catch (Error | RuntimeException e) {
settableFuture.setException(e);
} catch (CancellationException unused) {
settableFuture.cancel(false);
} catch (ExecutionException e2) {
e = e2;
Throwable cause = e.getCause();
if (cause != null) {
e = cause;
}
settableFuture.setException(e);
}
}
public static Looper getCurrentOrMainLooper() {
Looper myLooper = Looper.myLooper();
return myLooper != null ? myLooper : Looper.getMainLooper();
}
/* JADX INFO: Access modifiers changed from: package-private */
public static /* synthetic */ Thread lambda$newSingleThreadExecutor$3(String str, Runnable runnable) {
return new Thread(runnable, str);
}
public static ExecutorService newSingleThreadExecutor(final String str) {
return Executors.newSingleThreadExecutor(new ThreadFactory() { // from class: androidx.media3.common.util.Util$$ExternalSyntheticLambda3
@Override // java.util.concurrent.ThreadFactory
public final Thread newThread(Runnable runnable) {
return Util.lambda$newSingleThreadExecutor$3(str, runnable);
}
});
}
/* JADX INFO: Access modifiers changed from: package-private */
public static /* synthetic */ Thread lambda$newSingleThreadScheduledExecutor$4(String str, Runnable runnable) {
return new Thread(runnable, str);
}
public static ScheduledExecutorService newSingleThreadScheduledExecutor(final String str) {
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { // from class: androidx.media3.common.util.Util$$ExternalSyntheticLambda4
@Override // java.util.concurrent.ThreadFactory
public final Thread newThread(Runnable runnable) {
return Util.lambda$newSingleThreadScheduledExecutor$4(str, runnable);
}
});
}
public static void closeQuietly(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException unused) {
}
}
}
public static boolean readBoolean(Parcel parcel) {
return parcel.readInt() != 0;
}
public static void writeBoolean(Parcel parcel, boolean z) {
parcel.writeInt(z ? 1 : 0);
}
public static String getLocaleLanguageTag(Locale locale) {
return SDK_INT >= 21 ? getLocaleLanguageTagV21(locale) : locale.toString();
}
public static String normalizeLanguageCode(String str) {
if (str == null) {
return null;
}
String replace = str.replace('_', '-');
if (!replace.isEmpty() && !replace.equals("und")) {
str = replace;
}
String lowerCase = Ascii.toLowerCase(str);
String str2 = splitAtFirst(lowerCase, "-")[0];
if (languageTagReplacementMap == null) {
languageTagReplacementMap = createIsoLanguageReplacementMap();
}
String str3 = languageTagReplacementMap.get(str2);
if (str3 != null) {
lowerCase = str3 + lowerCase.substring(str2.length());
str2 = str3;
}
return ("no".equals(str2) || CmcdHeadersFactory.OBJECT_TYPE_INIT_SEGMENT.equals(str2) || "zh".equals(str2)) ? maybeReplaceLegacyLanguageTags(lowerCase) : lowerCase;
}
public static String fromUtf8Bytes(byte[] bArr) {
return new String(bArr, Charsets.UTF_8);
}
public static String fromUtf8Bytes(byte[] bArr, int i, int i2) {
return new String(bArr, i, i2, Charsets.UTF_8);
}
public static byte[] getUtf8Bytes(String str) {
return str.getBytes(Charsets.UTF_8);
}
public static String[] split(String str, String str2) {
return str.split(str2, -1);
}
public static String[] splitAtFirst(String str, String str2) {
return str.split(str2, 2);
}
public static String formatInvariant(String str, Object... objArr) {
return String.format(Locale.US, str, objArr);
}
public static int ceilDivide(int i, int i2) {
return ((i + i2) - 1) / i2;
}
public static long ceilDivide(long j, long j2) {
return ((j + j2) - 1) / j2;
}
public static int constrainValue(int i, int i2, int i3) {
return Math.max(i2, Math.min(i, i3));
}
public static long constrainValue(long j, long j2, long j3) {
return Math.max(j2, Math.min(j, j3));
}
public static float constrainValue(float f, float f2, float f3) {
return Math.max(f2, Math.min(f, f3));
}
public static int linearSearch(int[] iArr, int i) {
for (int i2 = 0; i2 < iArr.length; i2++) {
if (iArr[i2] == i) {
return i2;
}
}
return -1;
}
public static int linearSearch(long[] jArr, long j) {
for (int i = 0; i < jArr.length; i++) {
if (jArr[i] == j) {
return i;
}
}
return -1;
}
public static int binarySearchFloor(int[] iArr, int i, boolean z, boolean z2) {
int i2;
int i3;
int binarySearch = Arrays.binarySearch(iArr, i);
if (binarySearch < 0) {
i3 = -(binarySearch + 2);
} else {
while (true) {
i2 = binarySearch - 1;
if (i2 < 0 || iArr[i2] != i) {
break;
}
binarySearch = i2;
}
i3 = z ? binarySearch : i2;
}
return z2 ? Math.max(0, i3) : i3;
}
public static int binarySearchFloor(long[] jArr, long j, boolean z, boolean z2) {
int i;
int i2;
int binarySearch = Arrays.binarySearch(jArr, j);
if (binarySearch < 0) {
i2 = -(binarySearch + 2);
} else {
while (true) {
i = binarySearch - 1;
if (i < 0 || jArr[i] != j) {
break;
}
binarySearch = i;
}
i2 = z ? binarySearch : i;
}
return z2 ? Math.max(0, i2) : i2;
}
public static <T extends Comparable<? super T>> int binarySearchFloor(List<? extends Comparable<? super T>> list, T t, boolean z, boolean z2) {
int i;
int i2;
int binarySearch = Collections.binarySearch(list, t);
if (binarySearch < 0) {
i2 = -(binarySearch + 2);
} else {
while (true) {
i = binarySearch - 1;
if (i < 0 || list.get(i).compareTo(t) != 0) {
break;
}
binarySearch = i;
}
i2 = z ? binarySearch : i;
}
return z2 ? Math.max(0, i2) : i2;
}
public static int binarySearchFloor(LongArray longArray, long j, boolean z, boolean z2) {
int i;
int size = longArray.size() - 1;
int i2 = 0;
while (i2 <= size) {
int i3 = (i2 + size) >>> 1;
if (longArray.get(i3) < j) {
i2 = i3 + 1;
} else {
size = i3 - 1;
}
}
if (z && (i = size + 1) < longArray.size() && longArray.get(i) == j) {
return i;
}
if (z2 && size == -1) {
return 0;
}
return size;
}
public static int binarySearchCeil(int[] iArr, int i, boolean z, boolean z2) {
int i2;
int i3;
int binarySearch = Arrays.binarySearch(iArr, i);
if (binarySearch < 0) {
i3 = ~binarySearch;
} else {
while (true) {
i2 = binarySearch + 1;
if (i2 >= iArr.length || iArr[i2] != i) {
break;
}
binarySearch = i2;
}
i3 = z ? binarySearch : i2;
}
return z2 ? Math.min(iArr.length - 1, i3) : i3;
}
public static int binarySearchCeil(long[] jArr, long j, boolean z, boolean z2) {
int i;
int i2;
int binarySearch = Arrays.binarySearch(jArr, j);
if (binarySearch < 0) {
i2 = ~binarySearch;
} else {
while (true) {
i = binarySearch + 1;
if (i >= jArr.length || jArr[i] != j) {
break;
}
binarySearch = i;
}
i2 = z ? binarySearch : i;
}
return z2 ? Math.min(jArr.length - 1, i2) : i2;
}
public static <T extends Comparable<? super T>> int binarySearchCeil(List<? extends Comparable<? super T>> list, T t, boolean z, boolean z2) {
int i;
int i2;
int binarySearch = Collections.binarySearch(list, t);
if (binarySearch < 0) {
i2 = ~binarySearch;
} else {
int size = list.size();
while (true) {
i = binarySearch + 1;
if (i >= size || list.get(i).compareTo(t) != 0) {
break;
}
binarySearch = i;
}
i2 = z ? binarySearch : i;
}
return z2 ? Math.min(list.size() - 1, i2) : i2;
}
public static long minValue(SparseLongArray sparseLongArray) {
if (sparseLongArray.size() == 0) {
throw new NoSuchElementException();
}
long j = Long.MAX_VALUE;
for (int i = 0; i < sparseLongArray.size(); i++) {
j = Math.min(j, sparseLongArray.valueAt(i));
}
return j;
}
public static long maxValue(SparseLongArray sparseLongArray) {
if (sparseLongArray.size() == 0) {
throw new NoSuchElementException();
}
long j = Long.MIN_VALUE;
for (int i = 0; i < sparseLongArray.size(); i++) {
j = Math.max(j, sparseLongArray.valueAt(i));
}
return j;
}
public static long usToMs(long j) {
return (j == -9223372036854775807L || j == Long.MIN_VALUE) ? j : j / 1000;
}
public static long sampleCountToDurationUs(long j, int i) {
return (j * 1000000) / i;
}
public static long durationUsToSampleCount(long j, int i) {
return ceilDivide(j * i, 1000000L);
}
public static long parseXsDuration(String str) {
Matcher matcher = XS_DURATION_PATTERN.matcher(str);
if (matcher.matches()) {
boolean isEmpty = true ^ TextUtils.isEmpty(matcher.group(1));
String group = matcher.group(3);
double d = BuildConfig.SENTRY_SAMPLE_RATE;
double parseDouble = group != null ? Double.parseDouble(group) * 3.1556908E7d : 0.0d;
String group2 = matcher.group(5);
double parseDouble2 = parseDouble + (group2 != null ? Double.parseDouble(group2) * 2629739.0d : 0.0d);
String group3 = matcher.group(7);
double parseDouble3 = parseDouble2 + (group3 != null ? Double.parseDouble(group3) * 86400.0d : 0.0d);
String group4 = matcher.group(10);
double parseDouble4 = parseDouble3 + (group4 != null ? Double.parseDouble(group4) * 3600.0d : 0.0d);
String group5 = matcher.group(12);
double parseDouble5 = parseDouble4 + (group5 != null ? Double.parseDouble(group5) * 60.0d : 0.0d);
String group6 = matcher.group(14);
if (group6 != null) {
d = Double.parseDouble(group6);
}
long j = (long) ((parseDouble5 + d) * 1000.0d);
return isEmpty ? -j : j;
}
return (long) (Double.parseDouble(str) * 3600.0d * 1000.0d);
}
public static long parseXsDateTime(String str) throws ParserException {
Matcher matcher = XS_DATE_TIME_PATTERN.matcher(str);
if (!matcher.matches()) {
throw ParserException.createForMalformedContainer("Invalid date/time format: " + str, null);
}
int i = 0;
if (matcher.group(9) != null && !matcher.group(9).equalsIgnoreCase("Z")) {
i = (Integer.parseInt(matcher.group(12)) * 60) + Integer.parseInt(matcher.group(13));
if ("-".equals(matcher.group(11))) {
i *= -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 i != 0 ? timeInMillis - (i * 60000) : timeInMillis;
}
public static long scaleLargeTimestamp(long j, long j2, long j3) {
if (j3 >= j2 && j3 % j2 == 0) {
return j / (j3 / j2);
}
if (j3 < j2 && j2 % j3 == 0) {
return j * (j2 / j3);
}
return (long) (j * (j2 / j3));
}
public static long[] scaleLargeTimestamps(List<Long> list, long j, long j2) {
int size = list.size();
long[] jArr = new long[size];
int i = 0;
if (j2 >= j && j2 % j == 0) {
long j3 = j2 / j;
while (i < size) {
jArr[i] = list.get(i).longValue() / j3;
i++;
}
} else if (j2 >= j || j % j2 != 0) {
double d = j / j2;
while (i < size) {
jArr[i] = (long) (list.get(i).longValue() * d);
i++;
}
} else {
long j4 = j / j2;
while (i < size) {
jArr[i] = list.get(i).longValue() * j4;
i++;
}
}
return jArr;
}
public static void scaleLargeTimestampsInPlace(long[] jArr, long j, long j2) {
int i = 0;
if (j2 >= j && j2 % j == 0) {
long j3 = j2 / j;
while (i < jArr.length) {
jArr[i] = jArr[i] / j3;
i++;
}
return;
}
if (j2 < j && j % j2 == 0) {
long j4 = j / j2;
while (i < jArr.length) {
jArr[i] = jArr[i] * j4;
i++;
}
return;
}
double d = j / j2;
while (i < jArr.length) {
jArr[i] = (long) (jArr[i] * d);
i++;
}
}
public static long getMediaDurationForPlayoutDuration(long j, float f) {
return f == 1.0f ? j : Math.round(j * f);
}
public static long getPlayoutDurationForMediaDuration(long j, float f) {
return f == 1.0f ? j : Math.round(j / f);
}
public static int getIntegerCodeForString(String str) {
int length = str.length();
Assertions.checkArgument(length <= 4);
int i = 0;
for (int i2 = 0; i2 < length; i2++) {
i = (i << 8) | str.charAt(i2);
}
return i;
}
public static long toLong(int i, int i2) {
return toUnsignedLong(i2) | (toUnsignedLong(i) << 32);
}
public static byte[] getBytesFromHexString(String str) {
int length = str.length() / 2;
byte[] bArr = new byte[length];
for (int i = 0; i < length; i++) {
int i2 = i * 2;
bArr[i] = (byte) ((Character.digit(str.charAt(i2), 16) << 4) + Character.digit(str.charAt(i2 + 1), 16));
}
return bArr;
}
public static String toHexString(byte[] bArr) {
StringBuilder sb = new StringBuilder(bArr.length * 2);
for (int i = 0; i < bArr.length; i++) {
sb.append(Character.forDigit((bArr[i] >> 4) & 15, 16)).append(Character.forDigit(bArr[i] & Ascii.SI, 16));
}
return sb.toString();
}
public static String getCommaDelimitedSimpleClassNames(Object[] objArr) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < objArr.length; i++) {
sb.append(objArr[i].getClass().getSimpleName());
if (i < objArr.length - 1) {
sb.append(", ");
}
}
return sb.toString();
}
public static String getUserAgent(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 + ") AndroidXMedia3/1.1.1";
}
public static int getCodecCountOfType(String str, int i) {
int i2 = 0;
for (String str2 : splitCodecs(str)) {
if (i == MimeTypes.getTrackTypeOfCodec(str2)) {
i2++;
}
}
return i2;
}
public static String getCodecsOfType(String str, int i) {
String[] splitCodecs = splitCodecs(str);
if (splitCodecs.length == 0) {
return null;
}
StringBuilder sb = new StringBuilder();
for (String str2 : splitCodecs) {
if (i == MimeTypes.getTrackTypeOfCodec(str2)) {
if (sb.length() > 0) {
sb.append(",");
}
sb.append(str2);
}
}
if (sb.length() > 0) {
return sb.toString();
}
return null;
}
public static String[] splitCodecs(String str) {
return TextUtils.isEmpty(str) ? new String[0] : split(str.trim(), "(\\s*,\\s*)");
}
public static Format getPcmFormat(int i, int i2, int i3) {
return new Format.Builder().setSampleMimeType("audio/raw").setChannelCount(i2).setSampleRate(i3).setPcmEncoding(i).build();
}
public static int getPcmFrameSize(int i, int i2) {
if (i != 2) {
if (i == 3) {
return i2;
}
if (i != 4) {
if (i != 268435456) {
if (i == 536870912) {
return i2 * 3;
}
if (i != 805306368) {
throw new IllegalArgumentException();
}
}
}
return i2 * 4;
}
return i2 * 2;
}
public static int generateAudioSessionIdV21(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService("audio");
if (audioManager == null) {
return -1;
}
return audioManager.generateAudioSessionId();
}
public static UUID getDrmUuid(String str) {
String lowerCase = Ascii.toLowerCase(str);
lowerCase.hashCode();
char c = 65535;
switch (lowerCase.hashCode()) {
case -1860423953:
if (lowerCase.equals("playready")) {
c = 0;
break;
}
break;
case -1400551171:
if (lowerCase.equals("widevine")) {
c = 1;
break;
}
break;
case 790309106:
if (lowerCase.equals("clearkey")) {
c = 2;
break;
}
break;
}
switch (c) {
case 0:
return C.PLAYREADY_UUID;
case 1:
return C.WIDEVINE_UUID;
case 2:
return C.CLEARKEY_UUID;
default:
try {
return UUID.fromString(str);
} catch (RuntimeException unused) {
return null;
}
}
}
@Deprecated
public static int inferContentType(Uri uri, String str) {
if (TextUtils.isEmpty(str)) {
return inferContentType(uri);
}
return inferContentTypeForExtension(str);
}
public static int inferContentType(Uri uri) {
int inferContentTypeForExtension;
String scheme = uri.getScheme();
if (scheme != null && Ascii.equalsIgnoreCase("rtsp", scheme)) {
return 3;
}
String lastPathSegment = uri.getLastPathSegment();
if (lastPathSegment == null) {
return 4;
}
int lastIndexOf = lastPathSegment.lastIndexOf(46);
if (lastIndexOf >= 0 && (inferContentTypeForExtension = inferContentTypeForExtension(lastPathSegment.substring(lastIndexOf + 1))) != 4) {
return inferContentTypeForExtension;
}
Matcher matcher = ISM_PATH_PATTERN.matcher((CharSequence) Assertions.checkNotNull(uri.getPath()));
if (!matcher.matches()) {
return 4;
}
String group = matcher.group(2);
if (group != null) {
if (group.contains(ISM_DASH_FORMAT_EXTENSION)) {
return 0;
}
if (group.contains(ISM_HLS_FORMAT_EXTENSION)) {
return 2;
}
}
return 1;
}
@Deprecated
public static int inferContentType(String str) {
return inferContentType(Uri.parse("file:///" + str));
}
public static int inferContentTypeForExtension(String str) {
String lowerCase = Ascii.toLowerCase(str);
lowerCase.hashCode();
char c = 65535;
switch (lowerCase.hashCode()) {
case 104579:
if (lowerCase.equals("ism")) {
c = 0;
break;
}
break;
case 108321:
if (lowerCase.equals("mpd")) {
c = 1;
break;
}
break;
case 3242057:
if (lowerCase.equals("isml")) {
c = 2;
break;
}
break;
case 3299913:
if (lowerCase.equals("m3u8")) {
c = 3;
break;
}
break;
}
switch (c) {
case 0:
case 2:
return 1;
case 1:
return 0;
case 3:
return 2;
default:
return 4;
}
}
public static int inferContentTypeForUriAndMimeType(Uri uri, String str) {
if (str == null) {
return inferContentType(uri);
}
str.hashCode();
char c = 65535;
switch (str.hashCode()) {
case -979127466:
if (str.equals("application/x-mpegURL")) {
c = 0;
break;
}
break;
case -156749520:
if (str.equals("application/vnd.ms-sstr+xml")) {
c = 1;
break;
}
break;
case 64194685:
if (str.equals("application/dash+xml")) {
c = 2;
break;
}
break;
case 1154777587:
if (str.equals("application/x-rtsp")) {
c = 3;
break;
}
break;
}
switch (c) {
case 0:
return 2;
case 1:
return 1;
case 2:
return 0;
case 3:
return 3;
default:
return 4;
}
}
public static Uri fixSmoothStreamingIsmManifestUri(Uri uri) {
String path = uri.getPath();
if (path == null) {
return uri;
}
Matcher matcher = ISM_PATH_PATTERN.matcher(path);
return (matcher.matches() && matcher.group(1) == null) ? Uri.withAppendedPath(uri, "Manifest") : uri;
}
public static String getStringForTime(StringBuilder sb, Formatter formatter, long j) {
if (j == -9223372036854775807L) {
j = 0;
}
String str = j < 0 ? "-" : "";
long abs = (Math.abs(j) + 500) / 1000;
long j2 = abs % 60;
long j3 = (abs / 60) % 60;
long j4 = abs / 3600;
sb.setLength(0);
if (j4 > 0) {
return formatter.format("%s%d:%02d:%02d", str, Long.valueOf(j4), Long.valueOf(j3), Long.valueOf(j2)).toString();
}
return formatter.format("%s%02d:%02d", str, Long.valueOf(j3), Long.valueOf(j2)).toString();
}
public static String escapeFileName(String str) {
int length = str.length();
int i = 0;
int i2 = 0;
for (int i3 = 0; i3 < length; i3++) {
if (shouldEscapeCharacter(str.charAt(i3))) {
i2++;
}
}
if (i2 == 0) {
return str;
}
StringBuilder sb = new StringBuilder((i2 * 2) + length);
while (i2 > 0) {
int i4 = i + 1;
char charAt = str.charAt(i);
if (shouldEscapeCharacter(charAt)) {
sb.append('%').append(Integer.toHexString(charAt));
i2--;
} else {
sb.append(charAt);
}
i = i4;
}
if (i < length) {
sb.append((CharSequence) str, i, length);
}
return sb.toString();
}
public static String unescapeFileName(String str) {
int length = str.length();
int i = 0;
int i2 = 0;
for (int i3 = 0; i3 < length; i3++) {
if (str.charAt(i3) == '%') {
i2++;
}
}
if (i2 == 0) {
return str;
}
int i4 = length - (i2 * 2);
StringBuilder sb = new StringBuilder(i4);
Matcher matcher = ESCAPED_CHARACTER_PATTERN.matcher(str);
while (i2 > 0 && matcher.find()) {
sb.append((CharSequence) str, i, matcher.start()).append((char) Integer.parseInt((String) Assertions.checkNotNull(matcher.group(1)), 16));
i = matcher.end();
i2--;
}
if (i < length) {
sb.append((CharSequence) str, i, length);
}
if (sb.length() != i4) {
return null;
}
return sb.toString();
}
public static Uri getDataUriForString(String str, String str2) {
return Uri.parse("data:" + str + ";base64," + Base64.encodeToString(str2.getBytes(), 2));
}
public static void sneakyThrow(Throwable th) {
sneakyThrowInternal(th);
}
private static <T extends Throwable> void sneakyThrowInternal(Throwable th) throws Throwable {
throw th;
}
public static void recursiveDelete(File file) {
File[] listFiles = file.listFiles();
if (listFiles != null) {
for (File file2 : listFiles) {
recursiveDelete(file2);
}
}
file.delete();
}
public static File createTempDirectory(Context context, String str) throws IOException {
File createTempFile = createTempFile(context, str);
createTempFile.delete();
createTempFile.mkdir();
return createTempFile;
}
public static File createTempFile(Context context, String str) throws IOException {
return File.createTempFile(str, null, (File) Assertions.checkNotNull(context.getCacheDir()));
}
public static int crc32(byte[] bArr, int i, int i2, int i3) {
while (i < i2) {
i3 = CRC32_BYTES_MSBF[((i3 >>> 24) ^ (bArr[i] & 255)) & 255] ^ (i3 << 8);
i++;
}
return i3;
}
public static int crc8(byte[] bArr, int i, int i2, int i3) {
while (i < i2) {
i3 = CRC8_BYTES_MSBF[i3 ^ (bArr[i] & 255)];
i++;
}
return i3;
}
public static byte[] gzip(byte[] bArr) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
try {
gZIPOutputStream.write(bArr);
gZIPOutputStream.close();
return byteArrayOutputStream.toByteArray();
} finally {
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public static int getBigEndianInt(ByteBuffer byteBuffer, int i) {
int i2 = byteBuffer.getInt(i);
return byteBuffer.order() == ByteOrder.BIG_ENDIAN ? i2 : Integer.reverseBytes(i2);
}
public static String getCountryCode(Context context) {
TelephonyManager telephonyManager;
if (context != null && (telephonyManager = (TelephonyManager) context.getSystemService(HintConstants.AUTOFILL_HINT_PHONE)) != null) {
String networkCountryIso = telephonyManager.getNetworkCountryIso();
if (!TextUtils.isEmpty(networkCountryIso)) {
return Ascii.toUpperCase(networkCountryIso);
}
}
return Ascii.toUpperCase(Locale.getDefault().getCountry());
}
public static String[] getSystemLanguageCodes() {
String[] systemLocales = getSystemLocales();
for (int i = 0; i < systemLocales.length; i++) {
systemLocales[i] = normalizeLanguageCode(systemLocales[i]);
}
return systemLocales;
}
public static Locale getDefaultDisplayLocale() {
return SDK_INT >= 24 ? Locale.getDefault(Locale.Category.DISPLAY) : Locale.getDefault();
}
public static boolean inflate(ParsableByteArray parsableByteArray, ParsableByteArray parsableByteArray2, Inflater inflater) {
if (parsableByteArray.bytesLeft() <= 0) {
return false;
}
if (parsableByteArray2.capacity() < parsableByteArray.bytesLeft()) {
parsableByteArray2.ensureCapacity(parsableByteArray.bytesLeft() * 2);
}
if (inflater == null) {
inflater = new Inflater();
}
inflater.setInput(parsableByteArray.getData(), parsableByteArray.getPosition(), parsableByteArray.bytesLeft());
int i = 0;
while (true) {
try {
i += inflater.inflate(parsableByteArray2.getData(), i, parsableByteArray2.capacity() - i);
if (inflater.finished()) {
parsableByteArray2.setLimit(i);
inflater.reset();
return true;
}
if (inflater.needsDictionary() || inflater.needsInput()) {
break;
}
if (i == parsableByteArray2.capacity()) {
parsableByteArray2.ensureCapacity(parsableByteArray2.capacity() * 2);
}
} catch (DataFormatException unused) {
return false;
} finally {
inflater.reset();
}
}
return false;
}
public static boolean isTv(Context context) {
UiModeManager uiModeManager = (UiModeManager) context.getApplicationContext().getSystemService("uimode");
return uiModeManager != null && uiModeManager.getCurrentModeType() == 4;
}
public static boolean isAutomotive(Context context) {
return SDK_INT >= 23 && context.getPackageManager().hasSystemFeature("android.hardware.type.automotive");
}
public static Point getCurrentDisplayModeSize(Context context) {
DisplayManager displayManager;
Display display = (SDK_INT < 17 || (displayManager = (DisplayManager) context.getSystemService("display")) == null) ? null : displayManager.getDisplay(0);
if (display == null) {
display = ((WindowManager) Assertions.checkNotNull((WindowManager) context.getSystemService("window"))).getDefaultDisplay();
}
return getCurrentDisplayModeSize(context, display);
}
public static Point getCurrentDisplayModeSize(Context context, Display display) {
String systemProperty;
if (display.getDisplayId() == 0 && isTv(context)) {
if (SDK_INT < 28) {
systemProperty = getSystemProperty("sys.display-size");
} else {
systemProperty = getSystemProperty("vendor.display-size");
}
if (!TextUtils.isEmpty(systemProperty)) {
try {
String[] split = split(systemProperty.trim(), ViewHierarchyNode.JsonKeys.X);
if (split.length == 2) {
int parseInt = Integer.parseInt(split[0]);
int parseInt2 = Integer.parseInt(split[1]);
if (parseInt > 0 && parseInt2 > 0) {
return new Point(parseInt, parseInt2);
}
}
} catch (NumberFormatException unused) {
}
Log.e(TAG, "Invalid display size: " + systemProperty);
}
if ("Sony".equals(MANUFACTURER) && MODEL.startsWith("BRAVIA") && context.getPackageManager().hasSystemFeature("com.sony.dtv.hardware.panel.qfhd")) {
return new Point(3840, 2160);
}
}
Point point = new Point();
int i = SDK_INT;
if (i >= 23) {
getDisplaySizeV23(display, point);
} else if (i >= 17) {
getDisplaySizeV17(display, point);
} else {
getDisplaySizeV16(display, point);
}
return point;
}
public static String getTrackTypeString(int i) {
switch (i) {
case -2:
return "none";
case -1:
return "unknown";
case 0:
return "default";
case 1:
return "audio";
case 2:
return "video";
case 3:
return "text";
case 4:
return "image";
case 5:
return "metadata";
case 6:
return "camera motion";
default:
return i >= 10000 ? "custom (" + i + ")" : "?";
}
}
public static long getNowUnixTimeMs(long j) {
if (j == -9223372036854775807L) {
return System.currentTimeMillis();
}
return j + android.os.SystemClock.elapsedRealtime();
}
public static <T> void moveItems(List<T> list, int i, int i2, int i3) {
ArrayDeque arrayDeque = new ArrayDeque();
for (int i4 = (i2 - i) - 1; i4 >= 0; i4--) {
arrayDeque.addFirst(list.remove(i + i4));
}
list.addAll(Math.min(i3, list.size()), arrayDeque);
}
public static boolean tableExists(SQLiteDatabase sQLiteDatabase, String str) {
return DatabaseUtils.queryNumEntries(sQLiteDatabase, "sqlite_master", "tbl_name = ?", new String[]{str}) > 0;
}
public static int getErrorCodeFromPlatformDiagnosticsInfo(String str) {
String[] split;
int length;
if (str == null || (length = (split = split(str, "_")).length) < 2) {
return 0;
}
String str2 = split[length - 1];
boolean z = length >= 3 && "neg".equals(split[length - 2]);
try {
int parseInt = Integer.parseInt((String) Assertions.checkNotNull(str2));
return z ? -parseInt : parseInt;
} catch (NumberFormatException unused) {
return 0;
}
}
public static int getMaxPendingFramesCountForMediaCodecDecoders(Context context, String str, boolean z) {
return (SDK_INT < 29 || context.getApplicationContext().getApplicationInfo().targetSdkVersion < 29) ? 1 : 5;
}
public static String getFormatSupportString(int i) {
if (i == 0) {
return "NO";
}
if (i == 1) {
return "NO_UNSUPPORTED_TYPE";
}
if (i == 2) {
return "NO_UNSUPPORTED_DRM";
}
if (i == 3) {
return "NO_EXCEEDS_CAPABILITIES";
}
if (i == 4) {
return "YES";
}
throw new IllegalStateException();
}
public static Player.Commands getAvailableCommands(Player player, Player.Commands commands) {
boolean isPlayingAd = player.isPlayingAd();
boolean isCurrentMediaItemSeekable = player.isCurrentMediaItemSeekable();
boolean hasPreviousMediaItem = player.hasPreviousMediaItem();
boolean hasNextMediaItem = player.hasNextMediaItem();
boolean isCurrentMediaItemLive = player.isCurrentMediaItemLive();
boolean isCurrentMediaItemDynamic = player.isCurrentMediaItemDynamic();
boolean isEmpty = player.getCurrentTimeline().isEmpty();
boolean z = false;
Player.Commands.Builder addIf = new Player.Commands.Builder().addAll(commands).addIf(4, !isPlayingAd).addIf(5, isCurrentMediaItemSeekable && !isPlayingAd).addIf(6, hasPreviousMediaItem && !isPlayingAd).addIf(7, !isEmpty && (hasPreviousMediaItem || !isCurrentMediaItemLive || isCurrentMediaItemSeekable) && !isPlayingAd).addIf(8, hasNextMediaItem && !isPlayingAd).addIf(9, !isEmpty && (hasNextMediaItem || (isCurrentMediaItemLive && isCurrentMediaItemDynamic)) && !isPlayingAd).addIf(10, !isPlayingAd).addIf(11, isCurrentMediaItemSeekable && !isPlayingAd);
if (isCurrentMediaItemSeekable && !isPlayingAd) {
z = true;
}
return addIf.addIf(12, z).build();
}
public static long sum(long... jArr) {
long j = 0;
for (long j2 : jArr) {
j += j2;
}
return j;
}
public static Drawable getDrawable(Context context, Resources resources, int i) {
if (SDK_INT >= 21) {
return Api21.getDrawable(context, resources, i);
}
return resources.getDrawable(i);
}
public static String intToStringMaxRadix(int i) {
return Integer.toString(i, 36);
}
@EnsuresNonNullIf(expression = {"#1"}, result = false)
public static boolean shouldShowPlayButton(Player player) {
return player == null || !player.getPlayWhenReady() || player.getPlaybackState() == 1 || player.getPlaybackState() == 4;
}
/* JADX WARN: Removed duplicated region for block: B:13:0x002a */
/* JADX WARN: Removed duplicated region for block: B:15:0x002e */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static boolean handlePlayButtonAction(androidx.media3.common.Player r4) {
/*
r0 = 0
if (r4 != 0) goto L4
return r0
L4:
int r1 = r4.getPlaybackState()
r2 = 1
if (r1 != r2) goto L17
r3 = 2
boolean r3 = r4.isCommandAvailable(r3)
if (r3 == 0) goto L17
r4.prepare()
L15:
r0 = r2
goto L24
L17:
r3 = 4
if (r1 != r3) goto L24
boolean r1 = r4.isCommandAvailable(r3)
if (r1 == 0) goto L24
r4.seekToDefaultPosition()
goto L15
L24:
boolean r1 = r4.isCommandAvailable(r2)
if (r1 == 0) goto L2e
r4.play()
goto L2f
L2e:
r2 = r0
L2f:
return r2
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.media3.common.util.Util.handlePlayButtonAction(androidx.media3.common.Player):boolean");
}
public static boolean handlePauseButtonAction(Player player) {
if (player == null || !player.isCommandAvailable(1)) {
return false;
}
player.pause();
return true;
}
public static boolean handlePlayPauseButtonAction(Player player) {
if (shouldShowPlayButton(player)) {
return handlePlayButtonAction(player);
}
return handlePauseButtonAction(player);
}
private static String getSystemProperty(String str) {
try {
Class<?> cls = Class.forName("android.os.SystemProperties");
return (String) cls.getMethod("get", String.class).invoke(cls, str);
} catch (Exception e) {
Log.e(TAG, "Failed to read system property " + str, e);
return null;
}
}
private static void getDisplaySizeV23(Display display, Point point) {
Display.Mode mode = display.getMode();
point.x = mode.getPhysicalWidth();
point.y = mode.getPhysicalHeight();
}
private static void getDisplaySizeV17(Display display, Point point) {
display.getRealSize(point);
}
private static void getDisplaySizeV16(Display display, Point point) {
display.getSize(point);
}
private static String[] getSystemLocales() {
Configuration configuration = Resources.getSystem().getConfiguration();
if (SDK_INT >= 24) {
return getSystemLocalesV24(configuration);
}
return new String[]{getLocaleLanguageTag(configuration.locale)};
}
private static String[] getSystemLocalesV24(Configuration configuration) {
return split(configuration.getLocales().toLanguageTags(), ",");
}
private static String getLocaleLanguageTagV21(Locale locale) {
return locale.toLanguageTag();
}
private static HashMap<String, String> createIsoLanguageReplacementMap() {
String[] iSOLanguages = Locale.getISOLanguages();
HashMap<String, String> hashMap = new HashMap<>(iSOLanguages.length + additionalIsoLanguageReplacements.length);
int i = 0;
for (String str : iSOLanguages) {
try {
String iSO3Language = new Locale(str).getISO3Language();
if (!TextUtils.isEmpty(iSO3Language)) {
hashMap.put(iSO3Language, str);
}
} catch (MissingResourceException unused) {
}
}
while (true) {
String[] strArr = additionalIsoLanguageReplacements;
if (i >= strArr.length) {
return hashMap;
}
hashMap.put(strArr[i], strArr[i + 1]);
i += 2;
}
}
private static boolean requestExternalStoragePermission(Activity activity) {
if (activity.checkSelfPermission("android.permission.READ_EXTERNAL_STORAGE") == 0) {
return false;
}
activity.requestPermissions(new String[]{"android.permission.READ_EXTERNAL_STORAGE"}, 0);
return true;
}
private static boolean isTrafficRestricted(Uri uri) {
return "http".equals(uri.getScheme()) && !NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted((String) Assertions.checkNotNull(uri.getHost()));
}
private static String maybeReplaceLegacyLanguageTags(String str) {
int i = 0;
while (true) {
String[] strArr = isoLegacyTagReplacements;
if (i >= strArr.length) {
return str;
}
if (str.startsWith(strArr[i])) {
return strArr[i + 1] + str.substring(strArr[i].length());
}
i += 2;
}
}
/* loaded from: classes2.dex */
private static final class Api21 {
private Api21() {
}
public static Drawable getDrawable(Context context, Resources resources, int i) {
return resources.getDrawable(i, context.getTheme());
}
}
}