Search in sources :

Example 1 with LowDiskException

use of android.taobao.atlas.runtime.LowDiskException in project atlas by alibaba.

the class BundleInstaller method call.

@Override
public synchronized Void call() throws Exception {
    Bundle bundle = null;
    if (!mTransitive) {
        for (int x = 0; x < mLocation.length; x++) {
            if (FileUtils.getUsableSpace(Environment.getDataDirectory()) >= 5) {
                if (mBundleSourceInputStream != null && mBundleSourceInputStream.length > x && mBundleSourceInputStream[x] != null) {
                    if ((bundle = getInstalledBundle(mLocation[x])) == null) {
                        bundle = Framework.installNewBundle(mLocation[x], mBundleSourceInputStream[x]);
                    }
                    if (bundle != null) {
                        ((BundleImpl) bundle).optDexFile();
                    }
                } else if (mBundleSourceFile != null && mBundleSourceFile.length > x && mBundleSourceFile[x] != null) {
                    if ((bundle = getInstalledBundle(mLocation[x])) == null) {
                        bundle = Framework.installNewBundle(mLocation[x], mBundleSourceFile[x]);
                    }
                    if (bundle != null) {
                        ((BundleImpl) bundle).optDexFile();
                    }
                } else {
                    if ((bundle = getInstalledBundle(mLocation[x])) == null && AtlasBundleInfoManager.instance().isInternalBundle(mLocation[x])) {
                        bundle = installBundleFromApk(mLocation[x]);
                        if (bundle != null) {
                            ((BundleImpl) bundle).optDexFile();
                        }
                    }
                }
            } else {
                throw new LowDiskException("no enough space");
            }
        }
    } else {
        for (int x = 0; x < mLocation.length; x++) {
            List<String> bundlesForInstall = AtlasBundleInfoManager.instance().getBundleInfo(mLocation[x]).getTotalDependency();
            Log.e("BundleInstaller", mLocation[x] + "-->" + bundlesForInstall.toString());
            for (String bundleName : bundlesForInstall) {
                if ((bundle = getInstalledBundle(bundleName)) == null) {
                    if (FileUtils.getUsableSpace(Environment.getDataDirectory()) >= 5) {
                        //has enough space
                        if (AtlasBundleInfoManager.instance().isInternalBundle(bundleName)) {
                            bundle = installBundleFromApk(bundleName);
                            if (bundle != null) {
                                ((BundleImpl) bundle).optDexFile();
                            }
                        }
                    } else {
                        throw new LowDiskException("no enough space");
                    }
                } else {
                    if (bundle != null && ((BundleImpl) bundle).getArchive() != null && !((BundleImpl) bundle).getArchive().isDexOpted()) {
                        ((BundleImpl) bundle).optDexFile();
                    }
                }
            }
        }
    }
    return null;
}
Also used : Bundle(org.osgi.framework.Bundle) LowDiskException(android.taobao.atlas.runtime.LowDiskException)

Example 2 with LowDiskException

use of android.taobao.atlas.runtime.LowDiskException in project atlas by alibaba.

the class Framework method installNewBundle.

/**
     * install a bundle from input stream.
     *
     * @param location the bundle location.
     * @param in       the input stream.
     * @return a Bundle object.
     * @throws BundleException if the installation failed.
     */
static BundleImpl installNewBundle(final String location, final InputStream in) throws BundleException {
    File bundleDir = null;
    try {
        BundleLock.WriteLock(location);
        /*
	         * <specs page="58">Every bundle is uniquely identified by its location string. If an installed bundle is using
	         * the specified location, the installBundle method must return the Bundle object for that installed bundle and
	         * not install a new bundle.</specs>
	         */
        bundleDir = new File(STORAGE_LOCATION, location);
        if (!bundleDir.exists()) {
            bundleDir.mkdirs();
        }
        AtlasFileLock.getInstance().LockExclusive(bundleDir);
        final BundleImpl cached;
        if ((cached = (BundleImpl) getBundle(location)) != null) {
            return cached;
        }
        Log.e("BundleInstaller", "real install " + location);
        BundleImpl bundle = null;
        BundleListing.BundleInfo info = AtlasBundleInfoManager.instance().getBundleInfo(location);
        String version = info != null ? info.getVersion() : "-1";
        bundle = new BundleImpl(bundleDir, location, new BundleContext(), in, null, version, true, -1);
        storeMetadata();
        return bundle;
    } catch (IOException e) {
        BundleException e1 = new BundleException("Failed to install bundle." + FileUtils.getAvailableDisk(), e);
        if (bundleDir != null)
            Framework.deleteDirectory(bundleDir);
        if (FileUtils.getUsableSpace(Environment.getDataDirectory()) < LowDiskException.thredshold) {
            throw new LowDiskException(FileUtils.getAvailableDisk(), e);
        }
        throw new BundleException("Failed to install bundle.", e);
    } catch (BundleException e) {
        BundleException e1 = new BundleException("Failed to install bundle." + FileUtils.getAvailableDisk(), e);
        if (bundleDir != null)
            Framework.deleteDirectory(bundleDir);
        throw e1;
    } finally {
        BundleLock.WriteUnLock(location);
        if (bundleDir != null) {
            AtlasFileLock.getInstance().unLock(bundleDir);
        }
    }
}
Also used : BundleListing(android.taobao.atlas.bundleInfo.BundleListing) LowDiskException(android.taobao.atlas.runtime.LowDiskException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Example 3 with LowDiskException

use of android.taobao.atlas.runtime.LowDiskException in project atlas by alibaba.

the class Framework method installNewBundle.

/**
     * install a bundle from input file, the file will move to bundle storage directory.
     *
     * @param location the bundle location.
     * @param file     the input file.
     * @return a Bundle object.
     * @throws BundleException if the installation failed.
     * @throws
     */
static BundleImpl installNewBundle(final String location, final File file) throws BundleException {
    File bundleDir = null;
    try {
        bundleDir = new File(STORAGE_LOCATION, location);
        if (!bundleDir.exists()) {
            bundleDir.mkdirs();
        }
        BundleLock.WriteLock(location);
        AtlasFileLock.getInstance().LockExclusive(bundleDir);
        /*
	         * <specs page="58">Every bundle is uniquely identified by its location string. If an installed bundle is using
	         * the specified location, the installBundle method must return the Bundle object for that installed bundle and
	         * not install a new bundle.</specs>
	         */
        final BundleImpl cached;
        if ((cached = (BundleImpl) getBundle(location)) != null) {
            return cached;
        }
        Log.e("BundleInstaller", "real install " + location);
        BundleImpl bundle = null;
        BundleListing.BundleInfo info = AtlasBundleInfoManager.instance().getBundleInfo(location);
        String version = info != null ? info.getVersion() : "-1";
        bundle = new BundleImpl(bundleDir, location, new BundleContext(), null, file, version, true, -1);
        storeMetadata();
        return bundle;
    } catch (IOException e) {
        BundleException e1 = new BundleException("Failed to install bundle." + FileUtils.getAvailableDisk(), e);
        if (bundleDir != null)
            Framework.deleteDirectory(bundleDir);
        if (FileUtils.getUsableSpace(Environment.getDataDirectory()) < LowDiskException.thredshold) {
            throw new LowDiskException(FileUtils.getAvailableDisk(), e);
        }
        throw new BundleException("Failed to install bundle.", e);
    } catch (BundleException e) {
        BundleException e1 = new BundleException("Failed to install bundle." + FileUtils.getAvailableDisk(), e);
        if (bundleDir != null)
            Framework.deleteDirectory(bundleDir);
        throw e1;
    } finally {
        BundleLock.WriteUnLock(location);
        if (bundleDir != null) {
            AtlasFileLock.getInstance().unLock(bundleDir);
        }
    }
}
Also used : BundleListing(android.taobao.atlas.bundleInfo.BundleListing) LowDiskException(android.taobao.atlas.runtime.LowDiskException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Aggregations

LowDiskException (android.taobao.atlas.runtime.LowDiskException)3 BundleListing (android.taobao.atlas.bundleInfo.BundleListing)2 File (java.io.File)2 IOException (java.io.IOException)2 BundleException (org.osgi.framework.BundleException)2 Bundle (org.osgi.framework.Bundle)1