Loading cmds/pm/src/com/android/commands/pm/Pm.java +1 −1 Original line number Diff line number Diff line Loading @@ -416,7 +416,7 @@ public final class Pm { PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null, null, null, null); params.sessionParams.setSize( PackageHelper.calculateInstalledSize(pkgLite, false, PackageHelper.calculateInstalledSize(pkgLite, params.sessionParams.abiOverride)); } catch (PackageParserException | IOException e) { System.err.println("Error: Failed to parse APK file: " + e); Loading core/java/android/content/pm/IPackageManager.aidl +0 −8 Original line number Diff line number Diff line Loading @@ -554,14 +554,6 @@ interface IPackageManager { */ void reconcileSecondaryDexFiles(String packageName); /** * Update status of external media on the package manager to scan and * install packages installed on the external media. Like say the * StorageManagerService uses this to call into the package manager to update * status of sdcard. */ void updateExternalMediaStatus(boolean mounted, boolean reportStatus); PackageCleanItem nextPackageToClean(in PackageCleanItem lastPackage); int getMoveStatus(int moveId); Loading core/java/android/os/storage/IStorageManager.aidl +0 −111 Original line number Diff line number Diff line Loading @@ -44,103 +44,11 @@ interface IStorageManager { * Unregisters an IStorageEventListener */ void unregisterListener(IStorageEventListener listener) = 1; /** * Returns true if a USB mass storage host is connected */ boolean isUsbMassStorageConnected() = 2; /** * Enables / disables USB mass storage. The caller should check actual * status of enabling/disabling USB mass storage via StorageEventListener. */ void setUsbMassStorageEnabled(boolean enable) = 3; /** * Returns true if a USB mass storage host is enabled (media is shared) */ boolean isUsbMassStorageEnabled() = 4; /** * Mount external storage at given mount point. Returns an int consistent * with StorageResultCode */ int mountVolume(in String mountPoint) = 5; /** * Safely unmount external storage at given mount point. The unmount is an * asynchronous operation. Applications should register StorageEventListener * for storage related status changes. * @param mountPoint the mount point * @param force whether or not to forcefully unmount it (e.g. even if programs are using this * data currently) * @param removeEncryption whether or not encryption mapping should be removed from the volume. * This value implies {@code force}. */ void unmountVolume(in String mountPoint, boolean force, boolean removeEncryption) = 6; /** * Format external storage given a mount point. Returns an int consistent * with StorageResultCode */ int formatVolume(in String mountPoint) = 7; /** * Returns an array of pids with open files on the specified path. */ int[] getStorageUsers(in String path) = 8; /** * Gets the state of a volume via its mountpoint. */ String getVolumeState(in String mountPoint) = 9; /* * Creates a secure container with the specified parameters. Returns an int * consistent with StorageResultCode */ int createSecureContainer(in String id, int sizeMb, in String fstype, in String key, int ownerUid, boolean external) = 10; /* * Finalize a container which has just been created and populated. After * finalization, the container is immutable. Returns an int consistent with * StorageResultCode */ int finalizeSecureContainer(in String id) = 11; /* * Destroy a secure container, and free up all resources associated with it. * NOTE: Ensure all references are released prior to deleting. Returns an * int consistent with StorageResultCode */ int destroySecureContainer(in String id, boolean force) = 12; /* * Mount a secure container with the specified key and owner UID. Returns an * int consistent with StorageResultCode */ int mountSecureContainer(in String id, in String key, int ownerUid, boolean readOnly) = 13; /* * Unount a secure container. Returns an int consistent with * StorageResultCode */ int unmountSecureContainer(in String id, boolean force) = 14; /* * Returns true if the specified container is mounted */ boolean isSecureContainerMounted(in String id) = 15; /* * Rename an unmounted secure container. Returns an int consistent with * StorageResultCode */ int renameSecureContainer(in String oldId, in String newId) = 16; /* * Returns the filesystem path of a mounted secure container. */ String getSecureContainerPath(in String id) = 17; /** * Gets an Array of currently known secure container IDs */ String[] getSecureContainerList() = 18; /** * Shuts down the StorageManagerService and gracefully unmounts all external media. * Invokes call back once the shutdown is complete. */ void shutdown(IStorageShutdownObserver observer) = 19; /** * Call into StorageManagerService by PackageManager to notify that its done * processing the media status update request. */ void finishMediaUpdate() = 20; /** * Mounts an Opaque Binary Blob (OBB) with the specified decryption key and * only allows the calling process's UID access to the contents. Loading @@ -165,10 +73,6 @@ interface IStorageManager { * Gets the path to the mounted Opaque Binary Blob (OBB). */ String getMountedObbPath(in String rawPath) = 24; /** * Returns whether or not the external storage is emulated. */ boolean isExternalStorageEmulated() = 25; /** * Decrypts any encrypted volumes. */ Loading @@ -185,14 +89,6 @@ interface IStorageManager { * Returns list of all mountable volumes. */ StorageVolume[] getVolumeList(int uid, in String packageName, int flags) = 29; /** * Gets the path on the filesystem for the ASEC container itself. * * @param cid ASEC container ID * @return path to filesystem or {@code null} if it's not found * @throws RemoteException */ String getSecureContainerFilesystemPath(in String cid) = 30; /** * Determines the encryption state of the volume. * @return a numerical value. See {@code ENCRYPTION_STATE_*} for possible Loading @@ -208,11 +104,6 @@ interface IStorageManager { * may only be called by the system process. */ int verifyEncryptionPassword(in String password) = 32; /* * Fix permissions in a container which has just been created and populated. * Returns an int consistent with StorageResultCode */ int fixPermissionsSecureContainer(in String id, int gid, in String filename) = 33; /** * Ensure that all directories along given path exist, creating parent * directories as needed. Validates that given path is absolute and that it Loading Loading @@ -247,7 +138,6 @@ interface IStorageManager { * @return contents of field */ String getField(in String field) = 39; int resizeSecureContainer(in String id, int sizeMb, in String key) = 40; /** * Report the time of the last maintenance operation such as fstrim. * @return Timestamp of the last maintenance operation, in the Loading @@ -260,7 +150,6 @@ interface IStorageManager { * @throws RemoteException */ void runMaintenance() = 42; void waitForAsecScan() = 43; DiskInfo[] getDisks() = 44; VolumeInfo[] getVolumes(int flags) = 45; VolumeRecord[] getVolumeRecords(int flags) = 46; Loading core/java/com/android/internal/app/IMediaContainerService.aidl +1 −3 Original line number Diff line number Diff line Loading @@ -21,12 +21,10 @@ import android.content.pm.PackageInfoLite; import android.content.res.ObbInfo; interface IMediaContainerService { String copyPackageToContainer(String packagePath, String containerId, String key, boolean isExternal, boolean isForwardLocked, String abiOverride); int copyPackage(String packagePath, in IParcelFileDescriptorFactory target); PackageInfoLite getMinimalPackageInfo(String packagePath, int flags, String abiOverride); ObbInfo getObbInfo(String filename); void clearDirectory(String directory); long calculateInstalledSize(String packagePath, boolean isForwardLocked, String abiOverride); long calculateInstalledSize(String packagePath, String abiOverride); } core/java/com/android/internal/content/PackageHelper.java +14 −269 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.internal.content; import static android.net.TrafficStats.MB_IN_BYTES; import static android.os.storage.VolumeInfo.ID_PRIVATE_INTERNAL; import android.content.Context; Loading @@ -27,13 +26,11 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageParser.PackageLite; import android.os.Environment; import android.os.FileUtils; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.os.storage.IStorageManager; import android.os.storage.StorageManager; import android.os.storage.StorageResultCode; import android.os.storage.StorageVolume; import android.os.storage.VolumeInfo; import android.provider.Settings; Loading @@ -45,15 +42,9 @@ import com.android.internal.annotations.VisibleForTesting; import libcore.io.IoUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collections; import java.util.Objects; import java.util.UUID; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; /** * Constants used internally between the PackageManager Loading @@ -72,7 +63,6 @@ public class PackageHelper { public static final int RECOMMEND_FAILED_INVALID_URI = -6; public static final int RECOMMEND_FAILED_VERSION_DOWNGRADE = -7; private static final boolean localLOGV = false; private static final String TAG = "PackageHelper"; // App installation location settings values public static final int APP_INSTALL_AUTO = 0; Loading @@ -91,259 +81,6 @@ public class PackageHelper { } } public static String createSdDir(long sizeBytes, String cid, String sdEncKey, int uid, boolean isExternal) { // Round up to nearest MB, plus another MB for filesystem overhead final int sizeMb = (int) ((sizeBytes + MB_IN_BYTES) / MB_IN_BYTES) + 1; try { IStorageManager storageManager = getStorageManager(); if (localLOGV) Log.i(TAG, "Size of container " + sizeMb + " MB"); int rc = storageManager.createSecureContainer(cid, sizeMb, "ext4", sdEncKey, uid, isExternal); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to create secure container " + cid); return null; } String cachePath = storageManager.getSecureContainerPath(cid); if (localLOGV) Log.i(TAG, "Created secure container " + cid + " at " + cachePath); return cachePath; } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } return null; } public static boolean resizeSdDir(long sizeBytes, String cid, String sdEncKey) { // Round up to nearest MB, plus another MB for filesystem overhead final int sizeMb = (int) ((sizeBytes + MB_IN_BYTES) / MB_IN_BYTES) + 1; try { IStorageManager storageManager = getStorageManager(); int rc = storageManager.resizeSecureContainer(cid, sizeMb, sdEncKey); if (rc == StorageResultCode.OperationSucceeded) { return true; } } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } Log.e(TAG, "Failed to create secure container " + cid); return false; } public static String mountSdDir(String cid, String key, int ownerUid) { return mountSdDir(cid, key, ownerUid, true); } public static String mountSdDir(String cid, String key, int ownerUid, boolean readOnly) { try { int rc = getStorageManager().mountSecureContainer(cid, key, ownerUid, readOnly); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to mount container " + cid + " rc : " + rc); return null; } return getStorageManager().getSecureContainerPath(cid); } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } return null; } public static boolean unMountSdDir(String cid) { try { int rc = getStorageManager().unmountSecureContainer(cid, true); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to unmount " + cid + " with rc " + rc); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } return false; } public static boolean renameSdDir(String oldId, String newId) { try { int rc = getStorageManager().renameSecureContainer(oldId, newId); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to rename " + oldId + " to " + newId + "with rc " + rc); return false; } return true; } catch (RemoteException e) { Log.i(TAG, "Failed ot rename " + oldId + " to " + newId + " with exception : " + e); } return false; } public static String getSdDir(String cid) { try { return getStorageManager().getSecureContainerPath(cid); } catch (RemoteException e) { Log.e(TAG, "Failed to get container path for " + cid + " with exception " + e); } return null; } public static String getSdFilesystem(String cid) { try { return getStorageManager().getSecureContainerFilesystemPath(cid); } catch (RemoteException e) { Log.e(TAG, "Failed to get container path for " + cid + " with exception " + e); } return null; } public static boolean finalizeSdDir(String cid) { try { int rc = getStorageManager().finalizeSecureContainer(cid); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to finalize container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to finalize container " + cid + " with exception " + e); } return false; } public static boolean destroySdDir(String cid) { try { if (localLOGV) Log.i(TAG, "Forcibly destroying container " + cid); int rc = getStorageManager().destroySecureContainer(cid, true); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to destroy container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to destroy container " + cid + " with exception " + e); } return false; } public static String[] getSecureContainerList() { try { return getStorageManager().getSecureContainerList(); } catch (RemoteException e) { Log.e(TAG, "Failed to get secure container list with exception" + e); } return null; } public static boolean isContainerMounted(String cid) { try { return getStorageManager().isSecureContainerMounted(cid); } catch (RemoteException e) { Log.e(TAG, "Failed to find out if container " + cid + " mounted"); } return false; } /** * Extract public files for the single given APK. */ public static long extractPublicFiles(File apkFile, File publicZipFile) throws IOException { final FileOutputStream fstr; final ZipOutputStream publicZipOutStream; if (publicZipFile == null) { fstr = null; publicZipOutStream = null; } else { fstr = new FileOutputStream(publicZipFile); publicZipOutStream = new ZipOutputStream(fstr); Log.d(TAG, "Extracting " + apkFile + " to " + publicZipFile); } long size = 0L; try { final ZipFile privateZip = new ZipFile(apkFile.getAbsolutePath()); try { // Copy manifest, resources.arsc and res directory to public zip for (final ZipEntry zipEntry : Collections.list(privateZip.entries())) { final String zipEntryName = zipEntry.getName(); if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) { size += zipEntry.getSize(); if (publicZipFile != null) { copyZipEntry(zipEntry, privateZip, publicZipOutStream); } } } } finally { try { privateZip.close(); } catch (IOException e) {} } if (publicZipFile != null) { publicZipOutStream.finish(); publicZipOutStream.flush(); FileUtils.sync(fstr); publicZipOutStream.close(); FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1); } } finally { IoUtils.closeQuietly(publicZipOutStream); } return size; } private static void copyZipEntry(ZipEntry zipEntry, ZipFile inZipFile, ZipOutputStream outZipStream) throws IOException { byte[] buffer = new byte[4096]; int num; ZipEntry newEntry; if (zipEntry.getMethod() == ZipEntry.STORED) { // Preserve the STORED method of the input entry. newEntry = new ZipEntry(zipEntry); } else { // Create a new entry so that the compressed len is recomputed. newEntry = new ZipEntry(zipEntry.getName()); } outZipStream.putNextEntry(newEntry); final InputStream data = inZipFile.getInputStream(zipEntry); try { while ((num = data.read(buffer)) > 0) { outZipStream.write(buffer, 0, num); } outZipStream.flush(); } finally { IoUtils.closeQuietly(data); } } public static boolean fixSdPermissions(String cid, int gid, String filename) { try { int rc = getStorageManager().fixPermissionsSecureContainer(cid, gid, filename); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to fixperms container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to fixperms container " + cid + " with exception " + e); } return false; } /** * A group of external dependencies used in * {@link #resolveInstallVolume(Context, String, int, long)}. It can be backed by real values Loading Loading @@ -638,29 +375,37 @@ public class PackageHelper { return PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE; } @Deprecated public static long calculateInstalledSize(PackageLite pkg, boolean isForwardLocked, String abiOverride) throws IOException { return calculateInstalledSize(pkg, abiOverride); } public static long calculateInstalledSize(PackageLite pkg, String abiOverride) throws IOException { NativeLibraryHelper.Handle handle = null; try { handle = NativeLibraryHelper.Handle.create(pkg); return calculateInstalledSize(pkg, handle, isForwardLocked, abiOverride); return calculateInstalledSize(pkg, handle, abiOverride); } finally { IoUtils.closeQuietly(handle); } } @Deprecated public static long calculateInstalledSize(PackageLite pkg, boolean isForwardLocked, NativeLibraryHelper.Handle handle, String abiOverride) throws IOException { return calculateInstalledSize(pkg, handle, abiOverride); } public static long calculateInstalledSize(PackageLite pkg, NativeLibraryHelper.Handle handle, boolean isForwardLocked, String abiOverride) throws IOException { 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 Loading Loading
cmds/pm/src/com/android/commands/pm/Pm.java +1 −1 Original line number Diff line number Diff line Loading @@ -416,7 +416,7 @@ public final class Pm { PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null, null, null, null); params.sessionParams.setSize( PackageHelper.calculateInstalledSize(pkgLite, false, PackageHelper.calculateInstalledSize(pkgLite, params.sessionParams.abiOverride)); } catch (PackageParserException | IOException e) { System.err.println("Error: Failed to parse APK file: " + e); Loading
core/java/android/content/pm/IPackageManager.aidl +0 −8 Original line number Diff line number Diff line Loading @@ -554,14 +554,6 @@ interface IPackageManager { */ void reconcileSecondaryDexFiles(String packageName); /** * Update status of external media on the package manager to scan and * install packages installed on the external media. Like say the * StorageManagerService uses this to call into the package manager to update * status of sdcard. */ void updateExternalMediaStatus(boolean mounted, boolean reportStatus); PackageCleanItem nextPackageToClean(in PackageCleanItem lastPackage); int getMoveStatus(int moveId); Loading
core/java/android/os/storage/IStorageManager.aidl +0 −111 Original line number Diff line number Diff line Loading @@ -44,103 +44,11 @@ interface IStorageManager { * Unregisters an IStorageEventListener */ void unregisterListener(IStorageEventListener listener) = 1; /** * Returns true if a USB mass storage host is connected */ boolean isUsbMassStorageConnected() = 2; /** * Enables / disables USB mass storage. The caller should check actual * status of enabling/disabling USB mass storage via StorageEventListener. */ void setUsbMassStorageEnabled(boolean enable) = 3; /** * Returns true if a USB mass storage host is enabled (media is shared) */ boolean isUsbMassStorageEnabled() = 4; /** * Mount external storage at given mount point. Returns an int consistent * with StorageResultCode */ int mountVolume(in String mountPoint) = 5; /** * Safely unmount external storage at given mount point. The unmount is an * asynchronous operation. Applications should register StorageEventListener * for storage related status changes. * @param mountPoint the mount point * @param force whether or not to forcefully unmount it (e.g. even if programs are using this * data currently) * @param removeEncryption whether or not encryption mapping should be removed from the volume. * This value implies {@code force}. */ void unmountVolume(in String mountPoint, boolean force, boolean removeEncryption) = 6; /** * Format external storage given a mount point. Returns an int consistent * with StorageResultCode */ int formatVolume(in String mountPoint) = 7; /** * Returns an array of pids with open files on the specified path. */ int[] getStorageUsers(in String path) = 8; /** * Gets the state of a volume via its mountpoint. */ String getVolumeState(in String mountPoint) = 9; /* * Creates a secure container with the specified parameters. Returns an int * consistent with StorageResultCode */ int createSecureContainer(in String id, int sizeMb, in String fstype, in String key, int ownerUid, boolean external) = 10; /* * Finalize a container which has just been created and populated. After * finalization, the container is immutable. Returns an int consistent with * StorageResultCode */ int finalizeSecureContainer(in String id) = 11; /* * Destroy a secure container, and free up all resources associated with it. * NOTE: Ensure all references are released prior to deleting. Returns an * int consistent with StorageResultCode */ int destroySecureContainer(in String id, boolean force) = 12; /* * Mount a secure container with the specified key and owner UID. Returns an * int consistent with StorageResultCode */ int mountSecureContainer(in String id, in String key, int ownerUid, boolean readOnly) = 13; /* * Unount a secure container. Returns an int consistent with * StorageResultCode */ int unmountSecureContainer(in String id, boolean force) = 14; /* * Returns true if the specified container is mounted */ boolean isSecureContainerMounted(in String id) = 15; /* * Rename an unmounted secure container. Returns an int consistent with * StorageResultCode */ int renameSecureContainer(in String oldId, in String newId) = 16; /* * Returns the filesystem path of a mounted secure container. */ String getSecureContainerPath(in String id) = 17; /** * Gets an Array of currently known secure container IDs */ String[] getSecureContainerList() = 18; /** * Shuts down the StorageManagerService and gracefully unmounts all external media. * Invokes call back once the shutdown is complete. */ void shutdown(IStorageShutdownObserver observer) = 19; /** * Call into StorageManagerService by PackageManager to notify that its done * processing the media status update request. */ void finishMediaUpdate() = 20; /** * Mounts an Opaque Binary Blob (OBB) with the specified decryption key and * only allows the calling process's UID access to the contents. Loading @@ -165,10 +73,6 @@ interface IStorageManager { * Gets the path to the mounted Opaque Binary Blob (OBB). */ String getMountedObbPath(in String rawPath) = 24; /** * Returns whether or not the external storage is emulated. */ boolean isExternalStorageEmulated() = 25; /** * Decrypts any encrypted volumes. */ Loading @@ -185,14 +89,6 @@ interface IStorageManager { * Returns list of all mountable volumes. */ StorageVolume[] getVolumeList(int uid, in String packageName, int flags) = 29; /** * Gets the path on the filesystem for the ASEC container itself. * * @param cid ASEC container ID * @return path to filesystem or {@code null} if it's not found * @throws RemoteException */ String getSecureContainerFilesystemPath(in String cid) = 30; /** * Determines the encryption state of the volume. * @return a numerical value. See {@code ENCRYPTION_STATE_*} for possible Loading @@ -208,11 +104,6 @@ interface IStorageManager { * may only be called by the system process. */ int verifyEncryptionPassword(in String password) = 32; /* * Fix permissions in a container which has just been created and populated. * Returns an int consistent with StorageResultCode */ int fixPermissionsSecureContainer(in String id, int gid, in String filename) = 33; /** * Ensure that all directories along given path exist, creating parent * directories as needed. Validates that given path is absolute and that it Loading Loading @@ -247,7 +138,6 @@ interface IStorageManager { * @return contents of field */ String getField(in String field) = 39; int resizeSecureContainer(in String id, int sizeMb, in String key) = 40; /** * Report the time of the last maintenance operation such as fstrim. * @return Timestamp of the last maintenance operation, in the Loading @@ -260,7 +150,6 @@ interface IStorageManager { * @throws RemoteException */ void runMaintenance() = 42; void waitForAsecScan() = 43; DiskInfo[] getDisks() = 44; VolumeInfo[] getVolumes(int flags) = 45; VolumeRecord[] getVolumeRecords(int flags) = 46; Loading
core/java/com/android/internal/app/IMediaContainerService.aidl +1 −3 Original line number Diff line number Diff line Loading @@ -21,12 +21,10 @@ import android.content.pm.PackageInfoLite; import android.content.res.ObbInfo; interface IMediaContainerService { String copyPackageToContainer(String packagePath, String containerId, String key, boolean isExternal, boolean isForwardLocked, String abiOverride); int copyPackage(String packagePath, in IParcelFileDescriptorFactory target); PackageInfoLite getMinimalPackageInfo(String packagePath, int flags, String abiOverride); ObbInfo getObbInfo(String filename); void clearDirectory(String directory); long calculateInstalledSize(String packagePath, boolean isForwardLocked, String abiOverride); long calculateInstalledSize(String packagePath, String abiOverride); }
core/java/com/android/internal/content/PackageHelper.java +14 −269 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.internal.content; import static android.net.TrafficStats.MB_IN_BYTES; import static android.os.storage.VolumeInfo.ID_PRIVATE_INTERNAL; import android.content.Context; Loading @@ -27,13 +26,11 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageParser.PackageLite; import android.os.Environment; import android.os.FileUtils; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.os.storage.IStorageManager; import android.os.storage.StorageManager; import android.os.storage.StorageResultCode; import android.os.storage.StorageVolume; import android.os.storage.VolumeInfo; import android.provider.Settings; Loading @@ -45,15 +42,9 @@ import com.android.internal.annotations.VisibleForTesting; import libcore.io.IoUtils; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Collections; import java.util.Objects; import java.util.UUID; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; /** * Constants used internally between the PackageManager Loading @@ -72,7 +63,6 @@ public class PackageHelper { public static final int RECOMMEND_FAILED_INVALID_URI = -6; public static final int RECOMMEND_FAILED_VERSION_DOWNGRADE = -7; private static final boolean localLOGV = false; private static final String TAG = "PackageHelper"; // App installation location settings values public static final int APP_INSTALL_AUTO = 0; Loading @@ -91,259 +81,6 @@ public class PackageHelper { } } public static String createSdDir(long sizeBytes, String cid, String sdEncKey, int uid, boolean isExternal) { // Round up to nearest MB, plus another MB for filesystem overhead final int sizeMb = (int) ((sizeBytes + MB_IN_BYTES) / MB_IN_BYTES) + 1; try { IStorageManager storageManager = getStorageManager(); if (localLOGV) Log.i(TAG, "Size of container " + sizeMb + " MB"); int rc = storageManager.createSecureContainer(cid, sizeMb, "ext4", sdEncKey, uid, isExternal); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to create secure container " + cid); return null; } String cachePath = storageManager.getSecureContainerPath(cid); if (localLOGV) Log.i(TAG, "Created secure container " + cid + " at " + cachePath); return cachePath; } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } return null; } public static boolean resizeSdDir(long sizeBytes, String cid, String sdEncKey) { // Round up to nearest MB, plus another MB for filesystem overhead final int sizeMb = (int) ((sizeBytes + MB_IN_BYTES) / MB_IN_BYTES) + 1; try { IStorageManager storageManager = getStorageManager(); int rc = storageManager.resizeSecureContainer(cid, sizeMb, sdEncKey); if (rc == StorageResultCode.OperationSucceeded) { return true; } } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } Log.e(TAG, "Failed to create secure container " + cid); return false; } public static String mountSdDir(String cid, String key, int ownerUid) { return mountSdDir(cid, key, ownerUid, true); } public static String mountSdDir(String cid, String key, int ownerUid, boolean readOnly) { try { int rc = getStorageManager().mountSecureContainer(cid, key, ownerUid, readOnly); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to mount container " + cid + " rc : " + rc); return null; } return getStorageManager().getSecureContainerPath(cid); } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } return null; } public static boolean unMountSdDir(String cid) { try { int rc = getStorageManager().unmountSecureContainer(cid, true); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to unmount " + cid + " with rc " + rc); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "StorageManagerService running?"); } return false; } public static boolean renameSdDir(String oldId, String newId) { try { int rc = getStorageManager().renameSecureContainer(oldId, newId); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to rename " + oldId + " to " + newId + "with rc " + rc); return false; } return true; } catch (RemoteException e) { Log.i(TAG, "Failed ot rename " + oldId + " to " + newId + " with exception : " + e); } return false; } public static String getSdDir(String cid) { try { return getStorageManager().getSecureContainerPath(cid); } catch (RemoteException e) { Log.e(TAG, "Failed to get container path for " + cid + " with exception " + e); } return null; } public static String getSdFilesystem(String cid) { try { return getStorageManager().getSecureContainerFilesystemPath(cid); } catch (RemoteException e) { Log.e(TAG, "Failed to get container path for " + cid + " with exception " + e); } return null; } public static boolean finalizeSdDir(String cid) { try { int rc = getStorageManager().finalizeSecureContainer(cid); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to finalize container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to finalize container " + cid + " with exception " + e); } return false; } public static boolean destroySdDir(String cid) { try { if (localLOGV) Log.i(TAG, "Forcibly destroying container " + cid); int rc = getStorageManager().destroySecureContainer(cid, true); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to destroy container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to destroy container " + cid + " with exception " + e); } return false; } public static String[] getSecureContainerList() { try { return getStorageManager().getSecureContainerList(); } catch (RemoteException e) { Log.e(TAG, "Failed to get secure container list with exception" + e); } return null; } public static boolean isContainerMounted(String cid) { try { return getStorageManager().isSecureContainerMounted(cid); } catch (RemoteException e) { Log.e(TAG, "Failed to find out if container " + cid + " mounted"); } return false; } /** * Extract public files for the single given APK. */ public static long extractPublicFiles(File apkFile, File publicZipFile) throws IOException { final FileOutputStream fstr; final ZipOutputStream publicZipOutStream; if (publicZipFile == null) { fstr = null; publicZipOutStream = null; } else { fstr = new FileOutputStream(publicZipFile); publicZipOutStream = new ZipOutputStream(fstr); Log.d(TAG, "Extracting " + apkFile + " to " + publicZipFile); } long size = 0L; try { final ZipFile privateZip = new ZipFile(apkFile.getAbsolutePath()); try { // Copy manifest, resources.arsc and res directory to public zip for (final ZipEntry zipEntry : Collections.list(privateZip.entries())) { final String zipEntryName = zipEntry.getName(); if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) { size += zipEntry.getSize(); if (publicZipFile != null) { copyZipEntry(zipEntry, privateZip, publicZipOutStream); } } } } finally { try { privateZip.close(); } catch (IOException e) {} } if (publicZipFile != null) { publicZipOutStream.finish(); publicZipOutStream.flush(); FileUtils.sync(fstr); publicZipOutStream.close(); FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1); } } finally { IoUtils.closeQuietly(publicZipOutStream); } return size; } private static void copyZipEntry(ZipEntry zipEntry, ZipFile inZipFile, ZipOutputStream outZipStream) throws IOException { byte[] buffer = new byte[4096]; int num; ZipEntry newEntry; if (zipEntry.getMethod() == ZipEntry.STORED) { // Preserve the STORED method of the input entry. newEntry = new ZipEntry(zipEntry); } else { // Create a new entry so that the compressed len is recomputed. newEntry = new ZipEntry(zipEntry.getName()); } outZipStream.putNextEntry(newEntry); final InputStream data = inZipFile.getInputStream(zipEntry); try { while ((num = data.read(buffer)) > 0) { outZipStream.write(buffer, 0, num); } outZipStream.flush(); } finally { IoUtils.closeQuietly(data); } } public static boolean fixSdPermissions(String cid, int gid, String filename) { try { int rc = getStorageManager().fixPermissionsSecureContainer(cid, gid, filename); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to fixperms container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to fixperms container " + cid + " with exception " + e); } return false; } /** * A group of external dependencies used in * {@link #resolveInstallVolume(Context, String, int, long)}. It can be backed by real values Loading Loading @@ -638,29 +375,37 @@ public class PackageHelper { return PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE; } @Deprecated public static long calculateInstalledSize(PackageLite pkg, boolean isForwardLocked, String abiOverride) throws IOException { return calculateInstalledSize(pkg, abiOverride); } public static long calculateInstalledSize(PackageLite pkg, String abiOverride) throws IOException { NativeLibraryHelper.Handle handle = null; try { handle = NativeLibraryHelper.Handle.create(pkg); return calculateInstalledSize(pkg, handle, isForwardLocked, abiOverride); return calculateInstalledSize(pkg, handle, abiOverride); } finally { IoUtils.closeQuietly(handle); } } @Deprecated public static long calculateInstalledSize(PackageLite pkg, boolean isForwardLocked, NativeLibraryHelper.Handle handle, String abiOverride) throws IOException { return calculateInstalledSize(pkg, handle, abiOverride); } public static long calculateInstalledSize(PackageLite pkg, NativeLibraryHelper.Handle handle, boolean isForwardLocked, String abiOverride) throws IOException { 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 Loading