Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction;
import com.mbridge.msdk.playercommon.exoplayer2.util.AtomicFile;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/* loaded from: classes4.dex */
public final class ActionFile {
static final int VERSION = 0;
private final File actionFile;
private final AtomicFile atomicFile;
public ActionFile(File file) {
this.actionFile = file;
this.atomicFile = new AtomicFile(file);
}
public final DownloadAction[] load(DownloadAction.Deserializer... deserializerArr) throws IOException {
if (!this.actionFile.exists()) {
return new DownloadAction[0];
}
try {
InputStream openRead = this.atomicFile.openRead();
DataInputStream dataInputStream = new DataInputStream(openRead);
int readInt = dataInputStream.readInt();
if (readInt > 0) {
throw new IOException("Unsupported action file version: " + readInt);
}
int readInt2 = dataInputStream.readInt();
DownloadAction[] downloadActionArr = new DownloadAction[readInt2];
for (int i = 0; i < readInt2; i++) {
downloadActionArr[i] = DownloadAction.deserializeFromStream(deserializerArr, dataInputStream);
}
Util.closeQuietly(openRead);
return downloadActionArr;
} catch (Throwable th) {
Util.closeQuietly((Closeable) null);
throw th;
}
}
public final void store(DownloadAction... downloadActionArr) throws IOException {
DataOutputStream dataOutputStream;
int i;
DataOutputStream dataOutputStream2 = null;
try {
dataOutputStream = new DataOutputStream(this.atomicFile.startWrite());
} catch (Throwable th) {
th = th;
}
try {
dataOutputStream.writeInt(0);
dataOutputStream.writeInt(downloadActionArr.length);
for (DownloadAction downloadAction : downloadActionArr) {
DownloadAction.serializeToStream(downloadAction, dataOutputStream);
}
this.atomicFile.endWrite(dataOutputStream);
Util.closeQuietly((Closeable) null);
} catch (Throwable th2) {
th = th2;
dataOutputStream2 = dataOutputStream;
Util.closeQuietly(dataOutputStream2);
throw th;
}
}
}

View File

@@ -0,0 +1,90 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.net.Uri;
import androidx.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
/* loaded from: classes4.dex */
public abstract class DownloadAction {
public final byte[] data;
public final boolean isRemoveAction;
public final String type;
public final Uri uri;
public final int version;
public abstract Downloader createDownloader(DownloaderConstructorHelper downloaderConstructorHelper);
public abstract void writeToStream(DataOutputStream dataOutputStream) throws IOException;
public static abstract class Deserializer {
public final String type;
public final int version;
public abstract DownloadAction readFromStream(int i, DataInputStream dataInputStream) throws IOException;
public Deserializer(String str, int i) {
this.type = str;
this.version = i;
}
}
public static DownloadAction deserializeFromStream(Deserializer[] deserializerArr, InputStream inputStream) throws IOException {
DataInputStream dataInputStream = new DataInputStream(inputStream);
String readUTF = dataInputStream.readUTF();
int readInt = dataInputStream.readInt();
for (Deserializer deserializer : deserializerArr) {
if (readUTF.equals(deserializer.type) && deserializer.version >= readInt) {
return deserializer.readFromStream(readInt, dataInputStream);
}
}
throw new DownloadException("No deserializer found for:" + readUTF + ", " + readInt);
}
public static void serializeToStream(DownloadAction downloadAction, OutputStream outputStream) throws IOException {
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeUTF(downloadAction.type);
dataOutputStream.writeInt(downloadAction.version);
downloadAction.writeToStream(dataOutputStream);
dataOutputStream.flush();
}
public DownloadAction(String str, int i, Uri uri, boolean z, @Nullable byte[] bArr) {
this.type = str;
this.version = i;
this.uri = uri;
this.isRemoveAction = z;
this.data = bArr == null ? new byte[0] : bArr;
}
public final byte[] toByteArray() {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
serializeToStream(this, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (IOException unused) {
throw new IllegalStateException();
}
}
public boolean isSameMedia(DownloadAction downloadAction) {
return this.uri.equals(downloadAction.uri);
}
public boolean equals(@Nullable Object obj) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
DownloadAction downloadAction = (DownloadAction) obj;
return this.type.equals(downloadAction.type) && this.version == downloadAction.version && this.uri.equals(downloadAction.uri) && this.isRemoveAction == downloadAction.isRemoveAction && Arrays.equals(this.data, downloadAction.data);
}
public int hashCode() {
return (((this.uri.hashCode() * 31) + (this.isRemoveAction ? 1 : 0)) * 31) + Arrays.hashCode(this.data);
}
}

View File

@@ -0,0 +1,14 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class DownloadException extends IOException {
public DownloadException(String str) {
super(str);
}
public DownloadException(Throwable th) {
super(th);
}
}

View File

@@ -0,0 +1,55 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.source.TrackGroupArray;
import java.io.IOException;
import java.util.List;
/* loaded from: classes4.dex */
public abstract class DownloadHelper {
public interface Callback {
void onPrepareError(DownloadHelper downloadHelper, IOException iOException);
void onPrepared(DownloadHelper downloadHelper);
}
public abstract DownloadAction getDownloadAction(@Nullable byte[] bArr, List<TrackKey> list);
public abstract int getPeriodCount();
public abstract DownloadAction getRemoveAction(@Nullable byte[] bArr);
public abstract TrackGroupArray getTrackGroups(int i);
public abstract void prepareInternal() throws IOException;
public void prepare(final Callback callback) {
final Handler handler = new Handler(Looper.myLooper() != null ? Looper.myLooper() : Looper.getMainLooper());
new Thread() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper.1
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
try {
DownloadHelper.this.prepareInternal();
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper.1.1
@Override // java.lang.Runnable
public void run() {
AnonymousClass1 anonymousClass1 = AnonymousClass1.this;
callback.onPrepared(DownloadHelper.this);
}
});
} catch (IOException e) {
handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper.1.2
@Override // java.lang.Runnable
public void run() {
AnonymousClass1 anonymousClass1 = AnonymousClass1.this;
callback.onPrepareError(DownloadHelper.this, e);
}
});
}
}
}.start();
}
}

View File

@@ -0,0 +1,608 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.os.ConditionVariable;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArraySet;
/* loaded from: classes4.dex */
public final class DownloadManager {
private static final boolean DEBUG = false;
public static final int DEFAULT_MAX_SIMULTANEOUS_DOWNLOADS = 1;
public static final int DEFAULT_MIN_RETRY_COUNT = 5;
private static final String TAG = "DownloadManager";
private final ActionFile actionFile;
private final ArrayList<Task> activeDownloadTasks;
private final DownloadAction.Deserializer[] deserializers;
private final DownloaderConstructorHelper downloaderConstructorHelper;
private boolean downloadsStopped;
private final Handler fileIOHandler;
private final HandlerThread fileIOThread;
private final Handler handler;
private boolean initialized;
private final CopyOnWriteArraySet<Listener> listeners;
private final int maxActiveDownloadTasks;
private final int minRetryCount;
private int nextTaskId;
private boolean released;
private final ArrayList<Task> tasks;
public interface Listener {
void onIdle(DownloadManager downloadManager);
void onInitialized(DownloadManager downloadManager);
void onTaskStateChanged(DownloadManager downloadManager, TaskState taskState);
}
/* JADX INFO: Access modifiers changed from: private */
public static void logd(String str) {
}
public DownloadManager(Cache cache, DataSource.Factory factory, File file, DownloadAction.Deserializer... deserializerArr) {
this(new DownloaderConstructorHelper(cache, factory), file, deserializerArr);
}
public DownloadManager(DownloaderConstructorHelper downloaderConstructorHelper, File file, DownloadAction.Deserializer... deserializerArr) {
this(downloaderConstructorHelper, 1, 5, file, deserializerArr);
}
public DownloadManager(DownloaderConstructorHelper downloaderConstructorHelper, int i, int i2, File file, DownloadAction.Deserializer... deserializerArr) {
Assertions.checkArgument(deserializerArr.length > 0, "At least one Deserializer is required.");
this.downloaderConstructorHelper = downloaderConstructorHelper;
this.maxActiveDownloadTasks = i;
this.minRetryCount = i2;
this.actionFile = new ActionFile(file);
this.deserializers = deserializerArr;
this.downloadsStopped = true;
this.tasks = new ArrayList<>();
this.activeDownloadTasks = new ArrayList<>();
Looper myLooper = Looper.myLooper();
this.handler = new Handler(myLooper == null ? Looper.getMainLooper() : myLooper);
HandlerThread handlerThread = new HandlerThread("DownloadManager file i/o");
this.fileIOThread = handlerThread;
handlerThread.start();
this.fileIOHandler = new Handler(handlerThread.getLooper());
this.listeners = new CopyOnWriteArraySet<>();
loadActions();
logd("Created");
}
public final void addListener(Listener listener) {
this.listeners.add(listener);
}
public final void removeListener(Listener listener) {
this.listeners.remove(listener);
}
public final void startDownloads() {
Assertions.checkState(!this.released);
if (this.downloadsStopped) {
this.downloadsStopped = false;
maybeStartTasks();
logd("Downloads are started");
}
}
public final void stopDownloads() {
Assertions.checkState(!this.released);
if (this.downloadsStopped) {
return;
}
this.downloadsStopped = true;
for (int i = 0; i < this.activeDownloadTasks.size(); i++) {
this.activeDownloadTasks.get(i).stop();
}
logd("Downloads are stopping");
}
public final int handleAction(byte[] bArr) throws IOException {
Assertions.checkState(!this.released);
return handleAction(DownloadAction.deserializeFromStream(this.deserializers, new ByteArrayInputStream(bArr)));
}
public final int handleAction(DownloadAction downloadAction) {
Assertions.checkState(!this.released);
Task addTaskForAction = addTaskForAction(downloadAction);
if (this.initialized) {
saveActions();
maybeStartTasks();
if (addTaskForAction.currentState == 0) {
notifyListenersTaskStateChange(addTaskForAction);
}
}
return addTaskForAction.id;
}
public final int getTaskCount() {
Assertions.checkState(!this.released);
return this.tasks.size();
}
public final int getDownloadCount() {
int i = 0;
for (int i2 = 0; i2 < this.tasks.size(); i2++) {
if (!this.tasks.get(i2).action.isRemoveAction) {
i++;
}
}
return i;
}
@Nullable
public final TaskState getTaskState(int i) {
Assertions.checkState(!this.released);
for (int i2 = 0; i2 < this.tasks.size(); i2++) {
Task task = this.tasks.get(i2);
if (task.id == i) {
return task.getDownloadState();
}
}
return null;
}
public final TaskState[] getAllTaskStates() {
Assertions.checkState(!this.released);
int size = this.tasks.size();
TaskState[] taskStateArr = new TaskState[size];
for (int i = 0; i < size; i++) {
taskStateArr[i] = this.tasks.get(i).getDownloadState();
}
return taskStateArr;
}
public final boolean isInitialized() {
Assertions.checkState(!this.released);
return this.initialized;
}
public final boolean isIdle() {
Assertions.checkState(!this.released);
if (!this.initialized) {
return false;
}
for (int i = 0; i < this.tasks.size(); i++) {
if (this.tasks.get(i).isActive()) {
return false;
}
}
return true;
}
public final void release() {
if (this.released) {
return;
}
this.released = true;
for (int i = 0; i < this.tasks.size(); i++) {
this.tasks.get(i).stop();
}
final ConditionVariable conditionVariable = new ConditionVariable();
this.fileIOHandler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.1
@Override // java.lang.Runnable
public void run() {
conditionVariable.open();
}
});
conditionVariable.block();
this.fileIOThread.quit();
logd("Released");
}
/* JADX INFO: Access modifiers changed from: private */
public Task addTaskForAction(DownloadAction downloadAction) {
int i = this.nextTaskId;
this.nextTaskId = i + 1;
Task task = new Task(i, this, downloadAction, this.minRetryCount);
this.tasks.add(task);
logd("Task is added", task);
return task;
}
/* JADX INFO: Access modifiers changed from: private */
public void maybeStartTasks() {
DownloadAction downloadAction;
boolean z;
if (!this.initialized || this.released) {
return;
}
boolean z2 = this.downloadsStopped || this.activeDownloadTasks.size() == this.maxActiveDownloadTasks;
for (int i = 0; i < this.tasks.size(); i++) {
Task task = this.tasks.get(i);
if (task.canStart() && ((z = (downloadAction = task.action).isRemoveAction) || !z2)) {
boolean z3 = true;
int i2 = 0;
while (true) {
if (i2 >= i) {
break;
}
Task task2 = this.tasks.get(i2);
if (task2.action.isSameMedia(downloadAction)) {
if (z) {
logd(task + " clashes with " + task2);
task2.cancel();
z3 = false;
} else if (task2.action.isRemoveAction) {
z2 = true;
z3 = false;
break;
}
}
i2++;
}
if (z3) {
task.start();
if (!z) {
this.activeDownloadTasks.add(task);
z2 = this.activeDownloadTasks.size() == this.maxActiveDownloadTasks;
}
}
}
}
}
private void maybeNotifyListenersIdle() {
if (isIdle()) {
logd("Notify idle state");
Iterator<Listener> it = this.listeners.iterator();
while (it.hasNext()) {
it.next().onIdle(this);
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public void onTaskStateChange(Task task) {
if (this.released) {
return;
}
boolean z = !task.isActive();
if (z) {
this.activeDownloadTasks.remove(task);
}
notifyListenersTaskStateChange(task);
if (task.isFinished()) {
this.tasks.remove(task);
saveActions();
}
if (z) {
maybeStartTasks();
maybeNotifyListenersIdle();
}
}
/* JADX INFO: Access modifiers changed from: private */
public void notifyListenersTaskStateChange(Task task) {
logd("Task state is changed", task);
TaskState downloadState = task.getDownloadState();
Iterator<Listener> it = this.listeners.iterator();
while (it.hasNext()) {
it.next().onTaskStateChanged(this, downloadState);
}
}
private void loadActions() {
this.fileIOHandler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.2
@Override // java.lang.Runnable
public void run() {
final DownloadAction[] downloadActionArr;
try {
downloadActionArr = DownloadManager.this.actionFile.load(DownloadManager.this.deserializers);
DownloadManager.logd("Action file is loaded.");
} catch (Throwable th) {
Log.e(DownloadManager.TAG, "Action file loading failed.", th);
downloadActionArr = new DownloadAction[0];
}
DownloadManager.this.handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.2.1
@Override // java.lang.Runnable
public void run() {
if (DownloadManager.this.released) {
return;
}
ArrayList arrayList = new ArrayList(DownloadManager.this.tasks);
DownloadManager.this.tasks.clear();
for (DownloadAction downloadAction : downloadActionArr) {
DownloadManager.this.addTaskForAction(downloadAction);
}
DownloadManager.logd("Tasks are created.");
DownloadManager.this.initialized = true;
Iterator it = DownloadManager.this.listeners.iterator();
while (it.hasNext()) {
((Listener) it.next()).onInitialized(DownloadManager.this);
}
if (!arrayList.isEmpty()) {
DownloadManager.this.tasks.addAll(arrayList);
DownloadManager.this.saveActions();
}
DownloadManager.this.maybeStartTasks();
for (int i = 0; i < DownloadManager.this.tasks.size(); i++) {
Task task = (Task) DownloadManager.this.tasks.get(i);
if (task.currentState == 0) {
DownloadManager.this.notifyListenersTaskStateChange(task);
}
}
}
});
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public void saveActions() {
if (this.released) {
return;
}
final DownloadAction[] downloadActionArr = new DownloadAction[this.tasks.size()];
for (int i = 0; i < this.tasks.size(); i++) {
downloadActionArr[i] = this.tasks.get(i).action;
}
this.fileIOHandler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.3
@Override // java.lang.Runnable
public void run() {
try {
DownloadManager.this.actionFile.store(downloadActionArr);
DownloadManager.logd("Actions persisted.");
} catch (IOException e) {
Log.e(DownloadManager.TAG, "Persisting actions failed.", e);
}
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public static void logd(String str, Task task) {
logd(str + ": " + task);
}
public static final class TaskState {
public static final int STATE_CANCELED = 3;
public static final int STATE_COMPLETED = 2;
public static final int STATE_FAILED = 4;
public static final int STATE_QUEUED = 0;
public static final int STATE_STARTED = 1;
public final DownloadAction action;
public final float downloadPercentage;
public final long downloadedBytes;
public final Throwable error;
public final int state;
public final int taskId;
@Retention(RetentionPolicy.SOURCE)
public @interface State {
}
public static String getStateString(int i) {
if (i == 0) {
return "QUEUED";
}
if (i == 1) {
return "STARTED";
}
if (i == 2) {
return "COMPLETED";
}
if (i == 3) {
return "CANCELED";
}
if (i == 4) {
return "FAILED";
}
throw new IllegalStateException();
}
private TaskState(int i, DownloadAction downloadAction, int i2, float f, long j, Throwable th) {
this.taskId = i;
this.action = downloadAction;
this.state = i2;
this.downloadPercentage = f;
this.downloadedBytes = j;
this.error = th;
}
}
public static final class Task implements Runnable {
public static final int STATE_QUEUED_CANCELING = 5;
public static final int STATE_STARTED_CANCELING = 6;
public static final int STATE_STARTED_STOPPING = 7;
private final DownloadAction action;
private volatile int currentState;
private final DownloadManager downloadManager;
private volatile Downloader downloader;
private Throwable error;
private final int id;
private final int minRetryCount;
private Thread thread;
@Retention(RetentionPolicy.SOURCE)
public @interface InternalState {
}
/* JADX INFO: Access modifiers changed from: private */
public boolean canStart() {
return this.currentState == 0;
}
private int getExternalState() {
int i = this.currentState;
if (i == 5) {
return 0;
}
if (i == 6 || i == 7) {
return 1;
}
return this.currentState;
}
public final boolean isActive() {
return this.currentState == 5 || this.currentState == 1 || this.currentState == 7 || this.currentState == 6;
}
public final boolean isFinished() {
return this.currentState == 4 || this.currentState == 2 || this.currentState == 3;
}
private Task(int i, DownloadManager downloadManager, DownloadAction downloadAction, int i2) {
this.id = i;
this.downloadManager = downloadManager;
this.action = downloadAction;
this.currentState = 0;
this.minRetryCount = i2;
}
public final TaskState getDownloadState() {
return new TaskState(this.id, this.action, getExternalState(), getDownloadPercentage(), getDownloadedBytes(), this.error);
}
public final float getDownloadPercentage() {
if (this.downloader != null) {
return this.downloader.getDownloadPercentage();
}
return -1.0f;
}
public final long getDownloadedBytes() {
if (this.downloader != null) {
return this.downloader.getDownloadedBytes();
}
return 0L;
}
public final String toString() {
return super.toString();
}
private static String toString(byte[] bArr) {
if (bArr.length > 100) {
return "<data is too long>";
}
return '\'' + Util.fromUtf8Bytes(bArr) + '\'';
}
private String getStateString() {
int i = this.currentState;
return (i == 5 || i == 6) ? "CANCELING" : i != 7 ? TaskState.getStateString(this.currentState) : "STOPPING";
}
/* JADX INFO: Access modifiers changed from: private */
public void start() {
if (changeStateAndNotify(0, 1)) {
Thread thread = new Thread(this);
this.thread = thread;
thread.start();
}
}
/* JADX INFO: Access modifiers changed from: private */
public void cancel() {
if (changeStateAndNotify(0, 5)) {
this.downloadManager.handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.Task.1
@Override // java.lang.Runnable
public void run() {
Task.this.changeStateAndNotify(5, 3);
}
});
} else if (changeStateAndNotify(1, 6)) {
cancelDownload();
}
}
/* JADX INFO: Access modifiers changed from: private */
public void stop() {
if (changeStateAndNotify(1, 7)) {
DownloadManager.logd("Stopping", this);
this.thread.interrupt();
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean changeStateAndNotify(int i, int i2) {
return changeStateAndNotify(i, i2, null);
}
/* JADX INFO: Access modifiers changed from: private */
public boolean changeStateAndNotify(int i, int i2, Throwable th) {
if (this.currentState != i) {
return false;
}
this.currentState = i2;
this.error = th;
if (this.currentState != getExternalState()) {
return true;
}
this.downloadManager.onTaskStateChange(this);
return true;
}
private void cancelDownload() {
if (this.downloader != null) {
this.downloader.cancel();
}
this.thread.interrupt();
}
@Override // java.lang.Runnable
public final void run() {
DownloadManager.logd("Task is started", this);
try {
this.downloader = this.action.createDownloader(this.downloadManager.downloaderConstructorHelper);
if (this.action.isRemoveAction) {
this.downloader.remove();
} else {
long j = -1;
int i = 0;
while (!Thread.interrupted()) {
try {
this.downloader.download();
break;
} catch (IOException e) {
long downloadedBytes = this.downloader.getDownloadedBytes();
if (downloadedBytes != j) {
DownloadManager.logd("Reset error count. downloadedBytes = " + downloadedBytes, this);
i = 0;
j = downloadedBytes;
}
if (this.currentState != 1 || (i = i + 1) > this.minRetryCount) {
throw e;
}
DownloadManager.logd("Download error. Retry " + i, this);
Thread.sleep((long) getRetryDelayMillis(i));
}
}
}
th = null;
} catch (Throwable th) {
th = th;
}
this.downloadManager.handler.post(new Runnable() { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.Task.2
@Override // java.lang.Runnable
public void run() {
Task task = Task.this;
Throwable th2 = th;
if (!task.changeStateAndNotify(1, th2 != null ? 4 : 2, th2) && !Task.this.changeStateAndNotify(6, 3) && !Task.this.changeStateAndNotify(7, 0)) {
throw new IllegalStateException();
}
}
});
}
private int getRetryDelayMillis(int i) {
return Math.min((i - 1) * 1000, 5000);
}
}
}

View File

@@ -0,0 +1,455 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.app.Notification;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.mbridge.msdk.foundation.controller.c;
import com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager;
import com.mbridge.msdk.playercommon.exoplayer2.scheduler.Requirements;
import com.mbridge.msdk.playercommon.exoplayer2.scheduler.RequirementsWatcher;
import com.mbridge.msdk.playercommon.exoplayer2.scheduler.Scheduler;
import com.mbridge.msdk.playercommon.exoplayer2.util.NotificationUtil;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.util.HashMap;
/* loaded from: classes4.dex */
public abstract class DownloadService extends Service {
public static final String ACTION_ADD = "com.google.android.exoplayer.downloadService.action.ADD";
public static final String ACTION_INIT = "com.google.android.exoplayer.downloadService.action.INIT";
private static final String ACTION_RESTART = "com.google.android.exoplayer.downloadService.action.RESTART";
private static final String ACTION_START_DOWNLOADS = "com.google.android.exoplayer.downloadService.action.START_DOWNLOADS";
private static final String ACTION_STOP_DOWNLOADS = "com.google.android.exoplayer.downloadService.action.STOP_DOWNLOADS";
private static final boolean DEBUG = false;
public static final long DEFAULT_FOREGROUND_NOTIFICATION_UPDATE_INTERVAL = 1000;
public static final String KEY_DOWNLOAD_ACTION = "download_action";
public static final String KEY_FOREGROUND = "foreground";
private static final String TAG = "DownloadService";
private static final HashMap<Class<? extends DownloadService>, RequirementsHelper> requirementsHelpers = new HashMap<>();
@Nullable
private final String channelId;
@StringRes
private final int channelName;
private DownloadManager downloadManager;
private DownloadManagerListener downloadManagerListener;
private final ForegroundNotificationUpdater foregroundNotificationUpdater;
private int lastStartId;
private boolean startedInForeground;
private boolean taskRemoved;
private void logd(String str) {
}
public abstract DownloadManager getDownloadManager();
public abstract Notification getForegroundNotification(DownloadManager.TaskState[] taskStateArr);
@Nullable
public abstract Scheduler getScheduler();
@Override // android.app.Service
@Nullable
public IBinder onBind(Intent intent) {
return null;
}
public void onTaskStateChanged(DownloadManager.TaskState taskState) {
}
public DownloadService(int i) {
this(i, 1000L);
}
public DownloadService(int i, long j) {
this(i, j, null, 0);
}
public DownloadService(int i, long j, @Nullable String str, @StringRes int i2) {
this.foregroundNotificationUpdater = new ForegroundNotificationUpdater(i, j);
this.channelId = str;
this.channelName = i2;
}
public static Intent buildAddActionIntent(Context context, Class<? extends DownloadService> cls, DownloadAction downloadAction, boolean z) {
return new Intent(context, cls).setAction(ACTION_ADD).putExtra(KEY_DOWNLOAD_ACTION, downloadAction.toByteArray()).putExtra(KEY_FOREGROUND, z);
}
public static void startWithAction(Context context, Class<? extends DownloadService> cls, DownloadAction downloadAction, boolean z) {
Intent buildAddActionIntent = buildAddActionIntent(context, cls, downloadAction, z);
if (z) {
Util.startForegroundService(context, buildAddActionIntent);
} else {
context.startService(buildAddActionIntent);
}
}
public static void start(Context context, Class<? extends DownloadService> cls) {
context.startService(new Intent(context, cls).setAction(ACTION_INIT));
}
public static void startForeground(Context context, Class<? extends DownloadService> cls) {
Util.startForegroundService(context, new Intent(context, cls).setAction(ACTION_INIT).putExtra(KEY_FOREGROUND, true));
}
@Override // android.app.Service
public void onCreate() {
logd("onCreate");
String str = this.channelId;
if (str != null) {
NotificationUtil.createNotificationChannel(this, str, this.channelName, 2);
}
this.downloadManager = getDownloadManager();
DownloadManagerListener downloadManagerListener = new DownloadManagerListener();
this.downloadManagerListener = downloadManagerListener;
this.downloadManager.addListener(downloadManagerListener);
}
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
/* JADX WARN: Code restructure failed: missing block: B:46:0x0080, code lost:
if (r2.equals(com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadService.ACTION_RESTART) == false) goto L18;
*/
@Override // android.app.Service
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public int onStartCommand(android.content.Intent r7, int r8, int r9) {
/*
r6 = this;
r6.lastStartId = r9
r8 = 0
r6.taskRemoved = r8
java.lang.String r0 = "com.google.android.exoplayer.downloadService.action.RESTART"
r1 = 1
if (r7 == 0) goto L26
java.lang.String r2 = r7.getAction()
boolean r3 = r6.startedInForeground
java.lang.String r4 = "foreground"
boolean r4 = r7.getBooleanExtra(r4, r8)
if (r4 != 0) goto L21
boolean r4 = r0.equals(r2)
if (r4 == 0) goto L1f
goto L21
L1f:
r4 = r8
goto L22
L21:
r4 = r1
L22:
r3 = r3 | r4
r6.startedInForeground = r3
goto L27
L26:
r2 = 0
L27:
java.lang.String r3 = "com.google.android.exoplayer.downloadService.action.INIT"
if (r2 != 0) goto L2c
r2 = r3
L2c:
java.lang.StringBuilder r4 = new java.lang.StringBuilder
r4.<init>()
java.lang.String r5 = "onStartCommand action: "
r4.append(r5)
r4.append(r2)
java.lang.String r5 = " startId: "
r4.append(r5)
r4.append(r9)
java.lang.String r9 = r4.toString()
r6.logd(r9)
int r9 = r2.hashCode()
r4 = -1
switch(r9) {
case -871181424: goto L7c;
case -382886238: goto L71;
case -337334865: goto L66;
case 1015676687: goto L5d;
case 1286088717: goto L52;
default: goto L50;
}
L50:
r8 = r4
goto L83
L52:
java.lang.String r8 = "com.google.android.exoplayer.downloadService.action.STOP_DOWNLOADS"
boolean r8 = r2.equals(r8)
if (r8 != 0) goto L5b
goto L50
L5b:
r8 = 4
goto L83
L5d:
boolean r8 = r2.equals(r3)
if (r8 != 0) goto L64
goto L50
L64:
r8 = 3
goto L83
L66:
java.lang.String r8 = "com.google.android.exoplayer.downloadService.action.START_DOWNLOADS"
boolean r8 = r2.equals(r8)
if (r8 != 0) goto L6f
goto L50
L6f:
r8 = 2
goto L83
L71:
java.lang.String r8 = "com.google.android.exoplayer.downloadService.action.ADD"
boolean r8 = r2.equals(r8)
if (r8 != 0) goto L7a
goto L50
L7a:
r8 = r1
goto L83
L7c:
boolean r9 = r2.equals(r0)
if (r9 != 0) goto L83
goto L50
L83:
java.lang.String r9 = "DownloadService"
switch(r8) {
case 0: goto Lc3;
case 1: goto La9;
case 2: goto La3;
case 3: goto Lc3;
case 4: goto L9d;
default: goto L88;
}
L88:
java.lang.StringBuilder r7 = new java.lang.StringBuilder
r7.<init>()
java.lang.String r8 = "Ignoring unrecognized action: "
r7.append(r8)
r7.append(r2)
java.lang.String r7 = r7.toString()
android.util.Log.e(r9, r7)
goto Lc3
L9d:
com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager r7 = r6.downloadManager
r7.stopDownloads()
goto Lc3
La3:
com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager r7 = r6.downloadManager
r7.startDownloads()
goto Lc3
La9:
java.lang.String r8 = "download_action"
byte[] r7 = r7.getByteArrayExtra(r8)
if (r7 != 0) goto Lb7
java.lang.String r7 = "Ignoring ADD action with no action data"
android.util.Log.e(r9, r7)
goto Lc3
Lb7:
com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager r8 = r6.downloadManager // Catch: java.io.IOException -> Lbd
r8.handleAction(r7) // Catch: java.io.IOException -> Lbd
goto Lc3
Lbd:
r7 = move-exception
java.lang.String r8 = "Failed to handle ADD action"
android.util.Log.e(r9, r8, r7)
Lc3:
r6.maybeStartWatchingRequirements()
com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager r7 = r6.downloadManager
boolean r7 = r7.isIdle()
if (r7 == 0) goto Ld1
r6.stop()
Ld1:
return r1
*/
throw new UnsupportedOperationException("Method not decompiled: com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadService.onStartCommand(android.content.Intent, int, int):int");
}
@Override // android.app.Service
public void onTaskRemoved(Intent intent) {
logd("onTaskRemoved rootIntent: " + intent);
this.taskRemoved = true;
}
@Override // android.app.Service
public void onDestroy() {
logd("onDestroy");
this.foregroundNotificationUpdater.stopPeriodicUpdates();
this.downloadManager.removeListener(this.downloadManagerListener);
maybeStopWatchingRequirements();
}
public Requirements getRequirements() {
return new Requirements(1, false, false);
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Multi-variable type inference failed */
public void maybeStartWatchingRequirements() {
if (this.downloadManager.getDownloadCount() == 0) {
return;
}
Class<?> cls = getClass();
HashMap<Class<? extends DownloadService>, RequirementsHelper> hashMap = requirementsHelpers;
if (((RequirementsHelper) hashMap.get(cls)) == null) {
RequirementsHelper requirementsHelper = new RequirementsHelper(this, getRequirements(), getScheduler(), cls);
hashMap.put(cls, requirementsHelper);
requirementsHelper.start();
logd("started watching requirements");
}
}
private void maybeStopWatchingRequirements() {
RequirementsHelper remove;
if (this.downloadManager.getDownloadCount() <= 0 && (remove = requirementsHelpers.remove(getClass())) != null) {
remove.stop();
logd("stopped watching requirements");
}
}
/* JADX INFO: Access modifiers changed from: private */
public void stop() {
this.foregroundNotificationUpdater.stopPeriodicUpdates();
if (this.startedInForeground && Util.SDK_INT >= 26) {
this.foregroundNotificationUpdater.showNotificationIfNotAlready();
}
if (Util.SDK_INT < 28 && this.taskRemoved) {
stopSelf();
logd("stopSelf()");
return;
}
logd("stopSelf(" + this.lastStartId + ") result: " + stopSelfResult(this.lastStartId));
}
public final class DownloadManagerListener implements DownloadManager.Listener {
private DownloadManagerListener() {
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.Listener
public final void onInitialized(DownloadManager downloadManager) {
DownloadService.this.maybeStartWatchingRequirements();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.Listener
public final void onTaskStateChanged(DownloadManager downloadManager, DownloadManager.TaskState taskState) {
DownloadService.this.onTaskStateChanged(taskState);
if (taskState.state == 1) {
DownloadService.this.foregroundNotificationUpdater.startPeriodicUpdates();
} else {
DownloadService.this.foregroundNotificationUpdater.update();
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadManager.Listener
public final void onIdle(DownloadManager downloadManager) {
DownloadService.this.stop();
}
}
public final class ForegroundNotificationUpdater implements Runnable {
private final Handler handler = new Handler(Looper.getMainLooper());
private boolean notificationDisplayed;
private final int notificationId;
private boolean periodicUpdatesStarted;
private final long updateInterval;
public ForegroundNotificationUpdater(int i, long j) {
this.notificationId = i;
this.updateInterval = j;
}
public final void startPeriodicUpdates() {
this.periodicUpdatesStarted = true;
update();
}
public final void stopPeriodicUpdates() {
this.periodicUpdatesStarted = false;
this.handler.removeCallbacks(this);
}
public final void update() {
DownloadManager.TaskState[] allTaskStates = DownloadService.this.downloadManager.getAllTaskStates();
DownloadService downloadService = DownloadService.this;
downloadService.startForeground(this.notificationId, downloadService.getForegroundNotification(allTaskStates));
this.notificationDisplayed = true;
if (this.periodicUpdatesStarted) {
this.handler.removeCallbacks(this);
this.handler.postDelayed(this, this.updateInterval);
}
}
public final void showNotificationIfNotAlready() {
if (this.notificationDisplayed) {
return;
}
update();
}
@Override // java.lang.Runnable
public final void run() {
update();
}
}
public static final class RequirementsHelper implements RequirementsWatcher.Listener {
private final Context context;
private final Requirements requirements;
private final RequirementsWatcher requirementsWatcher;
@Nullable
private final Scheduler scheduler;
private final Class<? extends DownloadService> serviceClass;
private RequirementsHelper(Context context, Requirements requirements, @Nullable Scheduler scheduler, Class<? extends DownloadService> cls) {
this.context = context;
this.requirements = requirements;
this.scheduler = scheduler;
this.serviceClass = cls;
this.requirementsWatcher = new RequirementsWatcher(context, this, requirements);
}
public final void start() {
this.requirementsWatcher.start();
}
public final void stop() {
this.requirementsWatcher.stop();
Scheduler scheduler = this.scheduler;
if (scheduler != null) {
scheduler.cancel();
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.scheduler.RequirementsWatcher.Listener
public final void requirementsMet(RequirementsWatcher requirementsWatcher) {
startServiceWithAction(DownloadService.ACTION_START_DOWNLOADS);
Scheduler scheduler = this.scheduler;
if (scheduler != null) {
scheduler.cancel();
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.scheduler.RequirementsWatcher.Listener
public final void requirementsNotMet(RequirementsWatcher requirementsWatcher) {
startServiceWithAction(DownloadService.ACTION_STOP_DOWNLOADS);
if (this.scheduler != null) {
String g = c.m().g();
if (TextUtils.isEmpty(g)) {
g = this.context.getPackageName();
}
if (this.scheduler.schedule(this.requirements, g, DownloadService.ACTION_RESTART)) {
return;
}
Log.e(DownloadService.TAG, "Scheduling downloads failed.");
}
}
private void startServiceWithAction(String str) {
Util.startForegroundService(this.context, new Intent(this.context, this.serviceClass).setAction(str).putExtra(DownloadService.KEY_FOREGROUND, true));
}
}
}

View File

@@ -0,0 +1,16 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import java.io.IOException;
/* loaded from: classes4.dex */
public interface Downloader {
void cancel();
void download() throws InterruptedException, IOException;
float getDownloadPercentage();
long getDownloadedBytes();
void remove() throws InterruptedException;
}

View File

@@ -0,0 +1,63 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSink;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DummyDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.FileDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.PriorityDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheDataSink;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.PriorityTaskManager;
/* loaded from: classes4.dex */
public final class DownloaderConstructorHelper {
private final Cache cache;
private final DataSource.Factory cacheReadDataSourceFactory;
private final DataSink.Factory cacheWriteDataSinkFactory;
private final PriorityTaskManager priorityTaskManager;
private final DataSource.Factory upstreamDataSourceFactory;
public final Cache getCache() {
return this.cache;
}
public DownloaderConstructorHelper(Cache cache, DataSource.Factory factory) {
this(cache, factory, null, null, null);
}
public DownloaderConstructorHelper(Cache cache, DataSource.Factory factory, @Nullable DataSource.Factory factory2, @Nullable DataSink.Factory factory3, @Nullable PriorityTaskManager priorityTaskManager) {
Assertions.checkNotNull(factory);
this.cache = cache;
this.upstreamDataSourceFactory = factory;
this.cacheReadDataSourceFactory = factory2;
this.cacheWriteDataSinkFactory = factory3;
this.priorityTaskManager = priorityTaskManager;
}
public final PriorityTaskManager getPriorityTaskManager() {
PriorityTaskManager priorityTaskManager = this.priorityTaskManager;
return priorityTaskManager != null ? priorityTaskManager : new PriorityTaskManager();
}
public final CacheDataSource buildCacheDataSource(boolean z) {
DataSink cacheDataSink;
DataSource.Factory factory = this.cacheReadDataSourceFactory;
DataSource createDataSource = factory != null ? factory.createDataSource() : new FileDataSource();
if (z) {
return new CacheDataSource(this.cache, DummyDataSource.INSTANCE, createDataSource, null, 1, null);
}
DataSink.Factory factory2 = this.cacheWriteDataSinkFactory;
if (factory2 != null) {
cacheDataSink = factory2.createDataSink();
} else {
cacheDataSink = new CacheDataSink(this.cache, 2097152L);
}
DataSink dataSink = cacheDataSink;
DataSource createDataSource2 = this.upstreamDataSourceFactory.createDataSource();
PriorityTaskManager priorityTaskManager = this.priorityTaskManager;
return new CacheDataSource(this.cache, priorityTaskManager == null ? createDataSource2 : new PriorityDataSource(createDataSource2, priorityTaskManager, -1000), createDataSource, dataSink, 1, null);
}
}

View File

@@ -0,0 +1,8 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import java.util.List;
/* loaded from: classes4.dex */
public interface FilterableManifest<T, K> {
T copy(List<K> list);
}

View File

@@ -0,0 +1,26 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.net.Uri;
import com.mbridge.msdk.playercommon.exoplayer2.offline.FilterableManifest;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.ParsingLoadable;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/* loaded from: classes4.dex */
public final class FilteringManifestParser<T extends FilterableManifest<T, K>, K> implements ParsingLoadable.Parser<T> {
private final ParsingLoadable.Parser<T> parser;
private final List<K> trackKeys;
public FilteringManifestParser(ParsingLoadable.Parser<T> parser, List<K> list) {
this.parser = parser;
this.trackKeys = list;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.ParsingLoadable.Parser
public final T parse(Uri uri, InputStream inputStream) throws IOException {
T parse = this.parser.parse(uri, inputStream);
List<K> list = this.trackKeys;
return (list == null || list.isEmpty()) ? parse : (T) parse.copy(this.trackKeys);
}
}

View File

@@ -0,0 +1,80 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheUtil;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/* loaded from: classes4.dex */
public final class ProgressiveDownloadAction extends DownloadAction {
private static final int VERSION = 0;
@Nullable
public final String customCacheKey;
private static final String TYPE = "progressive";
public static final DownloadAction.Deserializer DESERIALIZER = new DownloadAction.Deserializer(TYPE, 0) { // from class: com.mbridge.msdk.playercommon.exoplayer2.offline.ProgressiveDownloadAction.1
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction.Deserializer
public ProgressiveDownloadAction readFromStream(int i, DataInputStream dataInputStream) throws IOException {
Uri parse = Uri.parse(dataInputStream.readUTF());
boolean readBoolean = dataInputStream.readBoolean();
byte[] bArr = new byte[dataInputStream.readInt()];
dataInputStream.readFully(bArr);
return new ProgressiveDownloadAction(parse, readBoolean, bArr, dataInputStream.readBoolean() ? dataInputStream.readUTF() : null);
}
};
public ProgressiveDownloadAction(Uri uri, boolean z, @Nullable byte[] bArr, @Nullable String str) {
super(TYPE, 0, uri, z, bArr);
this.customCacheKey = str;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public final ProgressiveDownloader createDownloader(DownloaderConstructorHelper downloaderConstructorHelper) {
return new ProgressiveDownloader(this.uri, this.customCacheKey, downloaderConstructorHelper);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public final void writeToStream(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeUTF(this.uri.toString());
dataOutputStream.writeBoolean(this.isRemoveAction);
dataOutputStream.writeInt(this.data.length);
dataOutputStream.write(this.data);
boolean z = this.customCacheKey != null;
dataOutputStream.writeBoolean(z);
if (z) {
dataOutputStream.writeUTF(this.customCacheKey);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public final boolean isSameMedia(DownloadAction downloadAction) {
return (downloadAction instanceof ProgressiveDownloadAction) && getCacheKey().equals(((ProgressiveDownloadAction) downloadAction).getCacheKey());
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public final boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (super.equals(obj)) {
return Util.areEqual(this.customCacheKey, ((ProgressiveDownloadAction) obj).customCacheKey);
}
return false;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public final int hashCode() {
int hashCode = super.hashCode() * 31;
String str = this.customCacheKey;
return hashCode + (str != null ? str.hashCode() : 0);
}
private String getCacheKey() {
String str = this.customCacheKey;
return str != null ? str : CacheUtil.generateKey(this.uri);
}
}

View File

@@ -0,0 +1,47 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.source.TrackGroupArray;
import java.util.List;
/* loaded from: classes4.dex */
public final class ProgressiveDownloadHelper extends DownloadHelper {
@Nullable
private final String customCacheKey;
private final Uri uri;
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper
public final int getPeriodCount() {
return 1;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper
public final void prepareInternal() {
}
public ProgressiveDownloadHelper(Uri uri) {
this(uri, null);
}
public ProgressiveDownloadHelper(Uri uri, @Nullable String str) {
this.uri = uri;
this.customCacheKey = str;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper
public final TrackGroupArray getTrackGroups(int i) {
return TrackGroupArray.EMPTY;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper
public final DownloadAction getDownloadAction(@Nullable byte[] bArr, List<TrackKey> list) {
return new ProgressiveDownloadAction(this.uri, false, bArr, this.customCacheKey);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadHelper
public final DownloadAction getRemoveAction(@Nullable byte[] bArr) {
return new ProgressiveDownloadAction(this.uri, true, bArr, this.customCacheKey);
}
}

View File

@@ -0,0 +1,62 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.net.Uri;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSpec;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheUtil;
import com.mbridge.msdk.playercommon.exoplayer2.util.PriorityTaskManager;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
/* loaded from: classes4.dex */
public final class ProgressiveDownloader implements Downloader {
private static final int BUFFER_SIZE_BYTES = 131072;
private final Cache cache;
private final CacheDataSource dataSource;
private final DataSpec dataSpec;
private final PriorityTaskManager priorityTaskManager;
private final CacheUtil.CachingCounters cachingCounters = new CacheUtil.CachingCounters();
private final AtomicBoolean isCanceled = new AtomicBoolean();
public ProgressiveDownloader(Uri uri, String str, DownloaderConstructorHelper downloaderConstructorHelper) {
this.dataSpec = new DataSpec(uri, 0L, -1L, str, 0);
this.cache = downloaderConstructorHelper.getCache();
this.dataSource = downloaderConstructorHelper.buildCacheDataSource(false);
this.priorityTaskManager = downloaderConstructorHelper.getPriorityTaskManager();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final void download() throws InterruptedException, IOException {
this.priorityTaskManager.add(-1000);
try {
CacheUtil.cache(this.dataSpec, this.cache, this.dataSource, new byte[131072], this.priorityTaskManager, -1000, this.cachingCounters, this.isCanceled, true);
} finally {
this.priorityTaskManager.remove(-1000);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final void cancel() {
this.isCanceled.set(true);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final long getDownloadedBytes() {
return this.cachingCounters.totalCachedBytes();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final float getDownloadPercentage() {
long j = this.cachingCounters.contentLength;
if (j == -1) {
return -1.0f;
}
return (this.cachingCounters.totalCachedBytes() * 100.0f) / j;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final void remove() {
CacheUtil.remove(this.cache, CacheUtil.getKey(this.dataSpec));
}
}

View File

@@ -0,0 +1,84 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.Comparable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/* loaded from: classes4.dex */
public abstract class SegmentDownloadAction<K extends Comparable<K>> extends DownloadAction {
public final List<K> keys;
public abstract void writeKey(DataOutputStream dataOutputStream, K k) throws IOException;
public static abstract class SegmentDownloadActionDeserializer<K> extends DownloadAction.Deserializer {
public abstract DownloadAction createDownloadAction(Uri uri, boolean z, byte[] bArr, List<K> list);
public abstract K readKey(DataInputStream dataInputStream) throws IOException;
public SegmentDownloadActionDeserializer(String str, int i) {
super(str, i);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction.Deserializer
public final DownloadAction readFromStream(int i, DataInputStream dataInputStream) throws IOException {
Uri parse = Uri.parse(dataInputStream.readUTF());
boolean readBoolean = dataInputStream.readBoolean();
byte[] bArr = new byte[dataInputStream.readInt()];
dataInputStream.readFully(bArr);
int readInt = dataInputStream.readInt();
List<K> arrayList = new ArrayList<>();
for (int i2 = 0; i2 < readInt; i2++) {
arrayList.add(readKey(dataInputStream));
}
return createDownloadAction(parse, readBoolean, bArr, arrayList);
}
}
public SegmentDownloadAction(String str, int i, Uri uri, boolean z, @Nullable byte[] bArr, List<K> list) {
super(str, i, uri, z, bArr);
if (z) {
Assertions.checkArgument(list.isEmpty());
this.keys = Collections.emptyList();
} else {
ArrayList arrayList = new ArrayList(list);
Collections.sort(arrayList);
this.keys = Collections.unmodifiableList(arrayList);
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public final void writeToStream(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeUTF(this.uri.toString());
dataOutputStream.writeBoolean(this.isRemoveAction);
dataOutputStream.writeInt(this.data.length);
dataOutputStream.write(this.data);
dataOutputStream.writeInt(this.keys.size());
for (int i = 0; i < this.keys.size(); i++) {
writeKey(dataOutputStream, this.keys.get(i));
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (super.equals(obj)) {
return this.keys.equals(((SegmentDownloadAction) obj).keys);
}
return false;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.DownloadAction
public int hashCode() {
return (super.hashCode() * 31) + this.keys.hashCode();
}
}

View File

@@ -0,0 +1,150 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
import android.net.Uri;
import androidx.annotation.NonNull;
import com.mbridge.msdk.playercommon.exoplayer2.offline.FilterableManifest;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSpec;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.Cache;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheDataSource;
import com.mbridge.msdk.playercommon.exoplayer2.upstream.cache.CacheUtil;
import com.mbridge.msdk.playercommon.exoplayer2.util.PriorityTaskManager;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/* loaded from: classes4.dex */
public abstract class SegmentDownloader<M extends FilterableManifest<M, K>, K> implements Downloader {
private static final int BUFFER_SIZE_BYTES = 131072;
private final Cache cache;
private final CacheDataSource dataSource;
private volatile long downloadedBytes;
private volatile int downloadedSegments;
private final Uri manifestUri;
private final CacheDataSource offlineDataSource;
private final PriorityTaskManager priorityTaskManager;
private final ArrayList<K> streamKeys;
private volatile int totalSegments = -1;
private final AtomicBoolean isCanceled = new AtomicBoolean();
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final float getDownloadPercentage() {
int i = this.totalSegments;
int i2 = this.downloadedSegments;
if (i == -1 || i2 == -1) {
return -1.0f;
}
if (i == 0) {
return 100.0f;
}
return (i2 * 100.0f) / i;
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final long getDownloadedBytes() {
return this.downloadedBytes;
}
public abstract M getManifest(DataSource dataSource, Uri uri) throws IOException;
public abstract List<Segment> getSegments(DataSource dataSource, M m, boolean z) throws InterruptedException, IOException;
public static class Segment implements Comparable<Segment> {
public final DataSpec dataSpec;
public final long startTimeUs;
public Segment(long j, DataSpec dataSpec) {
this.startTimeUs = j;
this.dataSpec = dataSpec;
}
@Override // java.lang.Comparable
public int compareTo(@NonNull Segment segment) {
long j = this.startTimeUs - segment.startTimeUs;
if (j == 0) {
return 0;
}
return j < 0 ? -1 : 1;
}
}
public SegmentDownloader(Uri uri, List<K> list, DownloaderConstructorHelper downloaderConstructorHelper) {
this.manifestUri = uri;
this.streamKeys = new ArrayList<>(list);
this.cache = downloaderConstructorHelper.getCache();
this.dataSource = downloaderConstructorHelper.buildCacheDataSource(false);
this.offlineDataSource = downloaderConstructorHelper.buildCacheDataSource(true);
this.priorityTaskManager = downloaderConstructorHelper.getPriorityTaskManager();
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final void download() throws IOException, InterruptedException {
this.priorityTaskManager.add(-1000);
try {
List<Segment> initDownload = initDownload();
Collections.sort(initDownload);
byte[] bArr = new byte[131072];
CacheUtil.CachingCounters cachingCounters = new CacheUtil.CachingCounters();
for (int i = 0; i < initDownload.size(); i++) {
try {
CacheUtil.cache(initDownload.get(i).dataSpec, this.cache, this.dataSource, bArr, this.priorityTaskManager, -1000, cachingCounters, this.isCanceled, true);
this.downloadedSegments++;
this.downloadedBytes += cachingCounters.newlyCachedBytes;
} finally {
}
}
this.priorityTaskManager.remove(-1000);
} catch (Throwable th) {
this.priorityTaskManager.remove(-1000);
throw th;
}
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public void cancel() {
this.isCanceled.set(true);
}
@Override // com.mbridge.msdk.playercommon.exoplayer2.offline.Downloader
public final void remove() throws InterruptedException {
try {
List<Segment> segments = getSegments(this.offlineDataSource, getManifest(this.offlineDataSource, this.manifestUri), true);
for (int i = 0; i < segments.size(); i++) {
removeUri(segments.get(i).dataSpec.uri);
}
} catch (IOException unused) {
} catch (Throwable th) {
removeUri(this.manifestUri);
throw th;
}
removeUri(this.manifestUri);
}
/* JADX WARN: Multi-variable type inference failed */
private List<Segment> initDownload() throws IOException, InterruptedException {
FilterableManifest manifest = getManifest(this.dataSource, this.manifestUri);
if (!this.streamKeys.isEmpty()) {
manifest = (FilterableManifest) manifest.copy(this.streamKeys);
}
List<Segment> segments = getSegments(this.dataSource, manifest, false);
CacheUtil.CachingCounters cachingCounters = new CacheUtil.CachingCounters();
this.totalSegments = segments.size();
this.downloadedSegments = 0;
this.downloadedBytes = 0L;
for (int size = segments.size() - 1; size >= 0; size--) {
CacheUtil.getCached(segments.get(size).dataSpec, this.cache, cachingCounters);
this.downloadedBytes += cachingCounters.alreadyCachedBytes;
if (cachingCounters.alreadyCachedBytes == cachingCounters.contentLength) {
this.downloadedSegments++;
segments.remove(size);
}
}
return segments;
}
private void removeUri(Uri uri) {
CacheUtil.remove(this.cache, CacheUtil.generateKey(uri));
}
}

View File

@@ -0,0 +1,14 @@
package com.mbridge.msdk.playercommon.exoplayer2.offline;
/* loaded from: classes4.dex */
public final class TrackKey {
public final int groupIndex;
public final int periodIndex;
public final int trackIndex;
public TrackKey(int i, int i2, int i3) {
this.periodIndex = i;
this.groupIndex = i2;
this.trackIndex = i3;
}
}