106 lines
4.2 KiB
Java
106 lines
4.2 KiB
Java
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;
|
|
}
|
|
}
|