Loading core/tests/coretests/src/android/os/storage/StorageManagerBaseTest.java +13 −41 Original line number Original line Diff line number Diff line Loading @@ -18,24 +18,21 @@ package android.os.storage; import android.content.Context; import android.content.Context; import android.content.res.Resources; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.os.Environment; import android.os.SystemClock; import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase; import android.util.Log; import android.util.Log; import android.os.Environment; import android.os.FileUtils; import libcore.io.Streams; import android.os.storage.OnObbStateChangeListener; import android.os.storage.StorageManager; import java.io.BufferedReader; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataInputStream; import java.io.File; import java.io.File; import java.io.FileInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileReader; import java.io.InputStream; import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; import java.io.StringReader; public class StorageManagerBaseTest extends InstrumentationTestCase { public class StorageManagerBaseTest extends InstrumentationTestCase { Loading Loading @@ -218,29 +215,6 @@ public class StorageManagerBaseTest extends InstrumentationTestCase { } } /** * Helper to copy a raw resource file to an actual specified file * * @param rawResId The raw resource ID of the OBB resource file * @param outFile A File representing the file we want to copy the OBB to * @throws NotFoundException If the resource file could not be found */ private void copyRawToFile(int rawResId, File outFile) throws NotFoundException { Resources res = mContext.getResources(); InputStream is = null; try { is = res.openRawResource(rawResId); } catch (NotFoundException e) { Log.i(LOG_TAG, "Failed to load resource with id: " + rawResId); throw e; } FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1); assertTrue(FileUtils.copyToFile(is, outFile)); FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1); } /** /** * Creates an OBB file (with the given name), into the app's standard files directory * Creates an OBB file (with the given name), into the app's standard files directory * * Loading @@ -248,17 +222,15 @@ public class StorageManagerBaseTest extends InstrumentationTestCase { * @param rawResId The raw resource ID of the OBB file in the package * @param rawResId The raw resource ID of the OBB file in the package * @return A {@link File} representing the file to write to * @return A {@link File} representing the file to write to */ */ protected File createObbFile(String name, int rawResId) { protected File createObbFile(String name, int rawResId) throws IOException, Resources.NotFoundException { File outFile = null; final File outFile = new File(mContext.getObbDir(), name); try { final File filesDir = mContext.getFilesDir(); outFile = new File(filesDir, name); copyRawToFile(rawResId, outFile); } catch (NotFoundException e) { if (outFile != null) { outFile.delete(); outFile.delete(); try (InputStream in = mContext.getResources().openRawResource(rawResId); OutputStream out = new FileOutputStream(outFile)) { Streams.copy(in, out); } } } return outFile; return outFile; } } Loading core/tests/coretests/src/android/os/storage/StorageManagerIntegrationTest.java +29 −65 Original line number Original line Diff line number Diff line Loading @@ -16,61 +16,27 @@ package android.os.storage; package android.os.storage; import android.content.Context; import android.os.Environment; import android.os.ProxyFileDescriptorCallback; import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor; import android.os.ProxyFileDescriptorCallback; import android.system.ErrnoException; import android.system.ErrnoException; import android.system.Os; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; import android.util.Log; import android.util.Log; import com.android.frameworks.coretests.R; import com.android.frameworks.coretests.R; import com.android.internal.os.FuseAppLoop; import java.io.DataInputStream; import java.io.IOException; import java.util.concurrent.ThreadFactory; import java.io.File; import java.io.FileInputStream; import junit.framework.AssertionFailedError; import java.io.File; import java.util.concurrent.ThreadFactory; public class StorageManagerIntegrationTest extends StorageManagerBaseTest { public class StorageManagerIntegrationTest extends StorageManagerBaseTest { private static String LOG_TAG = "StorageManagerIntegrationTest"; private static String LOG_TAG = "StorageManagerBaseTest.StorageManagerIntegrationTest"; protected File mFile = null; /** * {@inheritDoc} */ @Override public void setUp() throws Exception { super.setUp(); mContext = getInstrumentation().getContext(); mFile = null; } /** * {@inheritDoc} */ @Override protected void tearDown() throws Exception { if (mFile != null) { mFile.delete(); mFile = null; } super.tearDown(); } /** /** * Tests mounting a single OBB file and verifies its contents. * Tests mounting a single OBB file and verifies its contents. */ */ @LargeTest @LargeTest public void testMountSingleObb() { public void testMountSingleObb() throws Exception { mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1); final File file = createObbFile(OBB_FILE_1, R.raw.obb_file1); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath); mountObb(filePath); verifyObb1Contents(filePath); verifyObb1Contents(filePath); unmountObb(filePath, DONT_FORCE); unmountObb(filePath, DONT_FORCE); Loading @@ -80,7 +46,7 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting several OBB files and verifies its contents. * Tests mounting several OBB files and verifies its contents. */ */ @LargeTest @LargeTest public void testMountMultipleObb() { public void testMountMultipleObb() throws Exception { File file1 = null; File file1 = null; File file2 = null; File file2 = null; File file3 = null; File file3 = null; Loading Loading @@ -120,9 +86,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single encrypted OBB file and verifies its contents. * Tests mounting a single encrypted OBB file and verifies its contents. */ */ @LargeTest @LargeTest public void testMountSingleEncryptedObb() { public void testMountSingleEncryptedObb() throws Exception { mFile = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3); final File file = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED); mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED); verifyObb3Contents(filePath); verifyObb3Contents(filePath); unmountObb(filePath, DONT_FORCE); unmountObb(filePath, DONT_FORCE); Loading @@ -132,19 +98,17 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single encrypted OBB file using an invalid password. * Tests mounting a single encrypted OBB file using an invalid password. */ */ @LargeTest @LargeTest @Suppress // Failing. public void testMountSingleEncryptedObbInvalidPassword() throws Exception { public void testMountSingleEncryptedObbInvalidPassword() { final File file = createObbFile("bad password@$%#@^*(!&)", R.raw.obb_enc_file100_orig3); mFile = createObbFile("bad password@$%#@^*(!&)", R.raw.obb_enc_file100_orig3); String filePath = file.getAbsolutePath(); String filePath = mFile.getAbsolutePath(); mountObb(filePath, OBB_FILE_1_PASSWORD, OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT); mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT); unmountObb(filePath, DONT_FORCE); } } /** /** * Tests simultaneously mounting 2 encrypted OBBs with different keys and verifies contents. * Tests simultaneously mounting 2 encrypted OBBs with different keys and verifies contents. */ */ @LargeTest @LargeTest public void testMountTwoEncryptedObb() { public void testMountTwoEncryptedObb() throws Exception { File file3 = null; File file3 = null; File file1 = null; File file1 = null; try { try { Loading Loading @@ -174,9 +138,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests that we can not force unmount when a file is currently open on the OBB. * Tests that we can not force unmount when a file is currently open on the OBB. */ */ @LargeTest @LargeTest public void testUnmount_DontForce() { public void testUnmount_DontForce() throws Exception { mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1); final File file = createObbFile(OBB_FILE_1, R.raw.obb_file1); String obbFilePath = mFile.getAbsolutePath(); String obbFilePath = file.getAbsolutePath(); MountingObbThread mountingThread = new MountingObbThread(obbFilePath, MountingObbThread mountingThread = new MountingObbThread(obbFilePath, OBB_FILE_1_CONTENTS_1); OBB_FILE_1_CONTENTS_1); Loading Loading @@ -218,9 +182,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single OBB that isn't signed. * Tests mounting a single OBB that isn't signed. */ */ @LargeTest @LargeTest public void testMountUnsignedObb() { public void testMountUnsignedObb() throws Exception { mFile = createObbFile(OBB_FILE_2_UNSIGNED, R.raw.obb_file2_nosign); final File file = createObbFile(OBB_FILE_2_UNSIGNED, R.raw.obb_file2_nosign); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath, OBB_FILE_2_UNSIGNED, OnObbStateChangeListener.ERROR_INTERNAL); mountObb(filePath, OBB_FILE_2_UNSIGNED, OnObbStateChangeListener.ERROR_INTERNAL); } } Loading @@ -228,9 +192,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single OBB that is signed with a different package. * Tests mounting a single OBB that is signed with a different package. */ */ @LargeTest @LargeTest public void testMountBadPackageNameObb() { public void testMountBadPackageNameObb() throws Exception { mFile = createObbFile(OBB_FILE_3_BAD_PACKAGENAME, R.raw.obb_file3_bad_packagename); final File file = createObbFile(OBB_FILE_3_BAD_PACKAGENAME, R.raw.obb_file3_bad_packagename); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath, OBB_FILE_3_BAD_PACKAGENAME, mountObb(filePath, OBB_FILE_3_BAD_PACKAGENAME, OnObbStateChangeListener.ERROR_PERMISSION_DENIED); OnObbStateChangeListener.ERROR_PERMISSION_DENIED); } } Loading @@ -239,9 +203,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests remounting a single OBB that has already been mounted. * Tests remounting a single OBB that has already been mounted. */ */ @LargeTest @LargeTest public void testRemountObb() { public void testRemountObb() throws Exception { mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1); final File file = createObbFile(OBB_FILE_1, R.raw.obb_file1); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath); mountObb(filePath); verifyObb1Contents(filePath); verifyObb1Contents(filePath); mountObb(filePath, null, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED); mountObb(filePath, null, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED); Loading Loading
core/tests/coretests/src/android/os/storage/StorageManagerBaseTest.java +13 −41 Original line number Original line Diff line number Diff line Loading @@ -18,24 +18,21 @@ package android.os.storage; import android.content.Context; import android.content.Context; import android.content.res.Resources; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.os.Environment; import android.os.SystemClock; import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase; import android.util.Log; import android.util.Log; import android.os.Environment; import android.os.FileUtils; import libcore.io.Streams; import android.os.storage.OnObbStateChangeListener; import android.os.storage.StorageManager; import java.io.BufferedReader; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataInputStream; import java.io.File; import java.io.File; import java.io.FileInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileReader; import java.io.InputStream; import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.StringReader; import java.io.StringReader; public class StorageManagerBaseTest extends InstrumentationTestCase { public class StorageManagerBaseTest extends InstrumentationTestCase { Loading Loading @@ -218,29 +215,6 @@ public class StorageManagerBaseTest extends InstrumentationTestCase { } } /** * Helper to copy a raw resource file to an actual specified file * * @param rawResId The raw resource ID of the OBB resource file * @param outFile A File representing the file we want to copy the OBB to * @throws NotFoundException If the resource file could not be found */ private void copyRawToFile(int rawResId, File outFile) throws NotFoundException { Resources res = mContext.getResources(); InputStream is = null; try { is = res.openRawResource(rawResId); } catch (NotFoundException e) { Log.i(LOG_TAG, "Failed to load resource with id: " + rawResId); throw e; } FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1); assertTrue(FileUtils.copyToFile(is, outFile)); FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1); } /** /** * Creates an OBB file (with the given name), into the app's standard files directory * Creates an OBB file (with the given name), into the app's standard files directory * * Loading @@ -248,17 +222,15 @@ public class StorageManagerBaseTest extends InstrumentationTestCase { * @param rawResId The raw resource ID of the OBB file in the package * @param rawResId The raw resource ID of the OBB file in the package * @return A {@link File} representing the file to write to * @return A {@link File} representing the file to write to */ */ protected File createObbFile(String name, int rawResId) { protected File createObbFile(String name, int rawResId) throws IOException, Resources.NotFoundException { File outFile = null; final File outFile = new File(mContext.getObbDir(), name); try { final File filesDir = mContext.getFilesDir(); outFile = new File(filesDir, name); copyRawToFile(rawResId, outFile); } catch (NotFoundException e) { if (outFile != null) { outFile.delete(); outFile.delete(); try (InputStream in = mContext.getResources().openRawResource(rawResId); OutputStream out = new FileOutputStream(outFile)) { Streams.copy(in, out); } } } return outFile; return outFile; } } Loading
core/tests/coretests/src/android/os/storage/StorageManagerIntegrationTest.java +29 −65 Original line number Original line Diff line number Diff line Loading @@ -16,61 +16,27 @@ package android.os.storage; package android.os.storage; import android.content.Context; import android.os.Environment; import android.os.ProxyFileDescriptorCallback; import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor; import android.os.ProxyFileDescriptorCallback; import android.system.ErrnoException; import android.system.ErrnoException; import android.system.Os; import android.test.InstrumentationTestCase; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; import android.util.Log; import android.util.Log; import com.android.frameworks.coretests.R; import com.android.frameworks.coretests.R; import com.android.internal.os.FuseAppLoop; import java.io.DataInputStream; import java.io.IOException; import java.util.concurrent.ThreadFactory; import java.io.File; import java.io.FileInputStream; import junit.framework.AssertionFailedError; import java.io.File; import java.util.concurrent.ThreadFactory; public class StorageManagerIntegrationTest extends StorageManagerBaseTest { public class StorageManagerIntegrationTest extends StorageManagerBaseTest { private static String LOG_TAG = "StorageManagerIntegrationTest"; private static String LOG_TAG = "StorageManagerBaseTest.StorageManagerIntegrationTest"; protected File mFile = null; /** * {@inheritDoc} */ @Override public void setUp() throws Exception { super.setUp(); mContext = getInstrumentation().getContext(); mFile = null; } /** * {@inheritDoc} */ @Override protected void tearDown() throws Exception { if (mFile != null) { mFile.delete(); mFile = null; } super.tearDown(); } /** /** * Tests mounting a single OBB file and verifies its contents. * Tests mounting a single OBB file and verifies its contents. */ */ @LargeTest @LargeTest public void testMountSingleObb() { public void testMountSingleObb() throws Exception { mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1); final File file = createObbFile(OBB_FILE_1, R.raw.obb_file1); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath); mountObb(filePath); verifyObb1Contents(filePath); verifyObb1Contents(filePath); unmountObb(filePath, DONT_FORCE); unmountObb(filePath, DONT_FORCE); Loading @@ -80,7 +46,7 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting several OBB files and verifies its contents. * Tests mounting several OBB files and verifies its contents. */ */ @LargeTest @LargeTest public void testMountMultipleObb() { public void testMountMultipleObb() throws Exception { File file1 = null; File file1 = null; File file2 = null; File file2 = null; File file3 = null; File file3 = null; Loading Loading @@ -120,9 +86,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single encrypted OBB file and verifies its contents. * Tests mounting a single encrypted OBB file and verifies its contents. */ */ @LargeTest @LargeTest public void testMountSingleEncryptedObb() { public void testMountSingleEncryptedObb() throws Exception { mFile = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3); final File file = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED); mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED); verifyObb3Contents(filePath); verifyObb3Contents(filePath); unmountObb(filePath, DONT_FORCE); unmountObb(filePath, DONT_FORCE); Loading @@ -132,19 +98,17 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single encrypted OBB file using an invalid password. * Tests mounting a single encrypted OBB file using an invalid password. */ */ @LargeTest @LargeTest @Suppress // Failing. public void testMountSingleEncryptedObbInvalidPassword() throws Exception { public void testMountSingleEncryptedObbInvalidPassword() { final File file = createObbFile("bad password@$%#@^*(!&)", R.raw.obb_enc_file100_orig3); mFile = createObbFile("bad password@$%#@^*(!&)", R.raw.obb_enc_file100_orig3); String filePath = file.getAbsolutePath(); String filePath = mFile.getAbsolutePath(); mountObb(filePath, OBB_FILE_1_PASSWORD, OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT); mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT); unmountObb(filePath, DONT_FORCE); } } /** /** * Tests simultaneously mounting 2 encrypted OBBs with different keys and verifies contents. * Tests simultaneously mounting 2 encrypted OBBs with different keys and verifies contents. */ */ @LargeTest @LargeTest public void testMountTwoEncryptedObb() { public void testMountTwoEncryptedObb() throws Exception { File file3 = null; File file3 = null; File file1 = null; File file1 = null; try { try { Loading Loading @@ -174,9 +138,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests that we can not force unmount when a file is currently open on the OBB. * Tests that we can not force unmount when a file is currently open on the OBB. */ */ @LargeTest @LargeTest public void testUnmount_DontForce() { public void testUnmount_DontForce() throws Exception { mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1); final File file = createObbFile(OBB_FILE_1, R.raw.obb_file1); String obbFilePath = mFile.getAbsolutePath(); String obbFilePath = file.getAbsolutePath(); MountingObbThread mountingThread = new MountingObbThread(obbFilePath, MountingObbThread mountingThread = new MountingObbThread(obbFilePath, OBB_FILE_1_CONTENTS_1); OBB_FILE_1_CONTENTS_1); Loading Loading @@ -218,9 +182,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single OBB that isn't signed. * Tests mounting a single OBB that isn't signed. */ */ @LargeTest @LargeTest public void testMountUnsignedObb() { public void testMountUnsignedObb() throws Exception { mFile = createObbFile(OBB_FILE_2_UNSIGNED, R.raw.obb_file2_nosign); final File file = createObbFile(OBB_FILE_2_UNSIGNED, R.raw.obb_file2_nosign); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath, OBB_FILE_2_UNSIGNED, OnObbStateChangeListener.ERROR_INTERNAL); mountObb(filePath, OBB_FILE_2_UNSIGNED, OnObbStateChangeListener.ERROR_INTERNAL); } } Loading @@ -228,9 +192,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests mounting a single OBB that is signed with a different package. * Tests mounting a single OBB that is signed with a different package. */ */ @LargeTest @LargeTest public void testMountBadPackageNameObb() { public void testMountBadPackageNameObb() throws Exception { mFile = createObbFile(OBB_FILE_3_BAD_PACKAGENAME, R.raw.obb_file3_bad_packagename); final File file = createObbFile(OBB_FILE_3_BAD_PACKAGENAME, R.raw.obb_file3_bad_packagename); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath, OBB_FILE_3_BAD_PACKAGENAME, mountObb(filePath, OBB_FILE_3_BAD_PACKAGENAME, OnObbStateChangeListener.ERROR_PERMISSION_DENIED); OnObbStateChangeListener.ERROR_PERMISSION_DENIED); } } Loading @@ -239,9 +203,9 @@ public class StorageManagerIntegrationTest extends StorageManagerBaseTest { * Tests remounting a single OBB that has already been mounted. * Tests remounting a single OBB that has already been mounted. */ */ @LargeTest @LargeTest public void testRemountObb() { public void testRemountObb() throws Exception { mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1); final File file = createObbFile(OBB_FILE_1, R.raw.obb_file1); String filePath = mFile.getAbsolutePath(); String filePath = file.getAbsolutePath(); mountObb(filePath); mountObb(filePath); verifyObb1Contents(filePath); verifyObb1Contents(filePath); mountObb(filePath, null, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED); mountObb(filePath, null, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED); Loading