diff options
author | Kenny Root <kroot@google.com> | 2012-04-12 14:23:49 -0700 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2012-04-25 14:17:02 -0700 |
commit | 6dceb88f1c7c42c6ab43834af2c993d599895d82 (patch) | |
tree | cbdc33b4dd84f7ad388a4f331c0e7a3056e142e5 /core/tests | |
parent | 7725180c646d1976a2a2097735862a75ec47c544 (diff) | |
download | frameworks_base-6dceb88f1c7c42c6ab43834af2c993d599895d82.zip frameworks_base-6dceb88f1c7c42c6ab43834af2c993d599895d82.tar.gz frameworks_base-6dceb88f1c7c42c6ab43834af2c993d599895d82.tar.bz2 |
Allow forward locked apps to be in ASECs
We couldn't put forward-locked apps in ASEC containers before since we
didn't have any permissioned filesystems. This adds the ability for
forward-locked applications to be in ASEC containers.
This means that forward locked applications will be able to be on the SD
card now.
This change also removes the old type of forward-locking that placed
parts of apps in /data/app-private. Now all forward-locked applications
will be in ASEC containers.
Change-Id: I17ae0b0d65a4a965ef33c0ac2c47e990e55707ad
Diffstat (limited to 'core/tests')
3 files changed, 454 insertions, 284 deletions
diff --git a/core/tests/coretests/src/android/content/pm/PackageHelperTests.java b/core/tests/coretests/src/android/content/pm/PackageHelperTests.java index 27112a6..7ad35d0 100644 --- a/core/tests/coretests/src/android/content/pm/PackageHelperTests.java +++ b/core/tests/coretests/src/android/content/pm/PackageHelperTests.java @@ -81,7 +81,8 @@ public class PackageHelperTests extends AndroidTestCase { public void testMountAndPullSdCard() { try { fullId = PREFIX; - fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid()); + fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid(), + true); Log.d(TAG,PackageHelper.getSdDir(fullId)); PackageHelper.unMountSdDir(fullId); diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java index 580b4da..8a5f8bb 100755 --- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java +++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java @@ -309,9 +309,7 @@ public class PackageManagerTests extends AndroidTestCase { private static final int INSTALL_LOC_ERR = -1; private int getInstallLoc(int flags, int expInstallLocation, long pkgLen) { // Flags explicitly over ride everything else. - if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0 ) { - return INSTALL_LOC_INT; - } else if ((flags & PackageManager.INSTALL_EXTERNAL) != 0 ) { + if ((flags & PackageManager.INSTALL_EXTERNAL) != 0 ) { return INSTALL_LOC_SD; } else if ((flags & PackageManager.INSTALL_INTERNAL) != 0) { return INSTALL_LOC_INT; @@ -380,61 +378,76 @@ public class PackageManagerTests extends AndroidTestCase { String publicSrcPath = publicSrcDir.getParent(); long pkgLen = new File(info.sourceDir).length(); - if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { - assertTrue((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); - assertEquals(srcPath, drmInstallPath); - assertEquals(publicSrcPath, appInstallPath); - assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath())); - } else { - assertFalse((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); - int rLoc = getInstallLoc(flags, expInstallLocation, pkgLen); - if (rLoc == INSTALL_LOC_INT) { - assertEquals(srcPath, appInstallPath); - assertEquals(publicSrcPath, appInstallPath); - assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); - assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath())); - - // Make sure the native library dir is not a symlink - final File nativeLibDir = new File(info.nativeLibraryDir); - assertTrue("Native library dir should exist at " + info.nativeLibraryDir, - nativeLibDir.exists()); - try { - assertEquals("Native library dir should not be a symlink", - info.nativeLibraryDir, - nativeLibDir.getCanonicalPath()); - } catch (IOException e) { - fail("Can't read " + nativeLibDir.getPath()); - } - } else if (rLoc == INSTALL_LOC_SD){ - assertTrue("Application flags (" + info.flags - + ") should contain FLAG_EXTERNAL_STORAGE", - (info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); + int rLoc = getInstallLoc(flags, expInstallLocation, pkgLen); + if (rLoc == INSTALL_LOC_INT) { + if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { + assertTrue("The application should be installed forward locked", + (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); assertTrue("The APK path (" + srcPath + ") should start with " - + SECURE_CONTAINERS_PREFIX, srcPath - .startsWith(SECURE_CONTAINERS_PREFIX)); + + SECURE_CONTAINERS_PREFIX, + srcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The public APK path (" + publicSrcPath + ") should start with " - + SECURE_CONTAINERS_PREFIX, publicSrcPath - .startsWith(SECURE_CONTAINERS_PREFIX)); + + SECURE_CONTAINERS_PREFIX, + publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The native library path (" + info.nativeLibraryDir + ") should start with " + SECURE_CONTAINERS_PREFIX, info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX)); + } else { + assertFalse((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); + assertEquals(srcPath, appInstallPath); + assertEquals(publicSrcPath, appInstallPath); + assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath())); + } + assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); - // Make sure the native library in /data/data/<app>/lib is a - // symlink to the ASEC - final File nativeLibSymLink = new File(info.dataDir, "lib"); - assertTrue("Native library symlink should exist at " + nativeLibSymLink.getPath(), - nativeLibSymLink.exists()); - try { - assertEquals(nativeLibSymLink.getPath() + " should be a symlink to " - + info.nativeLibraryDir, info.nativeLibraryDir, nativeLibSymLink - .getCanonicalPath()); - } catch (IOException e) { - fail("Can't read " + nativeLibSymLink.getPath()); - } + // Make sure the native library dir is not a symlink + final File nativeLibDir = new File(info.nativeLibraryDir); + assertTrue("Native library dir should exist at " + info.nativeLibraryDir, + nativeLibDir.exists()); + try { + assertEquals("Native library dir should not be a symlink", + info.nativeLibraryDir, + nativeLibDir.getCanonicalPath()); + } catch (IOException e) { + fail("Can't read " + nativeLibDir.getPath()); + } + } else if (rLoc == INSTALL_LOC_SD){ + if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { + assertTrue("The application should be installed forward locked", + (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); } else { - // TODO handle error. Install should have failed. - fail("Install should have failed"); + assertFalse("The application should not be installed forward locked", + (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); + } + assertTrue("Application flags (" + info.flags + + ") should contain FLAG_EXTERNAL_STORAGE", + (info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); + // Might need to check: + // ((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0) + assertTrue("The APK path (" + srcPath + ") should start with " + + SECURE_CONTAINERS_PREFIX, srcPath.startsWith(SECURE_CONTAINERS_PREFIX)); + assertTrue("The public APK path (" + publicSrcPath + ") should start with " + + SECURE_CONTAINERS_PREFIX, + publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX)); + assertTrue("The native library path (" + info.nativeLibraryDir + + ") should start with " + SECURE_CONTAINERS_PREFIX, + info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX)); + + // Make sure the native library in /data/data/<app>/lib is a + // symlink to the ASEC + final File nativeLibSymLink = new File(info.dataDir, "lib"); + assertTrue("Native library symlink should exist at " + nativeLibSymLink.getPath(), + nativeLibSymLink.exists()); + try { + assertEquals(nativeLibSymLink.getPath() + " should be a symlink to " + + info.nativeLibraryDir, info.nativeLibraryDir, nativeLibSymLink + .getCanonicalPath()); + } catch (IOException e) { + fail("Can't read " + nativeLibSymLink.getPath()); } + } else { + // TODO handle error. Install should have failed. + fail("Install should have failed"); } } catch (NameNotFoundException e) { failStr("failed with exception : " + e); @@ -1774,15 +1787,17 @@ public class PackageManagerTests extends AndroidTestCase { } /* - * Install an app with both external and forward-lock flags set. should fail + * Install an app with both external and forward-lock flags set. */ @LargeTest public void testFlagEF() { - installFromRawResource("install.apk", R.raw.install, - PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_EXTERNAL, - false, - true, PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION, - PackageInfo.INSTALL_LOCATION_AUTO); + // Do not run on devices with emulated external storage. + if (Environment.isExternalStorageEmulated()) { + return; + } + + sampleInstallFromRawResource(PackageManager.INSTALL_FORWARD_LOCK + | PackageManager.INSTALL_EXTERNAL, true); } /* @@ -1899,15 +1914,20 @@ public class PackageManagerTests extends AndroidTestCase { PackageManager.INSTALL_FORWARD_LOCK, true, false, -1, - PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL); + PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY); } /* * Install an app with fwd locked flag set and install location set to - * preferExternal. should install internally. + * preferExternal. Should install externally. */ @LargeTest public void testFlagFManifestE() { + // Do not run on devices with emulated external storage. + if (Environment.isExternalStorageEmulated()) { + return; + } + installFromRawResource("install.apk", R.raw.install_loc_sdcard, PackageManager.INSTALL_FORWARD_LOCK, true, @@ -1916,11 +1936,16 @@ public class PackageManagerTests extends AndroidTestCase { } /* - * Install an app with fwd locked flag set and install location set to - * auto. should install internally. + * Install an app with fwd locked flag set and install location set to auto. + * should install externally. */ @LargeTest public void testFlagFManifestA() { + // Do not run on devices with emulated external storage. + if (Environment.isExternalStorageEmulated()) { + return; + } + installFromRawResource("install.apk", R.raw.install_loc_auto, PackageManager.INSTALL_FORWARD_LOCK, true, diff --git a/core/tests/coretests/src/android/os/storage/AsecTests.java b/core/tests/coretests/src/android/os/storage/AsecTests.java index 5efbd88..abb8eae 100755 --- a/core/tests/coretests/src/android/os/storage/AsecTests.java +++ b/core/tests/coretests/src/android/os/storage/AsecTests.java @@ -27,20 +27,13 @@ import android.util.Log; import java.io.File; import java.io.FileOutputStream; -import junit.framework.Assert; - public class AsecTests extends AndroidTestCase { + private static final String SECURE_CONTAINER_PREFIX = "com.android.unittests.AsecTests."; private static final boolean localLOGV = true; public static final String TAG="AsecTests"; - void failStr(String errMsg) { - Log.w(TAG, "errMsg="+errMsg); - } - - void failStr(Exception e) { - Log.w(TAG, "e.getMessage="+e.getMessage()); - Log.w(TAG, "e="+e); - } + private static final String FS_FAT = "fat"; + private static final String FS_EXT4 = "ext4"; @Override protected void setUp() throws Exception { @@ -61,7 +54,9 @@ public class AsecTests extends AndroidTestCase { String[] containers = ms.getSecureContainerList(); for (int i = 0; i < containers.length; i++) { - if (containers[i].startsWith("com.android.unittests.AsecTests.")) { + if (containers[i].startsWith(SECURE_CONTAINER_PREFIX)) { + if (localLOGV) + Log.i(TAG, "Cleaning: " + containers[i]); ms.destroySecureContainer(containers[i], true); } } @@ -70,7 +65,7 @@ public class AsecTests extends AndroidTestCase { private boolean containerExists(String localId) throws RemoteException { IMountService ms = getMs(); String[] containers = ms.getSecureContainerList(); - String fullId = "com.android.unittests.AsecTests." + localId; + String fullId = SECURE_CONTAINER_PREFIX + localId; for (int i = 0; i < containers.length; i++) { if (containers[i].equals(fullId)) { @@ -80,50 +75,52 @@ public class AsecTests extends AndroidTestCase { return false; } - private int createContainer(String localId, int size, String key) throws RemoteException { - Assert.assertTrue(isMediaMounted()); - String fullId = "com.android.unittests.AsecTests." + localId; + private int createContainer(String localId, int size, String key, String filesystem, + boolean isExternal) throws Exception { + assertTrue("Media should be mounted", isMediaMounted()); + String fullId = SECURE_CONTAINER_PREFIX + localId; IMountService ms = getMs(); - return ms.createSecureContainer(fullId, size, "fat", key, android.os.Process.myUid()); + return ms.createSecureContainer(fullId, size, filesystem, key, android.os.Process.myUid(), + isExternal); } - private int mountContainer(String localId, String key) throws RemoteException { - Assert.assertTrue(isMediaMounted()); - String fullId = "com.android.unittests.AsecTests." + localId; + private int mountContainer(String localId, String key) throws Exception { + assertTrue("Media should be mounted", isMediaMounted()); + String fullId = SECURE_CONTAINER_PREFIX + localId; IMountService ms = getMs(); return ms.mountSecureContainer(fullId, key, android.os.Process.myUid()); } - private int renameContainer(String localId1, String localId2) throws RemoteException { - Assert.assertTrue(isMediaMounted()); - String fullId1 = "com.android.unittests.AsecTests." + localId1; - String fullId2 = "com.android.unittests.AsecTests." + localId2; + private int renameContainer(String localId1, String localId2) throws Exception { + assertTrue("Media should be mounted", isMediaMounted()); + String fullId1 = SECURE_CONTAINER_PREFIX + localId1; + String fullId2 = SECURE_CONTAINER_PREFIX + localId2; IMountService ms = getMs(); return ms.renameSecureContainer(fullId1, fullId2); } - private int unmountContainer(String localId, boolean force) throws RemoteException { - Assert.assertTrue(isMediaMounted()); - String fullId = "com.android.unittests.AsecTests." + localId; + private int unmountContainer(String localId, boolean force) throws Exception { + assertTrue("Media should be mounted", isMediaMounted()); + String fullId = SECURE_CONTAINER_PREFIX + localId; IMountService ms = getMs(); return ms.unmountSecureContainer(fullId, force); } - private int destroyContainer(String localId, boolean force) throws RemoteException { - Assert.assertTrue(isMediaMounted()); - String fullId = "com.android.unittests.AsecTests." + localId; + private int destroyContainer(String localId, boolean force) throws Exception { + assertTrue("Media should be mounted", isMediaMounted()); + String fullId = SECURE_CONTAINER_PREFIX + localId; IMountService ms = getMs(); return ms.destroySecureContainer(fullId, force); } - private boolean isContainerMounted(String localId) throws RemoteException { - Assert.assertTrue(isMediaMounted()); - String fullId = "com.android.unittests.AsecTests." + localId; + private boolean isContainerMounted(String localId) throws Exception { + assertTrue("Media should be mounted", isMediaMounted()); + String fullId = SECURE_CONTAINER_PREFIX + localId; IMountService ms = getMs(); return ms.isSecureContainerMounted(fullId); @@ -139,248 +136,392 @@ public class AsecTests extends AndroidTestCase { return null; } - private boolean isMediaMounted() { - try { + private boolean isMediaMounted() throws Exception { String mPath = Environment.getExternalStorageDirectory().toString(); String state = getMs().getVolumeState(mPath); return Environment.MEDIA_MOUNTED.equals(state); - } catch (RemoteException e) { - failStr(e); - return false; - } } - public void testCreateContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testCreateContainer", 4, "none")); - Assert.assertEquals(true, containerExists("testCreateContainer")); - } catch (Exception e) { - failStr(e); + + /* + * CREATE + */ + + public void test_Fat_External_Create_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 4, "none", FS_FAT, true)); + assertTrue(containerExists("testCreateContainer")); } - public void testCreateMinSizeContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testCreateContainer", 1, "none")); - Assert.assertEquals(true, containerExists("testCreateContainer")); - } catch (Exception e) { - failStr(e); + public void test_Ext4_External_Create_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 4, "none", FS_EXT4, true)); + assertTrue(containerExists("testCreateContainer")); } - public void testCreateZeroSizeContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationFailedInternalError, - createContainer("testCreateZeroContainer", 0, "none")); - } catch (Exception e) { - failStr(e); - } + public void test_Fat_Internal_Create_Success() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 4, "none", FS_FAT, false)); + assertTrue(containerExists("testCreateContainer")); } - public void testCreateDuplicateContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testCreateDupContainer", 4, "none")); + public void test_Ext4_Internal_Create_Success() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 4, "none", FS_EXT4, false)); + assertTrue(containerExists("testCreateContainer")); + } - Assert.assertEquals(StorageResultCode.OperationFailedInternalError, - createContainer("testCreateDupContainer", 4, "none")); - } catch (Exception e) { - failStr(e); + + /* + * CREATE MIN SIZE + */ + + public void test_Fat_External_CreateMinSize_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 1, "none", FS_FAT, true)); + assertTrue(containerExists("testCreateContainer")); } - public void testDestroyContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testDestroyContainer", 4, "none")); - Assert.assertEquals(StorageResultCode.OperationSucceeded, - destroyContainer("testDestroyContainer", false)); - } catch (Exception e) { - failStr(e); + public void test_Ext4_External_CreateMinSize_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 1, "none", FS_EXT4, true)); + assertTrue(containerExists("testCreateContainer")); } - public void testMountContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testMountContainer", 4, "none")); + public void test_Fat_Internal_CreateMinSize_Success() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 1, "none", FS_FAT, false)); + assertTrue(containerExists("testCreateContainer")); + } - Assert.assertEquals(StorageResultCode.OperationSucceeded, - unmountContainer("testMountContainer", false)); + public void test_Ext4_Internal_CreateMinSize_Success() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateContainer", 1, "none", FS_EXT4, false)); + assertTrue(containerExists("testCreateContainer")); + } + + + /* + * CREATE ZERO SIZE - FAIL CASE + */ - Assert.assertEquals(StorageResultCode.OperationSucceeded, - mountContainer("testMountContainer", "none")); - } catch (Exception e) { - failStr(e); + public void test_Fat_External_CreateZeroSize_Failure() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateZeroContainer", 0, "none", FS_FAT, true)); } - public void testMountBadKey() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testMountBadKey", 4, "00000000000000000000000000000000")); + public void test_Ext4_External_CreateZeroSize_Failure() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateZeroContainer", 0, "none", FS_EXT4, true)); + } - Assert.assertEquals(StorageResultCode.OperationSucceeded, - unmountContainer("testMountBadKey", false)); + public void test_Fat_Internal_CreateZeroSize_Failure() throws Exception { + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateZeroContainer", 0, "none", FS_FAT, false)); + } - Assert.assertEquals(StorageResultCode.OperationFailedInternalError, - mountContainer("testMountContainer", "000000000000000000000000000000001")); + public void test_Ext4_Internal_CreateZeroSize_Failure() throws Exception { + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateZeroContainer", 0, "none", FS_EXT4, false)); + } - Assert.assertEquals(StorageResultCode.OperationFailedInternalError, - mountContainer("testMountContainer", "none")); - } catch (Exception e) { - failStr(e); + + /* + * CREATE DUPLICATE - FAIL CASE + */ + + public void test_Fat_External_CreateDuplicate_Failure() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateDupContainer", 4, "none", FS_FAT, true)); + + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateDupContainer", 4, "none", FS_FAT, true)); } - public void testNonExistPath() { - IMountService ms = getMs(); - try { - String path = ms.getSecureContainerPath("jparks.broke.it"); - failStr(path); - } catch (IllegalArgumentException e) { - } catch (Exception e) { - failStr(e); + public void test_Ext4_External_CreateDuplicate_Failure() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateDupContainer", 4, "none", FS_EXT4, true)); + + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateDupContainer", 4, "none", FS_EXT4, true)); } - public void testUnmountBusyContainer() { - IMountService ms = getMs(); - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testUnmountBusyContainer", 4, "none")); + public void test_Fat_Internal_CreateDuplicate_Failure() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateDupContainer", 4, "none", FS_FAT, false)); + + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateDupContainer", 4, "none", FS_FAT, false)); + } + + public void test_Ext4_Internal_CreateDuplicate_Failure() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testCreateDupContainer", 4, "none", FS_EXT4, false)); - String path = ms.getSecureContainerPath("com.android.unittests.AsecTests.testUnmountBusyContainer"); + assertEquals(StorageResultCode.OperationFailedInternalError, + createContainer("testCreateDupContainer", 4, "none", FS_EXT4, false)); + } - File f = new File(path, "reference"); - FileOutputStream fos = new FileOutputStream(f); - Assert.assertEquals(StorageResultCode.OperationFailedStorageBusy, - unmountContainer("testUnmountBusyContainer", false)); + /* + * DESTROY + */ - fos.close(); - Assert.assertEquals(StorageResultCode.OperationSucceeded, - unmountContainer("testUnmountBusyContainer", false)); - } catch (Exception e) { - failStr(e); + public void test_Fat_External_Destroy_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testDestroyContainer", 4, "none", FS_FAT, true)); + assertEquals(StorageResultCode.OperationSucceeded, + destroyContainer("testDestroyContainer", false)); } - public void testDestroyBusyContainer() { - IMountService ms = getMs(); - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testDestroyBusyContainer", 4, "none")); + public void test_Ext4_External_Destroy_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testDestroyContainer", 4, "none", FS_EXT4, true)); + assertEquals(StorageResultCode.OperationSucceeded, + destroyContainer("testDestroyContainer", false)); + } - String path = ms.getSecureContainerPath("com.android.unittests.AsecTests.testDestroyBusyContainer"); + public void test_Fat_Internal_Destroy_Success() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testDestroyContainer", 4, "none", FS_FAT, false)); + assertEquals(StorageResultCode.OperationSucceeded, + destroyContainer("testDestroyContainer", false)); + } + + public void test_Ext4_Internal_Destroy_Success() throws Exception { + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testDestroyContainer", 4, "none", FS_EXT4, false)); + assertEquals(StorageResultCode.OperationSucceeded, + destroyContainer("testDestroyContainer", false)); + } - File f = new File(path, "reference"); - FileOutputStream fos = new FileOutputStream(f); - Assert.assertEquals(StorageResultCode.OperationFailedStorageBusy, - destroyContainer("testDestroyBusyContainer", false)); + /* + * MOUNT + */ - fos.close(); - Assert.assertEquals(StorageResultCode.OperationSucceeded, - destroyContainer("testDestroyBusyContainer", false)); - } catch (Exception e) { - failStr(e); + public void test_Fat_External_Mount() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testMountContainer", 4, "none", FS_FAT, true)); + + assertEquals(StorageResultCode.OperationSucceeded, + unmountContainer("testMountContainer", false)); + + assertEquals(StorageResultCode.OperationSucceeded, + mountContainer("testMountContainer", "none")); } - public void testRenameContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testRenameContainer.1", 4, "none")); - Assert.assertEquals(StorageResultCode.OperationSucceeded, - unmountContainer("testRenameContainer.1", false)); + /* + * MOUNT BAD KEY - FAIL CASE + */ + + public void test_Fat_External_MountBadKey_Failure() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testMountBadKey", 4, "00000000000000000000000000000000", FS_FAT, + true)); + + assertEquals(StorageResultCode.OperationSucceeded, + unmountContainer("testMountBadKey", false)); + + assertEquals(StorageResultCode.OperationFailedInternalError, + mountContainer("testMountContainer", "000000000000000000000000000000001")); + + assertEquals(StorageResultCode.OperationFailedInternalError, + mountContainer("testMountContainer", "none")); + } - Assert.assertEquals(StorageResultCode.OperationSucceeded, - renameContainer("testRenameContainer.1", "testRenameContainer.2")); - Assert.assertEquals(false, containerExists("testRenameContainer.1")); - Assert.assertEquals(true, containerExists("testRenameContainer.2")); - } catch (Exception e) { - failStr(e); + public void test_Fat_External_UnmountBusy_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + IMountService ms = getMs(); + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testUnmountBusyContainer", 4, "none", FS_FAT, true)); + + String path = ms.getSecureContainerPath(SECURE_CONTAINER_PREFIX + + "testUnmountBusyContainer"); + + File f = new File(path, "reference"); + FileOutputStream fos = new FileOutputStream(f); + + assertEquals(StorageResultCode.OperationFailedStorageBusy, + unmountContainer("testUnmountBusyContainer", false)); + + fos.close(); + assertEquals(StorageResultCode.OperationSucceeded, + unmountContainer("testUnmountBusyContainer", false)); } - public void testRenameSrcMountedContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testRenameContainer.1", 4, "none")); + public void test_Fat_External_DestroyBusy() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + + IMountService ms = getMs(); + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testDestroyBusyContainer", 4, "none", FS_FAT, true)); + + String path = ms.getSecureContainerPath(SECURE_CONTAINER_PREFIX + + "testDestroyBusyContainer"); + + File f = new File(path, "reference"); + FileOutputStream fos = new FileOutputStream(f); + + assertEquals(StorageResultCode.OperationFailedStorageBusy, + destroyContainer("testDestroyBusyContainer", false)); - Assert.assertEquals(StorageResultCode.OperationFailedStorageMounted, - renameContainer("testRenameContainer.1", "testRenameContainer.2")); - } catch (Exception e) { - failStr(e); + fos.close(); + assertEquals(StorageResultCode.OperationSucceeded, + destroyContainer("testDestroyBusyContainer", false)); + } + + public void test_Fat_External_Rename_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testRenameContainer.1", 4, "none", FS_FAT, true)); + + assertEquals(StorageResultCode.OperationSucceeded, + unmountContainer("testRenameContainer.1", false)); + + assertEquals(StorageResultCode.OperationSucceeded, + renameContainer("testRenameContainer.1", "testRenameContainer.2")); + + assertFalse(containerExists("testRenameContainer.1")); + assertTrue(containerExists("testRenameContainer.2")); } - public void testRenameDstMountedContainer() { - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testRenameContainer.1", 4, "none")); + public void test_Fat_External_RenameSrcMounted_Failure() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } - Assert.assertEquals(StorageResultCode.OperationSucceeded, - unmountContainer("testRenameContainer.1", false)); + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testRenameContainer.1", 4, "none", FS_FAT, true)); - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testRenameContainer.2", 4, "none")); + assertEquals(StorageResultCode.OperationFailedStorageMounted, + renameContainer("testRenameContainer.1", "testRenameContainer.2")); + } - Assert.assertEquals(StorageResultCode.OperationFailedStorageMounted, - renameContainer("testRenameContainer.1", "testRenameContainer.2")); - } catch (Exception e) { - failStr(e); + public void test_Fat_External_RenameDstMounted_Failure() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; } + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testRenameContainer.1", 4, "none", FS_FAT, true)); + + assertEquals(StorageResultCode.OperationSucceeded, + unmountContainer("testRenameContainer.1", false)); + + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testRenameContainer.2", 4, "none", FS_FAT, true)); + + assertEquals(StorageResultCode.OperationFailedStorageMounted, + renameContainer("testRenameContainer.1", "testRenameContainer.2")); } - public void testContainerSize() { + public void test_Fat_External_Size_Success() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + IMountService ms = getMs(); - try { - Assert.assertEquals(StorageResultCode.OperationSucceeded, - createContainer("testContainerSize", 1, "none")); - String path = ms.getSecureContainerPath("com.android.unittests.AsecTests.testUnmountBusyContainer"); - - byte[] buf = new byte[4096]; - File f = new File(path, "reference"); - FileOutputStream fos = new FileOutputStream(f); - for (int i = 0; i < (1024 * 1024); i+= buf.length) { - fos.write(buf); - } - fos.close(); - } catch (Exception e) { - failStr(e); + assertEquals(StorageResultCode.OperationSucceeded, + createContainer("testContainerSize", 1, "none", FS_FAT, true)); + String path = ms.getSecureContainerPath(SECURE_CONTAINER_PREFIX + "testContainerSize"); + + byte[] buf = new byte[4096]; + File f = new File(path, "reference"); + FileOutputStream fos = new FileOutputStream(f); + for (int i = 0; i < (1024 * 1024); i += buf.length) { + fos.write(buf); } + fos.close(); + } + + public void testGetSecureContainerPath_NonExistPath_Failure() throws Exception { + IMountService ms = getMs(); + assertNull("Getting the path for an invalid container should return null", + ms.getSecureContainerPath("jparks.broke.it")); } /*------------ Tests for unmounting volume ---*/ public final long MAX_WAIT_TIME=120*1000; public final long WAIT_TIME_INCR=20*1000; - boolean getMediaState() { - try { + + boolean getMediaState() throws Exception { String mPath = Environment.getExternalStorageDirectory().toString(); String state = getMs().getVolumeState(mPath); return Environment.MEDIA_MOUNTED.equals(state); - } catch (RemoteException e) { - return false; - } } - boolean mountMedia() { + boolean mountMedia() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return true; + } + if (getMediaState()) { return true; } - try { + String mPath = Environment.getExternalStorageDirectory().toString(); int ret = getMs().mountVolume(mPath); return ret == StorageResultCode.OperationSucceeded; - } catch (RemoteException e) { - return false; - } } class StorageListener extends StorageEventListener { @@ -410,10 +551,15 @@ public class AsecTests extends AndroidTestCase { } } - private boolean unmountMedia() { + private void unmountMedia() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + if (!getMediaState()) { - return true; + return; } + String path = Environment.getExternalStorageDirectory().toString(); StorageListener observer = new StorageListener(); StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); @@ -428,17 +574,15 @@ public class AsecTests extends AndroidTestCase { waitTime += WAIT_TIME_INCR; } if(!observer.isDone()) { - throw new Exception("Timed out waiting for packageInstalled callback"); + fail("Timed out waiting for packageInstalled callback"); } - return true; } - } catch (Exception e) { - return false; } finally { sm.unregisterListener(observer); } } - public void testUnmount() { + + public void testUnmount() throws Exception { boolean oldStatus = getMediaState(); Log.i(TAG, "oldStatus="+oldStatus); try { @@ -446,7 +590,7 @@ public class AsecTests extends AndroidTestCase { if (!getMediaState()) { mountMedia(); } - assertTrue(unmountMedia()); + unmountMedia(); } finally { // Restore old status boolean currStatus = getMediaState(); @@ -472,7 +616,11 @@ public class AsecTests extends AndroidTestCase { * This test invokes unmount multiple time and expects the call back * to be invoked just once. */ - public void testUnmountMultiple() { + public void testUnmountMultiple() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + boolean oldStatus = getMediaState(); StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE); MultipleStorageLis observer = new MultipleStorageLis(); @@ -494,12 +642,10 @@ public class AsecTests extends AndroidTestCase { waitTime += WAIT_TIME_INCR; } if(!observer.isDone()) { - failStr("Timed out waiting for packageInstalled callback"); + fail("Timed out waiting for packageInstalled callback"); } } assertEquals(observer.count, 1); - } catch (Exception e) { - failStr(e); } finally { sm.unregisterListener(observer); // Restore old status @@ -514,7 +660,7 @@ public class AsecTests extends AndroidTestCase { } } } - + class ShutdownObserver extends IMountShutdownObserver.Stub{ private boolean doneFlag = false; int statusCode; @@ -536,28 +682,26 @@ public class AsecTests extends AndroidTestCase { } - boolean invokeShutdown() { + void invokeShutdown() throws Exception { IMountService ms = getMs(); ShutdownObserver observer = new ShutdownObserver(); synchronized (observer) { - try { - ms.shutdown(observer); - return true; - } catch (RemoteException e) { - failStr(e); - } + ms.shutdown(observer); } - return false; } - public void testShutdown() { + public void testShutdown() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + boolean oldStatus = getMediaState(); try { // Mount media firsts if (!getMediaState()) { mountMedia(); } - assertTrue(invokeShutdown()); + invokeShutdown(); } finally { // Restore old status boolean currStatus = getMediaState(); @@ -576,7 +720,11 @@ public class AsecTests extends AndroidTestCase { * This test invokes unmount multiple time and expects the call back * to be invoked just once. */ - public void testShutdownMultiple() { + public void testShutdownMultiple() throws Exception { + if (Environment.isExternalStorageEmulated()) { + return; + } + boolean oldStatus = getMediaState(); try { // Mount media firsts @@ -586,13 +734,9 @@ public class AsecTests extends AndroidTestCase { IMountService ms = getMs(); ShutdownObserver observer = new ShutdownObserver(); synchronized (observer) { - try { - ms.shutdown(observer); - for (int i = 0; i < 4; i++) { - ms.shutdown(null); - } - } catch (RemoteException e) { - failStr(e); + ms.shutdown(observer); + for (int i = 0; i < 4; i++) { + ms.shutdown(null); } } } finally { |