Initial commit
This commit is contained in:
@@ -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);
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
247
sources/com/liulishuo/filedownloader/database/RemitDatabase.java
Normal file
247
sources/com/liulishuo/filedownloader/database/RemitDatabase.java
Normal 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);
|
||||
}
|
||||
}
|
@@ -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)});
|
||||
}
|
||||
}
|
@@ -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 ))");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user