Commit 8c787126 by pye52

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

parent 568f96b1
......@@ -60,12 +60,12 @@ public class UpdateCommandHandler extends CommandHandler {
synchronized (UpdateCommandHandler.class) {
if (instance == null) {
instance = new UpdateCommandHandler(command, gson, callback);
} else {
instance.init(command, gson, callback);
}
}
}
// 当callback发生变化时,重新设置
if (!callback.equals(instance.commandProgressCallback)) {
instance.commandProgressCallback = callback;
} else {
instance.init(command, gson, callback);
}
return instance;
}
......@@ -88,6 +88,15 @@ public class UpdateCommandHandler extends CommandHandler {
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
public synchronized CommandResponse run() {
if (start) {
......@@ -154,14 +163,14 @@ public class UpdateCommandHandler extends CommandHandler {
AppUtils.AppInfo info = AppUtils.getApkInfo(updateApk);
if (info == null || !info.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
FileUtils.delete(updateApk);
LogUtils.w(TAG, "更新包包名非法");
LogUtils.w(TAG, "更新包包名非法: " + (info == null ? "null" : info.getPackageName()));
idle("", 0);
start = false;
return;
}
if (info.getVersionCode() == BuildConfig.VERSION_CODE) {
FileUtils.delete(updateApk);
LogUtils.w(TAG, "更新包已安装");
LogUtils.w(TAG, "当前版本: " + BuildConfig.VERSION_CODE + ", 安装包版本: " + info.getVersionCode());
} else if (info.getVersionCode() < BuildConfig.VERSION_CODE) {
FileUtils.delete(updateApk);
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