Initial commit
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user