From 941a8ba1a6043cf84a7bf622e44a0b4f7abd0178 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 20 Aug 2014 16:26:32 -0700 Subject: Installing splits into ASECs! Sessions can now zero-copy data directly into pre-allocated ASEC containers. Then at commit time, we compute the total size of the final app, including any inherited APKs and unpacked libraries, and resize the container in one step. This supports both brand new ASEC installs and inheriting from existing ASEC installs. To keep things simple, it currently requires copying any inherited ASEC contents, but this could be optimized in the future. Expose new vold resize command, and allow read-write mounting of ASEC containers. Move native library extraction into the installer flow, since it needs to happen before ASEC is sealed. Move multiArch flag into NativeLibraryHelper, instead of making everyone pass it around. Migrate size calculation to shared location. Separate "other" package name in public API, provide a path to a storage device when relevant, and add more docs. Bug: 16514385 Change-Id: I06c6ce588d312ee7e64cce02733895d640b88456 --- .../defcontainer/DefaultContainerService.java | 52 ++++------------------ 1 file changed, 9 insertions(+), 43 deletions(-) (limited to 'packages/DefaultContainerService') diff --git a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java index fae30e5..1f28324 100644 --- a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java +++ b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java @@ -16,7 +16,7 @@ package com.android.defcontainer; -import static android.net.TrafficStats.MB_IN_BYTES; +import static com.android.internal.content.NativeLibraryHelper.LIB_DIR_NAME; import android.app.IntentService; import android.content.Context; @@ -67,8 +67,6 @@ import java.io.OutputStream; public class DefaultContainerService extends IntentService { private static final String TAG = "DefContainer"; - private static final String LIB_DIR_NAME = "lib"; - // TODO: migrate native code unpacking to always be a derivative work private IMediaContainerService.Stub mBinder = new IMediaContainerService.Stub() { @@ -168,7 +166,7 @@ public class DefaultContainerService extends IntentService { final long sizeBytes; try { pkg = PackageParser.parsePackageLite(packageFile, 0); - sizeBytes = calculateInstalledSizeInner(pkg, isForwardLocked, abiOverride); + sizeBytes = PackageHelper.calculateInstalledSize(pkg, isForwardLocked, abiOverride); } catch (PackageParserException | IOException e) { Slog.w(TAG, "Failed to parse package at " + packagePath + ": " + e); @@ -253,7 +251,7 @@ public class DefaultContainerService extends IntentService { final PackageParser.PackageLite pkg; try { pkg = PackageParser.parsePackageLite(packageFile, 0); - return calculateInstalledSizeInner(pkg, isForwardLocked, abiOverride); + return PackageHelper.calculateInstalledSize(pkg, isForwardLocked, abiOverride); } catch (PackageParserException | IOException e) { Slog.w(TAG, "Failed to calculate installed size: " + e); return Long.MAX_VALUE; @@ -315,13 +313,12 @@ public class DefaultContainerService extends IntentService { // Calculate container size, rounding up to nearest MB and adding an // extra MB for filesystem overhead - final long sizeBytes = calculateInstalledSizeInner(pkg, handle, isForwardLocked, - abiOverride); - final int sizeMb = ((int) ((sizeBytes + MB_IN_BYTES) / MB_IN_BYTES)) + 1; + final long sizeBytes = PackageHelper.calculateInstalledSize(pkg, handle, + isForwardLocked, abiOverride); // Create new container - final String newMountPath = PackageHelper.createSdDir(sizeMb, newCid, key, Process.myUid(), - isExternal); + final String newMountPath = PackageHelper.createSdDir(sizeBytes, newCid, key, + Process.myUid(), isExternal); if (newMountPath == null) { throw new IOException("Failed to create container " + newCid); } @@ -339,8 +336,8 @@ public class DefaultContainerService extends IntentService { // Extract native code final File libraryRoot = new File(targetDir, LIB_DIR_NAME); - final int res = NativeLibraryHelper.copyNativeBinariesIfNeededLI(handle, libraryRoot, - abiOverride, pkg.multiArch); + final int res = NativeLibraryHelper.copyNativeBinariesWithOverride(handle, libraryRoot, + abiOverride); if (res != PackageManager.INSTALL_SUCCEEDED) { throw new IOException("Failed to extract native code, res=" + res); } @@ -415,35 +412,4 @@ public class DefaultContainerService extends IntentService { Os.chmod(targetFile.getAbsolutePath(), 0644); } } - - private long calculateInstalledSizeInner(PackageLite pkg, boolean isForwardLocked, - String abiOverride) throws IOException { - NativeLibraryHelper.Handle handle = null; - try { - handle = NativeLibraryHelper.Handle.create(pkg); - return calculateInstalledSizeInner(pkg, handle, isForwardLocked, abiOverride); - } finally { - IoUtils.closeQuietly(handle); - } - } - - private long calculateInstalledSizeInner(PackageLite pkg, NativeLibraryHelper.Handle handle, - boolean isForwardLocked, String abiOverride) throws IOException { - long sizeBytes = 0; - - // Include raw APKs, and possibly unpacked resources - for (String codePath : pkg.getAllCodePaths()) { - final File codeFile = new File(codePath); - sizeBytes += codeFile.length(); - - if (isForwardLocked) { - sizeBytes += PackageHelper.extractPublicFiles(codeFile, null); - } - } - - // Include all relevant native code - sizeBytes += NativeLibraryHelper.sumNativeBinaries(handle, abiOverride, pkg.multiArch); - - return sizeBytes; - } } -- cgit v1.1