1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-11-03 23:03:11 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Run update process on a seperated executor.

This commit is contained in:
tdzl2003
2018-07-08 20:59:35 +08:00
parent 48abbc98c9
commit e483947884

View File

@@ -4,6 +4,8 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@@ -14,11 +16,13 @@ import java.net.URL;
public class UpdateContext { public class UpdateContext {
private Context context; private Context context;
private File rootDir; private File rootDir;
private Executor executor;
public static boolean DEBUG = false; public static boolean DEBUG = false;
public UpdateContext(Context context) { public UpdateContext(Context context) {
this.context = context; this.context = context;
this.executor = Executors.newSingleThreadExecutor();
this.rootDir = new File(context.getFilesDir(), "_update"); this.rootDir = new File(context.getFilesDir(), "_update");
@@ -68,7 +72,7 @@ public class UpdateContext {
params.listener = listener; params.listener = listener;
params.zipFilePath = new File(rootDir, hashName + ".ppk"); params.zipFilePath = new File(rootDir, hashName + ".ppk");
params.unzipDirectory = new File(rootDir, hashName); params.unzipDirectory = new File(rootDir, hashName);
new DownloadTask(context).execute(params); new DownloadTask(context).executeOnExecutor(this.executor, params);
} }
public void downloadPatchFromApk(String url, String hashName, DownloadFileListener listener) { public void downloadPatchFromApk(String url, String hashName, DownloadFileListener listener) {
@@ -79,7 +83,7 @@ public class UpdateContext {
params.listener = listener; params.listener = listener;
params.zipFilePath = new File(rootDir, hashName + ".apk.patch"); params.zipFilePath = new File(rootDir, hashName + ".apk.patch");
params.unzipDirectory = new File(rootDir, hashName); params.unzipDirectory = new File(rootDir, hashName);
new DownloadTask(context).execute(params); new DownloadTask(context).executeOnExecutor(this.executor, params);
} }
public void downloadPatchFromPpk(String url, String hashName, String originHashName, DownloadFileListener listener) { public void downloadPatchFromPpk(String url, String hashName, String originHashName, DownloadFileListener listener) {
@@ -92,7 +96,7 @@ public class UpdateContext {
params.zipFilePath = new File(rootDir, originHashName + "-" + hashName + ".ppk.patch"); params.zipFilePath = new File(rootDir, originHashName + "-" + hashName + ".ppk.patch");
params.unzipDirectory = new File(rootDir, hashName); params.unzipDirectory = new File(rootDir, hashName);
params.originDirectory = new File(rootDir, originHashName); params.originDirectory = new File(rootDir, originHashName);
new DownloadTask(context).execute(params); new DownloadTask(context).executeOnExecutor(this.executor, params);
} }
private SharedPreferences sp; private SharedPreferences sp;
@@ -210,6 +214,6 @@ public class UpdateContext {
public void onDownloadFailed(Throwable error) { public void onDownloadFailed(Throwable error) {
} }
}; };
new DownloadTask(context).execute(params); new DownloadTask(context).executeOnExecutor(this.executor, params);
} }
} }