summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2010-02-16 16:08:00 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-02-16 16:08:00 -0800
commit044a401292846098e3d40977be1346b6ce7ea327 (patch)
treeaab93d065e0cfa43c864d4dd5537d39ec955b76a
parentbb9a51768d2d9dddbe2394b99a00544a3d144fac (diff)
parent679bba339ef6948091180c776d6a284cddd812f5 (diff)
downloadframeworks_base-044a401292846098e3d40977be1346b6ce7ea327.zip
frameworks_base-044a401292846098e3d40977be1346b6ce7ea327.tar.gz
frameworks_base-044a401292846098e3d40977be1346b6ce7ea327.tar.bz2
Merge "Move mount service wrapper calls to PackageHelper"
-rw-r--r--core/java/com/android/internal/content/PackageHelper.java154
-rw-r--r--packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java143
-rw-r--r--services/java/com/android/server/PackageManagerService.java248
3 files changed, 209 insertions, 336 deletions
diff --git a/core/java/com/android/internal/content/PackageHelper.java b/core/java/com/android/internal/content/PackageHelper.java
index 4d7d2d1..c5b869b 100644
--- a/core/java/com/android/internal/content/PackageHelper.java
+++ b/core/java/com/android/internal/content/PackageHelper.java
@@ -16,13 +16,167 @@
package com.android.internal.content;
+import android.os.storage.IMountService;
+
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.storage.StorageResultCode;
+import android.util.Log;
+
+import java.io.File;
+
/**
* Constants used internally between the PackageManager
* and media container service transports.
+ * Some utility methods to invoke MountService api.
*/
public class PackageHelper {
public static final int RECOMMEND_INSTALL_INTERNAL = 1;
public static final int RECOMMEND_INSTALL_EXTERNAL = 2;
public static final int RECOMMEND_FAILED_INSUFFICIENT_STORAGE = -1;
public static final int RECOMMEND_FAILED_INVALID_APK = -2;
+ private static final boolean DEBUG_SD_INSTALL = true;
+ private static final String TAG = "PackageHelper";
+
+ public static IMountService getMountService() {
+ IBinder service = ServiceManager.getService("mount");
+ if (service != null) {
+ return IMountService.Stub.asInterface(service);
+ } else {
+ Log.e(TAG, "Can't get mount service");
+ }
+ return null;
+ }
+
+ public static String createSdDir(File tmpPackageFile, String cid,
+ String sdEncKey, int uid) {
+ // Create mount point via MountService
+ IMountService mountService = getMountService();
+ long len = tmpPackageFile.length();
+ int mbLen = (int) (len/(1024*1024));
+ if ((len - (mbLen * 1024 * 1024)) > 0) {
+ mbLen++;
+ }
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "Size of resource " + mbLen);
+
+ try {
+ int rc = mountService.createSecureContainer(
+ cid, mbLen, "vfat", sdEncKey, uid);
+ if (rc != StorageResultCode.OperationSucceeded) {
+ Log.e(TAG, "Failed to create secure container " + cid);
+ return null;
+ }
+ String cachePath = mountService.getSecureContainerPath(cid);
+ if (DEBUG_SD_INSTALL) Log.i(TAG, "Created secure container " + cid +
+ " at " + cachePath);
+ return cachePath;
+ } catch (RemoteException e) {
+ Log.e(TAG, "MountService running?");
+ }
+ return null;
+ }
+
+ public static String mountSdDir(String cid, String key, int ownerUid) {
+ try {
+ int rc = getMountService().mountSecureContainer(cid, key, ownerUid);
+ if (rc != StorageResultCode.OperationSucceeded) {
+ Log.i(TAG, "Failed to mount container " + cid + " rc : " + rc);
+ return null;
+ }
+ return getMountService().getSecureContainerPath(cid);
+ } catch (RemoteException e) {
+ Log.e(TAG, "MountService running?");
+ }
+ return null;
+ }
+
+ public static boolean unMountSdDir(String cid) {
+ try {
+ int rc = getMountService().unmountSecureContainer(cid);
+ if (rc != StorageResultCode.OperationSucceeded) {
+ Log.e(TAG, "Failed to unmount " + cid + " with rc " + rc);
+ return false;
+ }
+ return true;
+ } catch (RemoteException e) {
+ Log.e(TAG, "MountService running?");
+ }
+ return false;
+ }
+
+ public static boolean renameSdDir(String oldId, String newId) {
+ try {
+ int rc = getMountService().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 getMountService().getSecureContainerPath(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 = getMountService().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 {
+ int rc = getMountService().destroySecureContainer(cid);
+ 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 getMountService().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 getMountService().isSecureContainerMounted(cid);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to find out if container " + cid + " mounted");
+ }
+ return false;
+ }
}
diff --git a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
index 8e030e5..933a7e5 100644
--- a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
+++ b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
@@ -9,18 +9,14 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PackageParser.Package;
import android.net.Uri;
-import android.os.Debug;
import android.os.Environment;
import android.os.IBinder;
-import android.os.storage.IMountService;
-import android.os.storage.StorageResultCode;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StatFs;
import android.app.IntentService;
-import android.app.Service;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -30,7 +26,6 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import android.os.FileUtils;
import android.provider.Settings;
@@ -51,7 +46,7 @@ public class DefaultContainerService extends IntentService {
* Creates a new container and copies resource there.
* @param paackageURI the uri of resource to be copied. Can be either
* a content uri or a file uri
- * @param containerId the id of the secure container that should
+ * @param cid the id of the secure container that should
* be used for creating a secure container into which the resource
* will be copied.
* @param key Refers to key used for encrypting the secure container
@@ -61,12 +56,12 @@ public class DefaultContainerService extends IntentService {
*
*/
public String copyResourceToContainer(final Uri packageURI,
- final String containerId,
+ final String cid,
final String key, final String resFileName) {
- if (packageURI == null || containerId == null) {
+ if (packageURI == null || cid == null) {
return null;
}
- return copyResourceInner(packageURI, containerId, key, resFileName);
+ return copyResourceInner(packageURI, cid, key, resFileName);
}
/*
@@ -162,13 +157,10 @@ public class DefaultContainerService extends IntentService {
return mBinder;
}
- private IMountService getMountService() {
- return IMountService.Stub.asInterface(ServiceManager.getService("mount"));
- }
-
- private String copyResourceInner(Uri packageURI, String newCacheId, String key, String resFileName) {
+ private String copyResourceInner(Uri packageURI, String newCid, String key, String resFileName) {
// Create new container at newCachePath
String codePath = packageURI.getPath();
+ File codeFile = new File(codePath);
String newCachePath = null;
final int CREATE_FAILED = 1;
final int COPY_FAILED = 2;
@@ -176,8 +168,9 @@ public class DefaultContainerService extends IntentService {
final int PASS = 4;
int errCode = CREATE_FAILED;
// Create new container
- if ((newCachePath = createSdDir(packageURI, newCacheId, key)) != null) {
- if (localLOGV) Log.i(TAG, "Created container for " + newCacheId
+ if ((newCachePath = PackageHelper.createSdDir(codeFile,
+ newCid, key, Process.myUid())) != null) {
+ if (localLOGV) Log.i(TAG, "Created container for " + newCid
+ " at path : " + newCachePath);
File resFile = new File(newCachePath, resFileName);
errCode = COPY_FAILED;
@@ -185,7 +178,8 @@ public class DefaultContainerService extends IntentService {
if (FileUtils.copyFile(new File(codePath), resFile)) {
if (localLOGV) Log.i(TAG, "Copied " + codePath + " to " + resFile);
errCode = FINALIZE_FAILED;
- if (finalizeSdDir(newCacheId)) {
+ if (PackageHelper.finalizeSdDir(newCid)) {
+ if (localLOGV) Log.i(TAG, "Finalized container " + newCid);
errCode = PASS;
}
}
@@ -198,21 +192,25 @@ public class DefaultContainerService extends IntentService {
break;
case COPY_FAILED:
errMsg = "COPY_FAILED";
- if (localLOGV) Log.i(TAG, "Destroying " + newCacheId +
+ if (localLOGV) Log.i(TAG, "Destroying " + newCid +
" at path " + newCachePath + " after " + errMsg);
- destroySdDir(newCacheId);
+ PackageHelper.destroySdDir(newCid);
break;
case FINALIZE_FAILED:
errMsg = "FINALIZE_FAILED";
- if (localLOGV) Log.i(TAG, "Destroying " + newCacheId +
+ if (localLOGV) Log.i(TAG, "Destroying " + newCid +
" at path " + newCachePath + " after " + errMsg);
- destroySdDir(newCacheId);
+ PackageHelper.destroySdDir(newCid);
break;
default:
errMsg = "PASS";
- if (localLOGV) Log.i(TAG, "Unmounting " + newCacheId +
- " at path " + newCachePath + " after " + errMsg);
- unMountSdDir(newCacheId);
+ if (PackageHelper.isContainerMounted(newCid)) {
+ if (localLOGV) Log.i(TAG, "Unmounting " + newCid +
+ " at path " + newCachePath + " after " + errMsg);
+ PackageHelper.unMountSdDir(newCid);
+ } else {
+ if (localLOGV) Log.i(TAG, "Container " + newCid + " not mounted");
+ }
break;
}
if (errCode != PASS) {
@@ -221,102 +219,6 @@ public class DefaultContainerService extends IntentService {
return newCachePath;
}
- private String createSdDir(final Uri packageURI,
- String containerId, String sdEncKey) {
- File tmpPackageFile = new File(packageURI.getPath());
- // Create mount point via MountService
- IMountService mountService = getMountService();
- long len = tmpPackageFile.length();
- int mbLen = (int) (len/(1024*1024));
- if ((len - (mbLen * 1024 * 1024)) > 0) {
- mbLen++;
- }
- if (localLOGV) Log.i(TAG, "mbLen=" + mbLen);
- String cachePath = null;
- int ownerUid = Process.myUid();
- try {
- int rc = mountService.createSecureContainer(
- containerId, mbLen, "vfat", sdEncKey, ownerUid);
-
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.e(TAG, String.format("Container creation failed (%d)", rc));
-
- // XXX: This destroy should not be necessary
- rc = mountService.destroySecureContainer(containerId);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.e(TAG, String.format("Container creation-cleanup failed (%d)", rc));
- return null;
- }
-
- // XXX: Does this ever actually succeed?
- rc = mountService.createSecureContainer(
- containerId, mbLen, "vfat", sdEncKey, ownerUid);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.e(TAG, String.format("Container creation retry failed (%d)", rc));
- }
- }
-
- cachePath = mountService.getSecureContainerPath(containerId);
- if (localLOGV) Log.i(TAG, "Trying to create secure container for "
- + containerId + ", cachePath =" + cachePath);
- return cachePath;
- } catch(RemoteException e) {
- Log.e(TAG, "MountService not running?");
- return null;
- }
- }
-
- private boolean destroySdDir(String containerId) {
- try {
- // We need to destroy right away
- getMountService().destroySecureContainer(containerId);
- return true;
- } catch (IllegalStateException e) {
- Log.i(TAG, "Failed to destroy container : " + containerId);
- } catch(RemoteException e) {
- Log.e(TAG, "MountService not running?");
- }
- return false;
- }
-
- private boolean finalizeSdDir(String containerId){
- try {
- getMountService().finalizeSecureContainer(containerId);
- return true;
- } catch (IllegalStateException e) {
- Log.i(TAG, "Failed to finalize container for pkg : " + containerId);
- } catch(RemoteException e) {
- Log.e(TAG, "MountService not running?");
- }
- return false;
- }
-
- private boolean unMountSdDir(String containerId) {
- try {
- getMountService().unmountSecureContainer(containerId);
- return true;
- } catch (IllegalStateException e) {
- Log.e(TAG, "Failed to unmount id: " + containerId + " with exception " + e);
- } catch(RemoteException e) {
- Log.e(TAG, "MountService not running?");
- }
- return false;
- }
-
- private String mountSdDir(String containerId, String key) {
- try {
- int rc = getMountService().mountSecureContainer(containerId, key, Process.myUid());
- if (rc == StorageResultCode.OperationSucceeded) {
- return getMountService().getSecureContainerPath(containerId);
- } else {
- Log.e(TAG, String.format("Failed to mount id %s with rc %d ", containerId, rc));
- }
- } catch(RemoteException e) {
- Log.e(TAG, "MountService not running?");
- }
- return null;
- }
-
public static boolean copyToFile(InputStream inputStream, FileOutputStream out) {
try {
byte[] buffer = new byte[4096];
@@ -483,5 +385,4 @@ public class DefaultContainerService extends IntentService {
// Return error code
return ERR_LOC;
}
-
}
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 812ff64..4326efc 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -2180,10 +2180,15 @@ class PackageManagerService extends IPackageManager.Stub {
int i;
for (i=0; i<files.length; i++) {
File file = new File(dir, files[i]);
+ if (files[i] != null && files[i].endsWith(".zip")) {
+ // Public resource for forward locked package. Ignore
+ continue;
+ }
PackageParser.Package pkg = scanPackageLI(file,
flags|PackageParser.PARSE_MUST_BE_APK, scanMode);
// Don't mess around with apps in system partition.
- if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0) {
+ if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0 &&
+ mLastScanError == PackageManager.INSTALL_FAILED_INVALID_APK) {
// Delete the apk
Log.w(TAG, "Cleaning up failed install of " + file);
file.delete();
@@ -4631,13 +4636,11 @@ class PackageManagerService extends IPackageManager.Stub {
int doPreInstall(int status) {
if (status != PackageManager.INSTALL_SUCCEEDED) {
// Destroy container
- destroySdDir(cid);
+ PackageHelper.destroySdDir(cid);
} else {
- // STOPSHIP Remove once new api is added in MountService
- //boolean mounted = isContainerMounted(cid);
- boolean mounted = false;
+ boolean mounted = PackageHelper.isContainerMounted(cid);
if (!mounted) {
- cachePath = mountSdDir(cid, Process.SYSTEM_UID);
+ cachePath = PackageHelper.mountSdDir(cid, getEncryptKey(), Process.SYSTEM_UID);
if (cachePath == null) {
return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
}
@@ -4650,96 +4653,41 @@ class PackageManagerService extends IPackageManager.Stub {
String oldCodePath) {
String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME);
String newCachePath = null;
- /*final int RENAME_FAILED = 1;
+ final int RENAME_FAILED = 1;
final int MOUNT_FAILED = 2;
- final int DESTROY_FAILED = 3;
final int PASS = 4;
int errCode = RENAME_FAILED;
+ String errMsg = "RENAME_FAILED";
+ boolean mounted = PackageHelper.isContainerMounted(cid);
if (mounted) {
// Unmount the container
- if (!unMountSdDir(cid)) {
+ if (!PackageHelper.unMountSdDir(cid)) {
Log.i(TAG, "Failed to unmount " + cid + " before renaming");
return false;
}
mounted = false;
}
- if (renameSdDir(cid, newCacheId)) {
+ if (PackageHelper.renameSdDir(cid, newCacheId)) {
errCode = MOUNT_FAILED;
- if ((newCachePath = mountSdDir(newCacheId, Process.SYSTEM_UID)) != null) {
+ errMsg = "MOUNT_FAILED";
+ if ((newCachePath = PackageHelper.mountSdDir(newCacheId,
+ getEncryptKey(), Process.SYSTEM_UID)) != null) {
errCode = PASS;
- }
- }
- String errMsg = "";
- switch (errCode) {
- case RENAME_FAILED:
- errMsg = "RENAME_FAILED";
- break;
- case MOUNT_FAILED:
- errMsg = "MOUNT_FAILED";
- break;
- case DESTROY_FAILED:
- errMsg = "DESTROY_FAILED";
- break;
- default:
errMsg = "PASS";
- break;
- }
- Log.i(TAG, "Status: " + errMsg);
- if (errCode != PASS) {
- return false;
- }
- Log.i(TAG, "Succesfully renamed " + cid + " to " +newCacheId +
- " at path: " + cachePath + " to new path: " + newCachePath);
- cid = newCacheId;
- cachePath = newCachePath;
- return true;
- */
- // STOPSHIP TEMPORARY HACK FOR RENAME
- // Create new container at newCachePath
- String codePath = getCodePath();
- final int CREATE_FAILED = 1;
- final int COPY_FAILED = 3;
- final int FINALIZE_FAILED = 5;
- final int PASS = 7;
- int errCode = CREATE_FAILED;
-
- if ((newCachePath = createSdDir(new File(codePath), newCacheId)) != null) {
- errCode = COPY_FAILED;
- // Copy file from codePath
- if (FileUtils.copyFile(new File(codePath), new File(newCachePath, RES_FILE_NAME))) {
- errCode = FINALIZE_FAILED;
- if (finalizeSdDir(newCacheId)) {
- errCode = PASS;
- }
- }
- }
- // Print error based on errCode
- String errMsg = "";
- switch (errCode) {
- case CREATE_FAILED:
- errMsg = "CREATE_FAILED";
- break;
- case COPY_FAILED:
- errMsg = "COPY_FAILED";
- destroySdDir(newCacheId);
- break;
- case FINALIZE_FAILED:
- errMsg = "FINALIZE_FAILED";
- destroySdDir(newCacheId);
- break;
- default:
- errMsg = "PASS";
- break;
+ }
}
- // Destroy the temporary container
- destroySdDir(cid);
- Log.i(TAG, "Status: " + errMsg);
if (errCode != PASS) {
+ Log.i(TAG, "Failed to rename " + cid + " to " + newCacheId +
+ " at path: " + cachePath + " to new path: " + newCachePath +
+ "err = " + errMsg);
+ // Mount old container?
return false;
+ } else {
+ Log.i(TAG, "Succesfully renamed " + cid + " to " + newCacheId +
+ " at path: " + cachePath + " to new path: " + newCachePath);
}
cid = newCacheId;
cachePath = newCachePath;
-
return true;
}
@@ -4747,11 +4695,10 @@ class PackageManagerService extends IPackageManager.Stub {
if (status != PackageManager.INSTALL_SUCCEEDED) {
cleanUp();
} else {
- // STOP SHIP Change this once new api is added.
- //boolean mounted = isContainerMounted(cid);
- boolean mounted = false;
+ boolean mounted = PackageHelper.isContainerMounted(cid);
if (!mounted) {
- mountSdDir(cid, Process.SYSTEM_UID);
+ PackageHelper.mountSdDir(cid,
+ getEncryptKey(), Process.myUid());
}
}
return status;
@@ -4759,7 +4706,7 @@ class PackageManagerService extends IPackageManager.Stub {
private void cleanUp() {
// Destroy secure container
- destroySdDir(cid);
+ PackageHelper.destroySdDir(cid);
}
void cleanUpResourcesLI() {
@@ -4794,10 +4741,10 @@ class PackageManagerService extends IPackageManager.Stub {
boolean doPostDeleteLI(boolean delete) {
boolean ret = false;
- boolean mounted = isContainerMounted(cid);
+ boolean mounted = PackageHelper.isContainerMounted(cid);
if (mounted) {
// Unmount first
- ret = unMountSdDir(cid);
+ ret = PackageHelper.unMountSdDir(cid);
}
if (ret && delete) {
cleanUpResourcesLI();
@@ -8590,11 +8537,6 @@ class PackageManagerService extends IPackageManager.Stub {
private boolean mMediaMounted = false;
private static final int MAX_CONTAINERS = 250;
-
- static MountService getMountService() {
- return (MountService) ServiceManager.getService("mount");
- }
-
private String getEncryptKey() {
try {
String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(mSdEncryptKey);
@@ -8613,134 +8555,10 @@ class PackageManagerService extends IPackageManager.Stub {
}
}
- private String createSdDir(File tmpPackageFile, String pkgName) {
- // Create mount point via MountService
- MountService mountService = getMountService();
- long len = tmpPackageFile.length();
- int mbLen = (int) (len/(1024*1024));
- if ((len - (mbLen * 1024 * 1024)) > 0) {
- mbLen++;
- }
- if (DEBUG_SD_INSTALL) Log.i(TAG, "mbLen="+mbLen);
- String cachePath = null;
- String sdEncKey;
- try {
- sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(mSdEncryptKey);
- if (sdEncKey == null) {
- sdEncKey = SystemKeyStore.getInstance().
- generateNewKeyHexString(128, mSdEncryptAlg, mSdEncryptKey);
- if (sdEncKey == null) {
- Log.e(TAG, "Failed to create encryption keys for package: " + pkgName + ".");
- return null;
- }
- }
- } catch (NoSuchAlgorithmException nsae) {
- Log.e(TAG, "Failed to create encryption keys with exception: " + nsae);
- return null;
- }
-
- int rc = mountService.createSecureContainer(
- pkgName, mbLen, "vfat", sdEncKey, Process.SYSTEM_UID);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.e(TAG, String.format("Failed to create container (%d)", rc));
-
- rc = mountService.destroySecureContainer(pkgName);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.e(TAG, String.format("Failed to cleanup container (%d)", rc));
- return null;
- }
- rc = mountService.createSecureContainer(
- pkgName, mbLen, "vfat", sdEncKey, Process.SYSTEM_UID);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.e(TAG, String.format("Failed to create container (2nd try) (%d)", rc));
- return null;
- }
- }
-
- cachePath = mountService.getSecureContainerPath(pkgName);
- if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to install " + pkgName + ", cachePath =" + cachePath);
- return cachePath;
- }
-
- private String mountSdDir(String pkgName, int ownerUid) {
- String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(mSdEncryptKey);
- if (sdEncKey == null) {
- Log.e(TAG, "Failed to retrieve encryption keys to mount package code: " + pkgName + ".");
- return null;
- }
-
- int rc = getMountService().mountSecureContainer(pkgName, sdEncKey, ownerUid);
-
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.i(TAG, "Failed to mount container for pkg : " + pkgName + " rc : " + rc);
- return null;
- }
-
- return getMountService().getSecureContainerPath(pkgName);
- }
-
- private boolean unMountSdDir(String pkgName) {
- // STOPSHIP unmount directory
- int rc = getMountService().unmountSecureContainer(pkgName);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.e(TAG, "Failed to unmount : " + pkgName + " with rc " + rc);
- return false;
- }
- return true;
- }
-
- private boolean renameSdDir(String oldId, String newId) {
- try {
- getMountService().renameSecureContainer(oldId, newId);
- return true;
- } catch (IllegalStateException e) {
- Log.i(TAG, "Failed ot rename " + oldId + " to " + newId +
- " with exception : " + e);
- }
- return false;
- }
-
- private String getSdDir(String pkgName) {
- return getMountService().getSecureContainerPath(pkgName);
- }
-
- private boolean finalizeSdDir(String pkgName) {
- int rc = getMountService().finalizeSecureContainer(pkgName);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.i(TAG, "Failed to finalize container for pkg : " + pkgName);
- return false;
- }
- return true;
- }
-
- private boolean destroySdDir(String pkgName) {
- int rc = getMountService().destroySecureContainer(pkgName);
- if (rc != StorageResultCode.OperationSucceeded) {
- Log.i(TAG, "Failed to destroy container for pkg : " + pkgName);
- return false;
- }
- return true;
- }
-
- static String[] getSecureContainerList() {
- String[] list = getMountService().getSecureContainerList();
- return list.length == 0 ? null : list;
- }
-
- static boolean isContainerMounted(String cid) {
- // STOPSHIP
- // New api from MountService
- try {
- return (getMountService().getSecureContainerPath(cid) != null);
- } catch (IllegalStateException e) {
- }
- return false;
- }
-
static String getTempContainerId() {
String prefix = "smdl1tmp";
int tmpIdx = 1;
- String list[] = getSecureContainerList();
+ String list[] = PackageHelper.getSecureContainerList();
if (list != null) {
int idx = 0;
int idList[] = new int[MAX_CONTAINERS];
@@ -8799,7 +8617,7 @@ class PackageManagerService extends IPackageManager.Stub {
}
void updateExternalMediaStatusInner(boolean mediaStatus) {
- final String list[] = getSecureContainerList();
+ final String list[] = PackageHelper.getSecureContainerList();
if (list == null || list.length == 0) {
return;
}