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,255 @@
package com.baidu.license.download.a;
import com.baidu.license.download.DownloadRequest;
import com.baidu.license.download.base.DownloadResponse;
import com.baidu.license.download.base.DownloadTask;
import com.baidu.license.download.base.Downloader;
import com.baidu.license.download.base.HttpConnectTask;
import com.baidu.license.download.exception.DownloadException;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executor;
/* compiled from: DownloaderImpl.java */
/* loaded from: classes.dex */
public final class a implements DownloadTask.OnDownloadListener, Downloader, HttpConnectTask.OnConnectListener {
private DownloadRequest a;
private DownloadResponse b;
private Executor c;
private String d;
private com.baidu.license.download.oi e;
private Downloader.OnDownloaderDestroyedListener f;
private int g;
private oi h;
private HttpConnectTask i;
private List<DownloadTask> j = new LinkedList();
public a(DownloadRequest downloadRequest, DownloadResponse downloadResponse, Executor executor, String str, com.baidu.license.download.oi oiVar, Downloader.OnDownloaderDestroyedListener onDownloaderDestroyedListener) {
this.a = downloadRequest;
this.b = downloadResponse;
this.c = executor;
this.d = str;
this.e = oiVar;
this.f = onDownloaderDestroyedListener;
this.h = new oi(this.a.b().toString(), this.a.c(), this.a.a());
}
private void c() {
File file = new File(this.h.b(), this.h.a());
if (file.exists() && file.isFile()) {
file.delete();
}
}
@Override // com.baidu.license.download.base.HttpConnectTask.OnConnectListener
public final void a(long j, long j2, boolean z) {
if (this.i.isCanceled()) {
l();
return;
}
this.g = 103;
this.b.a(j, j2, z);
this.h.a(z);
this.h.a(j2);
this.g = 104;
this.j.clear();
if (z) {
ArrayList arrayList = new ArrayList();
int b = this.e.b();
int i = 0;
int i2 = 0;
while (i2 < b) {
long j3 = j2 / b;
long j4 = j3 * i2;
arrayList.add(new e(i2, this.d, this.a.c(), j4, i2 == b + (-1) ? j2 : (j3 + j4) - 1));
i2++;
}
Iterator it = arrayList.iterator();
while (it.hasNext()) {
i = (int) (i + ((e) it.next()).d());
}
this.h.b(i);
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
this.j.add(new c(this.h, (e) it2.next(), this));
}
} else {
this.j.add(new d(this.h, new e(this.d, this.a.c()), this));
}
Iterator<DownloadTask> it3 = this.j.iterator();
while (it3.hasNext()) {
this.c.execute(it3.next());
}
}
public final void b() {
this.f.a(this.d, this);
}
@Override // com.baidu.license.download.base.Downloader
public final void cancel() {
HttpConnectTask httpConnectTask = this.i;
if (httpConnectTask != null) {
httpConnectTask.cancel();
}
Iterator<DownloadTask> it = this.j.iterator();
while (it.hasNext()) {
it.next().cancel();
}
if (this.g != 104) {
j();
}
}
@Override // com.baidu.license.download.base.HttpConnectTask.OnConnectListener
public final void i() {
this.g = 102;
this.b.i();
}
@Override // com.baidu.license.download.base.Downloader
public final boolean isRunning() {
int i = this.g;
return i == 101 || i == 102 || i == 103 || i == 104;
}
@Override // com.baidu.license.download.base.DownloadTask.OnDownloadListener
public final void j() {
boolean z;
Iterator<DownloadTask> it = this.j.iterator();
while (true) {
if (!it.hasNext()) {
z = true;
break;
} else if (it.next().h()) {
z = false;
break;
}
}
if (z) {
c();
this.g = 107;
this.b.j();
b();
}
}
@Override // com.baidu.license.download.base.DownloadTask.OnDownloadListener
public final void k() {
boolean z;
Iterator<DownloadTask> it = this.j.iterator();
while (true) {
if (!it.hasNext()) {
z = true;
break;
} else if (it.next().h()) {
z = false;
break;
}
}
if (z) {
this.g = 106;
this.b.k();
b();
}
}
@Override // com.baidu.license.download.base.HttpConnectTask.OnConnectListener
public final void l() {
c();
this.g = 107;
this.b.l();
b();
}
@Override // com.baidu.license.download.base.Downloader
public final void pause() {
HttpConnectTask httpConnectTask = this.i;
if (httpConnectTask != null) {
httpConnectTask.pause();
}
Iterator<DownloadTask> it = this.j.iterator();
while (it.hasNext()) {
it.next().pause();
}
if (this.g != 104) {
k();
}
}
@Override // com.baidu.license.download.base.Downloader
public final void start() {
this.g = 101;
this.b.m();
this.i = new b(this.a.c(), this);
this.c.execute(this.i);
}
@Override // com.baidu.license.download.base.DownloadTask.OnDownloadListener
public final void b(DownloadException downloadException) {
boolean z;
Iterator<DownloadTask> it = this.j.iterator();
while (true) {
if (!it.hasNext()) {
z = true;
break;
} else if (it.next().h()) {
z = false;
break;
}
}
if (z) {
this.g = 108;
this.b.b(downloadException);
b();
}
}
@Override // com.baidu.license.download.base.HttpConnectTask.OnConnectListener
public final void a() {
k();
}
@Override // com.baidu.license.download.base.HttpConnectTask.OnConnectListener
public final void a(DownloadException downloadException) {
if (this.i.isCanceled()) {
l();
} else {
if (this.i.i()) {
k();
return;
}
this.g = 108;
this.b.a(downloadException);
b();
}
}
@Override // com.baidu.license.download.base.DownloadTask.OnDownloadListener
public final void a(long j, long j2) {
this.b.a(j, j2, (int) ((100 * j) / j2));
}
@Override // com.baidu.license.download.base.DownloadTask.OnDownloadListener
public final void a(String str) {
boolean z;
Iterator<DownloadTask> it = this.j.iterator();
while (true) {
if (!it.hasNext()) {
z = true;
break;
} else if (!it.next().g()) {
z = false;
break;
}
}
if (z) {
this.g = 105;
this.b.a(str);
b();
}
}
}

View File

@@ -0,0 +1,152 @@
package com.baidu.license.download.a;
import android.os.Process;
import android.text.TextUtils;
import com.baidu.license.download.base.HttpConnectTask;
import com.baidu.license.download.exception.DownloadException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
/* compiled from: HttpConnectTaskImpl.java */
/* loaded from: classes.dex */
public final class b implements HttpConnectTask {
private final String a;
private final HttpConnectTask.OnConnectListener b;
private volatile int c;
private volatile long d;
public b(String str, HttpConnectTask.OnConnectListener onConnectListener) {
this.a = str;
this.b = onConnectListener;
}
private void a(HttpURLConnection httpURLConnection, boolean z) {
String headerField = httpURLConnection.getHeaderField("Content-Length");
long contentLength = (TextUtils.isEmpty(headerField) || headerField.equals("0") || headerField.equals("-1")) ? httpURLConnection.getContentLength() : Long.parseLong(headerField);
if (contentLength <= 0) {
String headerField2 = httpURLConnection.getHeaderField("Ohc-File-Size");
contentLength = (TextUtils.isEmpty(headerField2) || headerField2.equals("0") || headerField2.equals("-1")) ? httpURLConnection.getContentLength() : Long.parseLong(headerField2);
if (contentLength <= 0) {
throw new DownloadException(108, "length <= 0");
}
}
a();
this.c = 103;
this.b.a(System.currentTimeMillis() - this.d, contentLength, z);
}
@Override // com.baidu.license.download.base.HttpConnectTask
public final void cancel() {
this.c = 107;
}
@Override // com.baidu.license.download.base.HttpConnectTask
public final boolean i() {
return this.c == 106;
}
@Override // com.baidu.license.download.base.HttpConnectTask
public final boolean isCanceled() {
return this.c == 107;
}
@Override // com.baidu.license.download.base.HttpConnectTask
public final void pause() {
this.c = 106;
}
@Override // java.lang.Runnable
public final void run() {
IOException e;
ProtocolException e2;
HttpURLConnection httpURLConnection;
Process.setThreadPriority(10);
this.c = 102;
this.b.i();
try {
this.d = System.currentTimeMillis();
HttpURLConnection httpURLConnection2 = null;
try {
try {
try {
httpURLConnection = (HttpURLConnection) new URL(this.a).openConnection();
} catch (ProtocolException e3) {
e2 = e3;
} catch (IOException e4) {
e = e4;
} catch (Throwable th) {
th = th;
if (0 != 0) {
httpURLConnection2.disconnect();
}
throw th;
}
try {
httpURLConnection.setConnectTimeout(4000);
httpURLConnection.setReadTimeout(4000);
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Range", "bytes=0-");
int responseCode = httpURLConnection.getResponseCode();
if (responseCode == 200) {
a(httpURLConnection, false);
} else {
if (responseCode != 206) {
throw new DownloadException(108, "UnSupported response code:".concat(String.valueOf(responseCode)));
}
a(httpURLConnection, true);
}
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
} catch (ProtocolException e5) {
e2 = e5;
throw new DownloadException(108, "Protocol error", e2);
} catch (IOException e6) {
e = e6;
throw new DownloadException(108, "IO error", e);
}
} catch (Throwable th2) {
th = th2;
}
} catch (MalformedURLException e7) {
throw new DownloadException(108, "Bad url.", e7);
}
} catch (DownloadException e8) {
switch (e8.getErrorCode()) {
case 106:
synchronized (this.b) {
this.c = 106;
this.b.a();
return;
}
case 107:
synchronized (this.b) {
this.c = 107;
this.b.l();
return;
}
case 108:
synchronized (this.b) {
this.c = 108;
this.b.a(e8);
return;
}
default:
throw new IllegalArgumentException("Unknown state");
}
}
}
private void a() {
if (!isCanceled()) {
if (i()) {
throw new DownloadException(106, "Connection Paused!");
}
return;
}
throw new DownloadException(107, "Connection Canceled!");
}
}

View File

@@ -0,0 +1,39 @@
package com.baidu.license.download.a;
import com.baidu.license.download.base.DownloadTask;
import java.io.File;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Map;
/* compiled from: MultiDownloadTask.java */
/* loaded from: classes.dex */
public final class c extends uiw {
public c(oi oiVar, e eVar, DownloadTask.OnDownloadListener onDownloadListener) {
super(oiVar, eVar, onDownloadListener);
}
@Override // com.baidu.license.download.a.uiw
protected final int a() {
return 206;
}
@Override // com.baidu.license.download.a.uiw
protected final Map<String, String> a(e eVar) {
HashMap hashMap = new HashMap();
hashMap.put("Range", "bytes=" + (eVar.b() + eVar.d()) + "-" + eVar.c());
return hashMap;
}
@Override // com.baidu.license.download.a.uiw
protected final String b() {
return c.class.getSimpleName();
}
@Override // com.baidu.license.download.a.uiw
protected final RandomAccessFile a(File file, String str, long j) {
RandomAccessFile randomAccessFile = new RandomAccessFile(new File(file, str), "rwd");
randomAccessFile.seek(j);
return randomAccessFile;
}
}

View File

@@ -0,0 +1,36 @@
package com.baidu.license.download.a;
import com.baidu.license.download.base.DownloadTask;
import java.io.File;
import java.io.RandomAccessFile;
import java.util.Map;
/* compiled from: SingleDownloadTask.java */
/* loaded from: classes.dex */
public final class d extends uiw {
public d(oi oiVar, e eVar, DownloadTask.OnDownloadListener onDownloadListener) {
super(oiVar, eVar, onDownloadListener);
}
@Override // com.baidu.license.download.a.uiw
protected final int a() {
return 200;
}
@Override // com.baidu.license.download.a.uiw
protected final RandomAccessFile a(File file, String str, long j) {
RandomAccessFile randomAccessFile = new RandomAccessFile(new File(file, str), "rwd");
randomAccessFile.seek(0L);
return randomAccessFile;
}
@Override // com.baidu.license.download.a.uiw
protected final Map<String, String> a(e eVar) {
return null;
}
@Override // com.baidu.license.download.a.uiw
protected final String b() {
return d.class.getSimpleName();
}
}

View File

@@ -0,0 +1,44 @@
package com.baidu.license.download.a;
/* compiled from: ThreadRecord.java */
/* loaded from: classes.dex */
public final class e {
private String a;
private long b;
private long c;
private long d;
public e() {
}
public final String a() {
return this.a;
}
public final long b() {
return this.b;
}
public final long c() {
return this.c;
}
public final long d() {
return this.d;
}
public e(String str, String str2) {
this(0, str, str2, 0L, 0L);
}
public final void a(long j) {
this.d = j;
}
public e(int i, String str, String str2, long j, long j2) {
this.a = str2;
this.b = j;
this.c = j2;
this.d = 0L;
}
}

View File

@@ -0,0 +1,19 @@
package com.baidu.license.download.a;
import android.os.Handler;
import java.util.concurrent.Executor;
/* compiled from: DownloadStatusDeliveryImpl.java */
/* loaded from: classes.dex */
final class mas implements Executor {
final /* synthetic */ Handler a;
mas(trw trwVar, Handler handler) {
this.a = handler;
}
@Override // java.util.concurrent.Executor
public final void execute(Runnable runnable) {
this.a.post(runnable);
}
}

View File

@@ -0,0 +1,87 @@
package com.baidu.license.download.a;
import com.baidu.license.download.base.DownloadCallback;
import com.baidu.license.download.base.DownloadResponse;
import com.baidu.license.download.base.DownloadStatus;
import com.baidu.license.download.base.DownloadStatusDelivery;
import com.baidu.license.download.exception.DownloadException;
/* compiled from: DownloadResponseImpl.java */
/* loaded from: classes.dex */
public final class nx implements DownloadResponse {
private DownloadStatusDelivery a;
private DownloadStatus b = new DownloadStatus();
public nx(DownloadStatusDelivery downloadStatusDelivery, DownloadCallback downloadCallback) {
this.a = downloadStatusDelivery;
this.b.a(downloadCallback);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void a(long j, long j2, boolean z) {
this.b.c(j);
this.b.a(z);
this.b.b(103);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void b(DownloadException downloadException) {
this.b.a(downloadException);
this.b.b(108);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void i() {
this.b.b(102);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void j() {
this.b.b(107);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void k() {
this.b.b(106);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void l() {
this.b.b(107);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void m() {
this.b.b(101);
this.b.a().d();
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void a(DownloadException downloadException) {
this.b.a(downloadException);
this.b.b(108);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void a(long j, long j2, int i) {
this.b.a(j);
this.b.b(j2);
this.b.a(i);
this.b.b(104);
this.a.a(this.b);
}
@Override // com.baidu.license.download.base.DownloadResponse
public final void a(String str) {
this.b.b(105);
this.b.a(str);
this.a.a(this.b);
}
}

View File

@@ -0,0 +1,44 @@
package com.baidu.license.download.a;
import java.io.File;
/* compiled from: DownloadInfo.java */
/* loaded from: classes.dex */
public final class oi {
private String a;
private File b;
private long c;
private long d;
public oi(String str, String str2, File file) {
this.a = str;
this.b = file;
}
public final String a() {
return this.a;
}
public final void a(boolean z) {
}
public final File b() {
return this.b;
}
public final long c() {
return this.c;
}
public final long d() {
return this.d;
}
public final void a(long j) {
this.c = j;
}
public final void b(long j) {
this.d = j;
}
}

View File

@@ -0,0 +1,73 @@
package com.baidu.license.download.a;
import android.os.Handler;
import com.baidu.license.download.base.DownloadCallback;
import com.baidu.license.download.base.DownloadStatus;
import com.baidu.license.download.base.DownloadStatusDelivery;
import com.baidu.license.download.exception.DownloadException;
import com.baidu.license.download.utils.LogUtils;
import java.util.concurrent.Executor;
/* compiled from: DownloadStatusDeliveryImpl.java */
/* loaded from: classes.dex */
public final class trw implements DownloadStatusDelivery {
private Executor a;
/* compiled from: DownloadStatusDeliveryImpl.java */
private static class oi implements Runnable {
private final DownloadStatus a;
private final DownloadCallback b;
public oi(DownloadStatus downloadStatus) {
this.a = downloadStatus;
this.b = this.a.a();
}
@Override // java.lang.Runnable
public final void run() {
switch (this.a.h()) {
case 102:
LogUtils.a("DownloadStatusDelivery", "STATUS_CONNECTING");
this.b.a();
break;
case 103:
LogUtils.a("DownloadStatusDelivery", "STATUS_CONNECTED length: " + this.a.e() + " acceptRanges: " + this.a.i());
this.b.a(this.a.e(), this.a.i());
break;
case 104:
LogUtils.a("DownloadStatusDelivery", "STATUS_PROGRESS finished: " + this.a.d() + " length: " + this.a.e() + " percent: " + this.a.f());
this.b.a(this.a.d(), this.a.e(), this.a.f());
break;
case 105:
LogUtils.a("DownloadStatusDelivery", "STATUS_COMPLETED Path:" + this.a.g());
if (!this.a.b()) {
this.a.b(true);
this.b.a(this.a.g());
break;
}
break;
case 106:
LogUtils.a("DownloadStatusDelivery", "STATUS_PAUSED");
this.b.c();
break;
case 107:
LogUtils.a("DownloadStatusDelivery", "STATUS_CANCELED");
this.b.b();
break;
case 108:
LogUtils.b("DownloadStatusDelivery", "STATUS_FAILED error: " + this.a.c().getCause());
this.b.a((DownloadException) this.a.c());
break;
}
}
}
public trw(Handler handler) {
this.a = new mas(this, handler);
}
@Override // com.baidu.license.download.base.DownloadStatusDelivery
public final void a(DownloadStatus downloadStatus) {
this.a.execute(new oi(downloadStatus));
}
}

View File

@@ -0,0 +1,122 @@
package com.baidu.license.download.a;
import android.text.TextUtils;
import com.baidu.license.download.base.DownloadTask;
import com.baidu.license.download.exception.DownloadException;
import com.ubt.jimu.unity.bluetooth.UnityActivity;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.URLConnection;
import java.util.Map;
/* compiled from: DownloadTaskImpl.java */
/* loaded from: classes.dex */
public abstract class uiw implements DownloadTask {
private String a;
private final oi b;
private final e c;
private final DownloadTask.OnDownloadListener d;
private volatile int e;
private volatile int f = 0;
public uiw(oi oiVar, e eVar, DownloadTask.OnDownloadListener onDownloadListener) {
this.b = oiVar;
this.c = eVar;
this.d = onDownloadListener;
this.a = b();
if (TextUtils.isEmpty(this.a)) {
this.a = getClass().getSimpleName();
}
}
private static void a(Map<String, String> map, URLConnection uRLConnection) {
if (map != null) {
for (String str : map.keySet()) {
uRLConnection.setRequestProperty(str, map.get(str));
}
}
}
protected abstract int a();
protected abstract RandomAccessFile a(File file, String str, long j);
protected abstract Map<String, String> a(e eVar);
protected abstract String b();
@Override // com.baidu.license.download.base.DownloadTask
public void cancel() {
this.f = 107;
}
@Override // com.baidu.license.download.base.DownloadTask
public boolean g() {
return this.e == 105;
}
@Override // com.baidu.license.download.base.DownloadTask
public boolean h() {
return this.e == 104;
}
@Override // com.baidu.license.download.base.DownloadTask
public void pause() {
this.f = 106;
}
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Removed duplicated region for block: B:75:0x010f A[Catch: DownloadException -> 0x011c, TRY_ENTER, TryCatch #11 {DownloadException -> 0x011c, blocks: (B:3:0x0009, B:5:0x000b, B:31:0x0077, B:32:0x007a, B:33:0x007c, B:42:0x00ae, B:75:0x010f, B:76:0x0112, B:85:0x0114, B:86:0x011b, B:36:0x007f, B:37:0x00aa), top: B:2:0x0009, inners: #9, #17 }] */
/* JADX WARN: Type inference failed for: r0v10 */
/* JADX WARN: Type inference failed for: r0v15, types: [java.net.HttpURLConnection] */
/* JADX WARN: Type inference failed for: r0v8, types: [java.net.URL] */
@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: 360
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.baidu.license.download.a.uiw.run():void");
}
private static void a(Closeable closeable) {
if (closeable != null) {
synchronized (uiw.class) {
closeable.close();
}
}
}
private void a(InputStream inputStream, RandomAccessFile randomAccessFile) {
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
while (this.f != 107) {
if (this.f != 106) {
try {
int read = inputStream.read(bArr);
if (read == -1) {
return;
}
randomAccessFile.write(bArr, 0, read);
long j = read;
this.c.a(this.c.d() + j);
synchronized (this.d) {
this.b.b(this.b.d() + j);
this.d.a(this.b.d(), this.b.c());
}
} catch (IOException e) {
throw new DownloadException(108, e);
}
} else {
throw new DownloadException(106, "Download paused!");
}
}
throw new DownloadException(107, "Download canceled!");
}
}