Commit 8c787126 by pye52

修复UpdateCommandHandler单例在已初始化后再次调用不刷新下载地址的问题

parent 568f96b1
...@@ -60,12 +60,12 @@ public class UpdateCommandHandler extends CommandHandler { ...@@ -60,12 +60,12 @@ public class UpdateCommandHandler extends CommandHandler {
synchronized (UpdateCommandHandler.class) { synchronized (UpdateCommandHandler.class) {
if (instance == null) { if (instance == null) {
instance = new UpdateCommandHandler(command, gson, callback); instance = new UpdateCommandHandler(command, gson, callback);
} else {
instance.init(command, gson, callback);
} }
} }
} } else {
// 当callback发生变化时,重新设置 instance.init(command, gson, callback);
if (!callback.equals(instance.commandProgressCallback)) {
instance.commandProgressCallback = callback;
} }
return instance; return instance;
} }
...@@ -88,6 +88,15 @@ public class UpdateCommandHandler extends CommandHandler { ...@@ -88,6 +88,15 @@ public class UpdateCommandHandler extends CommandHandler {
FileUtils.delete(updateApk); FileUtils.delete(updateApk);
} }
private void init(Command command, Gson gson, CommandProgressCallback callback) {
this.command = command;
this.gson = gson;
this.commandProgressCallback = callback;
this.commandUpdate = gson.fromJson(command.getData(), CommandUpdate.class);
this.updateApk = new File(Utils.getApp().getCacheDir(), UPDATE_APK);
FileUtils.delete(updateApk);
}
@Override @Override
public synchronized CommandResponse run() { public synchronized CommandResponse run() {
if (start) { if (start) {
...@@ -154,14 +163,14 @@ public class UpdateCommandHandler extends CommandHandler { ...@@ -154,14 +163,14 @@ public class UpdateCommandHandler extends CommandHandler {
AppUtils.AppInfo info = AppUtils.getApkInfo(updateApk); AppUtils.AppInfo info = AppUtils.getApkInfo(updateApk);
if (info == null || !info.getPackageName().equals(BuildConfig.APPLICATION_ID)) { if (info == null || !info.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
FileUtils.delete(updateApk); FileUtils.delete(updateApk);
LogUtils.w(TAG, "更新包包名非法"); LogUtils.w(TAG, "更新包包名非法: " + (info == null ? "null" : info.getPackageName()));
idle("", 0); idle("", 0);
start = false; start = false;
return; return;
} }
if (info.getVersionCode() == BuildConfig.VERSION_CODE) { if (info.getVersionCode() == BuildConfig.VERSION_CODE) {
FileUtils.delete(updateApk); FileUtils.delete(updateApk);
LogUtils.w(TAG, "更新包已安装"); LogUtils.w(TAG, "当前版本: " + BuildConfig.VERSION_CODE + ", 安装包版本: " + info.getVersionCode());
} else if (info.getVersionCode() < BuildConfig.VERSION_CODE) { } else if (info.getVersionCode() < BuildConfig.VERSION_CODE) {
FileUtils.delete(updateApk); FileUtils.delete(updateApk);
LogUtils.d(TAG, "不允许安装低版本"); LogUtils.d(TAG, "不允许安装低版本");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment