use of com.taobao.atlas.update.model.UpdateInfo in project atlas by alibaba.
the class Updater method update.
public static void update(final Context context) {
File updateInfo = new File(context.getExternalCacheDir(), "update.json");
if (!updateInfo.exists()) {
Log.e("update", "更新信息不存在,请先 执行 buildTpatch.sh");
toast("更新信息不存在,请先 执行 buildTpatch.sh", context);
return;
}
String jsonStr = new String(FileUtils.readFile(updateInfo));
UpdateInfo info = JSON.parseObject(jsonStr, UpdateInfo.class);
File patchFile = new File(context.getExternalCacheDir(), "patch-" + info.updateVersion + "@" + info.baseVersion + ".tpatch");
try {
// AtlasUpdater.update(info, patchFile);
PatchMerger patchMerger = new PatchMerger(info, patchFile, new MergeCallback() {
@Override
public void onMergeResult(boolean result, String bundleName) {
if (result) {
toast(bundleName + "merge success!", context);
} else {
toast(bundleName + "merge failed!", context);
}
}
});
try {
patchMerger.merge();
} catch (IOException e) {
e.printStackTrace();
}
Log.e("mergeOutputs:", String.valueOf(patchMerger.mergeOutputs.size()));
PatchInstaller patchInstaller = new PatchInstaller(patchMerger.mergeOutputs, info);
patchInstaller.install();
Log.e("update", "update success");
toast("更新成功,请重启app", context);
} catch (Throwable e) {
e.printStackTrace();
toast("更新失败, " + e.getMessage(), context);
}
}
use of com.taobao.atlas.update.model.UpdateInfo in project atlas by alibaba.
the class PatchInstaller method install.
public void install() throws BundleException {
if (mergeOutputs.isEmpty()) {
throw new BundleException("merge bundles is empty");
}
//
// buildBundleInventory(updateInfo);
//
// File fileDir = new File(RuntimeVariables.androidApplication.getFilesDir(), "bundlelisting");
// String fileName = String.format("%s%s.json", new Object[]{"bundleInfo-", updateInfo.dexPatchVersion>0 ? updateInfo.dexPatchVersion+"" : updateInfo.updateVersion});
//
// if (!fileDir.exists() || !new File(fileDir, fileName).exists()) {
// throw new BundleException("bundle file list is empty");
// }
Iterator entries = mergeOutputs.entrySet().iterator();
String[] packageName = new String[mergeOutputs.size()];
File[] bundleFilePath = new File[mergeOutputs.size()];
String[] versions = new String[mergeOutputs.size()];
int index = 0;
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
packageName[index] = (String) entry.getKey();
Pair<String, String> bundlePair = (Pair<String, String>) entry.getValue();
bundleFilePath[index] = new File(bundlePair.first);
if (!bundleFilePath[index].exists()) {
throw new BundleException("bundle input is wrong");
}
versions[index] = bundlePair.second;
index++;
}
List<String> realInstalledBundle = Arrays.asList(packageName);
for (UpdateInfo.Item bundle : updateInfo.updateBundles) {
if (!realInstalledBundle.contains(bundle.name) && AtlasBundleInfoManager.instance().isInternalBundle(bundle.name)) {
throw new BundleException("bundle " + bundle.name + " is error");
}
}
Atlas.getInstance().installOrUpdate(packageName, bundleFilePath, versions, updateInfo.dexPatchVersion);
List<String> rollbackBundles = new ArrayList<String>();
for (UpdateInfo.Item item : updateInfo.updateBundles) {
if (item != null) {
String bundleCodeVersion = item.version.split("@")[1];
if (bundleCodeVersion.trim().equals("-1")) {
rollbackBundles.add(item.name);
}
}
}
if (rollbackBundles.size() > 0) {
Atlas.getInstance().restoreBundle(rollbackBundles.toArray(new String[rollbackBundles.size()]));
}
saveBaselineInfo(updateInfo, realInstalledBundle);
}
use of com.taobao.atlas.update.model.UpdateInfo in project atlas by alibaba.
the class AwoPatchReceiver method parseObject.
public static UpdateInfo parseObject(String updateJsonStr) {
if (updateJsonStr == null) {
return null;
}
UpdateInfo info = new UpdateInfo();
info.updateBundles = new ArrayList<UpdateInfo.Item>();
try {
JSONObject json = new JSONObject(updateJsonStr);
info.baseVersion = json.getString("baseVersion");
info.updateVersion = json.getString("updateVersion");
JSONArray updateBundlesArray = json.getJSONArray("updateBundles");
for (int x = 0; x < updateBundlesArray.length(); x++) {
JSONObject updateBundleInfo = updateBundlesArray.getJSONObject(x);
UpdateInfo.Item item = new UpdateInfo.Item();
item.isMainDex = updateBundleInfo.getBoolean("isMainDex");
item.name = updateBundleInfo.getString("name");
item.version = updateBundleInfo.getString("version");
JSONArray array = updateBundleInfo.optJSONArray("dependency");
if (array != null && array.length() > 0) {
List<String> dependencies = new ArrayList<String>();
for (int n = 0; n < array.length(); n++) {
dependencies.add(dependencies.get(n));
}
item.dependency = dependencies;
}
info.updateBundles.add(item);
}
return info;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
Aggregations