正在查看: CallApp v2.226 应用的 RawResourceDataSource.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: CallApp v2.226 应用的 RawResourceDataSource.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package io.bidmachine.media3.datasource;
import a1.d0;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import io.bidmachine.media3.common.PlaybackException;
import io.bidmachine.media3.common.util.Assertions;
import io.bidmachine.media3.common.util.UnstableApi;
import io.bidmachine.media3.common.util.Util;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.util.List;
import java.util.Map;
import s4.y;
@UnstableApi
public final class RawResourceDataSource extends BaseDataSource {
@Deprecated
public static final String RAW_RESOURCE_SCHEME = "rawresource";
private final Context applicationContext;
@Nullable
private AssetFileDescriptor assetFileDescriptor;
private long bytesRemaining;
@Nullable
private DataSpec dataSpec;
@Nullable
private InputStream inputStream;
private boolean opened;
public static class RawResourceDataSourceException extends DataSourceException {
@Deprecated
public RawResourceDataSourceException(String str) {
super(str, null, 2000);
}
@Deprecated
public RawResourceDataSourceException(Throwable th) {
super(th, 2000);
}
public RawResourceDataSourceException(@Nullable String str, @Nullable Throwable th, int i) {
super(str, th, i);
}
}
public RawResourceDataSource(Context context) {
super(false);
this.applicationContext = context.getApplicationContext();
}
@Deprecated
public static Uri buildRawResourceUri(int i) {
return Uri.parse("rawresource:///" + i);
}
private static AssetFileDescriptor openAssetFileDescriptor(Context context, DataSpec dataSpec) throws RawResourceDataSourceException {
Resources resourcesForApplication;
int identifier;
Uri normalizeScheme = dataSpec.uri.normalizeScheme();
if (TextUtils.equals(RAW_RESOURCE_SCHEME, normalizeScheme.getScheme())) {
resourcesForApplication = context.getResources();
List<String> pathSegments = normalizeScheme.getPathSegments();
if (pathSegments.size() != 1) {
throw new RawResourceDataSourceException("rawresource:// URI must have exactly one path element, found " + pathSegments.size());
}
identifier = parseResourceId(pathSegments.get(0));
} else {
if (!TextUtils.equals("android.resource", normalizeScheme.getScheme())) {
throw new RawResourceDataSourceException("Unsupported URI scheme (" + normalizeScheme.getScheme() + "). Only android.resource is supported.", null, 1004);
}
String str = (String) Assertions.checkNotNull(normalizeScheme.getPath());
if (str.startsWith("/")) {
str = str.substring(1);
}
String packageName = TextUtils.isEmpty(normalizeScheme.getHost()) ? context.getPackageName() : normalizeScheme.getHost();
if (packageName.equals(context.getPackageName())) {
resourcesForApplication = context.getResources();
} else {
try {
resourcesForApplication = context.getPackageManager().getResourcesForApplication(packageName);
} catch (PackageManager.NameNotFoundException e) {
throw new RawResourceDataSourceException("Package in android.resource:// URI not found. Check http://g.co/dev/packagevisibility.", e, PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND);
}
}
if (str.matches("\\d+")) {
identifier = parseResourceId(str);
} else {
identifier = resourcesForApplication.getIdentifier(y.c(packageName, ":", str), "raw", null);
if (identifier == 0) {
throw new RawResourceDataSourceException("Resource not found.", null, PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND);
}
}
}
try {
AssetFileDescriptor openRawResourceFd = resourcesForApplication.openRawResourceFd(identifier);
if (openRawResourceFd != null) {
return openRawResourceFd;
}
throw new RawResourceDataSourceException(d0.m(normalizeScheme, "Resource is compressed: "), null, 2000);
} catch (Resources.NotFoundException e2) {
throw new RawResourceDataSourceException(null, e2, PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND);
}
}
private static int parseResourceId(String str) throws RawResourceDataSourceException {
try {
return Integer.parseInt(str);
} catch (NumberFormatException unused) {
throw new RawResourceDataSourceException("Resource identifier must be an integer.", null, 1004);
}
}
@Override
public void close() throws RawResourceDataSourceException {
this.dataSpec = null;
try {
try {
InputStream inputStream = this.inputStream;
if (inputStream != null) {
inputStream.close();
}
this.inputStream = null;
try {
try {
AssetFileDescriptor assetFileDescriptor = this.assetFileDescriptor;
if (assetFileDescriptor != null) {
assetFileDescriptor.close();
}
} catch (IOException e) {
throw new RawResourceDataSourceException(null, e, 2000);
}
} finally {
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
transferEnded();
}
}
} catch (IOException e2) {
throw new RawResourceDataSourceException(null, e2, 2000);
}
} catch (Throwable th) {
this.inputStream = null;
try {
try {
AssetFileDescriptor assetFileDescriptor2 = this.assetFileDescriptor;
if (assetFileDescriptor2 != null) {
assetFileDescriptor2.close();
}
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
transferEnded();
}
throw th;
} catch (IOException e3) {
throw new RawResourceDataSourceException(null, e3, 2000);
}
} finally {
this.assetFileDescriptor = null;
if (this.opened) {
this.opened = false;
transferEnded();
}
}
}
}
@Override
@UnstableApi
public Map getResponseHeaders() {
return super.getResponseHeaders();
}
@Override
@Nullable
public Uri getUri() {
DataSpec dataSpec = this.dataSpec;
if (dataSpec != null) {
return dataSpec.uri;
}
return null;
}
@Override
public long open(DataSpec dataSpec) throws RawResourceDataSourceException {
this.dataSpec = dataSpec;
transferInitializing(dataSpec);
AssetFileDescriptor openAssetFileDescriptor = openAssetFileDescriptor(this.applicationContext, dataSpec);
this.assetFileDescriptor = openAssetFileDescriptor;
long length = openAssetFileDescriptor.getLength();
FileInputStream fileInputStream = new FileInputStream(this.assetFileDescriptor.getFileDescriptor());
this.inputStream = fileInputStream;
if (length != -1) {
try {
if (dataSpec.position > length) {
throw new RawResourceDataSourceException(null, null, 2008);
}
} catch (RawResourceDataSourceException e) {
throw e;
} catch (IOException e2) {
throw new RawResourceDataSourceException(null, e2, 2000);
}
}
long startOffset = this.assetFileDescriptor.getStartOffset();
long skip = fileInputStream.skip(dataSpec.position + startOffset) - startOffset;
if (skip != dataSpec.position) {
throw new RawResourceDataSourceException(null, null, 2008);
}
if (length == -1) {
FileChannel channel = fileInputStream.getChannel();
if (channel.size() == 0) {
this.bytesRemaining = -1L;
} else {
long size = channel.size() - channel.position();
this.bytesRemaining = size;
if (size < 0) {
throw new RawResourceDataSourceException(null, null, 2008);
}
}
} else {
long j = length - skip;
this.bytesRemaining = j;
if (j < 0) {
throw new DataSourceException(2008);
}
}
long j2 = dataSpec.length;
if (j2 != -1) {
long j3 = this.bytesRemaining;
if (j3 != -1) {
j2 = Math.min(j3, j2);
}
this.bytesRemaining = j2;
}
this.opened = true;
transferStarted(dataSpec);
long j4 = dataSpec.length;
return j4 != -1 ? j4 : this.bytesRemaining;
}
@Override
public int read(byte[] bArr, int i, int i2) throws RawResourceDataSourceException {
if (i2 == 0) {
return 0;
}
long j = this.bytesRemaining;
if (j == 0) {
return -1;
}
if (j != -1) {
try {
i2 = (int) Math.min(j, i2);
} catch (IOException e) {
throw new RawResourceDataSourceException(null, e, 2000);
}
}
int read = ((InputStream) Util.castNonNull(this.inputStream)).read(bArr, i, i2);
if (read == -1) {
if (this.bytesRemaining == -1) {
return -1;
}
throw new RawResourceDataSourceException("End of stream reached having not read sufficient data.", new EOFException(), 2000);
}
long j2 = this.bytesRemaining;
if (j2 != -1) {
this.bytesRemaining = j2 - read;
}
bytesTransferred(read);
return read;
}
}