Search in sources :

Example 1 with UpdateInfo

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);
    }
}
Also used : MergeCallback(com.taobao.atlas.dexmerge.MergeCallback) PatchMerger(com.taobao.atlas.update.util.PatchMerger) PatchInstaller(com.taobao.atlas.update.util.PatchInstaller) IOException(java.io.IOException) File(java.io.File) UpdateInfo(com.taobao.atlas.update.model.UpdateInfo)

Example 2 with UpdateInfo

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);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) BundleException(org.osgi.framework.BundleException) File(java.io.File) Map(java.util.Map) UpdateInfo(com.taobao.atlas.update.model.UpdateInfo) Pair(android.util.Pair)

Example 3 with UpdateInfo

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;
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) UpdateInfo(com.taobao.atlas.update.model.UpdateInfo)

Aggregations

UpdateInfo (com.taobao.atlas.update.model.UpdateInfo)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Pair (android.util.Pair)1 MergeCallback (com.taobao.atlas.dexmerge.MergeCallback)1 PatchInstaller (com.taobao.atlas.update.util.PatchInstaller)1 PatchMerger (com.taobao.atlas.update.util.PatchMerger)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 BundleException (org.osgi.framework.BundleException)1