Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.ITaskHunter;
/* loaded from: classes.dex */
public interface BaseDownloadTask {
public interface FinishListener {
void a(BaseDownloadTask baseDownloadTask);
}
public interface IRunningTask {
void A();
boolean D();
BaseDownloadTask F();
boolean G();
void H();
boolean a(int i);
boolean a(FileDownloadListener fileDownloadListener);
void b();
void b(int i);
void g();
int i();
ITaskHunter.IMessageHandler k();
void u();
boolean x();
Object y();
}
public interface InQueueTask {
int a();
}
public interface LifeCycleCallback {
void i();
void j();
void k();
}
boolean B();
boolean E();
boolean I();
String J();
BaseDownloadTask a(FinishListener finishListener);
BaseDownloadTask a(Object obj);
BaseDownloadTask a(String str, String str2);
BaseDownloadTask a(String str, boolean z);
BaseDownloadTask a(boolean z);
Object a();
BaseDownloadTask b(FileDownloadListener fileDownloadListener);
BaseDownloadTask b(String str);
BaseDownloadTask b(boolean z);
boolean b(FinishListener finishListener);
int c();
BaseDownloadTask c(int i);
BaseDownloadTask c(boolean z);
BaseDownloadTask d(int i);
Throwable d();
BaseDownloadTask e(int i);
boolean e();
int f();
int getId();
byte getStatus();
String getUrl();
String h();
InQueueTask j();
long l();
boolean m();
int n();
boolean o();
boolean pause();
int q();
int r();
int start();
long t();
FileDownloadListener v();
String w();
int z();
}

View File

@@ -0,0 +1,61 @@
package com.liulishuo.filedownloader;
import android.os.SystemClock;
/* loaded from: classes.dex */
public class DownloadSpeedMonitor implements IDownloadSpeed$Monitor, IDownloadSpeed$Lookup {
private long a;
private long b;
private long c;
private long d;
private int e;
private int f = 1000;
@Override // com.liulishuo.filedownloader.IDownloadSpeed$Monitor
public void a(long j) {
if (this.d <= 0) {
return;
}
long j2 = j - this.c;
this.a = 0L;
long uptimeMillis = SystemClock.uptimeMillis() - this.d;
if (uptimeMillis <= 0) {
this.e = (int) j2;
} else {
this.e = (int) (j2 / uptimeMillis);
}
}
@Override // com.liulishuo.filedownloader.IDownloadSpeed$Monitor
public void b(long j) {
this.d = SystemClock.uptimeMillis();
this.c = j;
}
@Override // com.liulishuo.filedownloader.IDownloadSpeed$Monitor
public void c(long j) {
if (this.f <= 0) {
return;
}
boolean z = true;
if (this.a != 0) {
long uptimeMillis = SystemClock.uptimeMillis() - this.a;
if (uptimeMillis >= this.f || (this.e == 0 && uptimeMillis > 0)) {
this.e = (int) ((j - this.b) / uptimeMillis);
this.e = Math.max(0, this.e);
} else {
z = false;
}
}
if (z) {
this.b = j;
this.a = SystemClock.uptimeMillis();
}
}
@Override // com.liulishuo.filedownloader.IDownloadSpeed$Monitor
public void reset() {
this.e = 0;
this.a = 0L;
}
}

View File

@@ -0,0 +1,453 @@
package com.liulishuo.filedownloader;
import android.text.TextUtils;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.DownloadTaskHunter;
import com.liulishuo.filedownloader.ITaskHunter;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.model.FileDownloadStatus;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.File;
import java.util.ArrayList;
/* loaded from: classes.dex */
public class DownloadTask implements BaseDownloadTask, BaseDownloadTask.IRunningTask, DownloadTaskHunter.ICaptureTask {
private final ITaskHunter a;
private final ITaskHunter.IMessageHandler b;
private int c;
private ArrayList<BaseDownloadTask.FinishListener> d;
private final String e;
private String f;
private String g;
private boolean h;
private FileDownloadHeader i;
private FileDownloadListener j;
private Object k;
private int l = 0;
private boolean m = false;
private boolean n = false;
private int o = 100;
private int p = 10;
private boolean q = false;
volatile int r = 0;
private boolean s = false;
private final Object u = new Object();
private volatile boolean v = false;
private final Object t = new Object();
private static final class InQueueTaskImpl implements BaseDownloadTask.InQueueTask {
private final DownloadTask a;
@Override // com.liulishuo.filedownloader.BaseDownloadTask.InQueueTask
public int a() {
int id = this.a.getId();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "add the task[%d] to the queue", Integer.valueOf(id));
}
FileDownloadList.b().b(this.a);
return id;
}
private InQueueTaskImpl(DownloadTask downloadTask) {
this.a = downloadTask;
this.a.s = true;
}
}
DownloadTask(String str) {
this.e = str;
DownloadTaskHunter downloadTaskHunter = new DownloadTaskHunter(this, this.t);
this.a = downloadTaskHunter;
this.b = downloadTaskHunter;
}
private void M() {
if (this.i == null) {
synchronized (this.u) {
if (this.i == null) {
this.i = new FileDownloadHeader();
}
}
}
}
private int N() {
if (!L()) {
if (!m()) {
u();
}
this.a.a();
return getId();
}
if (K()) {
throw new IllegalStateException(FileDownloadUtils.a("This task is running %d, if you want to start the same task, please create a new one by FileDownloader.create", Integer.valueOf(getId())));
}
throw new IllegalStateException("This task is dirty to restart, If you want to reuse this task, please invoke #reuse method manually and retry to restart again." + this.a.toString());
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public void A() {
N();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean B() {
return this.q;
}
@Override // com.liulishuo.filedownloader.DownloadTaskHunter.ICaptureTask
public FileDownloadHeader C() {
return this.i;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public boolean D() {
return FileDownloadStatus.b(getStatus());
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean E() {
return this.h;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public BaseDownloadTask F() {
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public boolean G() {
ArrayList<BaseDownloadTask.FinishListener> arrayList = this.d;
return arrayList != null && arrayList.size() > 0;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public void H() {
this.v = true;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean I() {
return this.m;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public String J() {
return this.g;
}
public boolean K() {
if (FileDownloader.e().b().a(this)) {
return true;
}
return FileDownloadStatus.a(getStatus());
}
public boolean L() {
return this.a.getStatus() != 0;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask b(String str) {
a(str, false);
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask c(int i) {
this.l = i;
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask d(int i) {
this.o = i;
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask e(int i) {
this.p = i;
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int f() {
if (this.a.g() > 2147483647L) {
return Integer.MAX_VALUE;
}
return (int) this.a.g();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public void g() {
N();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int getId() {
int i = this.c;
if (i != 0) {
return i;
}
if (TextUtils.isEmpty(this.f) || TextUtils.isEmpty(this.e)) {
return 0;
}
int a = FileDownloadUtils.a(this.e, this.f, this.h);
this.c = a;
return a;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public byte getStatus() {
return this.a.getStatus();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public String getUrl() {
return this.e;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public String h() {
return FileDownloadUtils.a(w(), E(), J());
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public int i() {
return this.r;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask.InQueueTask j() {
return new InQueueTaskImpl();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public ITaskHunter.IMessageHandler k() {
return this.b;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public long l() {
return this.a.f();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean m() {
return this.r != 0;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int n() {
return this.p;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean o() {
return this.n;
}
@Override // com.liulishuo.filedownloader.DownloadTaskHunter.ICaptureTask
public BaseDownloadTask.IRunningTask p() {
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean pause() {
boolean pause;
synchronized (this.t) {
pause = this.a.pause();
}
return pause;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int q() {
return this.l;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int r() {
if (this.a.f() > 2147483647L) {
return Integer.MAX_VALUE;
}
return (int) this.a.f();
}
@Override // com.liulishuo.filedownloader.DownloadTaskHunter.ICaptureTask
public ArrayList<BaseDownloadTask.FinishListener> s() {
return this.d;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int start() {
if (this.s) {
throw new IllegalStateException("If you start the task manually, it means this task doesn't belong to a queue, so you must not invoke BaseDownloadTask#ready() or InQueueTask#enqueue() before you start() this method. For detail: If this task doesn't belong to a queue, what is just an isolated task, you just need to invoke BaseDownloadTask#start() to start this task, that's all. In other words, If this task doesn't belong to a queue, you must not invoke BaseDownloadTask#ready() method or InQueueTask#enqueue() method before invoke BaseDownloadTask#start(), If you do that and if there is the same listener object to start a queue in another thread, this task may be assembled by the queue, in that case, when you invoke BaseDownloadTask#start() manually to start this task or this task is started by the queue, there is an exception buried in there, because this task object is started two times without declare BaseDownloadTask#reuse() : 1. you invoke BaseDownloadTask#start() manually; 2. the queue start this task automatically.");
}
return N();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public long t() {
return this.a.g();
}
public String toString() {
return FileDownloadUtils.a("%d@%s", Integer.valueOf(getId()), super.toString());
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public void u() {
this.r = v() != null ? v().hashCode() : hashCode();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public FileDownloadListener v() {
return this.j;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public String w() {
return this.f;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public boolean x() {
return this.v;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public Object y() {
return this.t;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int z() {
return this.o;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask a(String str, boolean z) {
this.f = str;
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "setPath %s", str);
}
this.h = z;
if (z) {
this.g = null;
} else {
this.g = new File(str).getName();
}
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask b(FileDownloadListener fileDownloadListener) {
this.j = fileDownloadListener;
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "setListener %s", fileDownloadListener);
}
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask c(boolean z) {
this.m = z;
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public Throwable d() {
return this.a.d();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean e() {
return this.a.e();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public int c() {
return this.a.c();
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public boolean b(BaseDownloadTask.FinishListener finishListener) {
ArrayList<BaseDownloadTask.FinishListener> arrayList = this.d;
return arrayList != null && arrayList.remove(finishListener);
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask b(boolean z) {
this.n = z;
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public void b() {
this.a.b();
if (FileDownloadList.b().c(this)) {
this.v = false;
}
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask a(Object obj) {
this.k = obj;
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "setTag %s", obj);
}
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public void b(int i) {
this.r = i;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask a(boolean z) {
this.q = z;
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask a(BaseDownloadTask.FinishListener finishListener) {
if (this.d == null) {
this.d = new ArrayList<>();
}
if (!this.d.contains(finishListener)) {
this.d.add(finishListener);
}
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public BaseDownloadTask a(String str, String str2) {
M();
this.i.add(str, str2);
return this;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask
public Object a() {
return this.k;
}
@Override // com.liulishuo.filedownloader.DownloadTaskHunter.ICaptureTask
public void a(String str) {
this.g = str;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public boolean a(int i) {
return getId() == i;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.IRunningTask
public boolean a(FileDownloadListener fileDownloadListener) {
return v() == fileDownloadListener;
}
}

View File

@@ -0,0 +1,404 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.ITaskHunter;
import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.message.MessageSnapshotTaker;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.model.FileDownloadStatus;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.File;
import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.ArrayList;
/* loaded from: classes.dex */
public class DownloadTaskHunter implements ITaskHunter, ITaskHunter.IStarter, ITaskHunter.IMessageHandler, BaseDownloadTask.LifeCycleCallback {
private IFileDownloadMessenger a;
private final Object b;
private final ICaptureTask c;
private volatile byte d = 0;
private Throwable e = null;
private final IDownloadSpeed$Monitor f = new DownloadSpeedMonitor();
private long g;
private long h;
private int i;
private boolean j;
interface ICaptureTask {
FileDownloadHeader C();
void a(String str);
BaseDownloadTask.IRunningTask p();
ArrayList<BaseDownloadTask.FinishListener> s();
}
DownloadTaskHunter(ICaptureTask iCaptureTask, Object obj) {
this.b = obj;
this.c = iCaptureTask;
this.a = new FileDownloadMessenger(iCaptureTask.p(), this);
}
/* JADX WARN: Multi-variable type inference failed */
private void e(MessageSnapshot messageSnapshot) {
BaseDownloadTask F = this.c.p().F();
byte status = messageSnapshot.getStatus();
this.d = status;
this.j = messageSnapshot.isLargeFile();
if (status == -4) {
this.f.reset();
int a = FileDownloadList.b().a(F.getId());
if (a + ((a > 1 || !F.E()) ? 0 : FileDownloadList.b().a(FileDownloadUtils.c(F.getUrl(), F.h()))) <= 1) {
byte a2 = FileDownloadServiceProxy.c().a(F.getId());
FileDownloadLog.e(this, "warn, but no mListener to receive, switch to pending %d %d", Integer.valueOf(F.getId()), Integer.valueOf(a2));
if (FileDownloadStatus.a(a2)) {
this.d = (byte) 1;
this.h = messageSnapshot.getLargeTotalBytes();
this.g = messageSnapshot.getLargeSofarBytes();
this.f.b(this.g);
this.a.a(((MessageSnapshot.IWarnMessageSnapshot) messageSnapshot).turnToPending());
return;
}
}
FileDownloadList.b().a(this.c.p(), messageSnapshot);
return;
}
if (status == -3) {
messageSnapshot.isReusedDownloadedFile();
this.g = messageSnapshot.getLargeTotalBytes();
this.h = messageSnapshot.getLargeTotalBytes();
FileDownloadList.b().a(this.c.p(), messageSnapshot);
return;
}
if (status != -2) {
if (status == -1) {
this.e = messageSnapshot.getThrowable();
this.g = messageSnapshot.getLargeSofarBytes();
FileDownloadList.b().a(this.c.p(), messageSnapshot);
return;
}
if (status == 1) {
this.g = messageSnapshot.getLargeSofarBytes();
this.h = messageSnapshot.getLargeTotalBytes();
this.a.a(messageSnapshot);
return;
}
if (status == 2) {
this.h = messageSnapshot.getLargeTotalBytes();
messageSnapshot.isResuming();
messageSnapshot.getEtag();
String fileName = messageSnapshot.getFileName();
if (fileName != null) {
if (F.J() != null) {
FileDownloadLog.e(this, "already has mFilename[%s], but assign mFilename[%s] again", F.J(), fileName);
}
this.c.a(fileName);
}
this.f.b(this.g);
this.a.g(messageSnapshot);
return;
}
if (status == 3) {
this.g = messageSnapshot.getLargeSofarBytes();
this.f.c(messageSnapshot.getLargeSofarBytes());
this.a.e(messageSnapshot);
} else if (status != 5) {
if (status != 6) {
return;
}
this.a.i(messageSnapshot);
} else {
this.g = messageSnapshot.getLargeSofarBytes();
this.e = messageSnapshot.getThrowable();
this.i = messageSnapshot.getRetryingTimes();
this.f.reset();
this.a.d(messageSnapshot);
}
}
}
private int l() {
return this.c.p().F().getId();
}
private void m() throws IOException {
File file;
BaseDownloadTask F = this.c.p().F();
if (F.w() == null) {
F.b(FileDownloadUtils.g(F.getUrl()));
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "save Path is null to %s", F.w());
}
}
if (F.E()) {
file = new File(F.w());
} else {
String i = FileDownloadUtils.i(F.w());
if (i == null) {
throw new InvalidParameterException(FileDownloadUtils.a("the provided mPath[%s] is invalid, can't find its directory", F.w()));
}
file = new File(i);
}
if (!file.exists() && !file.mkdirs() && !file.exists()) {
throw new IOException(FileDownloadUtils.a("Create parent directory failed, please make sure you have permission to create file or directory on the path: %s", file.getAbsolutePath()));
}
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IMessageHandler
public boolean a(MessageSnapshot messageSnapshot) {
if (!this.c.p().F().E() || messageSnapshot.getStatus() != -4 || getStatus() != 2) {
return false;
}
e(messageSnapshot);
return true;
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IMessageHandler
public boolean b(MessageSnapshot messageSnapshot) {
if (FileDownloadStatus.a(getStatus(), messageSnapshot.getStatus())) {
e(messageSnapshot);
return true;
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "can't update mStatus change by keep ahead, %d, but the current mStatus is %d, %d", Byte.valueOf(this.d), Byte.valueOf(getStatus()), Integer.valueOf(l()));
}
return false;
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IMessageHandler
public boolean c(MessageSnapshot messageSnapshot) {
if (!FileDownloadStatus.a(this.c.p().F())) {
return false;
}
e(messageSnapshot);
return true;
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IMessageHandler
public boolean d(MessageSnapshot messageSnapshot) {
byte status = getStatus();
byte status2 = messageSnapshot.getStatus();
if (-2 == status && FileDownloadStatus.a(status2)) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "High concurrent cause, callback pending, but has already be paused %d", Integer.valueOf(l()));
}
return true;
}
if (FileDownloadStatus.b(status, status2)) {
e(messageSnapshot);
return true;
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "can't update mStatus change by keep flow, %d, but the current mStatus is %d, %d", Byte.valueOf(this.d), Byte.valueOf(getStatus()), Integer.valueOf(l()));
}
return false;
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public long f() {
return this.g;
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public long g() {
return this.h;
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public byte getStatus() {
return this.d;
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IMessageHandler
public IFileDownloadMessenger h() {
return this.a;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.LifeCycleCallback
public void i() {
BaseDownloadTask F = this.c.p().F();
if (FileDownloadMonitor.b()) {
FileDownloadMonitor.a().b(F);
}
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "filedownloader:lifecycle:over %s by %d ", toString(), Byte.valueOf(getStatus()));
}
this.f.a(this.g);
if (this.c.s() != null) {
ArrayList arrayList = (ArrayList) this.c.s().clone();
int size = arrayList.size();
for (int i = 0; i < size; i++) {
((BaseDownloadTask.FinishListener) arrayList.get(i)).a(F);
}
}
FileDownloader.e().b().c(this.c.p());
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.LifeCycleCallback
public void j() {
if (FileDownloadMonitor.b() && getStatus() == 6) {
FileDownloadMonitor.a().d(this.c.p().F());
}
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.LifeCycleCallback
public void k() {
if (FileDownloadMonitor.b()) {
FileDownloadMonitor.a().c(this.c.p().F());
}
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "filedownloader:lifecycle:start %s by %d ", toString(), Byte.valueOf(getStatus()));
}
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public boolean pause() {
if (FileDownloadStatus.b(getStatus())) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "High concurrent cause, Already is over, can't pause again, %d %d", Byte.valueOf(getStatus()), Integer.valueOf(this.c.p().F().getId()));
}
return false;
}
this.d = (byte) -2;
BaseDownloadTask.IRunningTask p = this.c.p();
BaseDownloadTask F = p.F();
FileDownloadTaskLauncher.a().a(this);
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "the task[%d] has been expired from the launch pool.", Integer.valueOf(l()));
}
if (FileDownloader.e().d()) {
FileDownloadServiceProxy.c().b(F.getId());
} else if (FileDownloadLog.a) {
FileDownloadLog.a(this, "request pause the task[%d] to the download service, but the download service isn't connected yet.", Integer.valueOf(F.getId()));
}
FileDownloadList.b().a(p);
FileDownloadList.b().a(p, MessageSnapshotTaker.a(F));
FileDownloader.e().b().c(p);
return true;
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IStarter
public void start() {
if (this.d != 10) {
FileDownloadLog.e(this, "High concurrent cause, this task %d will not start, because the of status isn't toLaunchPool: %d", Integer.valueOf(l()), Byte.valueOf(this.d));
return;
}
BaseDownloadTask.IRunningTask p = this.c.p();
BaseDownloadTask F = p.F();
ILostServiceConnectedHandler b = FileDownloader.e().b();
try {
if (b.b(p)) {
return;
}
synchronized (this.b) {
if (this.d != 10) {
FileDownloadLog.e(this, "High concurrent cause, this task %d will not start, the status can't assign to toFileDownloadService, because the status isn't toLaunchPool: %d", Integer.valueOf(l()), Byte.valueOf(this.d));
return;
}
this.d = (byte) 11;
FileDownloadList.b().a(p);
if (FileDownloadHelper.a(F.getId(), F.h(), F.B(), true)) {
return;
}
boolean a = FileDownloadServiceProxy.c().a(F.getUrl(), F.w(), F.E(), F.z(), F.n(), F.q(), F.B(), this.c.C(), F.o());
if (this.d == -2) {
FileDownloadLog.e(this, "High concurrent cause, this task %d will be paused,because of the status is paused, so the pause action must be applied", Integer.valueOf(l()));
if (a) {
FileDownloadServiceProxy.c().b(l());
return;
}
return;
}
if (a) {
b.c(p);
return;
}
if (b.b(p)) {
return;
}
MessageSnapshot a2 = a(new RuntimeException("Occur Unknown Error, when request to start maybe some problem in binder, maybe the process was killed in unexpected."));
if (FileDownloadList.b().c(p)) {
b.c(p);
FileDownloadList.b().a(p);
}
FileDownloadList.b().a(p, a2);
}
} catch (Throwable th) {
th.printStackTrace();
FileDownloadList.b().a(p, a(th));
}
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public int c() {
return this.i;
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IMessageHandler
public MessageSnapshot a(Throwable th) {
this.d = (byte) -1;
this.e = th;
return MessageSnapshotTaker.a(l(), f(), th);
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public void b() {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "free the task %d, when the status is %d", Integer.valueOf(l()), Byte.valueOf(this.d));
}
this.d = (byte) 0;
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public void a() {
boolean z;
synchronized (this.b) {
if (this.d != 0) {
FileDownloadLog.e(this, "High concurrent cause, this task %d will not input to launch pool, because of the status isn't idle : %d", Integer.valueOf(l()), Byte.valueOf(this.d));
return;
}
this.d = (byte) 10;
BaseDownloadTask.IRunningTask p = this.c.p();
BaseDownloadTask F = p.F();
if (FileDownloadMonitor.b()) {
FileDownloadMonitor.a().a(F);
}
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "call start Url[%s], Path[%s] Listener[%s], Tag[%s]", F.getUrl(), F.w(), F.v(), F.a());
}
try {
m();
z = true;
} catch (Throwable th) {
FileDownloadList.b().a(p);
FileDownloadList.b().a(p, a(th));
z = false;
}
if (z) {
FileDownloadTaskLauncher.a().b(this);
}
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "the task[%d] has been into the launch pool.", Integer.valueOf(l()));
}
}
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public Throwable d() {
return this.e;
}
@Override // com.liulishuo.filedownloader.ITaskHunter.IStarter
public boolean a(FileDownloadListener fileDownloadListener) {
return this.c.p().F().v() == fileDownloadListener;
}
@Override // com.liulishuo.filedownloader.ITaskHunter
public boolean e() {
return this.j;
}
}

View File

@@ -0,0 +1,32 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.event.DownloadServiceConnectChangedEvent;
import com.liulishuo.filedownloader.event.IDownloadEvent;
import com.liulishuo.filedownloader.event.IDownloadListener;
/* loaded from: classes.dex */
public abstract class FileDownloadConnectListener extends IDownloadListener {
private DownloadServiceConnectChangedEvent.ConnectStatus a;
public abstract void a();
@Override // com.liulishuo.filedownloader.event.IDownloadListener
public boolean a(IDownloadEvent iDownloadEvent) {
if (!(iDownloadEvent instanceof DownloadServiceConnectChangedEvent)) {
return false;
}
this.a = ((DownloadServiceConnectChangedEvent) iDownloadEvent).b();
if (this.a == DownloadServiceConnectChangedEvent.ConnectStatus.connected) {
a();
return false;
}
b();
return false;
}
public abstract void b();
public DownloadServiceConnectChangedEvent.ConnectStatus c() {
return this.a;
}
}

View File

@@ -0,0 +1,18 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.event.DownloadEventPoolImpl;
/* loaded from: classes.dex */
public class FileDownloadEventPool extends DownloadEventPoolImpl {
private static class HolderClass {
private static final FileDownloadEventPool a = new FileDownloadEventPool();
}
public static FileDownloadEventPool a() {
return HolderClass.a;
}
private FileDownloadEventPool() {
}
}

View File

@@ -0,0 +1,36 @@
package com.liulishuo.filedownloader;
/* loaded from: classes.dex */
public abstract class FileDownloadLargeFileListener extends FileDownloadListener {
protected abstract void a(BaseDownloadTask baseDownloadTask, long j, long j2);
protected void a(BaseDownloadTask baseDownloadTask, String str, boolean z, long j, long j2) {
}
protected void a(BaseDownloadTask baseDownloadTask, Throwable th, int i, long j) {
}
protected abstract void b(BaseDownloadTask baseDownloadTask, long j, long j2);
protected abstract void c(BaseDownloadTask baseDownloadTask, long j, long j2);
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void connected(BaseDownloadTask baseDownloadTask, String str, boolean z, int i, int i2) {
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void paused(BaseDownloadTask baseDownloadTask, int i, int i2) {
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void pending(BaseDownloadTask baseDownloadTask, int i, int i2) {
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void progress(BaseDownloadTask baseDownloadTask, int i, int i2) {
}
@Override // com.liulishuo.filedownloader.FileDownloadListener
protected void retry(BaseDownloadTask baseDownloadTask, Throwable th, int i, int i2) {
}
}

View File

@@ -0,0 +1,157 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.message.MessageSnapshotTaker;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public class FileDownloadList {
private final ArrayList<BaseDownloadTask.IRunningTask> a;
private static final class HolderClass {
private static final FileDownloadList a = new FileDownloadList();
}
public static FileDownloadList b() {
return HolderClass.a;
}
int a() {
return this.a.size();
}
boolean c(BaseDownloadTask.IRunningTask iRunningTask) {
return this.a.isEmpty() || !this.a.contains(iRunningTask);
}
private FileDownloadList() {
this.a = new ArrayList<>();
}
int a(int i) {
int i2;
synchronized (this.a) {
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
i2 = 0;
while (it.hasNext()) {
if (it.next().a(i)) {
i2++;
}
}
}
return i2;
}
List<BaseDownloadTask.IRunningTask> b(int i) {
byte status;
ArrayList arrayList = new ArrayList();
synchronized (this.a) {
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
while (it.hasNext()) {
BaseDownloadTask.IRunningTask next = it.next();
if (next.a(i) && !next.D() && (status = next.F().getStatus()) != 0 && status != 10) {
arrayList.add(next);
}
}
}
return arrayList;
}
List<BaseDownloadTask.IRunningTask> a(FileDownloadListener fileDownloadListener) {
ArrayList arrayList = new ArrayList();
synchronized (this.a) {
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
while (it.hasNext()) {
BaseDownloadTask.IRunningTask next = it.next();
if (next.a(fileDownloadListener)) {
arrayList.add(next);
}
}
}
return arrayList;
}
void b(BaseDownloadTask.IRunningTask iRunningTask) {
if (iRunningTask.x()) {
return;
}
synchronized (this.a) {
if (this.a.contains(iRunningTask)) {
FileDownloadLog.e(this, "already has %s", iRunningTask);
} else {
iRunningTask.H();
this.a.add(iRunningTask);
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "add list in all %s %d %d", iRunningTask, Byte.valueOf(iRunningTask.F().getStatus()), Integer.valueOf(this.a.size()));
}
}
}
}
List<BaseDownloadTask.IRunningTask> a(int i, FileDownloadListener fileDownloadListener) {
ArrayList arrayList = new ArrayList();
synchronized (this.a) {
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
while (it.hasNext()) {
BaseDownloadTask.IRunningTask next = it.next();
if (next.F().v() == fileDownloadListener && !next.F().m()) {
next.b(i);
arrayList.add(next);
}
}
}
return arrayList;
}
void a(List<BaseDownloadTask.IRunningTask> list) {
synchronized (this.a) {
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
while (it.hasNext()) {
BaseDownloadTask.IRunningTask next = it.next();
if (!list.contains(next)) {
list.add(next);
}
}
this.a.clear();
}
}
public boolean a(BaseDownloadTask.IRunningTask iRunningTask, MessageSnapshot messageSnapshot) {
boolean remove;
byte status = messageSnapshot.getStatus();
synchronized (this.a) {
remove = this.a.remove(iRunningTask);
}
if (FileDownloadLog.a && this.a.size() == 0) {
FileDownloadLog.d(this, "remove %s left %d %d", iRunningTask, Byte.valueOf(status), Integer.valueOf(this.a.size()));
}
if (remove) {
IFileDownloadMessenger h = iRunningTask.k().h();
if (status == -4) {
h.f(messageSnapshot);
} else if (status == -3) {
h.h(MessageSnapshotTaker.a(messageSnapshot));
} else if (status == -2) {
h.b(messageSnapshot);
} else if (status == -1) {
h.c(messageSnapshot);
}
} else {
FileDownloadLog.b(this, "remove error, not exist: %s %d", iRunningTask, Byte.valueOf(status));
}
return remove;
}
void a(BaseDownloadTask.IRunningTask iRunningTask) {
if (!iRunningTask.F().m()) {
iRunningTask.u();
}
if (iRunningTask.k().h().b()) {
b(iRunningTask);
}
}
}

View File

@@ -0,0 +1,41 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.util.FileDownloadLog;
/* loaded from: classes.dex */
public abstract class FileDownloadListener {
public FileDownloadListener() {
}
protected void blockComplete(BaseDownloadTask baseDownloadTask) throws Throwable {
}
protected abstract void completed(BaseDownloadTask baseDownloadTask);
protected void connected(BaseDownloadTask baseDownloadTask, String str, boolean z, int i, int i2) {
}
protected abstract void error(BaseDownloadTask baseDownloadTask, Throwable th);
protected boolean isInvalid() {
return false;
}
protected abstract void paused(BaseDownloadTask baseDownloadTask, int i, int i2);
protected abstract void pending(BaseDownloadTask baseDownloadTask, int i, int i2);
protected abstract void progress(BaseDownloadTask baseDownloadTask, int i, int i2);
protected void retry(BaseDownloadTask baseDownloadTask, Throwable th, int i, int i2) {
}
protected void started(BaseDownloadTask baseDownloadTask) {
}
protected abstract void warn(BaseDownloadTask baseDownloadTask);
public FileDownloadListener(int i) {
FileDownloadLog.e(this, "not handle priority any more", new Object[0]);
}
}

View File

@@ -0,0 +1,138 @@
package com.liulishuo.filedownloader;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
/* loaded from: classes.dex */
public class FileDownloadMessageStation {
static int f = 10;
static int g = 5;
private final Executor a;
private final Handler b;
private final LinkedBlockingQueue<IFileDownloadMessenger> c;
private final Object d;
private final ArrayList<IFileDownloadMessenger> e;
private static final class HolderClass {
private static final FileDownloadMessageStation a = new FileDownloadMessageStation();
}
private static class UIHandlerCallback implements Handler.Callback {
private UIHandlerCallback() {
}
private void a(ArrayList<IFileDownloadMessenger> arrayList) {
Iterator<IFileDownloadMessenger> it = arrayList.iterator();
while (it.hasNext()) {
it.next().d();
}
arrayList.clear();
}
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
int i = message.what;
if (i == 1) {
((IFileDownloadMessenger) message.obj).d();
} else if (i == 2) {
a((ArrayList) message.obj);
FileDownloadMessageStation.a().c();
}
return true;
}
}
private void b(IFileDownloadMessenger iFileDownloadMessenger) {
synchronized (this.d) {
this.c.offer(iFileDownloadMessenger);
}
c();
}
private void c(IFileDownloadMessenger iFileDownloadMessenger) {
Handler handler = this.b;
handler.sendMessage(handler.obtainMessage(1, iFileDownloadMessenger));
}
private FileDownloadMessageStation() {
this.a = FileDownloadExecutors.a(5, "BlockCompleted");
this.d = new Object();
this.e = new ArrayList<>();
this.b = new Handler(Looper.getMainLooper(), new UIHandlerCallback());
this.c = new LinkedBlockingQueue<>();
}
public static FileDownloadMessageStation a() {
return HolderClass.a;
}
/* JADX INFO: Access modifiers changed from: private */
public void c() {
int i;
synchronized (this.d) {
if (this.e.isEmpty()) {
if (this.c.isEmpty()) {
return;
}
if (b()) {
i = f;
int min = Math.min(this.c.size(), g);
for (int i2 = 0; i2 < min; i2++) {
this.e.add(this.c.remove());
}
} else {
this.c.drainTo(this.e);
i = 0;
}
Handler handler = this.b;
handler.sendMessageDelayed(handler.obtainMessage(2, this.e), i);
}
}
}
void a(IFileDownloadMessenger iFileDownloadMessenger) {
a(iFileDownloadMessenger, false);
}
void a(final IFileDownloadMessenger iFileDownloadMessenger, boolean z) {
if (iFileDownloadMessenger.a()) {
iFileDownloadMessenger.d();
return;
}
if (iFileDownloadMessenger.c()) {
this.a.execute(new Runnable(this) { // from class: com.liulishuo.filedownloader.FileDownloadMessageStation.1
@Override // java.lang.Runnable
public void run() {
iFileDownloadMessenger.d();
}
});
return;
}
if (!b() && !this.c.isEmpty()) {
synchronized (this.d) {
if (!this.c.isEmpty()) {
Iterator<IFileDownloadMessenger> it = this.c.iterator();
while (it.hasNext()) {
c(it.next());
}
}
this.c.clear();
}
}
if (b() && !z) {
b(iFileDownloadMessenger);
} else {
c(iFileDownloadMessenger);
}
}
public static boolean b() {
return f > 0;
}
}

View File

@@ -0,0 +1,278 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.ITaskHunter;
import com.liulishuo.filedownloader.message.BlockCompleteMessage;
import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.model.FileDownloadStatus;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
/* loaded from: classes.dex */
class FileDownloadMessenger implements IFileDownloadMessenger {
private BaseDownloadTask.IRunningTask a;
private BaseDownloadTask.LifeCycleCallback b;
private Queue<MessageSnapshot> c;
private boolean d = false;
FileDownloadMessenger(BaseDownloadTask.IRunningTask iRunningTask, BaseDownloadTask.LifeCycleCallback lifeCycleCallback) {
a(iRunningTask, lifeCycleCallback);
}
private void a(BaseDownloadTask.IRunningTask iRunningTask, BaseDownloadTask.LifeCycleCallback lifeCycleCallback) {
this.a = iRunningTask;
this.b = lifeCycleCallback;
this.c = new LinkedBlockingQueue();
}
private void k(MessageSnapshot messageSnapshot) {
BaseDownloadTask.IRunningTask iRunningTask = this.a;
if (iRunningTask == null) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "occur this case, it would be the host task of this messenger has been over(paused/warn/completed/error) on the other thread before receiving the snapshot(id[%d], status[%d])", Integer.valueOf(messageSnapshot.getId()), Byte.valueOf(messageSnapshot.getStatus()));
}
} else {
if (!this.d && iRunningTask.F().v() != null) {
this.c.offer(messageSnapshot);
FileDownloadMessageStation.a().a(this);
return;
}
if ((FileDownloadMonitor.b() || this.a.G()) && messageSnapshot.getStatus() == 4) {
this.b.i();
}
a(messageSnapshot.getStatus());
}
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public boolean b() {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify begin %s", this.a);
}
if (this.a == null) {
FileDownloadLog.e(this, "can't begin the task, the holder fo the messenger is nil, %d", Integer.valueOf(this.c.size()));
return false;
}
this.b.k();
return true;
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void c(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
BaseDownloadTask.IRunningTask iRunningTask = this.a;
FileDownloadLog.a(this, "notify error %s %s", iRunningTask, iRunningTask.F().d());
}
this.b.i();
k(messageSnapshot);
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void d(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
BaseDownloadTask F = this.a.F();
FileDownloadLog.a(this, "notify retry %s %d %d %s", this.a, Integer.valueOf(F.q()), Integer.valueOf(F.c()), F.d());
}
this.b.j();
k(messageSnapshot);
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void e(MessageSnapshot messageSnapshot) {
BaseDownloadTask F = this.a.F();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify progress %s %d %d", F, Long.valueOf(F.l()), Long.valueOf(F.t()));
}
if (F.z() > 0) {
this.b.j();
k(messageSnapshot);
} else if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify progress but client not request notify %s", this.a);
}
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void f(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify warn %s", this.a);
}
this.b.i();
k(messageSnapshot);
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void g(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify connected %s", this.a);
}
this.b.j();
k(messageSnapshot);
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void h(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify block completed %s %s", this.a, Thread.currentThread().getName());
}
this.b.j();
k(messageSnapshot);
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void i(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify started %s", this.a);
}
this.b.j();
k(messageSnapshot);
}
public void j(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify completed %s", this.a);
}
this.b.i();
k(messageSnapshot);
}
public String toString() {
Object[] objArr = new Object[2];
BaseDownloadTask.IRunningTask iRunningTask = this.a;
objArr[0] = Integer.valueOf(iRunningTask == null ? -1 : iRunningTask.F().getId());
objArr[1] = super.toString();
return FileDownloadUtils.a("%d:%s", objArr);
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void a(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify pending %s", this.a);
}
this.b.j();
k(messageSnapshot);
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public boolean c() {
return this.c.peek().getStatus() == 4;
}
private void a(int i) {
if (FileDownloadStatus.b(i)) {
if (!this.c.isEmpty()) {
MessageSnapshot peek = this.c.peek();
FileDownloadLog.e(this, "the messenger[%s](with id[%d]) has already accomplished all his job, but there still are some messages in parcel queue[%d] queue-top-status[%d]", this, Integer.valueOf(peek.getId()), Integer.valueOf(this.c.size()), Byte.valueOf(peek.getStatus()));
}
this.a = null;
}
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void b(MessageSnapshot messageSnapshot) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "notify paused %s", this.a);
}
this.b.i();
k(messageSnapshot);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public void d() {
if (this.d) {
return;
}
MessageSnapshot poll = this.c.poll();
byte status = poll.getStatus();
BaseDownloadTask.IRunningTask iRunningTask = this.a;
if (iRunningTask != null) {
BaseDownloadTask F = iRunningTask.F();
FileDownloadListener v = F.v();
ITaskHunter.IMessageHandler k = iRunningTask.k();
a(status);
if (v == null || v.isInvalid()) {
return;
}
if (status == 4) {
try {
v.blockComplete(F);
j(((BlockCompleteMessage) poll).transmitToCompleted());
return;
} catch (Throwable th) {
c(k.a(th));
return;
}
}
FileDownloadLargeFileListener fileDownloadLargeFileListener = v instanceof FileDownloadLargeFileListener ? (FileDownloadLargeFileListener) v : null;
if (status == -4) {
v.warn(F);
return;
}
if (status == -3) {
v.completed(F);
return;
}
if (status == -2) {
if (fileDownloadLargeFileListener != null) {
fileDownloadLargeFileListener.a(F, poll.getLargeSofarBytes(), poll.getLargeTotalBytes());
return;
} else {
v.paused(F, poll.getSmallSofarBytes(), poll.getSmallTotalBytes());
return;
}
}
if (status == -1) {
v.error(F, poll.getThrowable());
return;
}
if (status == 1) {
if (fileDownloadLargeFileListener != null) {
fileDownloadLargeFileListener.b(F, poll.getLargeSofarBytes(), poll.getLargeTotalBytes());
return;
} else {
v.pending(F, poll.getSmallSofarBytes(), poll.getSmallTotalBytes());
return;
}
}
if (status == 2) {
if (fileDownloadLargeFileListener != null) {
fileDownloadLargeFileListener.a(F, poll.getEtag(), poll.isResuming(), F.l(), poll.getLargeTotalBytes());
return;
} else {
v.connected(F, poll.getEtag(), poll.isResuming(), F.r(), poll.getSmallTotalBytes());
return;
}
}
if (status == 3) {
if (fileDownloadLargeFileListener != null) {
fileDownloadLargeFileListener.c(F, poll.getLargeSofarBytes(), F.t());
return;
} else {
v.progress(F, poll.getSmallSofarBytes(), F.f());
return;
}
}
if (status != 5) {
if (status != 6) {
return;
}
v.started(F);
return;
} else if (fileDownloadLargeFileListener != null) {
fileDownloadLargeFileListener.a(F, poll.getThrowable(), poll.getRetryingTimes(), poll.getLargeSofarBytes());
return;
} else {
v.retry(F, poll.getThrowable(), poll.getRetryingTimes(), poll.getSmallSofarBytes());
return;
}
}
throw new IllegalArgumentException(FileDownloadUtils.a("can't handover the message, no master to receive this message(status[%d]) size[%d]", Integer.valueOf(status), Integer.valueOf(this.c.size())));
}
@Override // com.liulishuo.filedownloader.IFileDownloadMessenger
public boolean a() {
return this.a.F().I();
}
}

View File

@@ -0,0 +1,26 @@
package com.liulishuo.filedownloader;
/* loaded from: classes.dex */
public class FileDownloadMonitor {
private static IMonitor a;
public interface IMonitor {
void a(int i, boolean z, FileDownloadListener fileDownloadListener);
void a(BaseDownloadTask baseDownloadTask);
void b(BaseDownloadTask baseDownloadTask);
void c(BaseDownloadTask baseDownloadTask);
void d(BaseDownloadTask baseDownloadTask);
}
public static IMonitor a() {
return a;
}
public static boolean b() {
return a() != null;
}
}

View File

@@ -0,0 +1,87 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.BaseDownloadTask;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public class FileDownloadQueueSet {
private FileDownloadListener a;
private boolean b;
private List<BaseDownloadTask.FinishListener> c;
private Integer d;
private Boolean e;
private Boolean f;
private Boolean g;
private Integer h;
private Integer i;
private Object j;
private String k;
private BaseDownloadTask[] l;
public FileDownloadQueueSet(FileDownloadListener fileDownloadListener) {
if (fileDownloadListener == null) {
throw new IllegalArgumentException("create FileDownloadQueueSet must with valid target!");
}
this.a = fileDownloadListener;
}
public FileDownloadQueueSet a(List<BaseDownloadTask> list) {
this.b = true;
this.l = new BaseDownloadTask[list.size()];
list.toArray(this.l);
return this;
}
public void a() {
for (BaseDownloadTask baseDownloadTask : this.l) {
baseDownloadTask.b(this.a);
Integer num = this.d;
if (num != null) {
baseDownloadTask.c(num.intValue());
}
Boolean bool = this.e;
if (bool != null) {
baseDownloadTask.c(bool.booleanValue());
}
Boolean bool2 = this.f;
if (bool2 != null) {
baseDownloadTask.a(bool2.booleanValue());
}
Integer num2 = this.h;
if (num2 != null) {
baseDownloadTask.d(num2.intValue());
}
Integer num3 = this.i;
if (num3 != null) {
baseDownloadTask.e(num3.intValue());
}
Object obj = this.j;
if (obj != null) {
baseDownloadTask.a(obj);
}
List<BaseDownloadTask.FinishListener> list = this.c;
if (list != null) {
Iterator<BaseDownloadTask.FinishListener> it = list.iterator();
while (it.hasNext()) {
baseDownloadTask.a(it.next());
}
}
String str = this.k;
if (str != null) {
baseDownloadTask.a(str, true);
}
Boolean bool3 = this.g;
if (bool3 != null) {
baseDownloadTask.b(bool3.booleanValue());
}
baseDownloadTask.j().a();
}
FileDownloader.e().a(this.a, this.b);
}
public FileDownloadQueueSet a(int i) {
this.d = Integer.valueOf(i);
return this;
}
}

View File

@@ -0,0 +1,55 @@
package com.liulishuo.filedownloader;
import android.content.Context;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.services.FDServiceSharedHandler;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
/* loaded from: classes.dex */
public class FileDownloadServiceProxy implements IFileDownloadServiceProxy {
private final IFileDownloadServiceProxy a;
private static final class HolderClass {
private static final FileDownloadServiceProxy a = new FileDownloadServiceProxy();
}
public static FDServiceSharedHandler.FileDownloadServiceSharedConnection a() {
if (c().a instanceof FileDownloadServiceSharedTransmit) {
return (FDServiceSharedHandler.FileDownloadServiceSharedConnection) c().a;
}
return null;
}
public static FileDownloadServiceProxy c() {
return HolderClass.a;
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean b(int i) {
return this.a.b(i);
}
private FileDownloadServiceProxy() {
this.a = FileDownloadProperties.a().d ? new FileDownloadServiceSharedTransmit() : new FileDownloadServiceUIGuard();
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean b() {
return this.a.b();
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) {
return this.a.a(str, str2, z, i, i2, i3, z2, fileDownloadHeader, z3);
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public byte a(int i) {
return this.a.a(i);
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public void a(Context context) {
this.a.a(context);
}
}

View File

@@ -0,0 +1,89 @@
package com.liulishuo.filedownloader;
import android.content.Context;
import android.content.Intent;
import com.liulishuo.filedownloader.event.DownloadServiceConnectChangedEvent;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.services.FDServiceSharedHandler;
import com.liulishuo.filedownloader.services.FileDownloadService;
import com.liulishuo.filedownloader.util.DownloadServiceNotConnectedHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
class FileDownloadServiceSharedTransmit implements IFileDownloadServiceProxy, FDServiceSharedHandler.FileDownloadServiceSharedConnection {
private static final Class<?> c = FileDownloadService.SharedMainProcessService.class;
private final ArrayList<Runnable> a = new ArrayList<>();
private FDServiceSharedHandler b;
FileDownloadServiceSharedTransmit() {
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) {
if (!b()) {
return DownloadServiceNotConnectedHelper.a(str, str2, z);
}
this.b.a(str, str2, z, i, i2, i3, z2, fileDownloadHeader, z3);
return true;
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean b(int i) {
return !b() ? DownloadServiceNotConnectedHelper.b(i) : this.b.b(i);
}
@Override // com.liulishuo.filedownloader.services.FDServiceSharedHandler.FileDownloadServiceSharedConnection
public void onDisconnected() {
this.b = null;
FileDownloadEventPool.a().a(new DownloadServiceConnectChangedEvent(DownloadServiceConnectChangedEvent.ConnectStatus.disconnected, c));
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public byte a(int i) {
if (!b()) {
return DownloadServiceNotConnectedHelper.a(i);
}
return this.b.a(i);
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean b() {
return this.b != null;
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public void a(Context context) {
a(context, null);
}
public void a(Context context, Runnable runnable) {
if (runnable != null && !this.a.contains(runnable)) {
this.a.add(runnable);
}
Intent intent = new Intent(context, c);
if (FileDownloadUtils.e(context)) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "start foreground service", new Object[0]);
}
context.startForegroundService(intent);
return;
}
context.startService(intent);
}
@Override // com.liulishuo.filedownloader.services.FDServiceSharedHandler.FileDownloadServiceSharedConnection
public void a(FDServiceSharedHandler fDServiceSharedHandler) {
this.b = fDServiceSharedHandler;
List list = (List) this.a.clone();
this.a.clear();
Iterator it = list.iterator();
while (it.hasNext()) {
((Runnable) it.next()).run();
}
FileDownloadEventPool.a().a(new DownloadServiceConnectChangedEvent(DownloadServiceConnectChangedEvent.ConnectStatus.connected, c));
}
}

View File

@@ -0,0 +1,94 @@
package com.liulishuo.filedownloader;
import android.os.IBinder;
import android.os.RemoteException;
import com.liulishuo.filedownloader.i.IFileDownloadIPCCallback;
import com.liulishuo.filedownloader.i.IFileDownloadIPCService;
import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.services.BaseFileServiceUIGuard;
import com.liulishuo.filedownloader.services.FileDownloadService;
import com.liulishuo.filedownloader.util.DownloadServiceNotConnectedHelper;
/* loaded from: classes.dex */
class FileDownloadServiceUIGuard extends BaseFileServiceUIGuard<FileDownloadServiceCallback, IFileDownloadIPCService> {
protected static class FileDownloadServiceCallback extends IFileDownloadIPCCallback.Stub {
protected FileDownloadServiceCallback() {
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCCallback
public void a(MessageSnapshot messageSnapshot) throws RemoteException {
MessageSnapshotFlow.a().a(messageSnapshot);
}
}
FileDownloadServiceUIGuard() {
super(FileDownloadService.SeparateProcessService.class);
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.liulishuo.filedownloader.services.BaseFileServiceUIGuard
public void b(IFileDownloadIPCService iFileDownloadIPCService, FileDownloadServiceCallback fileDownloadServiceCallback) throws RemoteException {
iFileDownloadIPCService.b(fileDownloadServiceCallback);
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean b(int i) {
if (!b()) {
return DownloadServiceNotConnectedHelper.b(i);
}
try {
return c().b(i);
} catch (RemoteException e) {
e.printStackTrace();
return false;
}
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.liulishuo.filedownloader.services.BaseFileServiceUIGuard
public FileDownloadServiceCallback a() {
return new FileDownloadServiceCallback();
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.liulishuo.filedownloader.services.BaseFileServiceUIGuard
public IFileDownloadIPCService a(IBinder iBinder) {
return IFileDownloadIPCService.Stub.a(iBinder);
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.liulishuo.filedownloader.services.BaseFileServiceUIGuard
public void a(IFileDownloadIPCService iFileDownloadIPCService, FileDownloadServiceCallback fileDownloadServiceCallback) throws RemoteException {
iFileDownloadIPCService.a(fileDownloadServiceCallback);
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) {
if (!b()) {
return DownloadServiceNotConnectedHelper.a(str, str2, z);
}
try {
c().a(str, str2, z, i, i2, i3, z2, fileDownloadHeader, z3);
return true;
} catch (RemoteException e) {
e.printStackTrace();
return false;
}
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public byte a(int i) {
if (!b()) {
return DownloadServiceNotConnectedHelper.a(i);
}
try {
return c().a(i);
} catch (RemoteException e) {
e.printStackTrace();
return (byte) 0;
}
}
}

View File

@@ -0,0 +1,121 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.ITaskHunter;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
/* loaded from: classes.dex */
class FileDownloadTaskLauncher {
private final LaunchTaskPool a = new LaunchTaskPool();
private static class HolderClass {
private static final FileDownloadTaskLauncher a = new FileDownloadTaskLauncher();
static {
MessageSnapshotFlow.a().a(new MessageSnapshotGate());
}
}
private static class LaunchTaskPool {
private ThreadPoolExecutor a;
private LinkedBlockingQueue<Runnable> b;
LaunchTaskPool() {
a();
}
public void a(ITaskHunter.IStarter iStarter) {
this.a.execute(new LaunchTaskRunnable(iStarter));
}
public void b(ITaskHunter.IStarter iStarter) {
this.b.remove(iStarter);
}
public void a(FileDownloadListener fileDownloadListener) {
if (fileDownloadListener == null) {
FileDownloadLog.e(this, "want to expire by listener, but the listener provided is null", new Object[0]);
return;
}
ArrayList arrayList = new ArrayList();
Iterator<Runnable> it = this.b.iterator();
while (it.hasNext()) {
Runnable next = it.next();
LaunchTaskRunnable launchTaskRunnable = (LaunchTaskRunnable) next;
if (launchTaskRunnable.a(fileDownloadListener)) {
launchTaskRunnable.a();
arrayList.add(next);
}
}
if (arrayList.isEmpty()) {
return;
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "expire %d tasks with listener[%s]", Integer.valueOf(arrayList.size()), fileDownloadListener);
}
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
this.a.remove((Runnable) it2.next());
}
}
private void a() {
this.b = new LinkedBlockingQueue<>();
this.a = FileDownloadExecutors.a(3, this.b, "LauncherTask");
}
}
private static class LaunchTaskRunnable implements Runnable {
private final ITaskHunter.IStarter a;
private boolean b = false;
LaunchTaskRunnable(ITaskHunter.IStarter iStarter) {
this.a = iStarter;
}
public boolean a(FileDownloadListener fileDownloadListener) {
ITaskHunter.IStarter iStarter = this.a;
return iStarter != null && iStarter.a(fileDownloadListener);
}
public boolean equals(Object obj) {
return super.equals(obj) || obj == this.a;
}
@Override // java.lang.Runnable
public void run() {
if (this.b) {
return;
}
this.a.start();
}
public void a() {
this.b = true;
}
}
FileDownloadTaskLauncher() {
}
public static FileDownloadTaskLauncher a() {
return HolderClass.a;
}
synchronized void b(ITaskHunter.IStarter iStarter) {
this.a.a(iStarter);
}
synchronized void a(ITaskHunter.IStarter iStarter) {
this.a.b(iStarter);
}
synchronized void a(FileDownloadListener fileDownloadListener) {
this.a.a(fileDownloadListener);
}
}

View File

@@ -0,0 +1,88 @@
package com.liulishuo.filedownloader;
import android.content.Context;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.util.Iterator;
/* loaded from: classes.dex */
public class FileDownloader {
private static final Object c = new Object();
private static final Object d = new Object();
private IQueuesHandler a;
private ILostServiceConnectedHandler b;
private static final class HolderClass {
private static final FileDownloader a = new FileDownloader();
}
public static void a(Context context) {
FileDownloadHelper.a(context.getApplicationContext());
}
public static FileDownloader e() {
return HolderClass.a;
}
ILostServiceConnectedHandler b() {
if (this.b == null) {
synchronized (d) {
if (this.b == null) {
this.b = new LostServiceConnectedHandler();
a((FileDownloadConnectListener) this.b);
}
}
}
return this.b;
}
IQueuesHandler c() {
if (this.a == null) {
synchronized (c) {
if (this.a == null) {
this.a = new QueuesHandler();
}
}
}
return this.a;
}
public boolean d() {
return FileDownloadServiceProxy.c().b();
}
public BaseDownloadTask a(String str) {
return new DownloadTask(str);
}
public boolean a(FileDownloadListener fileDownloadListener, boolean z) {
if (fileDownloadListener == null) {
FileDownloadLog.e(this, "Tasks with the listener can't start, because the listener provided is null: [null, %B]", Boolean.valueOf(z));
return false;
}
if (z) {
return c().b(fileDownloadListener);
}
return c().a(fileDownloadListener);
}
public void a(FileDownloadListener fileDownloadListener) {
FileDownloadTaskLauncher.a().a(fileDownloadListener);
Iterator<BaseDownloadTask.IRunningTask> it = FileDownloadList.b().a(fileDownloadListener).iterator();
while (it.hasNext()) {
it.next().F().pause();
}
}
public void a() {
if (d()) {
return;
}
FileDownloadServiceProxy.c().a(FileDownloadHelper.a());
}
public void a(FileDownloadConnectListener fileDownloadConnectListener) {
FileDownloadEventPool.a().a("event.service.connect.changed", fileDownloadConnectListener);
}
}

View File

@@ -0,0 +1,5 @@
package com.liulishuo.filedownloader;
/* loaded from: classes.dex */
public interface IDownloadSpeed$Lookup {
}

View File

@@ -0,0 +1,12 @@
package com.liulishuo.filedownloader;
/* loaded from: classes.dex */
public interface IDownloadSpeed$Monitor {
void a(long j);
void b(long j);
void c(long j);
void reset();
}

View File

@@ -0,0 +1,32 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.message.MessageSnapshot;
/* loaded from: classes.dex */
interface IFileDownloadMessenger {
void a(MessageSnapshot messageSnapshot);
boolean a();
void b(MessageSnapshot messageSnapshot);
boolean b();
void c(MessageSnapshot messageSnapshot);
boolean c();
void d();
void d(MessageSnapshot messageSnapshot);
void e(MessageSnapshot messageSnapshot);
void f(MessageSnapshot messageSnapshot);
void g(MessageSnapshot messageSnapshot);
void h(MessageSnapshot messageSnapshot);
void i(MessageSnapshot messageSnapshot);
}

View File

@@ -0,0 +1,17 @@
package com.liulishuo.filedownloader;
import android.content.Context;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
/* loaded from: classes.dex */
public interface IFileDownloadServiceProxy {
byte a(int i);
void a(Context context);
boolean a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3);
boolean b();
boolean b(int i);
}

View File

@@ -0,0 +1,12 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.BaseDownloadTask;
/* loaded from: classes.dex */
public interface ILostServiceConnectedHandler {
boolean a(BaseDownloadTask.IRunningTask iRunningTask);
boolean b(BaseDownloadTask.IRunningTask iRunningTask);
void c(BaseDownloadTask.IRunningTask iRunningTask);
}

View File

@@ -0,0 +1,18 @@
package com.liulishuo.filedownloader;
import java.util.List;
/* loaded from: classes.dex */
public interface IQueuesHandler {
int a();
void a(List<Integer> list);
boolean a(int i);
boolean a(FileDownloadListener fileDownloadListener);
void b();
boolean b(FileDownloadListener fileDownloadListener);
}

View File

@@ -0,0 +1,45 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.message.MessageSnapshot;
/* loaded from: classes.dex */
public interface ITaskHunter extends IDownloadSpeed$Lookup {
public interface IMessageHandler {
MessageSnapshot a(Throwable th);
boolean a(MessageSnapshot messageSnapshot);
boolean b(MessageSnapshot messageSnapshot);
boolean c(MessageSnapshot messageSnapshot);
boolean d(MessageSnapshot messageSnapshot);
IFileDownloadMessenger h();
}
public interface IStarter {
boolean a(FileDownloadListener fileDownloadListener);
void start();
}
void a();
void b();
int c();
Throwable d();
boolean e();
long f();
long g();
byte getStatus();
boolean pause();
}

View File

@@ -0,0 +1,10 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.model.FileDownloadModel;
/* loaded from: classes.dex */
public interface IThreadPoolMonitor {
int a(String str, int i);
boolean a(FileDownloadModel fileDownloadModel);
}

View File

@@ -0,0 +1,105 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.event.DownloadServiceConnectChangedEvent;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public class LostServiceConnectedHandler extends FileDownloadConnectListener implements ILostServiceConnectedHandler {
private final ArrayList<BaseDownloadTask.IRunningTask> b = new ArrayList<>();
@Override // com.liulishuo.filedownloader.FileDownloadConnectListener
public void a() {
IQueuesHandler c = FileDownloader.e().c();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "The downloader service is connected.", new Object[0]);
}
synchronized (this.b) {
List<BaseDownloadTask.IRunningTask> list = (List) this.b.clone();
this.b.clear();
ArrayList arrayList = new ArrayList(c.a());
for (BaseDownloadTask.IRunningTask iRunningTask : list) {
int i = iRunningTask.i();
if (c.a(i)) {
iRunningTask.F().j().a();
if (!arrayList.contains(Integer.valueOf(i))) {
arrayList.add(Integer.valueOf(i));
}
} else {
iRunningTask.g();
}
}
c.a(arrayList);
}
}
@Override // com.liulishuo.filedownloader.FileDownloadConnectListener
public void b() {
if (c() != DownloadServiceConnectChangedEvent.ConnectStatus.lost) {
if (FileDownloadList.b().a() > 0) {
FileDownloadLog.e(this, "file download service has be unbound but the size of active tasks are not empty %d ", Integer.valueOf(FileDownloadList.b().a()));
return;
}
return;
}
IQueuesHandler c = FileDownloader.e().c();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "lost the connection to the file download service, and current active task size is %d", Integer.valueOf(FileDownloadList.b().a()));
}
if (FileDownloadList.b().a() > 0) {
synchronized (this.b) {
FileDownloadList.b().a(this.b);
Iterator<BaseDownloadTask.IRunningTask> it = this.b.iterator();
while (it.hasNext()) {
it.next().b();
}
c.b();
}
try {
FileDownloader.e().a();
} catch (IllegalStateException unused) {
FileDownloadLog.e(this, "restart service failed, you may need to restart downloading manually when the app comes back to foreground", new Object[0]);
}
}
}
@Override // com.liulishuo.filedownloader.ILostServiceConnectedHandler
public void c(BaseDownloadTask.IRunningTask iRunningTask) {
if (this.b.isEmpty()) {
return;
}
synchronized (this.b) {
this.b.remove(iRunningTask);
}
}
@Override // com.liulishuo.filedownloader.ILostServiceConnectedHandler
public boolean a(BaseDownloadTask.IRunningTask iRunningTask) {
return !this.b.isEmpty() && this.b.contains(iRunningTask);
}
@Override // com.liulishuo.filedownloader.ILostServiceConnectedHandler
public boolean b(BaseDownloadTask.IRunningTask iRunningTask) {
if (!FileDownloader.e().d()) {
synchronized (this.b) {
if (!FileDownloader.e().d()) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "Waiting for connecting with the downloader service... %d", Integer.valueOf(iRunningTask.F().getId()));
}
FileDownloadServiceProxy.c().a(FileDownloadHelper.a());
if (!this.b.contains(iRunningTask)) {
iRunningTask.b();
this.b.add(iRunningTask);
}
return true;
}
}
}
c(iRunningTask);
return false;
}
}

View File

@@ -0,0 +1,74 @@
package com.liulishuo.filedownloader;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.util.List;
/* loaded from: classes.dex */
public class MessageSnapshotGate implements MessageSnapshotFlow.MessageReceiver {
private boolean a(List<BaseDownloadTask.IRunningTask> list, MessageSnapshot messageSnapshot) {
boolean b;
if (list.size() > 1 && messageSnapshot.getStatus() == -3) {
for (BaseDownloadTask.IRunningTask iRunningTask : list) {
synchronized (iRunningTask.y()) {
if (iRunningTask.k().c(messageSnapshot)) {
FileDownloadLog.a(this, "updateMoreLikelyCompleted", new Object[0]);
return true;
}
}
}
}
for (BaseDownloadTask.IRunningTask iRunningTask2 : list) {
synchronized (iRunningTask2.y()) {
if (iRunningTask2.k().d(messageSnapshot)) {
FileDownloadLog.a(this, "updateKeepFlow", new Object[0]);
return true;
}
}
}
if (-4 == messageSnapshot.getStatus()) {
for (BaseDownloadTask.IRunningTask iRunningTask3 : list) {
synchronized (iRunningTask3.y()) {
if (iRunningTask3.k().a(messageSnapshot)) {
FileDownloadLog.a(this, "updateSampleFilePathTaskRunning", new Object[0]);
return true;
}
}
}
}
if (list.size() != 1) {
return false;
}
BaseDownloadTask.IRunningTask iRunningTask4 = list.get(0);
synchronized (iRunningTask4.y()) {
FileDownloadLog.a(this, "updateKeepAhead", new Object[0]);
b = iRunningTask4.k().b(messageSnapshot);
}
return b;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshotFlow.MessageReceiver
public void a(MessageSnapshot messageSnapshot) {
synchronized (Integer.toString(messageSnapshot.getId()).intern()) {
List<BaseDownloadTask.IRunningTask> b = FileDownloadList.b().b(messageSnapshot.getId());
if (b.size() > 0) {
BaseDownloadTask F = b.get(0).F();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "~~~callback %s old[%s] new[%s] %d", Integer.valueOf(messageSnapshot.getId()), Byte.valueOf(F.getStatus()), Byte.valueOf(messageSnapshot.getStatus()), Integer.valueOf(b.size()));
}
if (!a(b, messageSnapshot)) {
StringBuilder sb = new StringBuilder("The event isn't consumed, id:" + messageSnapshot.getId() + " status:" + ((int) messageSnapshot.getStatus()) + " task-count:" + b.size());
for (BaseDownloadTask.IRunningTask iRunningTask : b) {
sb.append(" | ");
sb.append((int) iRunningTask.F().getStatus());
}
FileDownloadLog.c(this, sb.toString(), new Object[0]);
}
} else {
FileDownloadLog.c(this, "Receive the event %d, but there isn't any running task in the upper layer", Byte.valueOf(messageSnapshot.getStatus()));
}
}
}
}

View File

@@ -0,0 +1,228 @@
package com.liulishuo.filedownloader;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.util.SparseArray;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
class QueuesHandler implements IQueuesHandler {
private final SparseArray<Handler> a = new SparseArray<>();
private static class SerialFinishListener implements BaseDownloadTask.FinishListener {
private final WeakReference<SerialHandlerCallback> a;
private int b;
public BaseDownloadTask.FinishListener a(int i) {
this.b = i;
return this;
}
private SerialFinishListener(WeakReference<SerialHandlerCallback> weakReference) {
this.a = weakReference;
}
@Override // com.liulishuo.filedownloader.BaseDownloadTask.FinishListener
public void a(BaseDownloadTask baseDownloadTask) {
WeakReference<SerialHandlerCallback> weakReference = this.a;
if (weakReference == null || weakReference.get() == null) {
return;
}
this.a.get().a(this.b);
}
}
private class SerialHandlerCallback implements Handler.Callback {
private Handler a;
private List<BaseDownloadTask.IRunningTask> b;
private int c = 0;
private SerialFinishListener d = new SerialFinishListener(new WeakReference(this));
SerialHandlerCallback() {
}
public void b() {
a(this.c);
}
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
int i = message.what;
if (i == 1) {
if (message.arg1 < this.b.size()) {
this.c = message.arg1;
BaseDownloadTask.IRunningTask iRunningTask = this.b.get(this.c);
synchronized (iRunningTask.y()) {
if (iRunningTask.F().getStatus() == 0 && !FileDownloadList.b().c(iRunningTask)) {
BaseDownloadTask F = iRunningTask.F();
SerialFinishListener serialFinishListener = this.d;
serialFinishListener.a(this.c + 1);
F.a((BaseDownloadTask.FinishListener) serialFinishListener);
iRunningTask.A();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(SerialHandlerCallback.class, "direct go next by not contains %s %d", iRunningTask, Integer.valueOf(message.arg1));
}
a(message.arg1 + 1);
return true;
}
}
synchronized (QueuesHandler.this.a) {
QueuesHandler.this.a.remove(this.b.get(0).i());
}
Handler handler = this.a;
FileDownloadListener fileDownloadListener = null;
if (handler != null && handler.getLooper() != null) {
this.a.getLooper().quit();
this.a = null;
this.b = null;
this.d = null;
}
if (FileDownloadLog.a) {
Object[] objArr = new Object[2];
List<BaseDownloadTask.IRunningTask> list = this.b;
if (list != null && list.get(0) != null) {
fileDownloadListener = this.b.get(0).F().v();
}
objArr[0] = fileDownloadListener;
objArr[1] = Integer.valueOf(message.arg1);
FileDownloadLog.a(SerialHandlerCallback.class, "final serial %s %d", objArr);
}
return true;
}
if (i == 2) {
a();
} else if (i == 3) {
b();
}
return true;
}
public void a(Handler handler) {
this.a = handler;
}
public void a(List<BaseDownloadTask.IRunningTask> list) {
this.b = list;
}
public void a() {
this.b.get(this.c).F().b(this.d);
this.a.removeCallbacksAndMessages(null);
}
/* JADX INFO: Access modifiers changed from: private */
public void a(int i) {
Handler handler = this.a;
if (handler != null && this.b != null) {
Message obtainMessage = handler.obtainMessage();
obtainMessage.what = 1;
obtainMessage.arg1 = i;
if (FileDownloadLog.a) {
Object[] objArr = new Object[2];
List<BaseDownloadTask.IRunningTask> list = this.b;
FileDownloadListener fileDownloadListener = null;
if (list != null && list.get(0) != null) {
fileDownloadListener = this.b.get(0).F().v();
}
objArr[0] = fileDownloadListener;
objArr[1] = Integer.valueOf(obtainMessage.arg1);
FileDownloadLog.a(SerialHandlerCallback.class, "start next %s %s", objArr);
}
this.a.sendMessage(obtainMessage);
return;
}
FileDownloadLog.e(this, "need go next %d, but params is not ready %s %s", Integer.valueOf(i), this.a, this.b);
}
}
QueuesHandler() {
}
@Override // com.liulishuo.filedownloader.IQueuesHandler
public boolean b(FileDownloadListener fileDownloadListener) {
SerialHandlerCallback serialHandlerCallback = new SerialHandlerCallback();
int hashCode = serialHandlerCallback.hashCode();
List<BaseDownloadTask.IRunningTask> a = FileDownloadList.b().a(hashCode, fileDownloadListener);
if (a(hashCode, a, fileDownloadListener, true)) {
return false;
}
HandlerThread handlerThread = new HandlerThread(FileDownloadUtils.a("filedownloader serial thread %s-%d", fileDownloadListener, Integer.valueOf(hashCode)));
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper(), serialHandlerCallback);
serialHandlerCallback.a(handler);
serialHandlerCallback.a(a);
serialHandlerCallback.a(0);
synchronized (this.a) {
this.a.put(hashCode, handler);
}
return true;
}
@Override // com.liulishuo.filedownloader.IQueuesHandler
public boolean a(FileDownloadListener fileDownloadListener) {
int hashCode = fileDownloadListener.hashCode();
List<BaseDownloadTask.IRunningTask> a = FileDownloadList.b().a(hashCode, fileDownloadListener);
if (a(hashCode, a, fileDownloadListener, false)) {
return false;
}
Iterator<BaseDownloadTask.IRunningTask> it = a.iterator();
while (it.hasNext()) {
it.next().A();
}
return true;
}
@Override // com.liulishuo.filedownloader.IQueuesHandler
public void a(List<Integer> list) {
Iterator<Integer> it = list.iterator();
while (it.hasNext()) {
b(this.a.get(it.next().intValue()));
}
}
@Override // com.liulishuo.filedownloader.IQueuesHandler
public int a() {
return this.a.size();
}
@Override // com.liulishuo.filedownloader.IQueuesHandler
public boolean a(int i) {
return this.a.get(i) != null;
}
private boolean a(int i, List<BaseDownloadTask.IRunningTask> list, FileDownloadListener fileDownloadListener, boolean z) {
if (FileDownloadMonitor.b()) {
FileDownloadMonitor.a().a(list.size(), true, fileDownloadListener);
}
if (FileDownloadLog.a) {
FileDownloadLog.d(FileDownloader.class, "start list attachKey[%d] size[%d] listener[%s] isSerial[%B]", Integer.valueOf(i), Integer.valueOf(list.size()), fileDownloadListener, Boolean.valueOf(z));
}
if (list != null && !list.isEmpty()) {
return false;
}
FileDownloadLog.e(FileDownloader.class, "Tasks with the listener can't start, because can't find any task with the provided listener, maybe tasks instance has been started in the past, so they are all are inUsing, if in this case, you can use [BaseDownloadTask#reuse] to reuse theme first then start again: [%s, %B]", fileDownloadListener, Boolean.valueOf(z));
return true;
}
@Override // com.liulishuo.filedownloader.IQueuesHandler
public void b() {
for (int i = 0; i < this.a.size(); i++) {
a(this.a.get(this.a.keyAt(i)));
}
}
private void a(Handler handler) {
handler.sendEmptyMessage(2);
}
private void b(Handler handler) {
handler.sendEmptyMessage(3);
}
}

View File

@@ -0,0 +1,7 @@
package com.liulishuo.filedownloader;
/* loaded from: classes.dex */
public final class R$string {
public static final int default_filedownloader_notification_content = 2131820892;
public static final int default_filedownloader_notification_title = 2131820893;
}

View File

@@ -0,0 +1,21 @@
package com.liulishuo.filedownloader.connection;
import android.support.v4.media.session.PlaybackStateCompat;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
/* loaded from: classes.dex */
public class DefaultConnectionCountAdapter implements FileDownloadHelper.ConnectionCountAdapter {
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.ConnectionCountAdapter
public int a(int i, String str, String str2, long j) {
if (j < PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED) {
return 1;
}
if (j < 5242880) {
return 2;
}
if (j < 52428800) {
return 3;
}
return j < 104857600 ? 4 : 5;
}
}

View File

@@ -0,0 +1,30 @@
package com.liulishuo.filedownloader.connection;
import java.io.IOException;
import java.io.InputStream;
import java.net.ProtocolException;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public interface FileDownloadConnection {
InputStream a() throws IOException;
String a(String str);
void a(String str, String str2);
boolean a(String str, long j);
Map<String, List<String>> b();
boolean b(String str) throws ProtocolException;
int c() throws IOException;
void d();
Map<String, List<String>> e();
void execute() throws IOException;
}

View File

@@ -0,0 +1,122 @@
package com.liulishuo.filedownloader.connection;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public class FileDownloadUrlConnection implements FileDownloadConnection {
protected URLConnection a;
public static class Configuration {
private Proxy a;
private Integer b;
private Integer c;
}
public static class Creator implements FileDownloadHelper.ConnectionCreator {
private final Configuration a;
public Creator() {
this(null);
}
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.ConnectionCreator
public FileDownloadConnection a(String str) throws IOException {
return new FileDownloadUrlConnection(str, this.a);
}
public Creator(Configuration configuration) {
this.a = configuration;
}
}
public FileDownloadUrlConnection(String str, Configuration configuration) throws IOException {
this(new URL(str), configuration);
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public void a(String str, String str2) {
this.a.addRequestProperty(str, str2);
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public boolean a(String str, long j) {
return false;
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public Map<String, List<String>> b() {
return this.a.getHeaderFields();
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public int c() throws IOException {
URLConnection uRLConnection = this.a;
if (uRLConnection instanceof HttpURLConnection) {
return ((HttpURLConnection) uRLConnection).getResponseCode();
}
return 0;
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public void d() {
try {
this.a.getInputStream().close();
} catch (IOException unused) {
}
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public Map<String, List<String>> e() {
return this.a.getRequestProperties();
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public void execute() throws IOException {
this.a.connect();
}
public FileDownloadUrlConnection(URL url, Configuration configuration) throws IOException {
if (configuration == null || configuration.a == null) {
this.a = url.openConnection();
} else {
this.a = url.openConnection(configuration.a);
}
if (configuration != null) {
if (configuration.b != null) {
this.a.setReadTimeout(configuration.b.intValue());
}
if (configuration.c != null) {
this.a.setConnectTimeout(configuration.c.intValue());
}
}
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public InputStream a() throws IOException {
return this.a.getInputStream();
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public boolean b(String str) throws ProtocolException {
URLConnection uRLConnection = this.a;
if (!(uRLConnection instanceof HttpURLConnection)) {
return false;
}
((HttpURLConnection) uRLConnection).setRequestMethod(str);
return true;
}
@Override // com.liulishuo.filedownloader.connection.FileDownloadConnection
public String a(String str) {
return this.a.getHeaderField(str);
}
}

View File

@@ -0,0 +1,61 @@
package com.liulishuo.filedownloader.connection;
import com.liulishuo.filedownloader.download.CustomComponentHolder;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public class RedirectHandler {
public static FileDownloadConnection a(Map<String, List<String>> map, FileDownloadConnection fileDownloadConnection, List<String> list) throws IOException, IllegalAccessException {
int c = fileDownloadConnection.c();
String a = fileDownloadConnection.a("Location");
ArrayList arrayList = new ArrayList();
int i = 0;
while (a(c)) {
if (a == null) {
throw new IllegalAccessException(FileDownloadUtils.a("receive %d (redirect) but the location is null with response [%s]", Integer.valueOf(c), fileDownloadConnection.b()));
}
if (FileDownloadLog.a) {
FileDownloadLog.a(RedirectHandler.class, "redirect to %s with %d, %s", a, Integer.valueOf(c), arrayList);
}
fileDownloadConnection.d();
fileDownloadConnection = a(map, a);
arrayList.add(a);
fileDownloadConnection.execute();
c = fileDownloadConnection.c();
a = fileDownloadConnection.a("Location");
i++;
if (i >= 10) {
throw new IllegalAccessException(FileDownloadUtils.a("redirect too many times! %s", arrayList));
}
}
if (list != null) {
list.addAll(arrayList);
}
return fileDownloadConnection;
}
private static boolean a(int i) {
return i == 301 || i == 302 || i == 303 || i == 300 || i == 307 || i == 308;
}
private static FileDownloadConnection a(Map<String, List<String>> map, String str) throws IOException {
FileDownloadConnection a = CustomComponentHolder.i().a(str);
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String key = entry.getKey();
List<String> value = entry.getValue();
if (value != null) {
Iterator<String> it = value.iterator();
while (it.hasNext()) {
a.a(key, it.next());
}
}
}
return a;
}
}

View File

@@ -0,0 +1,57 @@
package com.liulishuo.filedownloader.database;
import com.liulishuo.filedownloader.model.ConnectionModel;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import java.util.List;
/* loaded from: classes.dex */
public interface FileDownloadDatabase {
public interface Maintainer extends Iterable<FileDownloadModel> {
void a(int i, FileDownloadModel fileDownloadModel);
void a(FileDownloadModel fileDownloadModel);
void b(FileDownloadModel fileDownloadModel);
void c();
}
Maintainer a();
void a(int i);
void a(int i, int i2);
void a(int i, int i2, long j);
void a(int i, long j);
void a(int i, long j, String str, String str2);
void a(int i, String str, long j, long j2, int i2);
void a(int i, Throwable th);
void a(int i, Throwable th, long j);
void a(ConnectionModel connectionModel);
void a(FileDownloadModel fileDownloadModel);
void b(int i);
void b(int i, long j);
void c(int i);
void c(int i, long j);
void clear();
List<ConnectionModel> d(int i);
FileDownloadModel e(int i);
boolean remove(int i);
}

View File

@@ -0,0 +1,180 @@
package com.liulishuo.filedownloader.database;
import android.util.SparseArray;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.model.ConnectionModel;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public class NoDatabaseImpl implements FileDownloadDatabase {
final SparseArray<FileDownloadModel> a = new SparseArray<>();
final SparseArray<List<ConnectionModel>> b = new SparseArray<>();
class Maintainer implements FileDownloadDatabase.Maintainer {
Maintainer() {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void a(int i, FileDownloadModel fileDownloadModel) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void a(FileDownloadModel fileDownloadModel) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void b(FileDownloadModel fileDownloadModel) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void c() {
}
@Override // java.lang.Iterable
public Iterator<FileDownloadModel> iterator() {
return new MaintainerIterator(NoDatabaseImpl.this);
}
}
class MaintainerIterator implements Iterator<FileDownloadModel> {
MaintainerIterator(NoDatabaseImpl noDatabaseImpl) {
}
@Override // java.util.Iterator
public boolean hasNext() {
return false;
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.util.Iterator
public FileDownloadModel next() {
return null;
}
@Override // java.util.Iterator
public void remove() {
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, int i2) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, long j, String str, String str2) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, String str, long j, long j2, int i2) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, Throwable th) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, Throwable th, long j) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(ConnectionModel connectionModel) {
int c = connectionModel.c();
List<ConnectionModel> list = this.b.get(c);
if (list == null) {
list = new ArrayList<>();
this.b.put(c, list);
}
list.add(connectionModel);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void b(int i) {
this.b.remove(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void b(int i, long j) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void c(int i) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void c(int i, long j) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void clear() {
this.a.clear();
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public List<ConnectionModel> d(int i) {
ArrayList arrayList = new ArrayList();
List<ConnectionModel> list = this.b.get(i);
if (list != null) {
arrayList.addAll(list);
}
return arrayList;
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public FileDownloadModel e(int i) {
return this.a.get(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public boolean remove(int i) {
this.a.remove(i);
return true;
}
public void b(FileDownloadModel fileDownloadModel) {
this.a.put(fileDownloadModel.getId(), fileDownloadModel);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, int i2, long j) {
List<ConnectionModel> list = this.b.get(i);
if (list == null) {
return;
}
for (ConnectionModel connectionModel : list) {
if (connectionModel.d() == i2) {
connectionModel.a(j);
return;
}
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(FileDownloadModel fileDownloadModel) {
if (fileDownloadModel == null) {
FileDownloadLog.e(this, "update but model == null!", new Object[0]);
} else if (e(fileDownloadModel.getId()) != null) {
this.a.remove(fileDownloadModel.getId());
this.a.put(fileDownloadModel.getId(), fileDownloadModel);
} else {
b(fileDownloadModel);
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, long j) {
remove(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public FileDownloadDatabase.Maintainer a() {
return new Maintainer();
}
}

View File

@@ -0,0 +1,247 @@
package com.liulishuo.filedownloader.database;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.model.ConnectionModel;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
/* loaded from: classes.dex */
public class RemitDatabase implements FileDownloadDatabase {
private Handler c;
private volatile Thread g;
private final List<Integer> e = new ArrayList();
private AtomicInteger f = new AtomicInteger();
private final NoDatabaseImpl a = new NoDatabaseImpl();
private final SqliteDatabaseImpl b = new SqliteDatabaseImpl();
private final long d = FileDownloadProperties.a().b;
public RemitDatabase() {
HandlerThread handlerThread = new HandlerThread(FileDownloadUtils.k("RemitHandoverToDB"));
handlerThread.start();
this.c = new Handler(handlerThread.getLooper(), new Handler.Callback() { // from class: com.liulishuo.filedownloader.database.RemitDatabase.1
@Override // android.os.Handler.Callback
public boolean handleMessage(Message message) {
int i = message.what;
if (i == 0) {
if (RemitDatabase.this.g != null) {
LockSupport.unpark(RemitDatabase.this.g);
RemitDatabase.this.g = null;
}
return false;
}
try {
RemitDatabase.this.f.set(i);
RemitDatabase.this.h(i);
RemitDatabase.this.e.add(Integer.valueOf(i));
return false;
} finally {
RemitDatabase.this.f.set(0);
if (RemitDatabase.this.g != null) {
LockSupport.unpark(RemitDatabase.this.g);
RemitDatabase.this.g = null;
}
}
}
});
}
private void f(int i) {
this.c.removeMessages(i);
if (this.f.get() != i) {
h(i);
return;
}
this.g = Thread.currentThread();
this.c.sendEmptyMessage(0);
LockSupport.park();
}
private boolean g(int i) {
return !this.e.contains(Integer.valueOf(i));
}
/* JADX INFO: Access modifiers changed from: private */
public void h(int i) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "sync cache to db %d", Integer.valueOf(i));
}
this.b.a(this.a.e(i));
List<ConnectionModel> d = this.a.d(i);
this.b.b(i);
Iterator<ConnectionModel> it = d.iterator();
while (it.hasNext()) {
this.b.a(it.next());
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void clear() {
this.a.clear();
this.b.clear();
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public List<ConnectionModel> d(int i) {
return this.a.d(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public FileDownloadModel e(int i) {
return this.a.e(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public boolean remove(int i) {
this.b.remove(i);
return this.a.remove(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void b(int i) {
this.a.b(i);
if (g(i)) {
return;
}
this.b.b(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void c(int i) {
this.c.sendEmptyMessageDelayed(i, this.d);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void c(int i, long j) {
this.a.c(i, j);
if (g(i)) {
f(i);
}
this.b.c(i, j);
this.e.remove(Integer.valueOf(i));
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(ConnectionModel connectionModel) {
this.a.a(connectionModel);
if (g(connectionModel.c())) {
return;
}
this.b.a(connectionModel);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void b(int i, long j) {
this.a.b(i, j);
if (g(i)) {
return;
}
this.b.b(i, j);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, int i2, long j) {
this.a.a(i, i2, j);
if (g(i)) {
return;
}
this.b.a(i, i2, j);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, int i2) {
this.a.a(i, i2);
if (g(i)) {
return;
}
this.b.a(i, i2);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(FileDownloadModel fileDownloadModel) {
this.a.a(fileDownloadModel);
if (g(fileDownloadModel.getId())) {
return;
}
this.b.a(fileDownloadModel);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, String str, long j, long j2, int i2) {
this.a.a(i, str, j, j2, i2);
if (g(i)) {
return;
}
this.b.a(i, str, j, j2, i2);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, long j, String str, String str2) {
this.a.a(i, j, str, str2);
if (g(i)) {
return;
}
this.b.a(i, j, str, str2);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i) {
this.a.a(i);
if (g(i)) {
return;
}
this.b.a(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, Throwable th) {
this.a.a(i, th);
if (g(i)) {
return;
}
this.b.a(i, th);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, Throwable th, long j) {
this.a.a(i, th, j);
if (g(i)) {
f(i);
}
this.b.a(i, th, j);
this.e.remove(Integer.valueOf(i));
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, long j) {
this.a.a(i, j);
if (g(i)) {
this.c.removeMessages(i);
if (this.f.get() == i) {
this.g = Thread.currentThread();
this.c.sendEmptyMessage(0);
LockSupport.park();
this.b.a(i, j);
}
} else {
this.b.a(i, j);
}
this.e.remove(Integer.valueOf(i));
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public FileDownloadDatabase.Maintainer a() {
SqliteDatabaseImpl sqliteDatabaseImpl = this.b;
NoDatabaseImpl noDatabaseImpl = this.a;
return sqliteDatabaseImpl.a(noDatabaseImpl.a, noDatabaseImpl.b);
}
}

View File

@@ -0,0 +1,347 @@
package com.liulishuo.filedownloader.database;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import android.util.SparseArray;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.model.ConnectionModel;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public class SqliteDatabaseImpl implements FileDownloadDatabase {
private final SQLiteDatabase a = new SqliteDatabaseOpenHelper(FileDownloadHelper.a()).getWritableDatabase();
public class Maintainer implements FileDownloadDatabase.Maintainer {
private final SparseArray<FileDownloadModel> a;
private MaintainerIterator b;
private final SparseArray<FileDownloadModel> c;
private final SparseArray<List<ConnectionModel>> d;
Maintainer(SqliteDatabaseImpl sqliteDatabaseImpl) {
this(null, null);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void a(int i, FileDownloadModel fileDownloadModel) {
this.a.put(i, fileDownloadModel);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void a(FileDownloadModel fileDownloadModel) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void b(FileDownloadModel fileDownloadModel) {
SparseArray<FileDownloadModel> sparseArray = this.c;
if (sparseArray != null) {
sparseArray.put(fileDownloadModel.getId(), fileDownloadModel);
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer
public void c() {
MaintainerIterator maintainerIterator = this.b;
if (maintainerIterator != null) {
maintainerIterator.a();
}
int size = this.a.size();
if (size < 0) {
return;
}
SqliteDatabaseImpl.this.a.beginTransaction();
for (int i = 0; i < size; i++) {
try {
int keyAt = this.a.keyAt(i);
FileDownloadModel fileDownloadModel = this.a.get(keyAt);
SqliteDatabaseImpl.this.a.delete("filedownloader", "_id = ?", new String[]{String.valueOf(keyAt)});
SqliteDatabaseImpl.this.a.insert("filedownloader", null, fileDownloadModel.toContentValues());
if (fileDownloadModel.getConnectionCount() > 1) {
List<ConnectionModel> d = SqliteDatabaseImpl.this.d(keyAt);
if (d.size() > 0) {
SqliteDatabaseImpl.this.a.delete("filedownloaderConnection", "id = ?", new String[]{String.valueOf(keyAt)});
for (ConnectionModel connectionModel : d) {
connectionModel.a(fileDownloadModel.getId());
SqliteDatabaseImpl.this.a.insert("filedownloaderConnection", null, connectionModel.f());
}
}
}
} finally {
SqliteDatabaseImpl.this.a.endTransaction();
}
}
if (this.c != null && this.d != null) {
int size2 = this.c.size();
for (int i2 = 0; i2 < size2; i2++) {
int id = this.c.valueAt(i2).getId();
List<ConnectionModel> d2 = SqliteDatabaseImpl.this.d(id);
if (d2 != null && d2.size() > 0) {
this.d.put(id, d2);
}
}
}
SqliteDatabaseImpl.this.a.setTransactionSuccessful();
}
@Override // java.lang.Iterable
public Iterator<FileDownloadModel> iterator() {
MaintainerIterator maintainerIterator = SqliteDatabaseImpl.this.new MaintainerIterator();
this.b = maintainerIterator;
return maintainerIterator;
}
Maintainer(SparseArray<FileDownloadModel> sparseArray, SparseArray<List<ConnectionModel>> sparseArray2) {
this.a = new SparseArray<>();
this.c = sparseArray;
this.d = sparseArray2;
}
}
class MaintainerIterator implements Iterator<FileDownloadModel> {
private final Cursor a;
private final List<Integer> b = new ArrayList();
private int c;
MaintainerIterator() {
this.a = SqliteDatabaseImpl.this.a.rawQuery("SELECT * FROM filedownloader", null);
}
void a() {
this.a.close();
if (this.b.isEmpty()) {
return;
}
String join = TextUtils.join(", ", this.b);
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "delete %s", join);
}
SqliteDatabaseImpl.this.a.execSQL(FileDownloadUtils.a("DELETE FROM %s WHERE %s IN (%s);", "filedownloader", FileDownloadModel.ID, join));
SqliteDatabaseImpl.this.a.execSQL(FileDownloadUtils.a("DELETE FROM %s WHERE %s IN (%s);", "filedownloaderConnection", JockstickDataConverter.ID, join));
}
@Override // java.util.Iterator
public boolean hasNext() {
return this.a.moveToNext();
}
@Override // java.util.Iterator
public void remove() {
this.b.add(Integer.valueOf(this.c));
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.util.Iterator
public FileDownloadModel next() {
FileDownloadModel b = SqliteDatabaseImpl.b(this.a);
this.c = b.getId();
return b;
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void b(int i) {
this.a.execSQL("DELETE FROM filedownloaderConnection WHERE id = " + i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void c(int i) {
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void c(int i, long j) {
ContentValues contentValues = new ContentValues();
contentValues.put(FileDownloadModel.STATUS, (Byte) (byte) -2);
contentValues.put(FileDownloadModel.SOFAR, Long.valueOf(j));
a(i, contentValues);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void clear() {
this.a.delete("filedownloader", null, null);
this.a.delete("filedownloaderConnection", null, null);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public List<ConnectionModel> d(int i) {
ArrayList arrayList = new ArrayList();
Cursor cursor = null;
try {
cursor = this.a.rawQuery(FileDownloadUtils.a("SELECT * FROM %s WHERE %s = ?", "filedownloaderConnection", JockstickDataConverter.ID), new String[]{Integer.toString(i)});
while (cursor.moveToNext()) {
ConnectionModel connectionModel = new ConnectionModel();
connectionModel.a(i);
connectionModel.b(cursor.getInt(cursor.getColumnIndex("connectionIndex")));
connectionModel.c(cursor.getLong(cursor.getColumnIndex("startOffset")));
connectionModel.a(cursor.getLong(cursor.getColumnIndex("currentOffset")));
connectionModel.b(cursor.getLong(cursor.getColumnIndex("endOffset")));
arrayList.add(connectionModel);
}
return arrayList;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public FileDownloadModel e(int i) {
Cursor rawQuery;
Cursor cursor = null;
try {
rawQuery = this.a.rawQuery(FileDownloadUtils.a("SELECT * FROM %s WHERE %s = ?", "filedownloader", FileDownloadModel.ID), new String[]{Integer.toString(i)});
} catch (Throwable th) {
th = th;
}
try {
if (!rawQuery.moveToNext()) {
if (rawQuery != null) {
rawQuery.close();
}
return null;
}
FileDownloadModel b = b(rawQuery);
if (rawQuery != null) {
rawQuery.close();
}
return b;
} catch (Throwable th2) {
cursor = rawQuery;
th = th2;
if (cursor != null) {
cursor.close();
}
throw th;
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public boolean remove(int i) {
return this.a.delete("filedownloader", "_id = ?", new String[]{String.valueOf(i)}) != 0;
}
public void b(FileDownloadModel fileDownloadModel) {
this.a.insert("filedownloader", null, fileDownloadModel.toContentValues());
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(ConnectionModel connectionModel) {
this.a.insert("filedownloaderConnection", null, connectionModel.f());
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void b(int i, long j) {
ContentValues contentValues = new ContentValues();
contentValues.put(FileDownloadModel.STATUS, (Byte) (byte) 3);
contentValues.put(FileDownloadModel.SOFAR, Long.valueOf(j));
a(i, contentValues);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, int i2, long j) {
ContentValues contentValues = new ContentValues();
contentValues.put("currentOffset", Long.valueOf(j));
this.a.update("filedownloaderConnection", contentValues, "id = ? AND connectionIndex = ?", new String[]{Integer.toString(i), Integer.toString(i2)});
}
/* JADX INFO: Access modifiers changed from: private */
public static FileDownloadModel b(Cursor cursor) {
FileDownloadModel fileDownloadModel = new FileDownloadModel();
fileDownloadModel.setId(cursor.getInt(cursor.getColumnIndex(FileDownloadModel.ID)));
fileDownloadModel.setUrl(cursor.getString(cursor.getColumnIndex("url")));
fileDownloadModel.setPath(cursor.getString(cursor.getColumnIndex(FileDownloadModel.PATH)), cursor.getShort(cursor.getColumnIndex(FileDownloadModel.PATH_AS_DIRECTORY)) == 1);
fileDownloadModel.setStatus((byte) cursor.getShort(cursor.getColumnIndex(FileDownloadModel.STATUS)));
fileDownloadModel.setSoFar(cursor.getLong(cursor.getColumnIndex(FileDownloadModel.SOFAR)));
fileDownloadModel.setTotal(cursor.getLong(cursor.getColumnIndex(FileDownloadModel.TOTAL)));
fileDownloadModel.setErrMsg(cursor.getString(cursor.getColumnIndex(FileDownloadModel.ERR_MSG)));
fileDownloadModel.setETag(cursor.getString(cursor.getColumnIndex(FileDownloadModel.ETAG)));
fileDownloadModel.setFilename(cursor.getString(cursor.getColumnIndex(FileDownloadModel.FILENAME)));
fileDownloadModel.setConnectionCount(cursor.getInt(cursor.getColumnIndex(FileDownloadModel.CONNECTION_COUNT)));
return fileDownloadModel;
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, int i2) {
ContentValues contentValues = new ContentValues();
contentValues.put(FileDownloadModel.CONNECTION_COUNT, Integer.valueOf(i2));
this.a.update("filedownloader", contentValues, "_id = ? ", new String[]{Integer.toString(i)});
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(FileDownloadModel fileDownloadModel) {
if (fileDownloadModel == null) {
FileDownloadLog.e(this, "update but model == null!", new Object[0]);
} else if (e(fileDownloadModel.getId()) != null) {
this.a.update("filedownloader", fileDownloadModel.toContentValues(), "_id = ? ", new String[]{String.valueOf(fileDownloadModel.getId())});
} else {
b(fileDownloadModel);
}
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, String str, long j, long j2, int i2) {
ContentValues contentValues = new ContentValues();
contentValues.put(FileDownloadModel.SOFAR, Long.valueOf(j));
contentValues.put(FileDownloadModel.TOTAL, Long.valueOf(j2));
contentValues.put(FileDownloadModel.ETAG, str);
contentValues.put(FileDownloadModel.CONNECTION_COUNT, Integer.valueOf(i2));
a(i, contentValues);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, long j, String str, String str2) {
ContentValues contentValues = new ContentValues();
contentValues.put(FileDownloadModel.STATUS, (Byte) (byte) 2);
contentValues.put(FileDownloadModel.TOTAL, Long.valueOf(j));
contentValues.put(FileDownloadModel.ETAG, str);
contentValues.put(FileDownloadModel.FILENAME, str2);
a(i, contentValues);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, Throwable th, long j) {
ContentValues contentValues = new ContentValues();
contentValues.put(FileDownloadModel.ERR_MSG, th.toString());
contentValues.put(FileDownloadModel.STATUS, (Byte) (byte) -1);
contentValues.put(FileDownloadModel.SOFAR, Long.valueOf(j));
a(i, contentValues);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, Throwable th) {
ContentValues contentValues = new ContentValues();
contentValues.put(FileDownloadModel.ERR_MSG, th.toString());
contentValues.put(FileDownloadModel.STATUS, (Byte) (byte) 5);
a(i, contentValues);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public void a(int i, long j) {
remove(i);
}
@Override // com.liulishuo.filedownloader.database.FileDownloadDatabase
public FileDownloadDatabase.Maintainer a() {
return new Maintainer(this);
}
public FileDownloadDatabase.Maintainer a(SparseArray<FileDownloadModel> sparseArray, SparseArray<List<ConnectionModel>> sparseArray2) {
return new Maintainer(sparseArray, sparseArray2);
}
private void a(int i, ContentValues contentValues) {
this.a.update("filedownloader", contentValues, "_id = ? ", new String[]{String.valueOf(i)});
}
}

View File

@@ -0,0 +1,48 @@
package com.liulishuo.filedownloader.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Build;
/* loaded from: classes.dex */
public class SqliteDatabaseOpenHelper extends SQLiteOpenHelper {
public SqliteDatabaseOpenHelper(Context context) {
super(context, "filedownloader.db", (SQLiteDatabase.CursorFactory) null, 3);
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onCreate(SQLiteDatabase sQLiteDatabase) {
sQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS filedownloader( _id INTEGER PRIMARY KEY, url VARCHAR, path VARCHAR, status TINYINT(7), sofar INTEGER, total INTEGER, errMsg VARCHAR, etag VARCHAR, pathAsDirectory TINYINT(1) DEFAULT 0, filename VARCHAR, connectionCount INTEGER DEFAULT 1)");
sQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS filedownloaderConnection( id INTEGER, connectionIndex INTEGER, startOffset INTEGER, currentOffset INTEGER, endOffset INTEGER, PRIMARY KEY ( id, connectionIndex ))");
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onDowngrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
sQLiteDatabase.delete("filedownloader", null, null);
sQLiteDatabase.delete("filedownloaderConnection", null, null);
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onOpen(SQLiteDatabase sQLiteDatabase) {
super.onOpen(sQLiteDatabase);
int i = Build.VERSION.SDK_INT;
if (i >= 16) {
setWriteAheadLoggingEnabled(true);
} else if (i >= 11) {
sQLiteDatabase.enableWriteAheadLogging();
}
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
if (i < 2) {
sQLiteDatabase.execSQL("ALTER TABLE filedownloader ADD COLUMN pathAsDirectory TINYINT(1) DEFAULT 0");
sQLiteDatabase.execSQL("ALTER TABLE filedownloader ADD COLUMN filename VARCHAR");
}
if (i < 3) {
sQLiteDatabase.execSQL("ALTER TABLE filedownloader ADD COLUMN connectionCount INTEGER DEFAULT 1");
sQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS filedownloaderConnection( id INTEGER, connectionIndex INTEGER, startOffset INTEGER, currentOffset INTEGER, endOffset INTEGER, PRIMARY KEY ( id, connectionIndex ))");
}
}
}

View File

@@ -0,0 +1,169 @@
package com.liulishuo.filedownloader.download;
import android.text.TextUtils;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.connection.RedirectHandler;
import com.liulishuo.filedownloader.download.ConnectionProfile;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.IOException;
import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public class ConnectTask {
final int a;
final String b;
final FileDownloadHeader c;
private ConnectionProfile d;
private String e;
private Map<String, List<String>> f;
private List<String> g;
static class Builder {
private Integer a;
private String b;
private String c;
private FileDownloadHeader d;
private ConnectionProfile e;
Builder() {
}
public Builder a(int i) {
this.a = Integer.valueOf(i);
return this;
}
public Builder b(String str) {
this.b = str;
return this;
}
public Builder a(String str) {
this.c = str;
return this;
}
public Builder a(FileDownloadHeader fileDownloadHeader) {
this.d = fileDownloadHeader;
return this;
}
public Builder a(ConnectionProfile connectionProfile) {
this.e = connectionProfile;
return this;
}
ConnectTask a() {
ConnectionProfile connectionProfile;
Integer num = this.a;
if (num != null && (connectionProfile = this.e) != null && this.b != null) {
return new ConnectTask(connectionProfile, num.intValue(), this.b, this.c, this.d);
}
throw new IllegalArgumentException();
}
}
private void b(FileDownloadConnection fileDownloadConnection) {
HashMap<String, List<String>> headers;
FileDownloadHeader fileDownloadHeader = this.c;
if (fileDownloadHeader == null || (headers = fileDownloadHeader.getHeaders()) == null) {
return;
}
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "%d add outside header: %s", Integer.valueOf(this.a), headers);
}
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String key = entry.getKey();
List<String> value = entry.getValue();
if (value != null) {
Iterator<String> it = value.iterator();
while (it.hasNext()) {
fileDownloadConnection.a(key, it.next());
}
}
}
}
private void c(FileDownloadConnection fileDownloadConnection) {
FileDownloadHeader fileDownloadHeader = this.c;
if (fileDownloadHeader == null || fileDownloadHeader.getHeaders().get("User-Agent") == null) {
fileDownloadConnection.a("User-Agent", FileDownloadUtils.a());
}
}
void a(long j) {
ConnectionProfile connectionProfile = this.d;
long j2 = connectionProfile.b;
if (j == j2) {
FileDownloadLog.e(this, "no data download, no need to update", new Object[0]);
return;
}
this.d = ConnectionProfile.ConnectionProfileBuild.a(connectionProfile.a, j, connectionProfile.c, connectionProfile.d - (j - j2));
if (FileDownloadLog.a) {
FileDownloadLog.c(this, "after update profile:%s", this.d);
}
}
public Map<String, List<String>> d() {
return this.f;
}
boolean e() {
return this.d.b > 0;
}
private ConnectTask(ConnectionProfile connectionProfile, int i, String str, String str2, FileDownloadHeader fileDownloadHeader) {
this.a = i;
this.b = str;
this.e = str2;
this.c = fileDownloadHeader;
this.d = connectionProfile;
}
public ConnectionProfile c() {
return this.d;
}
FileDownloadConnection a() throws IOException, IllegalAccessException {
FileDownloadConnection a = CustomComponentHolder.i().a(this.b);
b(a);
a(a);
c(a);
this.f = a.e();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "<---- %s request header %s", Integer.valueOf(this.a), this.f);
}
a.execute();
this.g = new ArrayList();
FileDownloadConnection a2 = RedirectHandler.a(this.f, a, this.g);
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "----> %s response header %s", Integer.valueOf(this.a), a2.b());
}
return a2;
}
String b() {
List<String> list = this.g;
if (list == null || list.isEmpty()) {
return null;
}
return this.g.get(r0.size() - 1);
}
private void a(FileDownloadConnection fileDownloadConnection) throws ProtocolException {
if (fileDownloadConnection.a(this.e, this.d.a)) {
return;
}
if (!TextUtils.isEmpty(this.e)) {
fileDownloadConnection.a("If-Match", this.e);
}
this.d.a(fileDownloadConnection);
}
}

View File

@@ -0,0 +1,78 @@
package com.liulishuo.filedownloader.download;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.net.ProtocolException;
/* loaded from: classes.dex */
public class ConnectionProfile {
final long a;
final long b;
final long c;
final long d;
private final boolean e;
private final boolean f;
public static class ConnectionProfileBuild {
public static ConnectionProfile a() {
return new ConnectionProfile();
}
public static ConnectionProfile b() {
return new ConnectionProfile(0L, 0L, 0L, 0L, true);
}
public static ConnectionProfile a(long j) {
return new ConnectionProfile(0L, 0L, -1L, j);
}
public static ConnectionProfile a(long j, long j2, long j3) {
return new ConnectionProfile(j, j2, -1L, j3);
}
public static ConnectionProfile a(long j, long j2, long j3, long j4) {
return new ConnectionProfile(j, j2, j3, j4);
}
}
public void a(FileDownloadConnection fileDownloadConnection) throws ProtocolException {
if (this.e) {
return;
}
if (this.f && FileDownloadProperties.a().h) {
fileDownloadConnection.b("HEAD");
}
fileDownloadConnection.a("Range", this.c == -1 ? FileDownloadUtils.a("bytes=%d-", Long.valueOf(this.b)) : FileDownloadUtils.a("bytes=%d-%d", Long.valueOf(this.b), Long.valueOf(this.c)));
}
public String toString() {
return FileDownloadUtils.a("range[%d, %d) current offset[%d]", Long.valueOf(this.a), Long.valueOf(this.c), Long.valueOf(this.b));
}
private ConnectionProfile() {
this.a = 0L;
this.b = 0L;
this.c = 0L;
this.d = 0L;
this.e = false;
this.f = true;
}
private ConnectionProfile(long j, long j2, long j3, long j4) {
this(j, j2, j3, j4, false);
}
private ConnectionProfile(long j, long j2, long j3, long j4, boolean z) {
if ((j == 0 && j3 == 0) || !z) {
this.a = j;
this.b = j2;
this.c = j3;
this.d = j4;
this.e = z;
this.f = false;
return;
}
throw new IllegalArgumentException();
}
}

View File

@@ -0,0 +1,168 @@
package com.liulishuo.filedownloader.download;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.services.DownloadMgrInitialParams;
import com.liulishuo.filedownloader.services.ForegroundServiceConfig;
import com.liulishuo.filedownloader.stream.FileDownloadOutputStream;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import java.io.File;
import java.io.IOException;
/* loaded from: classes.dex */
public class CustomComponentHolder {
private DownloadMgrInitialParams a;
private FileDownloadHelper.ConnectionCountAdapter b;
private FileDownloadHelper.ConnectionCreator c;
private FileDownloadHelper.OutputStreamCreator d;
private FileDownloadDatabase e;
private FileDownloadHelper.IdGenerator f;
private ForegroundServiceConfig g;
private static final class LazyLoader {
private static final CustomComponentHolder a = new CustomComponentHolder();
}
private FileDownloadHelper.ConnectionCountAdapter f() {
FileDownloadHelper.ConnectionCountAdapter connectionCountAdapter = this.b;
if (connectionCountAdapter != null) {
return connectionCountAdapter;
}
synchronized (this) {
if (this.b == null) {
this.b = h().a();
}
}
return this.b;
}
private FileDownloadHelper.ConnectionCreator g() {
FileDownloadHelper.ConnectionCreator connectionCreator = this.c;
if (connectionCreator != null) {
return connectionCreator;
}
synchronized (this) {
if (this.c == null) {
this.c = h().b();
}
}
return this.c;
}
private DownloadMgrInitialParams h() {
DownloadMgrInitialParams downloadMgrInitialParams = this.a;
if (downloadMgrInitialParams != null) {
return downloadMgrInitialParams;
}
synchronized (this) {
if (this.a == null) {
this.a = new DownloadMgrInitialParams();
}
}
return this.a;
}
public static CustomComponentHolder i() {
return LazyLoader.a;
}
private FileDownloadHelper.OutputStreamCreator j() {
FileDownloadHelper.OutputStreamCreator outputStreamCreator = this.d;
if (outputStreamCreator != null) {
return outputStreamCreator;
}
synchronized (this) {
if (this.d == null) {
this.d = h().f();
}
}
return this.d;
}
public FileDownloadConnection a(String str) throws IOException {
return g().a(str);
}
public ForegroundServiceConfig b() {
ForegroundServiceConfig foregroundServiceConfig = this.g;
if (foregroundServiceConfig != null) {
return foregroundServiceConfig;
}
synchronized (this) {
if (this.g == null) {
this.g = h().d();
}
}
return this.g;
}
public FileDownloadHelper.IdGenerator c() {
FileDownloadHelper.IdGenerator idGenerator = this.f;
if (idGenerator != null) {
return idGenerator;
}
synchronized (this) {
if (this.f == null) {
this.f = h().e();
}
}
return this.f;
}
public int d() {
return h().g();
}
public boolean e() {
return j().a();
}
public FileDownloadOutputStream a(File file) throws IOException {
return j().a(file);
}
public FileDownloadDatabase a() {
FileDownloadDatabase fileDownloadDatabase = this.e;
if (fileDownloadDatabase != null) {
return fileDownloadDatabase;
}
synchronized (this) {
if (this.e == null) {
this.e = h().c();
a(this.e.a());
}
}
return this.e;
}
public int a(int i, String str, String str2, long j) {
return f().a(i, str, str2, j);
}
/* JADX WARN: Code restructure failed: missing block: B:55:0x00d4, code lost:
if (r8.getSoFar() > 0) goto L46;
*/
/* JADX WARN: Code restructure failed: missing block: B:79:0x0051, code lost:
if (r8.getSoFar() <= 0) goto L18;
*/
/* JADX WARN: Removed duplicated region for block: B:12:0x005c */
/* JADX WARN: Removed duplicated region for block: B:15:0x00fb A[Catch: all -> 0x013f, TryCatch #3 {all -> 0x013f, blocks: (B:26:0x00f1, B:15:0x00fb, B:17:0x0111, B:19:0x0115, B:20:0x012d, B:21:0x0134, B:51:0x00a3, B:52:0x00c5, B:54:0x00cc, B:57:0x00da, B:60:0x00e5), top: B:25:0x00f1 }] */
/* JADX WARN: Removed duplicated region for block: B:25:0x00f1 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:33:0x019b */
/* JADX WARN: Removed duplicated region for block: B:36:0x0065 A[Catch: all -> 0x0141, TryCatch #0 {all -> 0x0141, blocks: (B:72:0x0034, B:74:0x003b, B:76:0x0042, B:78:0x0049, B:10:0x0056, B:36:0x0065, B:38:0x0070, B:9:0x0053), top: B:71:0x0034 }] */
/* JADX WARN: Removed duplicated region for block: B:54:0x00cc A[Catch: all -> 0x013f, TryCatch #3 {all -> 0x013f, blocks: (B:26:0x00f1, B:15:0x00fb, B:17:0x0111, B:19:0x0115, B:20:0x012d, B:21:0x0134, B:51:0x00a3, B:52:0x00c5, B:54:0x00cc, B:57:0x00da, B:60:0x00e5), top: B:25:0x00f1 }] */
/* JADX WARN: Removed duplicated region for block: B:64:0x00d8 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
private static void a(com.liulishuo.filedownloader.database.FileDownloadDatabase.Maintainer r26) {
/*
Method dump skipped, instructions count: 452
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.download.CustomComponentHolder.a(com.liulishuo.filedownloader.database.FileDownloadDatabase$Maintainer):void");
}
}

View File

@@ -0,0 +1,619 @@
package com.liulishuo.filedownloader.download;
import com.liulishuo.filedownloader.IThreadPoolMonitor;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.download.ConnectTask;
import com.liulishuo.filedownloader.download.ConnectionProfile;
import com.liulishuo.filedownloader.download.DownloadRunnable;
import com.liulishuo.filedownloader.exception.FileDownloadGiveUpRetryException;
import com.liulishuo.filedownloader.exception.FileDownloadHttpException;
import com.liulishuo.filedownloader.exception.FileDownloadNetworkPolicyException;
import com.liulishuo.filedownloader.exception.FileDownloadOutOfSpaceException;
import com.liulishuo.filedownloader.exception.FileDownloadSecurityException;
import com.liulishuo.filedownloader.model.ConnectionModel;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.stream.FileDownloadOutputStream;
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicBoolean;
/* loaded from: classes.dex */
public class DownloadLaunchRunnable implements Runnable, ProcessCallback {
private static final ThreadPoolExecutor x = FileDownloadExecutors.a("ConnectionBlock");
private final DownloadStatusCallback a;
private final FileDownloadModel b;
private final FileDownloadHeader c;
private final boolean d;
private final boolean e;
private final FileDownloadDatabase f;
private final IThreadPoolMonitor g;
private boolean h;
int i;
private boolean j;
private final boolean k;
private final ArrayList<DownloadRunnable> l;
private DownloadRunnable m;
private boolean n;
private boolean o;
private boolean p;
private boolean q;
private final AtomicBoolean r;
private volatile boolean s;
private volatile boolean t;
private volatile Exception u;
private String v;
public static class Builder {
private FileDownloadModel a;
private FileDownloadHeader b;
private IThreadPoolMonitor c;
private Integer d;
private Integer e;
private Boolean f;
private Boolean g;
private Integer h;
public Builder a(FileDownloadModel fileDownloadModel) {
this.a = fileDownloadModel;
return this;
}
public Builder b(Boolean bool) {
this.g = bool;
return this;
}
public Builder c(Integer num) {
this.d = num;
return this;
}
public Builder a(FileDownloadHeader fileDownloadHeader) {
this.b = fileDownloadHeader;
return this;
}
public Builder b(Integer num) {
this.h = num;
return this;
}
public Builder a(IThreadPoolMonitor iThreadPoolMonitor) {
this.c = iThreadPoolMonitor;
return this;
}
public Builder a(Integer num) {
this.e = num;
return this;
}
public Builder a(Boolean bool) {
this.f = bool;
return this;
}
public DownloadLaunchRunnable a() {
IThreadPoolMonitor iThreadPoolMonitor;
Integer num;
FileDownloadModel fileDownloadModel = this.a;
if (fileDownloadModel != null && (iThreadPoolMonitor = this.c) != null && (num = this.d) != null && this.e != null && this.f != null && this.g != null && this.h != null) {
return new DownloadLaunchRunnable(fileDownloadModel, this.b, iThreadPoolMonitor, num.intValue(), this.e.intValue(), this.f.booleanValue(), this.g.booleanValue(), this.h.intValue());
}
throw new IllegalArgumentException();
}
}
class DiscardSafely extends Throwable {
DiscardSafely(DownloadLaunchRunnable downloadLaunchRunnable) {
}
}
class RetryDirectly extends Throwable {
RetryDirectly(DownloadLaunchRunnable downloadLaunchRunnable) {
}
}
private int b(long j) {
if (k()) {
return this.o ? this.b.getConnectionCount() : CustomComponentHolder.i().a(this.b.getId(), this.b.getUrl(), this.b.getPath(), j);
}
return 1;
}
private void c(long j) throws IOException, IllegalAccessException {
ConnectionProfile a;
if (this.p) {
a = ConnectionProfile.ConnectionProfileBuild.a(this.b.getSoFar(), this.b.getSoFar(), j - this.b.getSoFar());
} else {
this.b.setSoFar(0L);
a = ConnectionProfile.ConnectionProfileBuild.a(j);
}
DownloadRunnable.Builder builder = new DownloadRunnable.Builder();
builder.a(this.b.getId());
builder.a((Integer) (-1));
builder.a(this);
builder.c(this.b.getUrl());
builder.a(this.b.getETag());
builder.a(this.c);
builder.a(this.e);
builder.a(a);
builder.b(this.b.getTempFilePath());
this.m = builder.a();
this.b.setConnectionCount(1);
this.f.a(this.b.getId(), 1);
if (!this.s) {
this.m.run();
} else {
this.b.setStatus((byte) -2);
this.m.pause();
}
}
private void f() throws RetryDirectly, DiscardSafely {
int id = this.b.getId();
if (this.b.isPathAsDirectory()) {
String targetFilePath = this.b.getTargetFilePath();
int c = FileDownloadUtils.c(this.b.getUrl(), targetFilePath);
if (FileDownloadHelper.a(id, targetFilePath, this.d, false)) {
this.f.remove(id);
this.f.b(id);
throw new DiscardSafely(this);
}
FileDownloadModel e = this.f.e(c);
if (e != null) {
if (FileDownloadHelper.a(id, e, this.g, false)) {
this.f.remove(id);
this.f.b(id);
throw new DiscardSafely(this);
}
List<ConnectionModel> d = this.f.d(c);
this.f.remove(c);
this.f.b(c);
FileDownloadUtils.d(this.b.getTargetFilePath());
if (FileDownloadUtils.a(c, e)) {
this.b.setSoFar(e.getSoFar());
this.b.setTotal(e.getTotal());
this.b.setETag(e.getETag());
this.b.setConnectionCount(e.getConnectionCount());
this.f.a(this.b);
if (d != null) {
for (ConnectionModel connectionModel : d) {
connectionModel.a(id);
this.f.a(connectionModel);
}
}
throw new RetryDirectly(this);
}
}
if (FileDownloadHelper.a(id, this.b.getSoFar(), this.b.getTempFilePath(), targetFilePath, this.g)) {
this.f.remove(id);
this.f.b(id);
throw new DiscardSafely(this);
}
}
}
private void j() throws FileDownloadGiveUpRetryException {
if (this.e && !FileDownloadUtils.a("android.permission.ACCESS_NETWORK_STATE")) {
throw new FileDownloadGiveUpRetryException(FileDownloadUtils.a("Task[%d] can't start the download runnable, because this task require wifi, but user application nor current process has %s, so we can't check whether the network type connection.", Integer.valueOf(this.b.getId()), "android.permission.ACCESS_NETWORK_STATE"));
}
if (this.e && FileDownloadUtils.e()) {
throw new FileDownloadNetworkPolicyException();
}
}
private boolean k() {
return (!this.o || this.b.getConnectionCount() > 1) && this.p && this.k && !this.q;
}
private void l() throws IOException, RetryDirectly, IllegalAccessException, FileDownloadSecurityException {
FileDownloadConnection fileDownloadConnection = null;
try {
ConnectionProfile b = this.j ? ConnectionProfile.ConnectionProfileBuild.b() : ConnectionProfile.ConnectionProfileBuild.a();
ConnectTask.Builder builder = new ConnectTask.Builder();
builder.a(this.b.getId());
builder.b(this.b.getUrl());
builder.a(this.b.getETag());
builder.a(this.c);
builder.a(b);
ConnectTask a = builder.a();
fileDownloadConnection = a.a();
a(a.d(), a, fileDownloadConnection);
} finally {
if (fileDownloadConnection != null) {
fileDownloadConnection.d();
}
}
}
/* JADX WARN: Removed duplicated region for block: B:12:0x0068 */
/* JADX WARN: Removed duplicated region for block: B:15:? A[RETURN, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:9:0x0061 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
void a(java.util.List<com.liulishuo.filedownloader.model.ConnectionModel> r11) {
/*
r10 = this;
com.liulishuo.filedownloader.model.FileDownloadModel r0 = r10.b
int r0 = r0.getConnectionCount()
com.liulishuo.filedownloader.model.FileDownloadModel r1 = r10.b
java.lang.String r1 = r1.getTempFilePath()
com.liulishuo.filedownloader.model.FileDownloadModel r2 = r10.b
java.lang.String r2 = r2.getTargetFilePath()
r3 = 0
r4 = 1
if (r0 <= r4) goto L18
r5 = 1
goto L19
L18:
r5 = 0
L19:
boolean r6 = r10.j
r7 = 0
if (r6 == 0) goto L21
L1f:
r5 = r7
goto L58
L21:
if (r5 == 0) goto L28
boolean r6 = r10.k
if (r6 != 0) goto L28
goto L1f
L28:
com.liulishuo.filedownloader.model.FileDownloadModel r6 = r10.b
int r6 = r6.getId()
com.liulishuo.filedownloader.model.FileDownloadModel r9 = r10.b
boolean r6 = com.liulishuo.filedownloader.util.FileDownloadUtils.a(r6, r9)
if (r6 == 0) goto L1f
boolean r6 = r10.k
if (r6 != 0) goto L44
java.io.File r11 = new java.io.File
r11.<init>(r1)
long r5 = r11.length()
goto L58
L44:
if (r5 == 0) goto L52
int r5 = r11.size()
if (r0 == r5) goto L4d
goto L1f
L4d:
long r5 = com.liulishuo.filedownloader.model.ConnectionModel.a(r11)
goto L58
L52:
com.liulishuo.filedownloader.model.FileDownloadModel r11 = r10.b
long r5 = r11.getSoFar()
L58:
com.liulishuo.filedownloader.model.FileDownloadModel r11 = r10.b
r11.setSoFar(r5)
int r11 = (r5 > r7 ? 1 : (r5 == r7 ? 0 : -1))
if (r11 <= 0) goto L62
r3 = 1
L62:
r10.o = r3
boolean r11 = r10.o
if (r11 != 0) goto L76
com.liulishuo.filedownloader.database.FileDownloadDatabase r11 = r10.f
com.liulishuo.filedownloader.model.FileDownloadModel r0 = r10.b
int r0 = r0.getId()
r11.b(r0)
com.liulishuo.filedownloader.util.FileDownloadUtils.a(r2, r1)
L76:
return
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.download.DownloadLaunchRunnable.a(java.util.List):void");
}
public boolean d() {
return this.r.get() || this.a.b();
}
public void e() {
a(this.f.d(this.b.getId()));
this.a.f();
}
public void pause() {
this.s = true;
DownloadRunnable downloadRunnable = this.m;
if (downloadRunnable != null) {
downloadRunnable.pause();
}
Iterator it = ((ArrayList) this.l.clone()).iterator();
while (it.hasNext()) {
DownloadRunnable downloadRunnable2 = (DownloadRunnable) it.next();
if (downloadRunnable2 != null) {
downloadRunnable2.pause();
}
}
}
/* JADX WARN: Removed duplicated region for block: B:106:0x01c3 A[Catch: all -> 0x01f8, TryCatch #13 {all -> 0x01f8, blocks: (B:3:0x0003, B:6:0x0012, B:8:0x001a, B:10:0x001e, B:25:0x0030, B:26:0x008d, B:28:0x0091, B:30:0x0096, B:116:0x009a, B:118:0x009e, B:33:0x00c6, B:35:0x00e2, B:44:0x0100, B:56:0x0136, B:58:0x013a, B:69:0x015f, B:71:0x0165, B:85:0x0169, B:87:0x0172, B:88:0x0176, B:90:0x017a, B:91:0x018d, B:100:0x018e, B:104:0x01bd, B:106:0x01c3, B:109:0x01c8), top: B:2:0x0003, inners: #15, #12, #11 }] */
/* JADX WARN: Removed duplicated region for block: B:108:0x01c8 A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:74:0x01d4 */
/* JADX WARN: Removed duplicated region for block: B:77:0x01da */
@Override // java.lang.Runnable
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public void run() {
/*
Method dump skipped, instructions count: 550
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.download.DownloadLaunchRunnable.run():void");
}
private DownloadLaunchRunnable(FileDownloadModel fileDownloadModel, FileDownloadHeader fileDownloadHeader, IThreadPoolMonitor iThreadPoolMonitor, int i, int i2, boolean z, boolean z2, int i3) {
this.j = false;
this.l = new ArrayList<>(5);
this.r = new AtomicBoolean(true);
this.s = false;
this.h = false;
this.b = fileDownloadModel;
this.c = fileDownloadHeader;
this.d = z;
this.e = z2;
this.f = CustomComponentHolder.i().a();
this.k = CustomComponentHolder.i().e();
this.g = iThreadPoolMonitor;
this.i = i3;
this.a = new DownloadStatusCallback(fileDownloadModel, i3, i, i2);
}
@Override // com.liulishuo.filedownloader.download.ProcessCallback
public void b(Exception exc) {
if (this.s) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "the task[%d] has already been paused, so pass the retry callback", Integer.valueOf(this.b.getId()));
}
} else {
int i = this.i;
this.i = i - 1;
if (i < 0) {
FileDownloadLog.b(this, "valid retry times is less than 0(%d) for download task(%d)", Integer.valueOf(this.i), Integer.valueOf(this.b.getId()));
}
this.a.a(exc, this.i);
}
}
/* JADX WARN: Removed duplicated region for block: B:11:0x008a */
/* JADX WARN: Removed duplicated region for block: B:22:0x011b */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
private void a(java.util.Map<java.lang.String, java.util.List<java.lang.String>> r18, com.liulishuo.filedownloader.download.ConnectTask r19, com.liulishuo.filedownloader.connection.FileDownloadConnection r20) throws java.io.IOException, com.liulishuo.filedownloader.download.DownloadLaunchRunnable.RetryDirectly, java.lang.IllegalArgumentException, com.liulishuo.filedownloader.exception.FileDownloadSecurityException {
/*
Method dump skipped, instructions count: 357
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.download.DownloadLaunchRunnable.a(java.util.Map, com.liulishuo.filedownloader.download.ConnectTask, com.liulishuo.filedownloader.connection.FileDownloadConnection):void");
}
public int b() {
return this.b.getId();
}
@Override // com.liulishuo.filedownloader.download.ProcessCallback
public boolean c(Exception exc) {
if (exc instanceof FileDownloadHttpException) {
int code = ((FileDownloadHttpException) exc).getCode();
if (this.n && code == 416 && !this.h) {
FileDownloadUtils.a(this.b.getTargetFilePath(), this.b.getTempFilePath());
this.h = true;
return true;
}
}
return this.i > 0 && !(exc instanceof FileDownloadGiveUpRetryException);
}
public String c() {
return this.b.getTempFilePath();
}
private void a(int i, List<ConnectionModel> list) throws InterruptedException {
if (i > 1 && list.size() == i) {
a(list, this.b.getTotal());
return;
}
throw new IllegalArgumentException();
}
private void a(long j, int i) throws InterruptedException {
long j2 = j / i;
int id = this.b.getId();
ArrayList arrayList = new ArrayList();
long j3 = 0;
int i2 = 0;
while (i2 < i) {
long j4 = i2 == i + (-1) ? -1L : (j3 + j2) - 1;
ConnectionModel connectionModel = new ConnectionModel();
connectionModel.a(id);
connectionModel.b(i2);
connectionModel.c(j3);
connectionModel.a(j3);
connectionModel.b(j4);
arrayList.add(connectionModel);
this.f.a(connectionModel);
j3 += j2;
i2++;
}
this.b.setConnectionCount(i);
this.f.a(id, i);
a(arrayList, j);
}
private void a(List<ConnectionModel> list, long j) throws InterruptedException {
long b;
int id = this.b.getId();
String eTag = this.b.getETag();
String str = this.v;
if (str == null) {
str = this.b.getUrl();
}
String tempFilePath = this.b.getTempFilePath();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "fetch data with multiple connection(count: [%d]) for task[%d] totalLength[%d]", Integer.valueOf(list.size()), Integer.valueOf(id), Long.valueOf(j));
}
boolean z = this.o;
long j2 = 0;
long j3 = 0;
for (ConnectionModel connectionModel : list) {
if (connectionModel.b() == -1) {
b = j - connectionModel.a();
} else {
b = (connectionModel.b() - connectionModel.a()) + 1;
}
long j4 = b;
j3 += connectionModel.a() - connectionModel.e();
if (j4 == j2) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "pass connection[%d-%d], because it has been completed", Integer.valueOf(connectionModel.c()), Integer.valueOf(connectionModel.d()));
}
} else {
DownloadRunnable.Builder builder = new DownloadRunnable.Builder();
ConnectionProfile a = ConnectionProfile.ConnectionProfileBuild.a(connectionModel.e(), connectionModel.a(), connectionModel.b(), j4);
builder.a(id);
builder.a(Integer.valueOf(connectionModel.d()));
builder.a(this);
builder.c(str);
builder.a(z ? eTag : null);
builder.a(this.c);
builder.a(this.e);
builder.a(a);
builder.b(tempFilePath);
DownloadRunnable a2 = builder.a();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "enable multiple connection: %s", connectionModel);
}
if (a2 != null) {
this.l.add(a2);
} else {
throw new IllegalArgumentException("the download runnable must not be null!");
}
}
j2 = 0;
}
if (j3 != this.b.getSoFar()) {
FileDownloadLog.e(this, "correct the sofar[%d] from connection table[%d]", Long.valueOf(this.b.getSoFar()), Long.valueOf(j3));
this.b.setSoFar(j3);
}
ArrayList arrayList = new ArrayList(this.l.size());
Iterator<DownloadRunnable> it = this.l.iterator();
while (it.hasNext()) {
DownloadRunnable next = it.next();
if (this.s) {
next.pause();
} else {
arrayList.add(Executors.callable(next));
}
}
if (this.s) {
this.b.setStatus((byte) -2);
return;
}
List<Future> invokeAll = x.invokeAll(arrayList);
if (FileDownloadLog.a) {
for (Future future : invokeAll) {
FileDownloadLog.a(this, "finish sub-task for [%d] %B %B", Integer.valueOf(id), Boolean.valueOf(future.isDone()), Boolean.valueOf(future.isCancelled()));
}
}
}
private void a(long j, String str) throws IOException, IllegalAccessException {
FileDownloadOutputStream fileDownloadOutputStream = null;
if (j != -1) {
try {
fileDownloadOutputStream = FileDownloadUtils.c(this.b.getTempFilePath());
long length = new File(str).length();
long j2 = j - length;
long h = FileDownloadUtils.h(str);
if (h >= j2) {
if (!FileDownloadProperties.a().f) {
fileDownloadOutputStream.a(j);
}
} else {
throw new FileDownloadOutOfSpaceException(h, j2, length);
}
} finally {
if (0 != 0) {
fileDownloadOutputStream.close();
}
}
}
}
@Override // com.liulishuo.filedownloader.download.ProcessCallback
public void a(long j) {
if (this.s) {
return;
}
this.a.a(j);
}
@Override // com.liulishuo.filedownloader.download.ProcessCallback
public void a(DownloadRunnable downloadRunnable, long j, long j2) {
if (this.s) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "the task[%d] has already been paused, so pass the completed callback", Integer.valueOf(this.b.getId()));
return;
}
return;
}
int i = downloadRunnable.h;
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "the connection has been completed(%d): [%d, %d) %d", Integer.valueOf(i), Long.valueOf(j), Long.valueOf(j2), Long.valueOf(this.b.getTotal()));
}
if (!this.n) {
synchronized (this.l) {
this.l.remove(downloadRunnable);
}
} else {
if (j == 0 || j2 == this.b.getTotal()) {
return;
}
FileDownloadLog.b(this, "the single task not completed corrected(%d, %d != %d) for task(%d)", Long.valueOf(j), Long.valueOf(j2), Long.valueOf(this.b.getTotal()), Integer.valueOf(this.b.getId()));
}
}
@Override // com.liulishuo.filedownloader.download.ProcessCallback
public void a(Exception exc) {
this.t = true;
this.u = exc;
if (this.s) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "the task[%d] has already been paused, so pass the error callback", Integer.valueOf(this.b.getId()));
}
} else {
Iterator it = ((ArrayList) this.l.clone()).iterator();
while (it.hasNext()) {
DownloadRunnable downloadRunnable = (DownloadRunnable) it.next();
if (downloadRunnable != null) {
downloadRunnable.a();
}
}
}
}
@Override // com.liulishuo.filedownloader.download.ProcessCallback
public void a() {
this.f.b(this.b.getId(), this.b.getSoFar());
}
}

View File

@@ -0,0 +1,129 @@
package com.liulishuo.filedownloader.download;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.download.ConnectTask;
import com.liulishuo.filedownloader.model.ConnectionModel;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
/* loaded from: classes.dex */
public class DownloadRunnable implements Runnable {
private final ConnectTask a;
private final ProcessCallback b;
private final String c;
private final boolean d;
private FetchDataTask e;
private volatile boolean f;
private final int g;
final int h;
public static class Builder {
private final ConnectTask.Builder a = new ConnectTask.Builder();
private ProcessCallback b;
private String c;
private Boolean d;
private Integer e;
public Builder a(ProcessCallback processCallback) {
this.b = processCallback;
return this;
}
public Builder b(String str) {
this.c = str;
return this;
}
public Builder c(String str) {
this.a.b(str);
return this;
}
public Builder a(int i) {
this.a.a(i);
return this;
}
public Builder a(String str) {
this.a.a(str);
return this;
}
public Builder a(FileDownloadHeader fileDownloadHeader) {
this.a.a(fileDownloadHeader);
return this;
}
public Builder a(ConnectionProfile connectionProfile) {
this.a.a(connectionProfile);
return this;
}
public Builder a(boolean z) {
this.d = Boolean.valueOf(z);
return this;
}
public Builder a(Integer num) {
this.e = num;
return this;
}
public DownloadRunnable a() {
if (this.b != null && this.c != null && this.d != null && this.e != null) {
ConnectTask a = this.a.a();
return new DownloadRunnable(a.a, this.e.intValue(), a, this.b, this.d.booleanValue(), this.c);
}
throw new IllegalArgumentException(FileDownloadUtils.a("%s %s %B", this.b, this.c, this.d));
}
}
private long b() {
FileDownloadDatabase a = CustomComponentHolder.i().a();
if (this.h < 0) {
return a.e(this.g).getSoFar();
}
for (ConnectionModel connectionModel : a.d(this.g)) {
if (connectionModel.d() == this.h) {
return connectionModel.a();
}
}
return 0L;
}
public void a() {
pause();
}
public void pause() {
this.f = true;
FetchDataTask fetchDataTask = this.e;
if (fetchDataTask != null) {
fetchDataTask.a();
}
}
/* JADX WARN: Removed duplicated region for block: B:71:0x014f */
@Override // java.lang.Runnable
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public void run() {
/*
Method dump skipped, instructions count: 339
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.download.DownloadRunnable.run():void");
}
private DownloadRunnable(int i, int i2, ConnectTask connectTask, ProcessCallback processCallback, boolean z, String str) {
this.g = i;
this.h = i2;
this.f = false;
this.b = processCallback;
this.c = str;
this.a = connectTask;
this.d = z;
}
}

View File

@@ -0,0 +1,430 @@
package com.liulishuo.filedownloader.download;
import android.database.sqlite.SQLiteFullException;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.exception.FileDownloadGiveUpRetryException;
import com.liulishuo.filedownloader.exception.FileDownloadOutOfSpaceException;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.message.MessageSnapshotTaker;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.services.FileDownloadBroadcastHandler;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.LockSupport;
/* loaded from: classes.dex */
public class DownloadStatusCallback implements Handler.Callback {
private final FileDownloadModel a;
private final ProcessParams c;
private final int d;
private final int e;
private final int f;
private long g;
private Handler h;
private HandlerThread i;
private volatile Thread k;
private volatile boolean j = false;
private volatile long l = 0;
private final AtomicLong m = new AtomicLong();
private final AtomicBoolean n = new AtomicBoolean(false);
private final AtomicBoolean o = new AtomicBoolean(false);
private final AtomicBoolean p = new AtomicBoolean(true);
private final FileDownloadDatabase b = CustomComponentHolder.i().a();
public static class ProcessParams {
private boolean a;
private Exception b;
private int c;
void a(boolean z) {
this.a = z;
}
public int b() {
return this.c;
}
public boolean c() {
return this.a;
}
void a(Exception exc) {
this.b = exc;
}
void a(int i) {
this.c = i;
}
public Exception a() {
return this.b;
}
}
DownloadStatusCallback(FileDownloadModel fileDownloadModel, int i, int i2, int i3) {
this.a = fileDownloadModel;
this.e = i2 >= 5 ? i2 : 5;
this.f = i3;
this.c = new ProcessParams();
this.d = i;
}
private void h() throws IOException {
l();
this.a.setStatus((byte) -3);
this.b.a(this.a.getId(), this.a.getTotal());
this.b.b(this.a.getId());
a((byte) -3);
if (FileDownloadProperties.a().g) {
FileDownloadBroadcastHandler.a(this.a);
}
}
private void i() {
this.a.setStatus((byte) -2);
this.b.c(this.a.getId(), this.a.getSoFar());
a((byte) -2);
}
private void j() {
if (this.a.getSoFar() == this.a.getTotal()) {
this.b.b(this.a.getId(), this.a.getSoFar());
return;
}
if (this.o.compareAndSet(true, false)) {
if (FileDownloadLog.a) {
FileDownloadLog.c(this, "handleProgress update model's status with progress", new Object[0]);
}
this.a.setStatus((byte) 3);
}
if (this.n.compareAndSet(true, false)) {
if (FileDownloadLog.a) {
FileDownloadLog.c(this, "handleProgress notify user progress status", new Object[0]);
}
a((byte) 3);
}
}
private boolean k() {
if (this.a.isChunked()) {
FileDownloadModel fileDownloadModel = this.a;
fileDownloadModel.setTotal(fileDownloadModel.getSoFar());
} else if (this.a.getSoFar() != this.a.getTotal()) {
a(new FileDownloadGiveUpRetryException(FileDownloadUtils.a("sofar[%d] not equal total[%d]", Long.valueOf(this.a.getSoFar()), Long.valueOf(this.a.getTotal()))));
return true;
}
return false;
}
private void l() throws IOException {
boolean z;
String tempFilePath = this.a.getTempFilePath();
String targetFilePath = this.a.getTargetFilePath();
File file = new File(tempFilePath);
try {
File file2 = new File(targetFilePath);
if (file2.exists()) {
long length = file2.length();
if (!file2.delete()) {
throw new IOException(FileDownloadUtils.a("Can't delete the old file([%s], [%d]), so can't replace it with the new downloaded one.", targetFilePath, Long.valueOf(length)));
}
FileDownloadLog.e(this, "The target file([%s], [%d]) will be replaced with the new downloaded file[%d]", targetFilePath, Long.valueOf(length), Long.valueOf(file.length()));
}
z = !file.renameTo(file2);
if (!z) {
if (z && file.exists() && !file.delete()) {
FileDownloadLog.e(this, "delete the temp file(%s) failed, on completed downloading.", tempFilePath);
return;
}
return;
}
try {
throw new IOException(FileDownloadUtils.a("Can't rename the temp downloaded file(%s) to the target file(%s)", tempFilePath, targetFilePath));
} catch (Throwable th) {
th = th;
if (z && file.exists() && !file.delete()) {
FileDownloadLog.e(this, "delete the temp file(%s) failed, on completed downloading.", tempFilePath);
}
throw th;
}
} catch (Throwable th2) {
th = th2;
z = true;
}
}
void a() {
Handler handler = this.h;
if (handler != null) {
handler.removeCallbacksAndMessages(null);
this.i.quit();
this.k = Thread.currentThread();
while (this.j) {
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
}
this.k = null;
}
}
public boolean b() {
HandlerThread handlerThread = this.i;
return handlerThread != null && handlerThread.isAlive();
}
void c() throws IOException {
if (k()) {
return;
}
h();
}
void d() {
this.i = new HandlerThread("source-status-callback");
this.i.start();
this.h = new Handler(this.i.getLooper(), this);
}
void e() {
i();
}
public void f() {
this.a.setStatus((byte) 1);
this.b.a(this.a.getId());
a((byte) 1);
}
void g() {
this.a.setStatus((byte) 6);
a((byte) 6);
this.b.c(this.a.getId());
}
/* JADX WARN: Removed duplicated region for block: B:11:0x0020 A[DONT_GENERATE] */
@Override // android.os.Handler.Callback
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public boolean handleMessage(android.os.Message r5) {
/*
r4 = this;
r0 = 1
r4.j = r0
int r1 = r5.what
r2 = 3
r3 = 0
if (r1 == r2) goto L17
r2 = 5
if (r1 == r2) goto Ld
goto L1a
Ld:
java.lang.Object r1 = r5.obj // Catch: java.lang.Throwable -> L26
java.lang.Exception r1 = (java.lang.Exception) r1 // Catch: java.lang.Throwable -> L26
int r5 = r5.arg1 // Catch: java.lang.Throwable -> L26
r4.b(r1, r5) // Catch: java.lang.Throwable -> L26
goto L1a
L17:
r4.j() // Catch: java.lang.Throwable -> L26
L1a:
r4.j = r3
java.lang.Thread r5 = r4.k
if (r5 == 0) goto L25
java.lang.Thread r5 = r4.k
java.util.concurrent.locks.LockSupport.unpark(r5)
L25:
return r0
L26:
r5 = move-exception
r4.j = r3
java.lang.Thread r0 = r4.k
if (r0 == 0) goto L32
java.lang.Thread r0 = r4.k
java.util.concurrent.locks.LockSupport.unpark(r0)
L32:
throw r5
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.download.DownloadStatusCallback.handleMessage(android.os.Message):boolean");
}
private Exception b(Exception exc) {
long length;
String tempFilePath = this.a.getTempFilePath();
if ((!this.a.isChunked() && !FileDownloadProperties.a().f) || !(exc instanceof IOException) || !new File(tempFilePath).exists()) {
return exc;
}
long h = FileDownloadUtils.h(tempFilePath);
if (h > 4096) {
return exc;
}
File file = new File(tempFilePath);
if (file.exists()) {
length = file.length();
} else {
FileDownloadLog.a(this, exc, "Exception with: free space isn't enough, and the target file not exist.", new Object[0]);
length = 0;
}
return Build.VERSION.SDK_INT >= 9 ? new FileDownloadOutOfSpaceException(h, 4096L, length, exc) : new FileDownloadOutOfSpaceException(h, 4096L, length);
}
private void c(Exception exc) {
Exception exc2;
Exception b = b(exc);
if (b instanceof SQLiteFullException) {
a((SQLiteFullException) b);
exc2 = b;
} else {
try {
this.a.setStatus((byte) -1);
this.a.setErrMsg(exc.toString());
this.b.a(this.a.getId(), b, this.a.getSoFar());
exc2 = b;
} catch (SQLiteFullException e) {
SQLiteFullException sQLiteFullException = e;
a(sQLiteFullException);
exc2 = sQLiteFullException;
}
}
this.c.a(exc2);
a((byte) -1);
}
void a(boolean z, long j, String str, String str2) throws IllegalArgumentException {
String eTag = this.a.getETag();
if (eTag != null && !eTag.equals(str)) {
throw new IllegalArgumentException(FileDownloadUtils.a("callback onConnected must with precondition succeed, but the etag is changes(%s != %s)", str, eTag));
}
this.c.a(z);
this.a.setStatus((byte) 2);
this.a.setTotal(j);
this.a.setETag(str);
this.a.setFilename(str2);
this.b.a(this.a.getId(), j, str, str2);
a((byte) 2);
this.g = a(j, this.f);
this.o.compareAndSet(false, true);
}
private void b(Exception exc, int i) {
Exception b = b(exc);
this.c.a(b);
this.c.a(this.d - i);
this.a.setStatus((byte) 5);
this.a.setErrMsg(b.toString());
this.b.a(this.a.getId(), b);
a((byte) 5);
}
private void b(long j) {
boolean z;
if (!this.p.compareAndSet(true, false)) {
long j2 = j - this.l;
if (this.g == -1 || this.m.get() < this.g || j2 < this.e) {
z = false;
if (z || !this.n.compareAndSet(false, true)) {
}
if (FileDownloadLog.a) {
FileDownloadLog.c(this, "inspectNeedCallbackToUser need callback to user", new Object[0]);
}
this.l = j;
this.m.set(0L);
return;
}
}
z = true;
if (z) {
}
}
void a(long j) {
this.m.addAndGet(j);
this.a.increaseSoFar(j);
b(SystemClock.elapsedRealtime());
if (this.h == null) {
j();
} else if (this.n.get()) {
a(this.h.obtainMessage(3));
}
}
void a(Exception exc, int i) {
this.m.set(0L);
Handler handler = this.h;
if (handler == null) {
b(exc, i);
} else {
a(handler.obtainMessage(5, i, 0, exc));
}
}
void a(Exception exc) {
c(exc);
}
private synchronized void a(Message message) {
if (!this.i.isAlive()) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "require callback %d but the host thread of the flow has already dead, what is occurred because of there are several reason can final this flow on different thread.", Integer.valueOf(message.what));
}
return;
}
try {
this.h.sendMessage(message);
} catch (IllegalStateException e) {
if (!this.i.isAlive()) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "require callback %d but the host thread of the flow has already dead, what is occurred because of there are several reason can final this flow on different thread.", Integer.valueOf(message.what));
}
} else {
throw e;
}
}
}
private static long a(long j, long j2) {
if (j2 <= 0) {
return -1L;
}
if (j == -1) {
return 1L;
}
long j3 = j / j2;
if (j3 <= 0) {
return 1L;
}
return j3;
}
private void a(SQLiteFullException sQLiteFullException) {
int id = this.a.getId();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "the data of the task[%d] is dirty, because the SQLite full exception[%s], so remove it from the database directly.", Integer.valueOf(id), sQLiteFullException.toString());
}
this.a.setErrMsg(sQLiteFullException.toString());
this.a.setStatus((byte) -1);
this.b.remove(id);
this.b.b(id);
}
private void a(byte b) {
if (b == -2) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "High concurrent cause, Already paused and we don't need to call-back to Task in here, %d", Integer.valueOf(this.a.getId()));
return;
}
return;
}
MessageSnapshotFlow.a().a(MessageSnapshotTaker.a(b, this.a, this.c));
}
}

View File

@@ -0,0 +1,160 @@
package com.liulishuo.filedownloader.download;
import android.os.SystemClock;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.stream.FileDownloadOutputStream;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.IOException;
/* loaded from: classes.dex */
public class FetchDataTask {
private final ProcessCallback a;
private final int b;
private final int c;
private final DownloadRunnable d;
private final FileDownloadConnection e;
private final boolean f;
private final long g;
private final long h;
private final long i;
private final String j;
long k;
private FileDownloadOutputStream l;
private volatile boolean m;
private final FileDownloadDatabase n;
private volatile long o;
private volatile long p;
public static class Builder {
DownloadRunnable a;
FileDownloadConnection b;
ConnectionProfile c;
ProcessCallback d;
String e;
Boolean f;
Integer g;
Integer h;
public Builder a(FileDownloadConnection fileDownloadConnection) {
this.b = fileDownloadConnection;
return this;
}
public Builder b(int i) {
this.h = Integer.valueOf(i);
return this;
}
public Builder a(ConnectionProfile connectionProfile) {
this.c = connectionProfile;
return this;
}
public Builder a(ProcessCallback processCallback) {
this.d = processCallback;
return this;
}
public Builder a(String str) {
this.e = str;
return this;
}
public Builder a(boolean z) {
this.f = Boolean.valueOf(z);
return this;
}
public Builder a(DownloadRunnable downloadRunnable) {
this.a = downloadRunnable;
return this;
}
public Builder a(int i) {
this.g = Integer.valueOf(i);
return this;
}
public FetchDataTask a() throws IllegalArgumentException {
FileDownloadConnection fileDownloadConnection;
ConnectionProfile connectionProfile;
Integer num;
if (this.f != null && (fileDownloadConnection = this.b) != null && (connectionProfile = this.c) != null && this.d != null && this.e != null && (num = this.h) != null && this.g != null) {
return new FetchDataTask(fileDownloadConnection, connectionProfile, this.a, num.intValue(), this.g.intValue(), this.f.booleanValue(), this.d, this.e);
}
throw new IllegalArgumentException();
}
}
private void c() {
long elapsedRealtime = SystemClock.elapsedRealtime();
if (FileDownloadUtils.a(this.k - this.o, elapsedRealtime - this.p)) {
d();
this.o = this.k;
this.p = elapsedRealtime;
}
}
private void d() {
boolean z;
long uptimeMillis = SystemClock.uptimeMillis();
try {
this.l.a();
z = true;
} catch (IOException e) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "Because of the system cannot guarantee that all the buffers have been synchronized with physical media, or write to filefailed, we just not flushAndSync process to database too %s", e);
}
z = false;
}
if (z) {
if (this.c >= 0) {
this.n.a(this.b, this.c, this.k);
} else {
this.a.a();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "require flushAndSync id[%d] index[%d] offset[%d], consume[%d]", Integer.valueOf(this.b), Integer.valueOf(this.c), Long.valueOf(this.k), Long.valueOf(SystemClock.uptimeMillis() - uptimeMillis));
}
}
}
public void a() {
this.m = true;
}
/* JADX WARN: Code restructure failed: missing block: B:83:0x01f9, code lost:
throw new com.liulishuo.filedownloader.exception.FileDownloadNetworkPolicyException();
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public void b() throws java.io.IOException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, com.liulishuo.filedownloader.exception.FileDownloadGiveUpRetryException {
/*
Method dump skipped, instructions count: 589
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.download.FetchDataTask.b():void");
}
private FetchDataTask(FileDownloadConnection fileDownloadConnection, ConnectionProfile connectionProfile, DownloadRunnable downloadRunnable, int i, int i2, boolean z, ProcessCallback processCallback, String str) {
this.o = 0L;
this.p = 0L;
this.a = processCallback;
this.j = str;
this.e = fileDownloadConnection;
this.f = z;
this.d = downloadRunnable;
this.c = i2;
this.b = i;
this.n = CustomComponentHolder.i().a();
this.g = connectionProfile.a;
this.h = connectionProfile.c;
this.k = connectionProfile.b;
this.i = connectionProfile.d;
}
}

View File

@@ -0,0 +1,16 @@
package com.liulishuo.filedownloader.download;
/* loaded from: classes.dex */
public interface ProcessCallback {
void a();
void a(long j);
void a(DownloadRunnable downloadRunnable, long j, long j2);
void a(Exception exc);
void b(Exception exc);
boolean c(Exception exc);
}

View File

@@ -0,0 +1,91 @@
package com.liulishuo.filedownloader.event;
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.concurrent.Executor;
/* loaded from: classes.dex */
public class DownloadEventPoolImpl implements IDownloadEventPool {
private final Executor a = FileDownloadExecutors.a(10, "EventPool");
private final HashMap<String, LinkedList<IDownloadListener>> b = new HashMap<>();
public boolean a(String str, IDownloadListener iDownloadListener) {
boolean add;
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "setListener %s", str);
}
if (iDownloadListener == null) {
throw new IllegalArgumentException("listener must not be null!");
}
LinkedList<IDownloadListener> linkedList = this.b.get(str);
if (linkedList == null) {
synchronized (str.intern()) {
linkedList = this.b.get(str);
if (linkedList == null) {
HashMap<String, LinkedList<IDownloadListener>> hashMap = this.b;
LinkedList<IDownloadListener> linkedList2 = new LinkedList<>();
hashMap.put(str, linkedList2);
linkedList = linkedList2;
}
}
}
synchronized (str.intern()) {
add = linkedList.add(iDownloadListener);
}
return add;
}
public boolean b(IDownloadEvent iDownloadEvent) {
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "publish %s", iDownloadEvent.a());
}
if (iDownloadEvent == null) {
throw new IllegalArgumentException("event must not be null!");
}
String a = iDownloadEvent.a();
LinkedList<IDownloadListener> linkedList = this.b.get(a);
if (linkedList == null) {
synchronized (a.intern()) {
linkedList = this.b.get(a);
if (linkedList == null) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "No listener for this event %s", a);
}
return false;
}
}
}
a(linkedList, iDownloadEvent);
return true;
}
public void a(final IDownloadEvent iDownloadEvent) {
if (FileDownloadLog.a) {
FileDownloadLog.d(this, "asyncPublishInNewThread %s", iDownloadEvent.a());
}
if (iDownloadEvent != null) {
this.a.execute(new Runnable() { // from class: com.liulishuo.filedownloader.event.DownloadEventPoolImpl.1
@Override // java.lang.Runnable
public void run() {
DownloadEventPoolImpl.this.b(iDownloadEvent);
}
});
return;
}
throw new IllegalArgumentException("event must not be null!");
}
private void a(LinkedList<IDownloadListener> linkedList, IDownloadEvent iDownloadEvent) {
for (Object obj : linkedList.toArray()) {
if (obj != null && ((IDownloadListener) obj).a(iDownloadEvent)) {
break;
}
}
Runnable runnable = iDownloadEvent.a;
if (runnable != null) {
runnable.run();
}
}
}

View File

@@ -0,0 +1,21 @@
package com.liulishuo.filedownloader.event;
/* loaded from: classes.dex */
public class DownloadServiceConnectChangedEvent extends IDownloadEvent {
private final ConnectStatus c;
public enum ConnectStatus {
connected,
disconnected,
lost
}
public DownloadServiceConnectChangedEvent(ConnectStatus connectStatus, Class<?> cls) {
super("event.service.connect.changed");
this.c = connectStatus;
}
public ConnectStatus b() {
return this.c;
}
}

View File

@@ -0,0 +1,15 @@
package com.liulishuo.filedownloader.event;
/* loaded from: classes.dex */
public abstract class IDownloadEvent {
public Runnable a = null;
protected final String b;
public IDownloadEvent(String str) {
this.b = str;
}
public final String a() {
return this.b;
}
}

View File

@@ -0,0 +1,5 @@
package com.liulishuo.filedownloader.event;
/* loaded from: classes.dex */
interface IDownloadEventPool {
}

View File

@@ -0,0 +1,6 @@
package com.liulishuo.filedownloader.event;
/* loaded from: classes.dex */
public abstract class IDownloadListener {
public abstract boolean a(IDownloadEvent iDownloadEvent);
}

View File

@@ -0,0 +1,8 @@
package com.liulishuo.filedownloader.exception;
/* loaded from: classes.dex */
public class FileDownloadGiveUpRetryException extends RuntimeException {
public FileDownloadGiveUpRetryException(String str) {
super(str);
}
}

View File

@@ -0,0 +1,42 @@
package com.liulishuo.filedownloader.exception;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public class FileDownloadHttpException extends IOException {
private final int mCode;
private final Map<String, List<String>> mRequestHeaderMap;
private final Map<String, List<String>> mResponseHeaderMap;
public FileDownloadHttpException(int i, Map<String, List<String>> map, Map<String, List<String>> map2) {
super(FileDownloadUtils.a("response code error: %d, \n request headers: %s \n response headers: %s", Integer.valueOf(i), map, map2));
this.mCode = i;
this.mRequestHeaderMap = cloneSerializableMap(map);
this.mResponseHeaderMap = cloneSerializableMap(map);
}
private static Map<String, List<String>> cloneSerializableMap(Map<String, List<String>> map) {
HashMap hashMap = new HashMap();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
hashMap.put(entry.getKey(), new ArrayList(entry.getValue()));
}
return hashMap;
}
public int getCode() {
return this.mCode;
}
public Map<String, List<String>> getRequestHeader() {
return this.mRequestHeaderMap;
}
public Map<String, List<String>> getResponseHeader() {
return this.mResponseHeaderMap;
}
}

View File

@@ -0,0 +1,8 @@
package com.liulishuo.filedownloader.exception;
/* loaded from: classes.dex */
public class FileDownloadNetworkPolicyException extends FileDownloadGiveUpRetryException {
public FileDownloadNetworkPolicyException() {
super("Only allows downloading this task on the wifi network type");
}
}

View File

@@ -0,0 +1,41 @@
package com.liulishuo.filedownloader.exception;
import android.annotation.TargetApi;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.IOException;
/* loaded from: classes.dex */
public class FileDownloadOutOfSpaceException extends IOException {
private long breakpointBytes;
private long freeSpaceBytes;
private long requiredSpaceBytes;
@TargetApi(9)
public FileDownloadOutOfSpaceException(long j, long j2, long j3, Throwable th) {
super(FileDownloadUtils.a("The file is too large to store, breakpoint in bytes: %d, required space in bytes: %d, but free space in bytes: %d", Long.valueOf(j3), Long.valueOf(j2), Long.valueOf(j)), th);
init(j, j2, j3);
}
private void init(long j, long j2, long j3) {
this.freeSpaceBytes = j;
this.requiredSpaceBytes = j2;
this.breakpointBytes = j3;
}
public long getBreakpointBytes() {
return this.breakpointBytes;
}
public long getFreeSpaceBytes() {
return this.freeSpaceBytes;
}
public long getRequiredSpaceBytes() {
return this.requiredSpaceBytes;
}
public FileDownloadOutOfSpaceException(long j, long j2, long j3) {
super(FileDownloadUtils.a("The file is too large to store, breakpoint in bytes: %d, required space in bytes: %d, but free space in bytes: %d", Long.valueOf(j3), Long.valueOf(j2), Long.valueOf(j)));
init(j, j2, j3);
}
}

View File

@@ -0,0 +1,8 @@
package com.liulishuo.filedownloader.exception;
/* loaded from: classes.dex */
public class FileDownloadSecurityException extends Exception {
public FileDownloadSecurityException(String str) {
super(str);
}
}

View File

@@ -0,0 +1,29 @@
package com.liulishuo.filedownloader.exception;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
/* loaded from: classes.dex */
public class PathConflictException extends IllegalAccessException {
private final int mAnotherSamePathTaskId;
private final String mDownloadingConflictPath;
private final String mTargetFilePath;
public PathConflictException(int i, String str, String str2) {
super(FileDownloadUtils.a("There is an another running task(%d) with the same downloading path(%s), because of they are with the same target-file-path(%s), so if the current task is started, the path of the file is sure to be written by multiple tasks, it is wrong, then you receive this exception to avoid such conflict.", Integer.valueOf(i), str, str2));
this.mAnotherSamePathTaskId = i;
this.mDownloadingConflictPath = str;
this.mTargetFilePath = str2;
}
public int getAnotherSamePathTaskId() {
return this.mAnotherSamePathTaskId;
}
public String getDownloadingConflictPath() {
return this.mDownloadingConflictPath;
}
public String getTargetFilePath() {
return this.mTargetFilePath;
}
}

View File

@@ -0,0 +1,78 @@
package com.liulishuo.filedownloader.i;
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import com.liulishuo.filedownloader.message.MessageSnapshot;
/* loaded from: classes.dex */
public interface IFileDownloadIPCCallback extends IInterface {
public static abstract class Stub extends Binder implements IFileDownloadIPCCallback {
private static class Proxy implements IFileDownloadIPCCallback {
private IBinder a;
Proxy(IBinder iBinder) {
this.a = iBinder;
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCCallback
public void a(MessageSnapshot messageSnapshot) throws RemoteException {
Parcel obtain = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.liulishuo.filedownloader.i.IFileDownloadIPCCallback");
if (messageSnapshot != null) {
obtain.writeInt(1);
messageSnapshot.writeToParcel(obtain, 0);
} else {
obtain.writeInt(0);
}
this.a.transact(1, obtain, null, 1);
} finally {
obtain.recycle();
}
}
@Override // android.os.IInterface
public IBinder asBinder() {
return this.a;
}
}
public Stub() {
attachInterface(this, "com.liulishuo.filedownloader.i.IFileDownloadIPCCallback");
}
public static IFileDownloadIPCCallback a(IBinder iBinder) {
if (iBinder == null) {
return null;
}
IInterface queryLocalInterface = iBinder.queryLocalInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCCallback");
return (queryLocalInterface == null || !(queryLocalInterface instanceof IFileDownloadIPCCallback)) ? new Proxy(iBinder) : (IFileDownloadIPCCallback) queryLocalInterface;
}
@Override // android.os.IInterface
public IBinder asBinder() {
return this;
}
@Override // android.os.Binder
public boolean onTransact(int i, Parcel parcel, Parcel parcel2, int i2) throws RemoteException {
if (i == 1) {
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCCallback");
a(parcel.readInt() != 0 ? MessageSnapshot.CREATOR.createFromParcel(parcel) : null);
return true;
}
if (i != 1598968902) {
return super.onTransact(i, parcel, parcel2, i2);
}
parcel2.writeString("com.liulishuo.filedownloader.i.IFileDownloadIPCCallback");
return true;
}
}
void a(MessageSnapshot messageSnapshot) throws RemoteException;
}

View File

@@ -0,0 +1,254 @@
package com.liulishuo.filedownloader.i;
import android.app.Notification;
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import com.liulishuo.filedownloader.i.IFileDownloadIPCCallback;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
/* loaded from: classes.dex */
public interface IFileDownloadIPCService extends IInterface {
byte a(int i) throws RemoteException;
void a(int i, Notification notification) throws RemoteException;
void a(IFileDownloadIPCCallback iFileDownloadIPCCallback) throws RemoteException;
void a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) throws RemoteException;
void a(boolean z) throws RemoteException;
boolean a(String str, String str2) throws RemoteException;
void b(IFileDownloadIPCCallback iFileDownloadIPCCallback) throws RemoteException;
boolean b(int i) throws RemoteException;
void c() throws RemoteException;
boolean c(int i) throws RemoteException;
boolean d() throws RemoteException;
boolean d(int i) throws RemoteException;
long e(int i) throws RemoteException;
void e() throws RemoteException;
long f(int i) throws RemoteException;
public static abstract class Stub extends Binder implements IFileDownloadIPCService {
public Stub() {
attachInterface(this, "com.liulishuo.filedownloader.i.IFileDownloadIPCService");
}
public static IFileDownloadIPCService a(IBinder iBinder) {
if (iBinder == null) {
return null;
}
IInterface queryLocalInterface = iBinder.queryLocalInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
return (queryLocalInterface == null || !(queryLocalInterface instanceof IFileDownloadIPCService)) ? new Proxy(iBinder) : (IFileDownloadIPCService) queryLocalInterface;
}
@Override // android.os.IInterface
public IBinder asBinder() {
return this;
}
@Override // android.os.Binder
public boolean onTransact(int i, Parcel parcel, Parcel parcel2, int i2) throws RemoteException {
if (i == 1598968902) {
parcel2.writeString("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
return true;
}
switch (i) {
case 1:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
a(IFileDownloadIPCCallback.Stub.a(parcel.readStrongBinder()));
return true;
case 2:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
b(IFileDownloadIPCCallback.Stub.a(parcel.readStrongBinder()));
return true;
case 3:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
boolean a = a(parcel.readString(), parcel.readString());
parcel2.writeNoException();
parcel2.writeInt(a ? 1 : 0);
return true;
case 4:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
a(parcel.readString(), parcel.readString(), parcel.readInt() != 0, parcel.readInt(), parcel.readInt(), parcel.readInt(), parcel.readInt() != 0, parcel.readInt() != 0 ? FileDownloadHeader.CREATOR.createFromParcel(parcel) : null, parcel.readInt() != 0);
parcel2.writeNoException();
return true;
case 5:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
boolean b = b(parcel.readInt());
parcel2.writeNoException();
parcel2.writeInt(b ? 1 : 0);
return true;
case 6:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
e();
parcel2.writeNoException();
return true;
case 7:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
boolean c = c(parcel.readInt());
parcel2.writeNoException();
parcel2.writeInt(c ? 1 : 0);
return true;
case 8:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
long f = f(parcel.readInt());
parcel2.writeNoException();
parcel2.writeLong(f);
return true;
case 9:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
long e = e(parcel.readInt());
parcel2.writeNoException();
parcel2.writeLong(e);
return true;
case 10:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
byte a2 = a(parcel.readInt());
parcel2.writeNoException();
parcel2.writeByte(a2);
return true;
case 11:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
boolean d = d();
parcel2.writeNoException();
parcel2.writeInt(d ? 1 : 0);
return true;
case 12:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
a(parcel.readInt(), parcel.readInt() != 0 ? (Notification) Notification.CREATOR.createFromParcel(parcel) : null);
return true;
case 13:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
a(parcel.readInt() != 0);
return true;
case 14:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
boolean d2 = d(parcel.readInt());
parcel2.writeNoException();
parcel2.writeInt(d2 ? 1 : 0);
return true;
case 15:
parcel.enforceInterface("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
c();
parcel2.writeNoException();
return true;
default:
return super.onTransact(i, parcel, parcel2, i2);
}
}
private static class Proxy implements IFileDownloadIPCService {
private IBinder a;
Proxy(IBinder iBinder) {
this.a = iBinder;
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(IFileDownloadIPCCallback iFileDownloadIPCCallback) throws RemoteException {
Parcel obtain = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
obtain.writeStrongBinder(iFileDownloadIPCCallback != null ? iFileDownloadIPCCallback.asBinder() : null);
this.a.transact(1, obtain, null, 1);
} finally {
obtain.recycle();
}
}
@Override // android.os.IInterface
public IBinder asBinder() {
return this.a;
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void b(IFileDownloadIPCCallback iFileDownloadIPCCallback) throws RemoteException {
Parcel obtain = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
obtain.writeStrongBinder(iFileDownloadIPCCallback != null ? iFileDownloadIPCCallback.asBinder() : null);
this.a.transact(2, obtain, null, 1);
} finally {
obtain.recycle();
}
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
obtain.writeString(str);
obtain.writeString(str2);
int i4 = 1;
obtain.writeInt(z ? 1 : 0);
obtain.writeInt(i);
obtain.writeInt(i2);
obtain.writeInt(i3);
obtain.writeInt(z2 ? 1 : 0);
if (fileDownloadHeader != null) {
obtain.writeInt(1);
fileDownloadHeader.writeToParcel(obtain, 0);
} else {
obtain.writeInt(0);
}
if (!z3) {
i4 = 0;
}
obtain.writeInt(i4);
this.a.transact(4, obtain, obtain2, 0);
obtain2.readException();
} finally {
obtain2.recycle();
obtain.recycle();
}
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean b(int i) throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
obtain.writeInt(i);
this.a.transact(5, obtain, obtain2, 0);
obtain2.readException();
return obtain2.readInt() != 0;
} finally {
obtain2.recycle();
obtain.recycle();
}
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public byte a(int i) throws RemoteException {
Parcel obtain = Parcel.obtain();
Parcel obtain2 = Parcel.obtain();
try {
obtain.writeInterfaceToken("com.liulishuo.filedownloader.i.IFileDownloadIPCService");
obtain.writeInt(i);
this.a.transact(10, obtain, obtain2, 0);
obtain2.readException();
return obtain2.readByte();
} finally {
obtain2.recycle();
obtain.recycle();
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
package com.liulishuo.filedownloader.message;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
/* loaded from: classes.dex */
public interface BlockCompleteMessage {
public static class BlockCompleteMessageImpl extends MessageSnapshot implements BlockCompleteMessage {
private final MessageSnapshot mCompletedSnapshot;
public BlockCompleteMessageImpl(MessageSnapshot messageSnapshot) {
super(messageSnapshot.getId());
if (messageSnapshot.getStatus() != -3) {
throw new IllegalArgumentException(FileDownloadUtils.a("can't create the block complete message for id[%d], status[%d]", Integer.valueOf(messageSnapshot.getId()), Byte.valueOf(messageSnapshot.getStatus())));
}
this.mCompletedSnapshot = messageSnapshot;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 4;
}
@Override // com.liulishuo.filedownloader.message.BlockCompleteMessage
public MessageSnapshot transmitToCompleted() {
return this.mCompletedSnapshot;
}
}
MessageSnapshot transmitToCompleted();
}

View File

@@ -0,0 +1,5 @@
package com.liulishuo.filedownloader.message;
/* loaded from: classes.dex */
public interface IFlowDirectly {
}

View File

@@ -0,0 +1,5 @@
package com.liulishuo.filedownloader.message;
/* loaded from: classes.dex */
interface IMessageSnapshot {
}

View File

@@ -0,0 +1,352 @@
package com.liulishuo.filedownloader.message;
import android.os.Parcel;
import com.liulishuo.filedownloader.message.MessageSnapshot;
/* loaded from: classes.dex */
public abstract class LargeMessageSnapshot extends MessageSnapshot {
public static class CompletedFlowDirectlySnapshot extends CompletedSnapshot implements IFlowDirectly {
CompletedFlowDirectlySnapshot(int i, boolean z, long j) {
super(i, z, j);
}
CompletedFlowDirectlySnapshot(Parcel parcel) {
super(parcel);
}
}
public static class PausedSnapshot extends PendingMessageSnapshot {
PausedSnapshot(int i, long j, long j2) {
super(i, j, j2);
}
@Override // com.liulishuo.filedownloader.message.LargeMessageSnapshot.PendingMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -2;
}
}
public static class PendingMessageSnapshot extends LargeMessageSnapshot {
private final long sofarBytes;
private final long totalBytes;
PendingMessageSnapshot(PendingMessageSnapshot pendingMessageSnapshot) {
this(pendingMessageSnapshot.getId(), pendingMessageSnapshot.getLargeSofarBytes(), pendingMessageSnapshot.getLargeTotalBytes());
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeSofarBytes() {
return this.sofarBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeTotalBytes() {
return this.totalBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 1;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeLong(this.sofarBytes);
parcel.writeLong(this.totalBytes);
}
PendingMessageSnapshot(int i, long j, long j2) {
super(i);
this.sofarBytes = j;
this.totalBytes = j2;
}
PendingMessageSnapshot(Parcel parcel) {
super(parcel);
this.sofarBytes = parcel.readLong();
this.totalBytes = parcel.readLong();
}
}
public static class WarnFlowDirectlySnapshot extends WarnMessageSnapshot implements IFlowDirectly {
WarnFlowDirectlySnapshot(int i, long j, long j2) {
super(i, j, j2);
}
WarnFlowDirectlySnapshot(Parcel parcel) {
super(parcel);
}
}
public static class WarnMessageSnapshot extends PendingMessageSnapshot implements MessageSnapshot.IWarnMessageSnapshot {
WarnMessageSnapshot(int i, long j, long j2) {
super(i, j, j2);
}
@Override // com.liulishuo.filedownloader.message.LargeMessageSnapshot.PendingMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -4;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot.IWarnMessageSnapshot
public MessageSnapshot turnToPending() {
return new PendingMessageSnapshot(this);
}
WarnMessageSnapshot(Parcel parcel) {
super(parcel);
}
}
LargeMessageSnapshot(int i) {
super(i);
this.isLargeFile = true;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallSofarBytes() {
if (getLargeSofarBytes() > 2147483647L) {
return Integer.MAX_VALUE;
}
return (int) getLargeSofarBytes();
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallTotalBytes() {
if (getLargeTotalBytes() > 2147483647L) {
return Integer.MAX_VALUE;
}
return (int) getLargeTotalBytes();
}
public static class ProgressMessageSnapshot extends LargeMessageSnapshot {
private final long sofarBytes;
ProgressMessageSnapshot(int i, long j) {
super(i);
this.sofarBytes = j;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeSofarBytes() {
return this.sofarBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 3;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeLong(this.sofarBytes);
}
ProgressMessageSnapshot(Parcel parcel) {
super(parcel);
this.sofarBytes = parcel.readLong();
}
}
public static class RetryMessageSnapshot extends ErrorMessageSnapshot {
private final int retryingTimes;
RetryMessageSnapshot(int i, long j, Throwable th, int i2) {
super(i, j, th);
this.retryingTimes = i2;
}
@Override // com.liulishuo.filedownloader.message.LargeMessageSnapshot.ErrorMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getRetryingTimes() {
return this.retryingTimes;
}
@Override // com.liulishuo.filedownloader.message.LargeMessageSnapshot.ErrorMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 5;
}
@Override // com.liulishuo.filedownloader.message.LargeMessageSnapshot.ErrorMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeInt(this.retryingTimes);
}
RetryMessageSnapshot(Parcel parcel) {
super(parcel);
this.retryingTimes = parcel.readInt();
}
}
public static class CompletedSnapshot extends LargeMessageSnapshot {
private final boolean reusedDownloadedFile;
private final long totalBytes;
CompletedSnapshot(int i, boolean z, long j) {
super(i);
this.reusedDownloadedFile = z;
this.totalBytes = j;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeTotalBytes() {
return this.totalBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -3;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public boolean isReusedDownloadedFile() {
return this.reusedDownloadedFile;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeByte(this.reusedDownloadedFile ? (byte) 1 : (byte) 0);
parcel.writeLong(this.totalBytes);
}
CompletedSnapshot(Parcel parcel) {
super(parcel);
this.reusedDownloadedFile = parcel.readByte() != 0;
this.totalBytes = parcel.readLong();
}
}
public static class ErrorMessageSnapshot extends LargeMessageSnapshot {
private final long sofarBytes;
private final Throwable throwable;
ErrorMessageSnapshot(int i, long j, Throwable th) {
super(i);
this.sofarBytes = j;
this.throwable = th;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeSofarBytes() {
return this.sofarBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -1;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public Throwable getThrowable() {
return this.throwable;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeLong(this.sofarBytes);
parcel.writeSerializable(this.throwable);
}
ErrorMessageSnapshot(Parcel parcel) {
super(parcel);
this.sofarBytes = parcel.readLong();
this.throwable = (Throwable) parcel.readSerializable();
}
}
LargeMessageSnapshot(Parcel parcel) {
super(parcel);
}
public static class ConnectedMessageSnapshot extends LargeMessageSnapshot {
private final String etag;
private final String fileName;
private final boolean resuming;
private final long totalBytes;
ConnectedMessageSnapshot(int i, boolean z, long j, String str, String str2) {
super(i);
this.resuming = z;
this.totalBytes = j;
this.etag = str;
this.fileName = str2;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public String getEtag() {
return this.etag;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public String getFileName() {
return this.fileName;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeTotalBytes() {
return this.totalBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 2;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public boolean isResuming() {
return this.resuming;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeByte(this.resuming ? (byte) 1 : (byte) 0);
parcel.writeLong(this.totalBytes);
parcel.writeString(this.etag);
parcel.writeString(this.fileName);
}
ConnectedMessageSnapshot(Parcel parcel) {
super(parcel);
this.resuming = parcel.readByte() != 0;
this.totalBytes = parcel.readLong();
this.etag = parcel.readString();
this.fileName = parcel.readString();
}
}
}

View File

@@ -0,0 +1,126 @@
package com.liulishuo.filedownloader.message;
import android.os.Parcel;
import android.os.Parcelable;
import com.liulishuo.filedownloader.message.LargeMessageSnapshot;
import com.liulishuo.filedownloader.message.SmallMessageSnapshot;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
/* loaded from: classes.dex */
public abstract class MessageSnapshot implements IMessageSnapshot, Parcelable {
public static final Parcelable.Creator<MessageSnapshot> CREATOR = new Parcelable.Creator<MessageSnapshot>() { // from class: com.liulishuo.filedownloader.message.MessageSnapshot.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public MessageSnapshot createFromParcel(Parcel parcel) {
boolean z = parcel.readByte() == 1;
byte readByte = parcel.readByte();
MessageSnapshot startedMessageSnapshot = readByte != -4 ? readByte != -3 ? readByte != -1 ? readByte != 1 ? readByte != 2 ? readByte != 3 ? readByte != 5 ? readByte != 6 ? null : new StartedMessageSnapshot(parcel) : z ? new LargeMessageSnapshot.RetryMessageSnapshot(parcel) : new SmallMessageSnapshot.RetryMessageSnapshot(parcel) : z ? new LargeMessageSnapshot.ProgressMessageSnapshot(parcel) : new SmallMessageSnapshot.ProgressMessageSnapshot(parcel) : z ? new LargeMessageSnapshot.ConnectedMessageSnapshot(parcel) : new SmallMessageSnapshot.ConnectedMessageSnapshot(parcel) : z ? new LargeMessageSnapshot.PendingMessageSnapshot(parcel) : new SmallMessageSnapshot.PendingMessageSnapshot(parcel) : z ? new LargeMessageSnapshot.ErrorMessageSnapshot(parcel) : new SmallMessageSnapshot.ErrorMessageSnapshot(parcel) : z ? new LargeMessageSnapshot.CompletedSnapshot(parcel) : new SmallMessageSnapshot.CompletedSnapshot(parcel) : z ? new LargeMessageSnapshot.WarnMessageSnapshot(parcel) : new SmallMessageSnapshot.WarnMessageSnapshot(parcel);
if (startedMessageSnapshot != null) {
startedMessageSnapshot.isLargeFile = z;
return startedMessageSnapshot;
}
throw new IllegalStateException("Can't restore the snapshot because unknown status: " + ((int) readByte));
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public MessageSnapshot[] newArray(int i) {
return new MessageSnapshot[i];
}
};
private final int id;
protected boolean isLargeFile;
public interface IWarnMessageSnapshot {
MessageSnapshot turnToPending();
}
public static class NoFieldException extends IllegalStateException {
NoFieldException(String str, MessageSnapshot messageSnapshot) {
super(FileDownloadUtils.a("There isn't a field for '%s' in this message %d %d %s", str, Integer.valueOf(messageSnapshot.getId()), Byte.valueOf(messageSnapshot.getStatus()), messageSnapshot.getClass().getName()));
}
}
public static class StartedMessageSnapshot extends MessageSnapshot {
StartedMessageSnapshot(int i) {
super(i);
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 6;
}
StartedMessageSnapshot(Parcel parcel) {
super(parcel);
}
}
MessageSnapshot(int i) {
this.id = i;
}
public int describeContents() {
return 0;
}
public String getEtag() {
throw new NoFieldException("getEtag", this);
}
public String getFileName() {
throw new NoFieldException("getFileName", this);
}
public int getId() {
return this.id;
}
public long getLargeSofarBytes() {
throw new NoFieldException("getLargeSofarBytes", this);
}
public long getLargeTotalBytes() {
throw new NoFieldException("getLargeTotalBytes", this);
}
public int getRetryingTimes() {
throw new NoFieldException("getRetryingTimes", this);
}
public int getSmallSofarBytes() {
throw new NoFieldException("getSmallSofarBytes", this);
}
public int getSmallTotalBytes() {
throw new NoFieldException("getSmallTotalBytes", this);
}
public abstract /* synthetic */ byte getStatus();
public Throwable getThrowable() {
throw new NoFieldException("getThrowable", this);
}
public boolean isLargeFile() {
return this.isLargeFile;
}
public boolean isResuming() {
throw new NoFieldException("isResuming", this);
}
public boolean isReusedDownloadedFile() {
throw new NoFieldException("isReusedDownloadedFile", this);
}
public void writeToParcel(Parcel parcel, int i) {
parcel.writeByte(this.isLargeFile ? (byte) 1 : (byte) 0);
parcel.writeByte(getStatus());
parcel.writeInt(this.id);
}
MessageSnapshot(Parcel parcel) {
this.id = parcel.readInt();
}
}

View File

@@ -0,0 +1,38 @@
package com.liulishuo.filedownloader.message;
/* loaded from: classes.dex */
public class MessageSnapshotFlow {
private volatile MessageSnapshotThreadPool a;
private volatile MessageReceiver b;
public static final class HolderClass {
private static final MessageSnapshotFlow a = new MessageSnapshotFlow();
}
public interface MessageReceiver {
void a(MessageSnapshot messageSnapshot);
}
public static MessageSnapshotFlow a() {
return HolderClass.a;
}
public void a(MessageReceiver messageReceiver) {
this.b = messageReceiver;
if (messageReceiver == null) {
this.a = null;
} else {
this.a = new MessageSnapshotThreadPool(5, messageReceiver);
}
}
public void a(MessageSnapshot messageSnapshot) {
if (messageSnapshot instanceof IFlowDirectly) {
if (this.b != null) {
this.b.a(messageSnapshot);
}
} else if (this.a != null) {
this.a.a(messageSnapshot);
}
}
}

View File

@@ -0,0 +1,116 @@
package com.liulishuo.filedownloader.message;
import com.liulishuo.filedownloader.BaseDownloadTask;
import com.liulishuo.filedownloader.download.DownloadStatusCallback;
import com.liulishuo.filedownloader.message.BlockCompleteMessage;
import com.liulishuo.filedownloader.message.LargeMessageSnapshot;
import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.message.SmallMessageSnapshot;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.File;
/* loaded from: classes.dex */
public class MessageSnapshotTaker {
public static MessageSnapshot a(int i, File file, boolean z) {
long length = file.length();
return length > 2147483647L ? z ? new LargeMessageSnapshot.CompletedFlowDirectlySnapshot(i, true, length) : new LargeMessageSnapshot.CompletedSnapshot(i, true, length) : z ? new SmallMessageSnapshot.CompletedFlowDirectlySnapshot(i, true, (int) length) : new SmallMessageSnapshot.CompletedSnapshot(i, true, (int) length);
}
public static MessageSnapshot a(int i, long j, long j2, boolean z) {
if (j2 > 2147483647L) {
if (z) {
return new LargeMessageSnapshot.WarnFlowDirectlySnapshot(i, j, j2);
}
return new LargeMessageSnapshot.WarnMessageSnapshot(i, j, j2);
}
if (z) {
return new SmallMessageSnapshot.WarnFlowDirectlySnapshot(i, (int) j, (int) j2);
}
return new SmallMessageSnapshot.WarnMessageSnapshot(i, (int) j, (int) j2);
}
public static MessageSnapshot a(int i, long j, Throwable th) {
if (j > 2147483647L) {
return new LargeMessageSnapshot.ErrorMessageSnapshot(i, j, th);
}
return new SmallMessageSnapshot.ErrorMessageSnapshot(i, (int) j, th);
}
public static MessageSnapshot a(BaseDownloadTask baseDownloadTask) {
if (baseDownloadTask.e()) {
return new LargeMessageSnapshot.PausedSnapshot(baseDownloadTask.getId(), baseDownloadTask.l(), baseDownloadTask.t());
}
return new SmallMessageSnapshot.PausedSnapshot(baseDownloadTask.getId(), baseDownloadTask.r(), baseDownloadTask.f());
}
public static MessageSnapshot a(MessageSnapshot messageSnapshot) {
if (messageSnapshot.getStatus() == -3) {
return new BlockCompleteMessage.BlockCompleteMessageImpl(messageSnapshot);
}
throw new IllegalStateException(FileDownloadUtils.a("take block completed snapshot, must has already be completed. %d %d", Integer.valueOf(messageSnapshot.getId()), Byte.valueOf(messageSnapshot.getStatus())));
}
public static MessageSnapshot a(byte b, FileDownloadModel fileDownloadModel, DownloadStatusCallback.ProcessParams processParams) {
MessageSnapshot errorMessageSnapshot;
IllegalStateException illegalStateException;
int id = fileDownloadModel.getId();
if (b == -4) {
throw new IllegalStateException(FileDownloadUtils.a("please use #catchWarn instead %d", Integer.valueOf(id)));
}
if (b == -3) {
if (fileDownloadModel.isLargeFile()) {
return new LargeMessageSnapshot.CompletedSnapshot(id, false, fileDownloadModel.getTotal());
}
return new SmallMessageSnapshot.CompletedSnapshot(id, false, (int) fileDownloadModel.getTotal());
}
if (b != -1) {
if (b != 1) {
if (b == 2) {
String filename = fileDownloadModel.isPathAsDirectory() ? fileDownloadModel.getFilename() : null;
if (fileDownloadModel.isLargeFile()) {
return new LargeMessageSnapshot.ConnectedMessageSnapshot(id, processParams.c(), fileDownloadModel.getTotal(), fileDownloadModel.getETag(), filename);
}
return new SmallMessageSnapshot.ConnectedMessageSnapshot(id, processParams.c(), (int) fileDownloadModel.getTotal(), fileDownloadModel.getETag(), filename);
}
if (b == 3) {
if (fileDownloadModel.isLargeFile()) {
return new LargeMessageSnapshot.ProgressMessageSnapshot(id, fileDownloadModel.getSoFar());
}
return new SmallMessageSnapshot.ProgressMessageSnapshot(id, (int) fileDownloadModel.getSoFar());
}
if (b != 5) {
if (b != 6) {
String a = FileDownloadUtils.a("it can't takes a snapshot for the task(%s) when its status is %d,", fileDownloadModel, Byte.valueOf(b));
FileDownloadLog.e(MessageSnapshotTaker.class, "it can't takes a snapshot for the task(%s) when its status is %d,", fileDownloadModel, Byte.valueOf(b));
if (processParams.a() != null) {
illegalStateException = new IllegalStateException(a, processParams.a());
} else {
illegalStateException = new IllegalStateException(a);
}
if (fileDownloadModel.isLargeFile()) {
return new LargeMessageSnapshot.ErrorMessageSnapshot(id, fileDownloadModel.getSoFar(), illegalStateException);
}
return new SmallMessageSnapshot.ErrorMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), illegalStateException);
}
return new MessageSnapshot.StartedMessageSnapshot(id);
}
if (fileDownloadModel.isLargeFile()) {
errorMessageSnapshot = new LargeMessageSnapshot.RetryMessageSnapshot(id, fileDownloadModel.getSoFar(), processParams.a(), processParams.b());
} else {
errorMessageSnapshot = new SmallMessageSnapshot.RetryMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), processParams.a(), processParams.b());
}
} else if (fileDownloadModel.isLargeFile()) {
errorMessageSnapshot = new LargeMessageSnapshot.PendingMessageSnapshot(id, fileDownloadModel.getSoFar(), fileDownloadModel.getTotal());
} else {
return new SmallMessageSnapshot.PendingMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), (int) fileDownloadModel.getTotal());
}
} else if (fileDownloadModel.isLargeFile()) {
errorMessageSnapshot = new LargeMessageSnapshot.ErrorMessageSnapshot(id, fileDownloadModel.getSoFar(), processParams.a());
} else {
errorMessageSnapshot = new SmallMessageSnapshot.ErrorMessageSnapshot(id, (int) fileDownloadModel.getSoFar(), processParams.a());
}
return errorMessageSnapshot;
}
}

View File

@@ -0,0 +1,84 @@
package com.liulishuo.filedownloader.message;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executor;
/* loaded from: classes.dex */
public class MessageSnapshotThreadPool {
private final List<FlowSingleExecutor> a = new ArrayList();
private final MessageSnapshotFlow.MessageReceiver b;
public class FlowSingleExecutor {
private final List<Integer> a = new ArrayList();
private final Executor b;
public FlowSingleExecutor(int i) {
this.b = FileDownloadExecutors.a(1, "Flow-" + i);
}
public void a(int i) {
this.a.add(Integer.valueOf(i));
}
public void a(final MessageSnapshot messageSnapshot) {
this.b.execute(new Runnable() { // from class: com.liulishuo.filedownloader.message.MessageSnapshotThreadPool.FlowSingleExecutor.1
@Override // java.lang.Runnable
public void run() {
MessageSnapshotThreadPool.this.b.a(messageSnapshot);
FlowSingleExecutor.this.a.remove(Integer.valueOf(messageSnapshot.getId()));
}
});
}
}
MessageSnapshotThreadPool(int i, MessageSnapshotFlow.MessageReceiver messageReceiver) {
this.b = messageReceiver;
for (int i2 = 0; i2 < i; i2++) {
this.a.add(new FlowSingleExecutor(i2));
}
}
public void a(MessageSnapshot messageSnapshot) {
FlowSingleExecutor flowSingleExecutor = null;
try {
synchronized (this.a) {
int id = messageSnapshot.getId();
Iterator<FlowSingleExecutor> it = this.a.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
FlowSingleExecutor next = it.next();
if (next.a.contains(Integer.valueOf(id))) {
flowSingleExecutor = next;
break;
}
}
if (flowSingleExecutor == null) {
int i = 0;
Iterator<FlowSingleExecutor> it2 = this.a.iterator();
while (true) {
if (!it2.hasNext()) {
break;
}
FlowSingleExecutor next2 = it2.next();
if (next2.a.size() <= 0) {
flowSingleExecutor = next2;
break;
} else if (i == 0 || next2.a.size() < i) {
i = next2.a.size();
flowSingleExecutor = next2;
}
}
}
flowSingleExecutor.a(id);
}
} finally {
flowSingleExecutor.a(messageSnapshot);
}
}
}

View File

@@ -0,0 +1,341 @@
package com.liulishuo.filedownloader.message;
import android.os.Parcel;
import com.liulishuo.filedownloader.message.MessageSnapshot;
/* loaded from: classes.dex */
public abstract class SmallMessageSnapshot extends MessageSnapshot {
public static class CompletedFlowDirectlySnapshot extends CompletedSnapshot implements IFlowDirectly {
CompletedFlowDirectlySnapshot(int i, boolean z, int i2) {
super(i, z, i2);
}
CompletedFlowDirectlySnapshot(Parcel parcel) {
super(parcel);
}
}
public static class PausedSnapshot extends PendingMessageSnapshot {
PausedSnapshot(int i, int i2, int i3) {
super(i, i2, i3);
}
@Override // com.liulishuo.filedownloader.message.SmallMessageSnapshot.PendingMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -2;
}
}
public static class PendingMessageSnapshot extends SmallMessageSnapshot {
private final int sofarBytes;
private final int totalBytes;
PendingMessageSnapshot(PendingMessageSnapshot pendingMessageSnapshot) {
this(pendingMessageSnapshot.getId(), pendingMessageSnapshot.getSmallSofarBytes(), pendingMessageSnapshot.getSmallTotalBytes());
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallSofarBytes() {
return this.sofarBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallTotalBytes() {
return this.totalBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 1;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeInt(this.sofarBytes);
parcel.writeInt(this.totalBytes);
}
PendingMessageSnapshot(int i, int i2, int i3) {
super(i);
this.sofarBytes = i2;
this.totalBytes = i3;
}
PendingMessageSnapshot(Parcel parcel) {
super(parcel);
this.sofarBytes = parcel.readInt();
this.totalBytes = parcel.readInt();
}
}
public static class WarnFlowDirectlySnapshot extends WarnMessageSnapshot implements IFlowDirectly {
WarnFlowDirectlySnapshot(int i, int i2, int i3) {
super(i, i2, i3);
}
WarnFlowDirectlySnapshot(Parcel parcel) {
super(parcel);
}
}
public static class WarnMessageSnapshot extends PendingMessageSnapshot implements MessageSnapshot.IWarnMessageSnapshot {
WarnMessageSnapshot(int i, int i2, int i3) {
super(i, i2, i3);
}
@Override // com.liulishuo.filedownloader.message.SmallMessageSnapshot.PendingMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -4;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot.IWarnMessageSnapshot
public MessageSnapshot turnToPending() {
return new PendingMessageSnapshot(this);
}
WarnMessageSnapshot(Parcel parcel) {
super(parcel);
}
}
SmallMessageSnapshot(int i) {
super(i);
this.isLargeFile = false;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeSofarBytes() {
return getSmallSofarBytes();
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public long getLargeTotalBytes() {
return getSmallTotalBytes();
}
public static class ProgressMessageSnapshot extends SmallMessageSnapshot {
private final int sofarBytes;
ProgressMessageSnapshot(int i, int i2) {
super(i);
this.sofarBytes = i2;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallSofarBytes() {
return this.sofarBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 3;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeInt(this.sofarBytes);
}
ProgressMessageSnapshot(Parcel parcel) {
super(parcel);
this.sofarBytes = parcel.readInt();
}
}
public static class RetryMessageSnapshot extends ErrorMessageSnapshot {
private final int retryingTimes;
RetryMessageSnapshot(int i, int i2, Throwable th, int i3) {
super(i, i2, th);
this.retryingTimes = i3;
}
@Override // com.liulishuo.filedownloader.message.SmallMessageSnapshot.ErrorMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getRetryingTimes() {
return this.retryingTimes;
}
@Override // com.liulishuo.filedownloader.message.SmallMessageSnapshot.ErrorMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 5;
}
@Override // com.liulishuo.filedownloader.message.SmallMessageSnapshot.ErrorMessageSnapshot, com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeInt(this.retryingTimes);
}
RetryMessageSnapshot(Parcel parcel) {
super(parcel);
this.retryingTimes = parcel.readInt();
}
}
public static class CompletedSnapshot extends SmallMessageSnapshot {
private final boolean reusedDownloadedFile;
private final int totalBytes;
CompletedSnapshot(int i, boolean z, int i2) {
super(i);
this.reusedDownloadedFile = z;
this.totalBytes = i2;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallTotalBytes() {
return this.totalBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -3;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public boolean isReusedDownloadedFile() {
return this.reusedDownloadedFile;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeByte(this.reusedDownloadedFile ? (byte) 1 : (byte) 0);
parcel.writeInt(this.totalBytes);
}
CompletedSnapshot(Parcel parcel) {
super(parcel);
this.reusedDownloadedFile = parcel.readByte() != 0;
this.totalBytes = parcel.readInt();
}
}
public static class ErrorMessageSnapshot extends SmallMessageSnapshot {
private final int sofarBytes;
private final Throwable throwable;
ErrorMessageSnapshot(int i, int i2, Throwable th) {
super(i);
this.sofarBytes = i2;
this.throwable = th;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallSofarBytes() {
return this.sofarBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) -1;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public Throwable getThrowable() {
return this.throwable;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeInt(this.sofarBytes);
parcel.writeSerializable(this.throwable);
}
ErrorMessageSnapshot(Parcel parcel) {
super(parcel);
this.sofarBytes = parcel.readInt();
this.throwable = (Throwable) parcel.readSerializable();
}
}
SmallMessageSnapshot(Parcel parcel) {
super(parcel);
}
public static class ConnectedMessageSnapshot extends SmallMessageSnapshot {
private final String etag;
private final String fileName;
private final boolean resuming;
private final int totalBytes;
ConnectedMessageSnapshot(int i, boolean z, int i2, String str, String str2) {
super(i);
this.resuming = z;
this.totalBytes = i2;
this.etag = str;
this.fileName = str2;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public int describeContents() {
return 0;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public String getEtag() {
return this.etag;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public String getFileName() {
return this.fileName;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public int getSmallTotalBytes() {
return this.totalBytes;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public byte getStatus() {
return (byte) 2;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot
public boolean isResuming() {
return this.resuming;
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshot, android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
super.writeToParcel(parcel, i);
parcel.writeByte(this.resuming ? (byte) 1 : (byte) 0);
parcel.writeInt(this.totalBytes);
parcel.writeString(this.etag);
parcel.writeString(this.fileName);
}
ConnectedMessageSnapshot(Parcel parcel) {
super(parcel);
this.resuming = parcel.readByte() != 0;
this.totalBytes = parcel.readInt();
this.etag = parcel.readString();
this.fileName = parcel.readString();
}
}
}

View File

@@ -0,0 +1,77 @@
package com.liulishuo.filedownloader.model;
import android.content.ContentValues;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import com.ubt.jimu.controller.data.widget.JockstickDataConverter;
import java.util.List;
/* loaded from: classes.dex */
public class ConnectionModel {
private int a;
private int b;
private long c;
private long d;
private long e;
public void a(int i) {
this.a = i;
}
public void b(int i) {
this.b = i;
}
public int c() {
return this.a;
}
public int d() {
return this.b;
}
public long e() {
return this.c;
}
public ContentValues f() {
ContentValues contentValues = new ContentValues();
contentValues.put(JockstickDataConverter.ID, Integer.valueOf(this.a));
contentValues.put("connectionIndex", Integer.valueOf(this.b));
contentValues.put("startOffset", Long.valueOf(this.c));
contentValues.put("currentOffset", Long.valueOf(this.d));
contentValues.put("endOffset", Long.valueOf(this.e));
return contentValues;
}
public String toString() {
return FileDownloadUtils.a("id[%d] index[%d] range[%d, %d) current offset(%d)", Integer.valueOf(this.a), Integer.valueOf(this.b), Long.valueOf(this.c), Long.valueOf(this.e), Long.valueOf(this.d));
}
public long a() {
return this.d;
}
public long b() {
return this.e;
}
public void c(long j) {
this.c = j;
}
public void a(long j) {
this.d = j;
}
public void b(long j) {
this.e = j;
}
public static long a(List<ConnectionModel> list) {
long j = 0;
for (ConnectionModel connectionModel : list) {
j += connectionModel.a() - connectionModel.e();
}
return j;
}
}

View File

@@ -0,0 +1,87 @@
package com.liulishuo.filedownloader.model;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/* loaded from: classes.dex */
public class FileDownloadHeader implements Parcelable {
public static final Parcelable.Creator<FileDownloadHeader> CREATOR = new Parcelable.Creator<FileDownloadHeader>() { // from class: com.liulishuo.filedownloader.model.FileDownloadHeader.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public FileDownloadHeader createFromParcel(Parcel parcel) {
return new FileDownloadHeader(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public FileDownloadHeader[] newArray(int i) {
return new FileDownloadHeader[i];
}
};
private HashMap<String, List<String>> mHeaderMap;
public FileDownloadHeader() {
}
public void add(String str, String str2) {
if (str == null) {
throw new NullPointerException("name == null");
}
if (str.isEmpty()) {
throw new IllegalArgumentException("name is empty");
}
if (str2 == null) {
throw new NullPointerException("value == null");
}
if (this.mHeaderMap == null) {
this.mHeaderMap = new HashMap<>();
}
List<String> list = this.mHeaderMap.get(str);
if (list == null) {
list = new ArrayList<>();
this.mHeaderMap.put(str, list);
}
if (list.contains(str2)) {
return;
}
list.add(str2);
}
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public HashMap<String, List<String>> getHeaders() {
return this.mHeaderMap;
}
public void removeAll(String str) {
HashMap<String, List<String>> hashMap = this.mHeaderMap;
if (hashMap == null) {
return;
}
hashMap.remove(str);
}
public String toString() {
return this.mHeaderMap.toString();
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeMap(this.mHeaderMap);
}
protected FileDownloadHeader(Parcel parcel) {
this.mHeaderMap = parcel.readHashMap(String.class.getClassLoader());
}
public void add(String str) {
String[] split = str.split(":");
add(split[0].trim(), split[1].trim());
}
}

View File

@@ -0,0 +1,252 @@
package com.liulishuo.filedownloader.model;
import android.content.ContentValues;
import android.os.Parcel;
import android.os.Parcelable;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/* loaded from: classes.dex */
public class FileDownloadModel implements Parcelable {
public static final String CONNECTION_COUNT = "connectionCount";
public static final Parcelable.Creator<FileDownloadModel> CREATOR = new Parcelable.Creator<FileDownloadModel>() { // from class: com.liulishuo.filedownloader.model.FileDownloadModel.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public FileDownloadModel createFromParcel(Parcel parcel) {
return new FileDownloadModel(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public FileDownloadModel[] newArray(int i) {
return new FileDownloadModel[i];
}
};
public static final int DEFAULT_CALLBACK_PROGRESS_TIMES = 100;
public static final String ERR_MSG = "errMsg";
public static final String ETAG = "etag";
public static final String FILENAME = "filename";
public static final String ID = "_id";
public static final String PATH = "path";
public static final String PATH_AS_DIRECTORY = "pathAsDirectory";
public static final String SOFAR = "sofar";
public static final String STATUS = "status";
public static final String TOTAL = "total";
public static final int TOTAL_VALUE_IN_CHUNKED_RESOURCE = -1;
public static final String URL = "url";
private int connectionCount;
private String eTag;
private String errMsg;
private String filename;
private int id;
private boolean isLargeFile;
private String path;
private boolean pathAsDirectory;
private final AtomicLong soFar;
private final AtomicInteger status;
private long total;
private String url;
public FileDownloadModel() {
this.soFar = new AtomicLong();
this.status = new AtomicInteger();
}
public void deleteTargetFile() {
String targetFilePath = getTargetFilePath();
if (targetFilePath != null) {
File file = new File(targetFilePath);
if (file.exists()) {
file.delete();
}
}
}
public void deleteTaskFiles() {
deleteTempFile();
deleteTargetFile();
}
public void deleteTempFile() {
String tempFilePath = getTempFilePath();
if (tempFilePath != null) {
File file = new File(tempFilePath);
if (file.exists()) {
file.delete();
}
}
}
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public int getConnectionCount() {
return this.connectionCount;
}
public String getETag() {
return this.eTag;
}
public String getErrMsg() {
return this.errMsg;
}
public String getFilename() {
return this.filename;
}
public int getId() {
return this.id;
}
public String getPath() {
return this.path;
}
public long getSoFar() {
return this.soFar.get();
}
public byte getStatus() {
return (byte) this.status.get();
}
public String getTargetFilePath() {
return FileDownloadUtils.a(getPath(), isPathAsDirectory(), getFilename());
}
public String getTempFilePath() {
if (getTargetFilePath() == null) {
return null;
}
return FileDownloadUtils.j(getTargetFilePath());
}
public long getTotal() {
return this.total;
}
public String getUrl() {
return this.url;
}
public void increaseSoFar(long j) {
this.soFar.addAndGet(j);
}
public boolean isChunked() {
return this.total == -1;
}
public boolean isLargeFile() {
return this.isLargeFile;
}
public boolean isPathAsDirectory() {
return this.pathAsDirectory;
}
public void resetConnectionCount() {
this.connectionCount = 1;
}
public void setConnectionCount(int i) {
this.connectionCount = i;
}
public void setETag(String str) {
this.eTag = str;
}
public void setErrMsg(String str) {
this.errMsg = str;
}
public void setFilename(String str) {
this.filename = str;
}
public void setId(int i) {
this.id = i;
}
public void setPath(String str, boolean z) {
this.path = str;
this.pathAsDirectory = z;
}
public void setSoFar(long j) {
this.soFar.set(j);
}
public void setStatus(byte b) {
this.status.set(b);
}
public void setTotal(long j) {
this.isLargeFile = j > 2147483647L;
this.total = j;
}
public void setUrl(String str) {
this.url = str;
}
public ContentValues toContentValues() {
ContentValues contentValues = new ContentValues();
contentValues.put(ID, Integer.valueOf(getId()));
contentValues.put("url", getUrl());
contentValues.put(PATH, getPath());
contentValues.put(STATUS, Byte.valueOf(getStatus()));
contentValues.put(SOFAR, Long.valueOf(getSoFar()));
contentValues.put(TOTAL, Long.valueOf(getTotal()));
contentValues.put(ERR_MSG, getErrMsg());
contentValues.put(ETAG, getETag());
contentValues.put(CONNECTION_COUNT, Integer.valueOf(getConnectionCount()));
contentValues.put(PATH_AS_DIRECTORY, Boolean.valueOf(isPathAsDirectory()));
if (isPathAsDirectory() && getFilename() != null) {
contentValues.put(FILENAME, getFilename());
}
return contentValues;
}
public String toString() {
return FileDownloadUtils.a("id[%d], url[%s], path[%s], status[%d], sofar[%s], total[%d], etag[%s], %s", Integer.valueOf(this.id), this.url, this.path, Integer.valueOf(this.status.get()), this.soFar, Long.valueOf(this.total), this.eTag, super.toString());
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(this.id);
parcel.writeString(this.url);
parcel.writeString(this.path);
parcel.writeByte(this.pathAsDirectory ? (byte) 1 : (byte) 0);
parcel.writeString(this.filename);
parcel.writeByte((byte) this.status.get());
parcel.writeLong(this.soFar.get());
parcel.writeLong(this.total);
parcel.writeString(this.errMsg);
parcel.writeString(this.eTag);
parcel.writeInt(this.connectionCount);
parcel.writeByte(this.isLargeFile ? (byte) 1 : (byte) 0);
}
protected FileDownloadModel(Parcel parcel) {
this.id = parcel.readInt();
this.url = parcel.readString();
this.path = parcel.readString();
this.pathAsDirectory = parcel.readByte() != 0;
this.filename = parcel.readString();
this.status = new AtomicInteger(parcel.readByte());
this.soFar = new AtomicLong(parcel.readLong());
this.total = parcel.readLong();
this.errMsg = parcel.readString();
this.eTag = parcel.readString();
this.connectionCount = parcel.readInt();
this.isLargeFile = parcel.readByte() != 0;
}
}

View File

@@ -0,0 +1,71 @@
package com.liulishuo.filedownloader.model;
import com.liulishuo.filedownloader.BaseDownloadTask;
/* loaded from: classes.dex */
public class FileDownloadStatus {
public static boolean a(int i) {
return i > 0;
}
public static boolean a(int i, int i2) {
if ((i != 3 && i != 5 && i == i2) || b(i)) {
return false;
}
if (i >= 1 && i <= 6 && i2 >= 10 && i2 <= 11) {
return false;
}
if (i == 1) {
return i2 != 0;
}
if (i == 2) {
return (i2 == 0 || i2 == 1 || i2 == 6) ? false : true;
}
if (i == 3) {
return (i2 == 0 || i2 == 1 || i2 == 2 || i2 == 6) ? false : true;
}
if (i == 5) {
return (i2 == 1 || i2 == 6) ? false : true;
}
if (i != 6) {
return true;
}
return (i2 == 0 || i2 == 1) ? false : true;
}
public static boolean b(int i) {
return i < 0;
}
public static boolean b(int i, int i2) {
if ((i != 3 && i != 5 && i == i2) || b(i)) {
return false;
}
if (i2 == -2 || i2 == -1) {
return true;
}
if (i == 0) {
return i2 == 10;
}
if (i == 1) {
return i2 == 6;
}
if (i == 2 || i == 3) {
return i2 == -3 || i2 == 3 || i2 == 5;
}
if (i == 5 || i == 6) {
return i2 == 2 || i2 == 5;
}
if (i == 10) {
return i2 == 11;
}
if (i != 11) {
return false;
}
return i2 == -4 || i2 == -3 || i2 == 1;
}
public static boolean a(BaseDownloadTask baseDownloadTask) {
return baseDownloadTask.getStatus() == 0 || baseDownloadTask.getStatus() == 3;
}
}

View File

@@ -0,0 +1,84 @@
package com.liulishuo.filedownloader.model;
import android.os.Parcel;
import android.os.Parcelable;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
/* loaded from: classes.dex */
public class FileDownloadTaskAtom implements Parcelable {
public static final Parcelable.Creator<FileDownloadTaskAtom> CREATOR = new Parcelable.Creator<FileDownloadTaskAtom>() { // from class: com.liulishuo.filedownloader.model.FileDownloadTaskAtom.1
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public FileDownloadTaskAtom createFromParcel(Parcel parcel) {
return new FileDownloadTaskAtom(parcel);
}
/* JADX WARN: Can't rename method to resolve collision */
@Override // android.os.Parcelable.Creator
public FileDownloadTaskAtom[] newArray(int i) {
return new FileDownloadTaskAtom[i];
}
};
private int id;
private String path;
private long totalBytes;
private String url;
public FileDownloadTaskAtom(String str, String str2, long j) {
setUrl(str);
setPath(str2);
setTotalBytes(j);
}
@Override // android.os.Parcelable
public int describeContents() {
return 0;
}
public int getId() {
int i = this.id;
if (i != 0) {
return i;
}
int c = FileDownloadUtils.c(getUrl(), getPath());
this.id = c;
return c;
}
public String getPath() {
return this.path;
}
public long getTotalBytes() {
return this.totalBytes;
}
public String getUrl() {
return this.url;
}
public void setPath(String str) {
this.path = str;
}
public void setTotalBytes(long j) {
this.totalBytes = j;
}
public void setUrl(String str) {
this.url = str;
}
@Override // android.os.Parcelable
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(this.url);
parcel.writeString(this.path);
parcel.writeLong(this.totalBytes);
}
protected FileDownloadTaskAtom(Parcel parcel) {
this.url = parcel.readString();
this.path = parcel.readString();
this.totalBytes = parcel.readLong();
}
}

View File

@@ -0,0 +1,127 @@
package com.liulishuo.filedownloader.services;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.os.RemoteException;
import com.liulishuo.filedownloader.FileDownloadEventPool;
import com.liulishuo.filedownloader.IFileDownloadServiceProxy;
import com.liulishuo.filedownloader.event.DownloadServiceConnectChangedEvent;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
public abstract class BaseFileServiceUIGuard<CALLBACK extends Binder, INTERFACE extends IInterface> implements IFileDownloadServiceProxy, ServiceConnection {
private final CALLBACK a;
private volatile INTERFACE b;
private final Class<?> c;
private final List<Context> d;
private final ArrayList<Runnable> e;
protected BaseFileServiceUIGuard(Class<?> cls) {
new HashMap();
this.d = new ArrayList();
this.e = new ArrayList<>();
this.c = cls;
this.a = a();
}
private void a(boolean z) {
if (!z && this.b != null) {
try {
b(this.b, this.a);
} catch (RemoteException e) {
e.printStackTrace();
}
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "release connect resources %s", this.b);
}
this.b = null;
FileDownloadEventPool.a().a(new DownloadServiceConnectChangedEvent(z ? DownloadServiceConnectChangedEvent.ConnectStatus.lost : DownloadServiceConnectChangedEvent.ConnectStatus.disconnected, this.c));
}
protected abstract CALLBACK a();
protected abstract INTERFACE a(IBinder iBinder);
protected abstract void a(INTERFACE r1, CALLBACK callback) throws RemoteException;
protected abstract void b(INTERFACE r1, CALLBACK callback) throws RemoteException;
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public boolean b() {
return c() != null;
}
protected INTERFACE c() {
return this.b;
}
@Override // android.content.ServiceConnection
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
this.b = a(iBinder);
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "onServiceConnected %s %s", componentName, this.b);
}
try {
a((BaseFileServiceUIGuard<CALLBACK, INTERFACE>) this.b, (INTERFACE) this.a);
} catch (RemoteException e) {
e.printStackTrace();
}
List list = (List) this.e.clone();
this.e.clear();
Iterator it = list.iterator();
while (it.hasNext()) {
((Runnable) it.next()).run();
}
FileDownloadEventPool.a().a(new DownloadServiceConnectChangedEvent(DownloadServiceConnectChangedEvent.ConnectStatus.connected, this.c));
}
@Override // android.content.ServiceConnection
public void onServiceDisconnected(ComponentName componentName) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "onServiceDisconnected %s %s", componentName, this.b);
}
a(true);
}
@Override // com.liulishuo.filedownloader.IFileDownloadServiceProxy
public void a(Context context) {
a(context, (Runnable) null);
}
public void a(Context context, Runnable runnable) {
if (!FileDownloadUtils.c(context)) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "bindStartByContext %s", context.getClass().getSimpleName());
}
Intent intent = new Intent(context, this.c);
if (runnable != null && !this.e.contains(runnable)) {
this.e.add(runnable);
}
if (!this.d.contains(context)) {
this.d.add(context);
}
context.bindService(intent, this, 1);
if (FileDownloadUtils.e(context)) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "start foreground service", new Object[0]);
}
context.startForegroundService(intent);
return;
}
context.startService(intent);
return;
}
throw new IllegalStateException("Fatal-Exception: You can't bind the FileDownloadService in :filedownloader process.\n It's the invalid operation and is likely to cause unexpected problems.\n Maybe you want to use non-separate process mode for FileDownloader, More detail about non-separate mode, please move to wiki manually: https://github.com/lingochamp/FileDownloader/wiki/filedownloader.properties");
}
}

View File

@@ -0,0 +1,17 @@
package com.liulishuo.filedownloader.services;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
/* loaded from: classes.dex */
public class DefaultIdGenerator implements FileDownloadHelper.IdGenerator {
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.IdGenerator
public int a(int i, String str, String str2, boolean z) {
return a(str, str2, z);
}
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.IdGenerator
public int a(String str, String str2, boolean z) {
return z ? FileDownloadUtils.m(FileDownloadUtils.a("%sp%s@dir", str, str2)).hashCode() : FileDownloadUtils.m(FileDownloadUtils.a("%sp%s", str, str2)).hashCode();
}
}

View File

@@ -0,0 +1,162 @@
package com.liulishuo.filedownloader.services;
import com.liulishuo.filedownloader.connection.DefaultConnectionCountAdapter;
import com.liulishuo.filedownloader.connection.FileDownloadUrlConnection;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.database.RemitDatabase;
import com.liulishuo.filedownloader.services.ForegroundServiceConfig;
import com.liulishuo.filedownloader.stream.FileDownloadRandomAccessFile;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
/* loaded from: classes.dex */
public class DownloadMgrInitialParams {
private final InitCustomMaker a = null;
public static class InitCustomMaker {
FileDownloadHelper.DatabaseCustomMaker a;
Integer b;
FileDownloadHelper.OutputStreamCreator c;
FileDownloadHelper.ConnectionCreator d;
FileDownloadHelper.ConnectionCountAdapter e;
FileDownloadHelper.IdGenerator f;
ForegroundServiceConfig g;
}
private FileDownloadHelper.ConnectionCountAdapter h() {
return new DefaultConnectionCountAdapter();
}
private FileDownloadHelper.ConnectionCreator i() {
return new FileDownloadUrlConnection.Creator();
}
private FileDownloadDatabase j() {
return new RemitDatabase();
}
private ForegroundServiceConfig k() {
ForegroundServiceConfig.Builder builder = new ForegroundServiceConfig.Builder();
builder.a(true);
return builder.a();
}
private FileDownloadHelper.IdGenerator l() {
return new DefaultIdGenerator();
}
private FileDownloadHelper.OutputStreamCreator m() {
return new FileDownloadRandomAccessFile.Creator();
}
private int n() {
return FileDownloadProperties.a().e;
}
public FileDownloadHelper.ConnectionCountAdapter a() {
InitCustomMaker initCustomMaker = this.a;
if (initCustomMaker == null) {
return h();
}
FileDownloadHelper.ConnectionCountAdapter connectionCountAdapter = initCustomMaker.e;
if (connectionCountAdapter == null) {
return h();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "initial FileDownloader manager with the customize connection count adapter: %s", connectionCountAdapter);
}
return connectionCountAdapter;
}
public FileDownloadHelper.ConnectionCreator b() {
InitCustomMaker initCustomMaker = this.a;
if (initCustomMaker == null) {
return i();
}
FileDownloadHelper.ConnectionCreator connectionCreator = initCustomMaker.d;
if (connectionCreator == null) {
return i();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "initial FileDownloader manager with the customize connection creator: %s", connectionCreator);
}
return connectionCreator;
}
public FileDownloadDatabase c() {
FileDownloadHelper.DatabaseCustomMaker databaseCustomMaker;
InitCustomMaker initCustomMaker = this.a;
if (initCustomMaker == null || (databaseCustomMaker = initCustomMaker.a) == null) {
return j();
}
FileDownloadDatabase a = databaseCustomMaker.a();
if (a == null) {
return j();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "initial FileDownloader manager with the customize database: %s", a);
}
return a;
}
public ForegroundServiceConfig d() {
InitCustomMaker initCustomMaker = this.a;
if (initCustomMaker == null) {
return k();
}
ForegroundServiceConfig foregroundServiceConfig = initCustomMaker.g;
if (foregroundServiceConfig == null) {
return k();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "initial FileDownloader manager with the customize foreground service config: %s", foregroundServiceConfig);
}
return foregroundServiceConfig;
}
public FileDownloadHelper.IdGenerator e() {
InitCustomMaker initCustomMaker = this.a;
if (initCustomMaker == null) {
return l();
}
FileDownloadHelper.IdGenerator idGenerator = initCustomMaker.f;
if (idGenerator == null) {
return l();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "initial FileDownloader manager with the customize id generator: %s", idGenerator);
}
return idGenerator;
}
public FileDownloadHelper.OutputStreamCreator f() {
InitCustomMaker initCustomMaker = this.a;
if (initCustomMaker == null) {
return m();
}
FileDownloadHelper.OutputStreamCreator outputStreamCreator = initCustomMaker.c;
if (outputStreamCreator == null) {
return m();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "initial FileDownloader manager with the customize output stream: %s", outputStreamCreator);
}
return outputStreamCreator;
}
public int g() {
InitCustomMaker initCustomMaker = this.a;
if (initCustomMaker == null) {
return n();
}
Integer num = initCustomMaker.b;
if (num == null) {
return n();
}
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "initial FileDownloader manager with the customize maxNetworkThreadCount: %d", num);
}
return FileDownloadProperties.a(num.intValue());
}
}

View File

@@ -0,0 +1,151 @@
package com.liulishuo.filedownloader.services;
import android.app.Notification;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import com.liulishuo.filedownloader.i.IFileDownloadIPCCallback;
import com.liulishuo.filedownloader.i.IFileDownloadIPCService;
import com.liulishuo.filedownloader.message.MessageSnapshot;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import java.lang.ref.WeakReference;
/* loaded from: classes.dex */
public class FDServiceSeparateHandler extends IFileDownloadIPCService.Stub implements MessageSnapshotFlow.MessageReceiver, IFileDownloadServiceHandler {
private final RemoteCallbackList<IFileDownloadIPCCallback> a = new RemoteCallbackList<>();
private final FileDownloadManager b;
private final WeakReference<FileDownloadService> c;
FDServiceSeparateHandler(WeakReference<FileDownloadService> weakReference, FileDownloadManager fileDownloadManager) {
this.c = weakReference;
this.b = fileDownloadManager;
MessageSnapshotFlow.a().a(this);
}
private synchronized int b(MessageSnapshot messageSnapshot) {
int beginBroadcast;
RemoteCallbackList<IFileDownloadIPCCallback> remoteCallbackList;
beginBroadcast = this.a.beginBroadcast();
for (int i = 0; i < beginBroadcast; i++) {
try {
try {
this.a.getBroadcastItem(i).a(messageSnapshot);
} catch (RemoteException e) {
FileDownloadLog.a(this, e, "callback error", new Object[0]);
remoteCallbackList = this.a;
}
} catch (Throwable th) {
this.a.finishBroadcast();
throw th;
}
}
remoteCallbackList = this.a;
remoteCallbackList.finishBroadcast();
return beginBroadcast;
}
@Override // com.liulishuo.filedownloader.services.IFileDownloadServiceHandler
public IBinder a(Intent intent) {
return this;
}
@Override // com.liulishuo.filedownloader.services.IFileDownloadServiceHandler
public void a(Intent intent, int i, int i2) {
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(IFileDownloadIPCCallback iFileDownloadIPCCallback) throws RemoteException {
this.a.register(iFileDownloadIPCCallback);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean c(int i) throws RemoteException {
return this.b.g(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean d() throws RemoteException {
return this.b.b();
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void e() throws RemoteException {
this.b.c();
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public long f(int i) throws RemoteException {
return this.b.b(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean a(String str, String str2) throws RemoteException {
return this.b.a(str, str2);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void c() throws RemoteException {
this.b.a();
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean d(int i) throws RemoteException {
return this.b.a(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public long e(int i) throws RemoteException {
return this.b.d(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) throws RemoteException {
this.b.a(str, str2, z, i, i2, i3, z2, fileDownloadHeader, z3);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public byte a(int i) throws RemoteException {
return this.b.c(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(int i, Notification notification) throws RemoteException {
WeakReference<FileDownloadService> weakReference = this.c;
if (weakReference == null || weakReference.get() == null) {
return;
}
this.c.get().startForeground(i, notification);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void b(IFileDownloadIPCCallback iFileDownloadIPCCallback) throws RemoteException {
this.a.unregister(iFileDownloadIPCCallback);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(boolean z) throws RemoteException {
WeakReference<FileDownloadService> weakReference = this.c;
if (weakReference == null || weakReference.get() == null) {
return;
}
this.c.get().stopForeground(z);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean b(int i) throws RemoteException {
return this.b.f(i);
}
@Override // com.liulishuo.filedownloader.services.IFileDownloadServiceHandler
public void a() {
MessageSnapshotFlow.a().a((MessageSnapshotFlow.MessageReceiver) null);
}
@Override // com.liulishuo.filedownloader.message.MessageSnapshotFlow.MessageReceiver
public void a(MessageSnapshot messageSnapshot) {
b(messageSnapshot);
}
}

View File

@@ -0,0 +1,123 @@
package com.liulishuo.filedownloader.services;
import android.app.Notification;
import android.content.Intent;
import android.os.IBinder;
import com.liulishuo.filedownloader.FileDownloadServiceProxy;
import com.liulishuo.filedownloader.i.IFileDownloadIPCCallback;
import com.liulishuo.filedownloader.i.IFileDownloadIPCService;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import java.lang.ref.WeakReference;
/* loaded from: classes.dex */
public class FDServiceSharedHandler extends IFileDownloadIPCService.Stub implements IFileDownloadServiceHandler {
private final FileDownloadManager a;
private final WeakReference<FileDownloadService> b;
public interface FileDownloadServiceSharedConnection {
void a(FDServiceSharedHandler fDServiceSharedHandler);
void onDisconnected();
}
FDServiceSharedHandler(WeakReference<FileDownloadService> weakReference, FileDownloadManager fileDownloadManager) {
this.b = weakReference;
this.a = fileDownloadManager;
}
@Override // com.liulishuo.filedownloader.services.IFileDownloadServiceHandler
public IBinder a(Intent intent) {
return null;
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(IFileDownloadIPCCallback iFileDownloadIPCCallback) {
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean a(String str, String str2) {
return this.a.a(str, str2);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void b(IFileDownloadIPCCallback iFileDownloadIPCCallback) {
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean b(int i) {
return this.a.f(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean c(int i) {
return this.a.g(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean d() {
return this.a.b();
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void e() {
this.a.c();
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public long f(int i) {
return this.a.b(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) {
this.a.a(str, str2, z, i, i2, i3, z2, fileDownloadHeader, z3);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void c() {
this.a.a();
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public boolean d(int i) {
return this.a.a(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public long e(int i) {
return this.a.d(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public byte a(int i) {
return this.a.c(i);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(int i, Notification notification) {
WeakReference<FileDownloadService> weakReference = this.b;
if (weakReference == null || weakReference.get() == null) {
return;
}
this.b.get().startForeground(i, notification);
}
@Override // com.liulishuo.filedownloader.i.IFileDownloadIPCService
public void a(boolean z) {
WeakReference<FileDownloadService> weakReference = this.b;
if (weakReference == null || weakReference.get() == null) {
return;
}
this.b.get().stopForeground(z);
}
@Override // com.liulishuo.filedownloader.services.IFileDownloadServiceHandler
public void a(Intent intent, int i, int i2) {
FileDownloadServiceProxy.a().a(this);
}
@Override // com.liulishuo.filedownloader.services.IFileDownloadServiceHandler
public void a() {
FileDownloadServiceProxy.a().onDisconnected();
}
}

View File

@@ -0,0 +1,20 @@
package com.liulishuo.filedownloader.services;
import android.content.Intent;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
/* loaded from: classes.dex */
public class FileDownloadBroadcastHandler {
public static void a(FileDownloadModel fileDownloadModel) {
if (fileDownloadModel == null) {
throw new IllegalArgumentException();
}
if (fileDownloadModel.getStatus() != -3) {
throw new IllegalStateException();
}
Intent intent = new Intent("filedownloader.intent.action.completed");
intent.putExtra("model", fileDownloadModel);
FileDownloadHelper.a().sendBroadcast(intent);
}
}

View File

@@ -0,0 +1,230 @@
package com.liulishuo.filedownloader.services;
import android.text.TextUtils;
import com.liulishuo.filedownloader.IThreadPoolMonitor;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.download.CustomComponentHolder;
import com.liulishuo.filedownloader.download.DownloadLaunchRunnable;
import com.liulishuo.filedownloader.model.ConnectionModel;
import com.liulishuo.filedownloader.model.FileDownloadHeader;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.model.FileDownloadStatus;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
class FileDownloadManager implements IThreadPoolMonitor {
private final FileDownloadDatabase a;
private final FileDownloadThreadPool b;
FileDownloadManager() {
CustomComponentHolder i = CustomComponentHolder.i();
this.a = i.a();
this.b = new FileDownloadThreadPool(i.d());
}
public synchronized void a(String str, String str2, boolean z, int i, int i2, int i3, boolean z2, FileDownloadHeader fileDownloadHeader, boolean z3) {
FileDownloadModel fileDownloadModel;
List<ConnectionModel> list;
boolean z4 = true;
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "request start the task with url(%s) path(%s) isDirectory(%B)", str, str2, Boolean.valueOf(z));
}
int a = FileDownloadUtils.a(str, str2, z);
FileDownloadModel e = this.a.e(a);
if (z || e != null) {
fileDownloadModel = e;
list = null;
} else {
int a2 = FileDownloadUtils.a(str, FileDownloadUtils.i(str2), true);
FileDownloadModel e2 = this.a.e(a2);
if (e2 == null || !str2.equals(e2.getTargetFilePath())) {
list = null;
} else {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "task[%d] find model by dirCaseId[%d]", Integer.valueOf(a), Integer.valueOf(a2));
}
list = this.a.d(a2);
}
fileDownloadModel = e2;
}
if (FileDownloadHelper.a(a, fileDownloadModel, (IThreadPoolMonitor) this, true)) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "has already started download %d", Integer.valueOf(a));
}
return;
}
String targetFilePath = fileDownloadModel != null ? fileDownloadModel.getTargetFilePath() : FileDownloadUtils.a(str2, z, (String) null);
if (FileDownloadHelper.a(a, targetFilePath, z2, true)) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "has already completed downloading %d", Integer.valueOf(a));
}
return;
}
if (FileDownloadHelper.a(a, fileDownloadModel != null ? fileDownloadModel.getSoFar() : 0L, fileDownloadModel != null ? fileDownloadModel.getTempFilePath() : FileDownloadUtils.j(targetFilePath), targetFilePath, this)) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "there is an another task with the same target-file-path %d %s", Integer.valueOf(a), targetFilePath);
}
if (fileDownloadModel != null) {
this.a.remove(a);
this.a.b(a);
}
return;
}
if (fileDownloadModel == null || !(fileDownloadModel.getStatus() == -2 || fileDownloadModel.getStatus() == -1 || fileDownloadModel.getStatus() == 1 || fileDownloadModel.getStatus() == 6 || fileDownloadModel.getStatus() == 2)) {
if (fileDownloadModel == null) {
fileDownloadModel = new FileDownloadModel();
}
fileDownloadModel.setUrl(str);
fileDownloadModel.setPath(str2, z);
fileDownloadModel.setId(a);
fileDownloadModel.setSoFar(0L);
fileDownloadModel.setTotal(0L);
fileDownloadModel.setStatus((byte) 1);
fileDownloadModel.setConnectionCount(1);
} else if (fileDownloadModel.getId() != a) {
this.a.remove(fileDownloadModel.getId());
this.a.b(fileDownloadModel.getId());
fileDownloadModel.setId(a);
fileDownloadModel.setPath(str2, z);
if (list != null) {
for (ConnectionModel connectionModel : list) {
connectionModel.a(a);
this.a.a(connectionModel);
}
}
} else if (TextUtils.equals(str, fileDownloadModel.getUrl())) {
z4 = false;
} else {
fileDownloadModel.setUrl(str);
}
if (z4) {
this.a.a(fileDownloadModel);
}
DownloadLaunchRunnable.Builder builder = new DownloadLaunchRunnable.Builder();
builder.a(fileDownloadModel);
builder.a(fileDownloadHeader);
builder.a(this);
builder.c(Integer.valueOf(i2));
builder.a(Integer.valueOf(i));
builder.a(Boolean.valueOf(z2));
builder.b(Boolean.valueOf(z3));
builder.b(Integer.valueOf(i3));
this.b.a(builder.a());
}
public long b(int i) {
FileDownloadModel e = this.a.e(i);
if (e == null) {
return 0L;
}
int connectionCount = e.getConnectionCount();
if (connectionCount <= 1) {
return e.getSoFar();
}
List<ConnectionModel> d = this.a.d(i);
if (d == null || d.size() != connectionCount) {
return 0L;
}
return ConnectionModel.a(d);
}
public void c() {
List<Integer> b = this.b.b();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "pause all tasks %d", Integer.valueOf(b.size()));
}
Iterator<Integer> it = b.iterator();
while (it.hasNext()) {
f(it.next().intValue());
}
}
public long d(int i) {
FileDownloadModel e = this.a.e(i);
if (e == null) {
return 0L;
}
return e.getTotal();
}
public boolean e(int i) {
return a(this.a.e(i));
}
public boolean f(int i) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "request pause the task %d", Integer.valueOf(i));
}
FileDownloadModel e = this.a.e(i);
if (e == null) {
return false;
}
e.setStatus((byte) -2);
this.b.a(i);
return true;
}
public synchronized boolean g(int i) {
return this.b.c(i);
}
public byte c(int i) {
FileDownloadModel e = this.a.e(i);
if (e == null) {
return (byte) 0;
}
return e.getStatus();
}
public boolean b() {
return this.b.a() <= 0;
}
public boolean a(String str, String str2) {
return e(FileDownloadUtils.c(str, str2));
}
@Override // com.liulishuo.filedownloader.IThreadPoolMonitor
public boolean a(FileDownloadModel fileDownloadModel) {
if (fileDownloadModel == null) {
return false;
}
boolean b = this.b.b(fileDownloadModel.getId());
if (FileDownloadStatus.b(fileDownloadModel.getStatus())) {
if (!b) {
return false;
}
} else if (!b) {
FileDownloadLog.b(this, "%d status is[%s](not finish) & but not in the pool", Integer.valueOf(fileDownloadModel.getId()), Byte.valueOf(fileDownloadModel.getStatus()));
return false;
}
return true;
}
@Override // com.liulishuo.filedownloader.IThreadPoolMonitor
public int a(String str, int i) {
return this.b.a(str, i);
}
public boolean a(int i) {
if (i == 0) {
FileDownloadLog.e(this, "The task[%d] id is invalid, can't clear it.", Integer.valueOf(i));
return false;
}
if (e(i)) {
FileDownloadLog.e(this, "The task[%d] is downloading, can't clear it.", Integer.valueOf(i));
return false;
}
this.a.remove(i);
this.a.b(i);
return true;
}
public void a() {
this.a.clear();
}
}

View File

@@ -0,0 +1,85 @@
package com.liulishuo.filedownloader.services;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import com.liulishuo.filedownloader.download.CustomComponentHolder;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
import com.liulishuo.filedownloader.util.FileDownloadUtils;
import java.lang.ref.WeakReference;
@SuppressLint({"Registered"})
/* loaded from: classes.dex */
public class FileDownloadService extends Service {
private IFileDownloadServiceHandler a;
public static class SeparateProcessService extends FileDownloadService {
}
public static class SharedMainProcessService extends FileDownloadService {
}
@TargetApi(26)
private void a() {
ForegroundServiceConfig b = CustomComponentHolder.i().b();
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "make service foreground: %s", b);
}
if (b.d()) {
NotificationChannel notificationChannel = new NotificationChannel(b.a(), b.b(), 2);
NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
if (notificationManager == null) {
return;
} else {
notificationManager.createNotificationChannel(notificationChannel);
}
}
startForeground(b.c(), b.a(this));
}
@Override // android.app.Service
public IBinder onBind(Intent intent) {
return this.a.a(intent);
}
@Override // android.app.Service
public void onCreate() {
super.onCreate();
FileDownloadHelper.a(this);
try {
FileDownloadUtils.a(FileDownloadProperties.a().a);
FileDownloadUtils.a(FileDownloadProperties.a().b);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
FileDownloadManager fileDownloadManager = new FileDownloadManager();
if (FileDownloadProperties.a().d) {
this.a = new FDServiceSharedHandler(new WeakReference(this), fileDownloadManager);
} else {
this.a = new FDServiceSeparateHandler(new WeakReference(this), fileDownloadManager);
}
}
@Override // android.app.Service
public void onDestroy() {
this.a.a();
stopForeground(true);
super.onDestroy();
}
@Override // android.app.Service
public int onStartCommand(Intent intent, int i, int i2) {
this.a.a(intent, i, i2);
if (!FileDownloadUtils.e(this)) {
return 1;
}
a();
return 1;
}
}

View File

@@ -0,0 +1,118 @@
package com.liulishuo.filedownloader.services;
import android.util.SparseArray;
import com.liulishuo.filedownloader.download.DownloadLaunchRunnable;
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
import com.liulishuo.filedownloader.util.FileDownloadLog;
import com.liulishuo.filedownloader.util.FileDownloadProperties;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;
/* loaded from: classes.dex */
class FileDownloadThreadPool {
private ThreadPoolExecutor b;
private int c;
private SparseArray<DownloadLaunchRunnable> a = new SparseArray<>();
private int d = 0;
FileDownloadThreadPool(int i) {
this.b = FileDownloadExecutors.a(i, "Network");
this.c = i;
}
public void a(DownloadLaunchRunnable downloadLaunchRunnable) {
downloadLaunchRunnable.e();
synchronized (this) {
this.a.put(downloadLaunchRunnable.b(), downloadLaunchRunnable);
}
this.b.execute(downloadLaunchRunnable);
int i = this.d;
if (i < 600) {
this.d = i + 1;
} else {
c();
this.d = 0;
}
}
public boolean b(int i) {
DownloadLaunchRunnable downloadLaunchRunnable = this.a.get(i);
return downloadLaunchRunnable != null && downloadLaunchRunnable.d();
}
public synchronized boolean c(int i) {
if (a() > 0) {
FileDownloadLog.e(this, "Can't change the max network thread count, because the network thread pool isn't in IDLE, please try again after all running tasks are completed or invoking FileDownloader#pauseAll directly.", new Object[0]);
return false;
}
int a = FileDownloadProperties.a(i);
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "change the max network thread count, from %d to %d", Integer.valueOf(this.c), Integer.valueOf(a));
}
List<Runnable> shutdownNow = this.b.shutdownNow();
this.b = FileDownloadExecutors.a(a, "Network");
if (shutdownNow.size() > 0) {
FileDownloadLog.e(this, "recreate the network thread pool and discard %d tasks", Integer.valueOf(shutdownNow.size()));
}
this.c = a;
return true;
}
public synchronized List<Integer> b() {
ArrayList arrayList;
c();
arrayList = new ArrayList();
for (int i = 0; i < this.a.size(); i++) {
arrayList.add(Integer.valueOf(this.a.get(this.a.keyAt(i)).b()));
}
return arrayList;
}
public void a(int i) {
c();
synchronized (this) {
DownloadLaunchRunnable downloadLaunchRunnable = this.a.get(i);
if (downloadLaunchRunnable != null) {
downloadLaunchRunnable.pause();
boolean remove = this.b.remove(downloadLaunchRunnable);
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "successful cancel %d %B", Integer.valueOf(i), Boolean.valueOf(remove));
}
}
this.a.remove(i);
}
}
private synchronized void c() {
SparseArray<DownloadLaunchRunnable> sparseArray = new SparseArray<>();
int size = this.a.size();
for (int i = 0; i < size; i++) {
int keyAt = this.a.keyAt(i);
DownloadLaunchRunnable downloadLaunchRunnable = this.a.get(keyAt);
if (downloadLaunchRunnable.d()) {
sparseArray.put(keyAt, downloadLaunchRunnable);
}
}
this.a = sparseArray;
}
public int a(String str, int i) {
if (str == null) {
return 0;
}
int size = this.a.size();
for (int i2 = 0; i2 < size; i2++) {
DownloadLaunchRunnable valueAt = this.a.valueAt(i2);
if (valueAt != null && valueAt.d() && valueAt.b() != i && str.equals(valueAt.c())) {
return valueAt.b();
}
}
return 0;
}
public synchronized int a() {
c();
return this.a.size();
}
}

View File

@@ -0,0 +1,114 @@
package com.liulishuo.filedownloader.services;
import android.R;
import android.annotation.TargetApi;
import android.app.Notification;
import android.content.Context;
import com.liulishuo.filedownloader.R$string;
import com.liulishuo.filedownloader.util.FileDownloadLog;
@TargetApi(26)
/* loaded from: classes.dex */
public class ForegroundServiceConfig {
private int a;
private String b;
private String c;
private Notification d;
private boolean e;
public static class Builder {
private int a;
private String b;
private String c;
private Notification d;
private boolean e;
public Builder a(boolean z) {
this.e = z;
return this;
}
public ForegroundServiceConfig a() {
ForegroundServiceConfig foregroundServiceConfig = new ForegroundServiceConfig();
String str = this.b;
if (str == null) {
str = "filedownloader_channel";
}
foregroundServiceConfig.a(str);
String str2 = this.c;
if (str2 == null) {
str2 = "Filedownloader";
}
foregroundServiceConfig.b(str2);
int i = this.a;
if (i == 0) {
i = R.drawable.arrow_down_float;
}
foregroundServiceConfig.a(i);
foregroundServiceConfig.a(this.e);
foregroundServiceConfig.a(this.d);
return foregroundServiceConfig;
}
}
public String a() {
return this.b;
}
public String b() {
return this.c;
}
public int c() {
return this.a;
}
public boolean d() {
return this.e;
}
public String toString() {
return "ForegroundServiceConfig{notificationId=" + this.a + ", notificationChannelId='" + this.b + "', notificationChannelName='" + this.c + "', notification=" + this.d + ", needRecreateChannelId=" + this.e + '}';
}
private ForegroundServiceConfig() {
}
public Notification a(Context context) {
if (this.d == null) {
if (FileDownloadLog.a) {
FileDownloadLog.a(this, "build default notification", new Object[0]);
}
this.d = b(context);
}
return this.d;
}
public void b(String str) {
this.c = str;
}
private Notification b(Context context) {
String string = context.getString(R$string.default_filedownloader_notification_title);
String string2 = context.getString(R$string.default_filedownloader_notification_content);
Notification.Builder builder = new Notification.Builder(context, this.b);
builder.setContentTitle(string).setContentText(string2).setSmallIcon(R.drawable.arrow_down_float);
return builder.build();
}
public void a(int i) {
this.a = i;
}
public void a(String str) {
this.b = str;
}
public void a(Notification notification) {
this.d = notification;
}
public void a(boolean z) {
this.e = z;
}
}

View File

@@ -0,0 +1,13 @@
package com.liulishuo.filedownloader.services;
import android.content.Intent;
import android.os.IBinder;
/* loaded from: classes.dex */
interface IFileDownloadServiceHandler {
IBinder a(Intent intent);
void a();
void a(Intent intent, int i, int i2);
}

View File

@@ -0,0 +1,16 @@
package com.liulishuo.filedownloader.stream;
import java.io.IOException;
/* loaded from: classes.dex */
public interface FileDownloadOutputStream {
void a() throws IOException;
void a(long j) throws IOException, IllegalAccessException;
void b(long j) throws IOException, IllegalAccessException;
void close() throws IOException;
void write(byte[] bArr, int i, int i2) throws IOException;
}

View File

@@ -0,0 +1,61 @@
package com.liulishuo.filedownloader.stream;
import com.liulishuo.filedownloader.util.FileDownloadHelper;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
/* loaded from: classes.dex */
public class FileDownloadRandomAccessFile implements FileDownloadOutputStream {
private final BufferedOutputStream a;
private final FileDescriptor b;
private final RandomAccessFile c;
public static class Creator implements FileDownloadHelper.OutputStreamCreator {
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.OutputStreamCreator
public FileDownloadOutputStream a(File file) throws IOException {
return new FileDownloadRandomAccessFile(file);
}
@Override // com.liulishuo.filedownloader.util.FileDownloadHelper.OutputStreamCreator
public boolean a() {
return true;
}
}
FileDownloadRandomAccessFile(File file) throws IOException {
this.c = new RandomAccessFile(file, "rw");
this.b = this.c.getFD();
this.a = new BufferedOutputStream(new FileOutputStream(this.c.getFD()));
}
@Override // com.liulishuo.filedownloader.stream.FileDownloadOutputStream
public void a() throws IOException {
this.a.flush();
this.b.sync();
}
@Override // com.liulishuo.filedownloader.stream.FileDownloadOutputStream
public void b(long j) throws IOException {
this.c.seek(j);
}
@Override // com.liulishuo.filedownloader.stream.FileDownloadOutputStream
public void close() throws IOException {
this.a.close();
this.c.close();
}
@Override // com.liulishuo.filedownloader.stream.FileDownloadOutputStream
public void write(byte[] bArr, int i, int i2) throws IOException {
this.a.write(bArr, i, i2);
}
@Override // com.liulishuo.filedownloader.stream.FileDownloadOutputStream
public void a(long j) throws IOException {
this.c.setLength(j);
}
}

View File

@@ -0,0 +1,23 @@
package com.liulishuo.filedownloader.util;
/* loaded from: classes.dex */
public class DownloadServiceNotConnectedHelper {
public static boolean a(String str, String str2, boolean z) {
a("request start the task([%s], [%s], [%B]) in the download service", str, str2, Boolean.valueOf(z));
return false;
}
public static boolean b(int i) {
a("request pause the task[%d] in the download service", Integer.valueOf(i));
return false;
}
public static byte a(int i) {
a("request get the status for the task[%d] in the download service", Integer.valueOf(i));
return (byte) 0;
}
private static void a(String str, Object... objArr) {
FileDownloadLog.e(DownloadServiceNotConnectedHelper.class, str + ", but the download service isn't connected yet.\nYou can use FileDownloader#isServiceConnected() to check whether the service has been connected, \nbesides you can use following functions easier to control your code invoke after the service has been connected: \n1. FileDownloader#bindService(Runnable)\n2. FileDownloader#insureServiceBind()\n3. FileDownloader#insureServiceBindAsync()", objArr);
}
}

View File

@@ -0,0 +1,52 @@
package com.liulishuo.filedownloader.util;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes.dex */
public class FileDownloadExecutors {
static class FileDownloadThreadFactory implements ThreadFactory {
private final String a;
private final AtomicInteger c = new AtomicInteger(1);
private final ThreadGroup b = Thread.currentThread().getThreadGroup();
static {
new AtomicInteger(1);
}
FileDownloadThreadFactory(String str) {
this.a = FileDownloadUtils.k(str);
}
@Override // java.util.concurrent.ThreadFactory
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(this.b, runnable, this.a + this.c.getAndIncrement(), 0L);
if (thread.isDaemon()) {
thread.setDaemon(false);
}
if (thread.getPriority() != 5) {
thread.setPriority(5);
}
return thread;
}
}
public static ThreadPoolExecutor a(String str) {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 15L, TimeUnit.SECONDS, new SynchronousQueue(), new FileDownloadThreadFactory(str));
}
public static ThreadPoolExecutor a(int i, String str) {
return a(i, new LinkedBlockingQueue(), str);
}
public static ThreadPoolExecutor a(int i, LinkedBlockingQueue<Runnable> linkedBlockingQueue, String str) {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(i, i, 15L, TimeUnit.SECONDS, linkedBlockingQueue, new FileDownloadThreadFactory(str));
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;
}
}

View File

@@ -0,0 +1,81 @@
package com.liulishuo.filedownloader.util;
import android.annotation.SuppressLint;
import android.content.Context;
import com.liulishuo.filedownloader.IThreadPoolMonitor;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.database.FileDownloadDatabase;
import com.liulishuo.filedownloader.exception.PathConflictException;
import com.liulishuo.filedownloader.message.MessageSnapshotFlow;
import com.liulishuo.filedownloader.message.MessageSnapshotTaker;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.stream.FileDownloadOutputStream;
import java.io.File;
import java.io.IOException;
/* loaded from: classes.dex */
public class FileDownloadHelper {
@SuppressLint({"StaticFieldLeak"})
private static Context a;
public interface ConnectionCountAdapter {
int a(int i, String str, String str2, long j);
}
public interface ConnectionCreator {
FileDownloadConnection a(String str) throws IOException;
}
public interface DatabaseCustomMaker {
FileDownloadDatabase a();
}
public interface IdGenerator {
int a(int i, String str, String str2, boolean z);
int a(String str, String str2, boolean z);
}
public interface OutputStreamCreator {
FileDownloadOutputStream a(File file) throws IOException;
boolean a();
}
public static void a(Context context) {
a = context;
}
public static Context a() {
return a;
}
public static boolean a(int i, String str, boolean z, boolean z2) {
if (!z && str != null) {
File file = new File(str);
if (file.exists()) {
MessageSnapshotFlow.a().a(MessageSnapshotTaker.a(i, file, z2));
return true;
}
}
return false;
}
public static boolean a(int i, FileDownloadModel fileDownloadModel, IThreadPoolMonitor iThreadPoolMonitor, boolean z) {
if (!iThreadPoolMonitor.a(fileDownloadModel)) {
return false;
}
MessageSnapshotFlow.a().a(MessageSnapshotTaker.a(i, fileDownloadModel.getSoFar(), fileDownloadModel.getTotal(), z));
return true;
}
public static boolean a(int i, long j, String str, String str2, IThreadPoolMonitor iThreadPoolMonitor) {
int a2;
if (str2 == null || str == null || (a2 = iThreadPoolMonitor.a(str, i)) == 0) {
return false;
}
MessageSnapshotFlow.a().a(MessageSnapshotTaker.a(i, j, new PathConflictException(a2, str, str2)));
return true;
}
}

View File

@@ -0,0 +1,52 @@
package com.liulishuo.filedownloader.util;
import android.util.Log;
/* loaded from: classes.dex */
public class FileDownloadLog {
public static boolean a = false;
public static void a(Object obj, Throwable th, String str, Object... objArr) {
a(6, obj, th, str, objArr);
}
public static void b(Object obj, String str, Object... objArr) {
a(6, obj, str, objArr);
}
public static void c(Object obj, String str, Object... objArr) {
a(4, obj, str, objArr);
}
public static void d(Object obj, String str, Object... objArr) {
a(2, obj, str, objArr);
}
public static void e(Object obj, String str, Object... objArr) {
a(5, obj, str, objArr);
}
public static void a(Object obj, String str, Object... objArr) {
a(3, obj, str, objArr);
}
private static void a(int i, Object obj, String str, Object... objArr) {
a(i, obj, null, str, objArr);
}
private static void a(int i, Object obj, Throwable th, String str, Object... objArr) {
if ((i >= 5) || a) {
Log.println(i, a(obj), FileDownloadUtils.a(str, objArr));
if (th != null) {
th.printStackTrace();
}
}
}
private static String a(Object obj) {
StringBuilder sb = new StringBuilder();
sb.append("FileDownloader.");
sb.append((obj instanceof Class ? (Class) obj : obj.getClass()).getSimpleName());
return sb.toString();
}
}

View File

@@ -0,0 +1,74 @@
package com.liulishuo.filedownloader.util;
/* loaded from: classes.dex */
public class FileDownloadProperties {
public final int a;
public final long b;
public final boolean c;
public final boolean d;
public final int e;
public final boolean f;
public final boolean g;
public final boolean h;
public static class HolderClass {
private static final FileDownloadProperties a = new FileDownloadProperties();
}
public static FileDownloadProperties a() {
return HolderClass.a;
}
/* JADX WARN: Removed duplicated region for block: B:106:0x00c7 A[Catch: all -> 0x02a7, TryCatch #1 {all -> 0x02a7, blocks: (B:104:0x00c3, B:106:0x00c7, B:108:0x00cb, B:117:0x00d9), top: B:103:0x00c3 }] */
/* JADX WARN: Removed duplicated region for block: B:111:0x00e0 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:117:0x00d9 A[Catch: all -> 0x02a7, TRY_LEAVE, TryCatch #1 {all -> 0x02a7, blocks: (B:104:0x00c3, B:106:0x00c7, B:108:0x00cb, B:117:0x00d9), top: B:103:0x00c3 }] */
/* JADX WARN: Removed duplicated region for block: B:121:0x02ac A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:128:? A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:12:0x00fe */
/* JADX WARN: Removed duplicated region for block: B:21:0x0130 */
/* JADX WARN: Removed duplicated region for block: B:29:0x015b */
/* JADX WARN: Removed duplicated region for block: B:31:0x0170 */
/* JADX WARN: Removed duplicated region for block: B:33:0x018b */
/* JADX WARN: Removed duplicated region for block: B:35:0x01a0 */
/* JADX WARN: Removed duplicated region for block: B:43:0x01cd */
/* JADX WARN: Removed duplicated region for block: B:51:0x01f8 */
/* JADX WARN: Removed duplicated region for block: B:60:0x0225 */
/* JADX WARN: Removed duplicated region for block: B:62:? A[RETURN, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:63:0x021f */
/* JADX WARN: Removed duplicated region for block: B:64:0x01f4 */
/* JADX WARN: Removed duplicated region for block: B:65:0x01c8 */
/* JADX WARN: Removed duplicated region for block: B:66:0x019b */
/* JADX WARN: Removed duplicated region for block: B:67:0x0183 */
/* JADX WARN: Removed duplicated region for block: B:68:0x016a */
/* JADX WARN: Removed duplicated region for block: B:69:0x0157 */
/* JADX WARN: Removed duplicated region for block: B:70:0x0129 */
/* JADX WARN: Type inference failed for: r7v4 */
/* JADX WARN: Type inference failed for: r7v5, types: [boolean] */
/* JADX WARN: Type inference failed for: r7v7 */
/* JADX WARN: Type inference failed for: r8v1 */
/* JADX WARN: Type inference failed for: r8v2, types: [boolean, int] */
/* JADX WARN: Type inference failed for: r8v7 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
private FileDownloadProperties() {
/*
Method dump skipped, instructions count: 702
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.liulishuo.filedownloader.util.FileDownloadProperties.<init>():void");
}
public static int a(int i) {
if (i > 12) {
FileDownloadLog.e(FileDownloadProperties.class, "require the count of network thread is %d, what is more than the max valid count(%d), so adjust to %d auto", Integer.valueOf(i), 12, 12);
return 12;
}
if (i >= 1) {
return i;
}
FileDownloadLog.e(FileDownloadProperties.class, "require the count of network thread is %d, what is less than the min valid count(%d), so adjust to %d auto", Integer.valueOf(i), 1, 1);
return 1;
}
}

View File

@@ -0,0 +1,500 @@
package com.liulishuo.filedownloader.util;
import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.os.StatFs;
import android.text.TextUtils;
import com.liulishuo.filedownloader.connection.FileDownloadConnection;
import com.liulishuo.filedownloader.download.CustomComponentHolder;
import com.liulishuo.filedownloader.exception.FileDownloadGiveUpRetryException;
import com.liulishuo.filedownloader.exception.FileDownloadSecurityException;
import com.liulishuo.filedownloader.model.FileDownloadModel;
import com.liulishuo.filedownloader.stream.FileDownloadOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* loaded from: classes.dex */
public class FileDownloadUtils {
private static int a = 65536;
private static long b = 2000;
private static String c;
private static Boolean d;
private static final Pattern e = Pattern.compile("attachment;\\s*filename\\*\\s*=\\s*\"*([^\"]*)'\\S*'([^\"]*)\"*");
private static final Pattern f = Pattern.compile("attachment;\\s*filename\\s*=\\s*\"*([^\"\\n]*)\"*");
public static void a(int i) throws IllegalAccessException {
if (!c(FileDownloadHelper.a())) {
throw new IllegalAccessException("This value is used in the :filedownloader process, so set this value in your process is without effect. You can add 'process.non-separate=true' in 'filedownloader.properties' to share the main process to FileDownloadService. Or you can configure this value in 'filedownloader.properties' by 'download.min-progress-step'.");
}
a = i;
}
public static String b() {
return !TextUtils.isEmpty(c) ? c : FileDownloadHelper.a().getExternalCacheDir() == null ? Environment.getDownloadCacheDirectory().getAbsolutePath() : FileDownloadHelper.a().getExternalCacheDir().getAbsolutePath();
}
public static int c() {
return a;
}
public static long d() {
return b;
}
public static boolean e() {
ConnectivityManager connectivityManager = (ConnectivityManager) FileDownloadHelper.a().getSystemService("connectivity");
if (connectivityManager == null) {
FileDownloadLog.e(FileDownloadUtils.class, "failed to get connectivity manager!", new Object[0]);
return true;
}
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo == null || activeNetworkInfo.getType() != 1;
}
public static String f(String str) {
return m(str);
}
public static String g(String str) {
return b(b(), f(str));
}
public static long h(String str) {
return Build.VERSION.SDK_INT >= 18 ? new StatFs(str).getAvailableBytes() : r0.getAvailableBlocks() * r0.getBlockSize();
}
public static String i(String str) {
int length = str.length();
int i = (File.separatorChar == '\\' && length > 2 && str.charAt(1) == ':') ? 2 : 0;
int lastIndexOf = str.lastIndexOf(File.separatorChar);
int i2 = (lastIndexOf != -1 || i <= 0) ? lastIndexOf : 2;
if (i2 == -1) {
return null;
}
char charAt = str.charAt(length - 1);
char c2 = File.separatorChar;
if (charAt == c2) {
return null;
}
return (str.indexOf(c2) == i2 && str.charAt(i) == File.separatorChar) ? str.substring(0, i2 + 1) : str.substring(0, i2);
}
public static String j(String str) {
return a("%s.temp", str);
}
public static String k(String str) {
return "FileDownloader-" + str;
}
public static boolean l(String str) {
return true;
}
public static String m(String str) {
try {
byte[] digest = MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8"));
StringBuilder sb = new StringBuilder(digest.length * 2);
for (byte b2 : digest) {
int i = b2 & 255;
if (i < 16) {
sb.append("0");
}
sb.append(Integer.toHexString(i));
}
return sb.toString();
} catch (UnsupportedEncodingException e2) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e2);
} catch (NoSuchAlgorithmException e3) {
throw new RuntimeException("Huh, MD5 should be supported?", e3);
}
}
public static String n(String str) {
Matcher matcher;
if (str == null) {
return null;
}
try {
matcher = e.matcher(str);
} catch (UnsupportedEncodingException | IllegalStateException unused) {
}
if (matcher.find()) {
return URLDecoder.decode(matcher.group(2), matcher.group(1));
}
Matcher matcher2 = f.matcher(str);
if (matcher2.find()) {
return matcher2.group(1);
}
return null;
}
public static long o(String str) {
if (str != null && str.length() != 0) {
try {
Matcher matcher = Pattern.compile("bytes (\\d+)-(\\d+)/\\d+").matcher(str);
if (matcher.find()) {
return (Long.parseLong(matcher.group(2)) - Long.parseLong(matcher.group(1))) + 1;
}
} catch (Exception e2) {
FileDownloadLog.a(FileDownloadUtils.class, e2, "parse content length from content range error", new Object[0]);
}
}
return -1L;
}
public static long p(String str) {
if (str == null) {
return -1L;
}
String[] split = str.split("/");
if (split.length >= 2) {
try {
return Long.parseLong(split[1]);
} catch (NumberFormatException unused) {
FileDownloadLog.e(FileDownloadUtils.class, "parse instance length failed with %s", str);
}
}
return -1L;
}
public static int c(String str, String str2) {
return CustomComponentHolder.i().c().a(str, str2, false);
}
public static void d(Context context) {
File a2 = a(context);
try {
a2.getParentFile().mkdirs();
a2.createNewFile();
} catch (IOException e2) {
e2.printStackTrace();
}
}
public static void a(long j) throws IllegalAccessException {
if (c(FileDownloadHelper.a())) {
b = j;
return;
}
throw new IllegalAccessException("This value is used in the :filedownloader process, so set this value in your process is without effect. You can add 'process.non-separate=true' in 'filedownloader.properties' to share the main process to FileDownloadService. Or you can configure this value in 'filedownloader.properties' by 'download.min-progress-time'.");
}
public static boolean c(Context context) {
Boolean bool = d;
if (bool != null) {
return bool.booleanValue();
}
boolean z = false;
if (!FileDownloadProperties.a().d) {
int myPid = Process.myPid();
ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
if (activityManager == null) {
FileDownloadLog.e(FileDownloadUtils.class, "fail to get the activity manager!", new Object[0]);
return false;
}
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager.getRunningAppProcesses();
if (runningAppProcesses != null && !runningAppProcesses.isEmpty()) {
Iterator<ActivityManager.RunningAppProcessInfo> it = runningAppProcesses.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
ActivityManager.RunningAppProcessInfo next = it.next();
if (next.pid == myPid) {
z = next.processName.endsWith(":filedownloader");
break;
}
}
} else {
FileDownloadLog.e(FileDownloadUtils.class, "The running app process info list from ActivityManager is null or empty, maybe current App is not running.", new Object[0]);
return false;
}
} else {
z = true;
}
d = Boolean.valueOf(z);
return d.booleanValue();
}
public static String b(String str, String str2) {
if (str2 == null) {
throw new IllegalStateException("can't generate real path, the file name is null");
}
if (str != null) {
return a("%s%s%s", str, File.separator, str2);
}
throw new IllegalStateException("can't generate real path, the directory is null");
}
private static String d(FileDownloadConnection fileDownloadConnection) {
return fileDownloadConnection.a("Content-Range");
}
public static void e(String str) {
if (str != null) {
File file = new File(str);
if (file.exists()) {
file.delete();
}
}
}
public static int a(String str, String str2, boolean z) {
return CustomComponentHolder.i().c().a(str, str2, z);
}
public static void d(String str) {
if (str != null) {
File file = new File(str);
if (file.exists()) {
file.delete();
}
}
}
public static String a(String str, Object... objArr) {
return String.format(Locale.ENGLISH, str, objArr);
}
public static long b(String str) {
if (str == null) {
return -1L;
}
try {
return Long.parseLong(str);
} catch (NumberFormatException unused) {
return -1L;
}
}
public static boolean e(Context context) {
return Build.VERSION.SDK_INT >= 26 && !b(context);
}
public static File a(Context context) {
return new File(context.getFilesDir().getAbsolutePath() + File.separator + "filedownloader", ".old_file_converted");
}
public static String b(int i, FileDownloadConnection fileDownloadConnection) {
if (fileDownloadConnection != null) {
String a2 = fileDownloadConnection.a("Etag");
if (FileDownloadLog.a) {
FileDownloadLog.a(FileDownloadUtils.class, "etag find %s for task(%d)", a2, Integer.valueOf(i));
}
return a2;
}
throw new RuntimeException("connection is null when findEtag");
}
public static String a(String str, boolean z, String str2) {
if (str == null) {
return null;
}
if (!z) {
return str;
}
if (str2 == null) {
return null;
}
return b(str, str2);
}
public static boolean a(String str) {
return FileDownloadHelper.a().checkCallingOrSelfPermission(str) == 0;
}
public static long a(int i, FileDownloadConnection fileDownloadConnection) {
long b2 = b(fileDownloadConnection.a("Content-Length"));
String a2 = fileDownloadConnection.a("Transfer-Encoding");
if (b2 >= 0) {
return b2;
}
if (a2 != null && a2.equals("chunked")) {
return -1L;
}
if (FileDownloadProperties.a().c) {
if (!FileDownloadLog.a) {
return -1L;
}
FileDownloadLog.a(FileDownloadUtils.class, "%d response header is not legal but HTTP lenient is true, so handle as the case of transfer encoding chunk", Integer.valueOf(i));
return -1L;
}
throw new FileDownloadGiveUpRetryException("can't know the size of the download file, and its Transfer-Encoding is not Chunked either.\nyou can ignore such exception by add http.lenient=true to the filedownloader.properties");
}
public static long b(FileDownloadConnection fileDownloadConnection) {
long c2 = c(fileDownloadConnection);
if (c2 < 0) {
FileDownloadLog.e(FileDownloadUtils.class, "don't get instance length fromContent-Range header", new Object[0]);
c2 = -1;
}
if (c2 == 0 && FileDownloadProperties.a().h) {
return -1L;
}
return c2;
}
private static boolean b(Context context) {
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses;
PowerManager powerManager;
ActivityManager activityManager = (ActivityManager) context.getApplicationContext().getSystemService("activity");
if (activityManager == null || (runningAppProcesses = activityManager.getRunningAppProcesses()) == null || (powerManager = (PowerManager) context.getSystemService("power")) == null) {
return false;
}
if (Build.VERSION.SDK_INT > 19) {
if (!powerManager.isInteractive()) {
return false;
}
} else if (!powerManager.isScreenOn()) {
return false;
}
String packageName = context.getApplicationContext().getPackageName();
for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
if (runningAppProcessInfo.processName.equals(packageName) && runningAppProcessInfo.importance == 100) {
return true;
}
}
return false;
}
public static boolean c(int i, FileDownloadConnection fileDownloadConnection) {
if (i == 206 || i == 1) {
return true;
}
return "bytes".equals(fileDownloadConnection.a("Accept-Ranges"));
}
public static long c(FileDownloadConnection fileDownloadConnection) {
return p(d(fileDownloadConnection));
}
public static FileDownloadOutputStream c(String str) throws IOException {
if (!TextUtils.isEmpty(str)) {
if (l(str)) {
File file = new File(str);
if (file.exists() && file.isDirectory()) {
throw new RuntimeException(a("found invalid internal destination path[%s], & path is directory[%B]", str, Boolean.valueOf(file.isDirectory())));
}
if (!file.exists() && !file.createNewFile()) {
throw new IOException(a("create new file error %s", file.getAbsolutePath()));
}
return CustomComponentHolder.i().a(file);
}
throw new RuntimeException(a("found invalid internal destination filename %s", str));
}
throw new RuntimeException("found invalid internal destination path, empty");
}
public static long a(FileDownloadConnection fileDownloadConnection) {
long o = o(d(fileDownloadConnection));
if (o < 0) {
return -1L;
}
return o;
}
public static String a(FileDownloadConnection fileDownloadConnection, String str) throws FileDownloadSecurityException {
String n = n(fileDownloadConnection.a("Content-Disposition"));
if (TextUtils.isEmpty(n)) {
return f(str);
}
if (n.contains("../")) {
throw new FileDownloadSecurityException(a("The filename [%s] from the response is not allowable, because it contains '../', which can raise the directory traversal vulnerability", n));
}
return n;
}
public static boolean a(int i, FileDownloadModel fileDownloadModel) {
return a(i, fileDownloadModel, (Boolean) null);
}
public static boolean a(int i, FileDownloadModel fileDownloadModel, Boolean bool) {
if (fileDownloadModel == null) {
if (FileDownloadLog.a) {
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d model == null", Integer.valueOf(i));
}
return false;
}
if (fileDownloadModel.getTempFilePath() == null) {
if (FileDownloadLog.a) {
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d temp path == null", Integer.valueOf(i));
}
return false;
}
return a(i, fileDownloadModel, fileDownloadModel.getTempFilePath(), bool);
}
public static boolean a(int i, FileDownloadModel fileDownloadModel, String str, Boolean bool) {
if (str == null) {
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d path = null", Integer.valueOf(i));
return false;
}
File file = new File(str);
boolean exists = file.exists();
boolean isDirectory = file.isDirectory();
if (exists && !isDirectory) {
long length = file.length();
long soFar = fileDownloadModel.getSoFar();
if (fileDownloadModel.getConnectionCount() <= 1 && soFar == 0) {
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d the downloaded-record is zero.", Integer.valueOf(i));
return false;
}
long total = fileDownloadModel.getTotal();
if (length >= soFar && (total == -1 || (length <= total && soFar < total))) {
if (bool == null || bool.booleanValue() || total != length) {
return true;
}
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d, because of the output stream doesn't support seek, but the task has already pre-allocated, so we only can download it from the very beginning.", Integer.valueOf(i));
return false;
}
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d dirty data fileLength[%d] sofar[%d] total[%d]", Integer.valueOf(i), Long.valueOf(length), Long.valueOf(soFar), Long.valueOf(total));
return false;
}
if (!FileDownloadLog.a) {
return false;
}
FileDownloadLog.a(FileDownloadUtils.class, "can't continue %d file not suit, exists[%B], directory[%B]", Integer.valueOf(i), Boolean.valueOf(exists), Boolean.valueOf(isDirectory));
return false;
}
public static void a(String str, String str2) {
e(str2);
d(str);
}
public static boolean a(long j, long j2) {
return j > ((long) c()) && j2 > d();
}
public static String a() {
return a("FileDownloader/%s", "1.7.5");
}
}