- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
227 lines
8.2 KiB
Java
227 lines
8.2 KiB
Java
package csdk.glucentralservices.network;
|
|
|
|
import android.app.DownloadManager;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.database.Cursor;
|
|
import android.net.Uri;
|
|
import android.text.TextUtils;
|
|
import com.facebook.share.internal.ShareConstants;
|
|
import com.vungle.ads.internal.presenter.NativeAdPresenter;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public class Downloader {
|
|
private final Context mContext;
|
|
private final Map<Long, DownloadInfo> mDownloadInfoMap = new ConcurrentHashMap();
|
|
private final DownloadManager mDownloadManager;
|
|
private BroadcastReceiver mReceiver;
|
|
|
|
public interface DownloadListener {
|
|
void onDownloadComplete(boolean z, DownloadInfo downloadInfo);
|
|
}
|
|
|
|
public Downloader(Context context) {
|
|
this.mContext = context;
|
|
this.mDownloadManager = (DownloadManager) context.getSystemService(NativeAdPresenter.DOWNLOAD);
|
|
}
|
|
|
|
public void init() {
|
|
this.mReceiver = new DownloadReceiver();
|
|
this.mContext.registerReceiver(this.mReceiver, new IntentFilter("android.intent.action.DOWNLOAD_COMPLETE"), 2);
|
|
}
|
|
|
|
public void destroy() {
|
|
BroadcastReceiver broadcastReceiver = this.mReceiver;
|
|
if (broadcastReceiver != null) {
|
|
this.mContext.unregisterReceiver(broadcastReceiver);
|
|
}
|
|
}
|
|
|
|
public void download(String str, String str2, DownloadListener downloadListener) {
|
|
long downloadID = getDownloadID(Uri.parse(str));
|
|
DownloadInfo downloadInfo = new DownloadInfo(downloadID, str, str2, downloadListener);
|
|
if (downloadID >= 0) {
|
|
int downloadStatus = downloadStatus(downloadID);
|
|
if (downloadStatus == 8) {
|
|
boolean copyToDestination = copyToDestination(downloadInfo);
|
|
deleteDownload(downloadID);
|
|
if (copyToDestination) {
|
|
onDownloadComplete(true, downloadInfo);
|
|
return;
|
|
}
|
|
} else if (downloadStatus == 1 || downloadStatus == 2) {
|
|
return;
|
|
}
|
|
}
|
|
if (startDownload(downloadInfo)) {
|
|
return;
|
|
}
|
|
onDownloadComplete(false, downloadInfo);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static void onDownloadComplete(boolean z, DownloadInfo downloadInfo) throws SecurityException {
|
|
DownloadListener downloadListener = downloadInfo.listener;
|
|
if (downloadListener != null) {
|
|
downloadListener.onDownloadComplete(z, downloadInfo);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public boolean copyToDestination(DownloadInfo downloadInfo) {
|
|
String str;
|
|
InputStream fileInputStream;
|
|
Cursor query = this.mDownloadManager.query(new DownloadManager.Query().setFilterById(downloadInfo.downloadID));
|
|
if (query == null) {
|
|
return false;
|
|
}
|
|
try {
|
|
if (!query.moveToFirst()) {
|
|
return false;
|
|
}
|
|
Uri parse = Uri.parse(query.getString(query.getColumnIndex("local_uri")));
|
|
InputStream inputStream = null;
|
|
try {
|
|
str = query.getString(query.getColumnIndex("local_filename"));
|
|
} catch (Exception unused) {
|
|
str = null;
|
|
}
|
|
query.close();
|
|
try {
|
|
try {
|
|
fileInputStream = this.mContext.getContentResolver().openInputStream(parse);
|
|
} catch (SecurityException unused2) {
|
|
fileInputStream = new FileInputStream(str);
|
|
}
|
|
inputStream = fileInputStream;
|
|
new File(downloadInfo.destinationPath).getParentFile().mkdirs();
|
|
NetworkUtils.copyIntoFile(inputStream, new File(downloadInfo.destinationPath));
|
|
if (inputStream != null) {
|
|
try {
|
|
inputStream.close();
|
|
} catch (IOException unused3) {
|
|
}
|
|
}
|
|
return true;
|
|
} catch (IOException unused4) {
|
|
if (inputStream != null) {
|
|
try {
|
|
inputStream.close();
|
|
} catch (IOException unused5) {
|
|
}
|
|
}
|
|
return false;
|
|
} catch (Exception unused6) {
|
|
if (inputStream != null) {
|
|
try {
|
|
inputStream.close();
|
|
} catch (IOException unused7) {
|
|
}
|
|
}
|
|
return false;
|
|
} catch (Throwable th) {
|
|
if (inputStream != null) {
|
|
try {
|
|
inputStream.close();
|
|
} catch (IOException unused8) {
|
|
}
|
|
}
|
|
throw th;
|
|
}
|
|
} finally {
|
|
query.close();
|
|
}
|
|
}
|
|
|
|
private boolean startDownload(DownloadInfo downloadInfo) {
|
|
try {
|
|
long enqueue = this.mDownloadManager.enqueue(new DownloadManager.Request(Uri.parse(downloadInfo.sourcePath)).setVisibleInDownloadsUi(false));
|
|
this.mDownloadInfoMap.put(Long.valueOf(enqueue), new DownloadInfo(enqueue, downloadInfo.sourcePath, downloadInfo.destinationPath, downloadInfo.listener));
|
|
return true;
|
|
} catch (IllegalArgumentException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private long getDownloadID(Uri uri) {
|
|
Cursor query = this.mDownloadManager.query(new DownloadManager.Query());
|
|
long j = -1;
|
|
if (query == null) {
|
|
return -1L;
|
|
}
|
|
try {
|
|
if (query.moveToFirst()) {
|
|
String uri2 = uri.toString();
|
|
int columnIndex = query.getColumnIndex(ShareConstants.MEDIA_URI);
|
|
int columnIndex2 = query.getColumnIndex("_id");
|
|
do {
|
|
if (TextUtils.equals(uri2, query.getString(columnIndex))) {
|
|
j = Math.max(query.getLong(columnIndex2), j);
|
|
}
|
|
} while (query.moveToNext());
|
|
query.close();
|
|
return j;
|
|
}
|
|
query.close();
|
|
return -1L;
|
|
} catch (Throwable th) {
|
|
query.close();
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public int downloadStatus(long j) {
|
|
Cursor query = this.mDownloadManager.query(new DownloadManager.Query().setFilterById(j));
|
|
if (query == null) {
|
|
return 16;
|
|
}
|
|
try {
|
|
if (query.moveToFirst()) {
|
|
return query.getInt(query.getColumnIndex("status"));
|
|
}
|
|
return 16;
|
|
} finally {
|
|
query.close();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void deleteDownload(long j) {
|
|
this.mDownloadManager.remove(j);
|
|
}
|
|
|
|
public class DownloadReceiver extends BroadcastReceiver {
|
|
public DownloadReceiver() {
|
|
}
|
|
|
|
@Override // android.content.BroadcastReceiver
|
|
public void onReceive(Context context, Intent intent) {
|
|
DownloadInfo downloadInfo;
|
|
boolean z;
|
|
if (TextUtils.equals(intent.getAction(), "android.intent.action.DOWNLOAD_COMPLETE")) {
|
|
long longExtra = intent.getLongExtra("extra_download_id", -1L);
|
|
if (longExtra >= 0 && (downloadInfo = (DownloadInfo) Downloader.this.mDownloadInfoMap.remove(Long.valueOf(longExtra))) != null) {
|
|
if (Downloader.this.downloadStatus(longExtra) == 8) {
|
|
z = Downloader.this.copyToDestination(downloadInfo);
|
|
if (z) {
|
|
Downloader.this.deleteDownload(longExtra);
|
|
}
|
|
} else {
|
|
z = false;
|
|
}
|
|
Downloader.onDownloadComplete(z, downloadInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|