FileDocCategorySizeDatePackage
StorageManagerIntegrationTest.javaAPI DocAndroid 5.1 API8181Thu Mar 12 22:22:12 GMT 2015android.os.storage

StorageManagerIntegrationTest

public class StorageManagerIntegrationTest extends StorageManagerBaseTest

Fields Summary
private static String
LOG_TAG
protected File
mFile
Constructors Summary
Methods Summary
public voidsetUp()
{@inheritDoc}


          
    
         
        super.setUp();
        mContext = getInstrumentation().getContext();
        mFile = null;
    
protected voidtearDown()
{@inheritDoc}

        if (mFile != null) {
            mFile.delete();
            mFile = null;
        }
        super.tearDown();
    
public voidtestMountBadPackageNameObb()
Tests mounting a single OBB that is signed with a different package.

        mFile = createObbFile(OBB_FILE_3_BAD_PACKAGENAME, R.raw.obb_file3_bad_packagename);
        String filePath = mFile.getAbsolutePath();
        mountObb(filePath, OBB_FILE_3_BAD_PACKAGENAME,
                OnObbStateChangeListener.ERROR_PERMISSION_DENIED);
    
public voidtestMountMultipleObb()
Tests mounting several OBB files and verifies its contents.

        File file1 = null;
        File file2 = null;
        File file3 = null;
        try {
            file1 = createObbFile(OBB_FILE_1, R.raw.obb_file1);
            String filePath1 = file1.getAbsolutePath();
            mountObb(filePath1);
            verifyObb1Contents(filePath1);

            file2 = createObbFile(OBB_FILE_2, R.raw.obb_file2);
            String filePath2 = file2.getAbsolutePath();
            mountObb(filePath2);
            verifyObb2Contents(filePath2);

            file3 = createObbFile(OBB_FILE_3, R.raw.obb_file3);
            String filePath3 = file3.getAbsolutePath();
            mountObb(filePath3);
            verifyObb3Contents(filePath3);

            unmountObb(filePath1, DONT_FORCE);
            unmountObb(filePath2, DONT_FORCE);
            unmountObb(filePath3, DONT_FORCE);
        } finally {
            if (file1 != null) {
                file1.delete();
            }
            if (file2 != null) {
                file2.delete();
            }
            if (file3 != null) {
                file3.delete();
            }
        }
    
public voidtestMountSingleEncryptedObb()
Tests mounting a single encrypted OBB file and verifies its contents.

        mFile = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3);
        String filePath = mFile.getAbsolutePath();
        mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED);
        verifyObb3Contents(filePath);
        unmountObb(filePath, DONT_FORCE);
    
public voidtestMountSingleEncryptedObbInvalidPassword()
Tests mounting a single encrypted OBB file using an invalid password.

        mFile = createObbFile("bad password@$%#@^*(!&)", R.raw.obb_enc_file100_orig3);
        String filePath = mFile.getAbsolutePath();
        mountObb(filePath, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT);
        unmountObb(filePath, DONT_FORCE);
    
public voidtestMountSingleObb()
Tests mounting a single OBB file and verifies its contents.

        mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1);
        String filePath = mFile.getAbsolutePath();
        mountObb(filePath);
        verifyObb1Contents(filePath);
        unmountObb(filePath, DONT_FORCE);
    
public voidtestMountTwoEncryptedObb()
Tests simultaneously mounting 2 encrypted OBBs with different keys and verifies contents.

        File file3 = null;
        File file1 = null;
        try {
            file3 = createObbFile(OBB_FILE_3_ENCRYPTED, R.raw.obb_enc_file100_orig3);
            String filePath3 = file3.getAbsolutePath();
            mountObb(filePath3, OBB_FILE_3_PASSWORD, OnObbStateChangeListener.MOUNTED);
            verifyObb3Contents(filePath3);

            file1 = createObbFile(OBB_FILE_1_ENCRYPTED, R.raw.obb_enc_file100_orig1);
            String filePath1 = file1.getAbsolutePath();
            mountObb(filePath1, OBB_FILE_1_PASSWORD, OnObbStateChangeListener.MOUNTED);
            verifyObb1Contents(filePath1);

            unmountObb(filePath3, DONT_FORCE);
            unmountObb(filePath1, DONT_FORCE);
        } finally {
            if (file3 != null) {
                file3.delete();
            }
            if (file1 != null) {
                file1.delete();
            }
        }
    
public voidtestMountUnsignedObb()
Tests mounting a single OBB that isn't signed.

        mFile = createObbFile(OBB_FILE_2_UNSIGNED, R.raw.obb_file2_nosign);
        String filePath = mFile.getAbsolutePath();
        mountObb(filePath, OBB_FILE_2_UNSIGNED, OnObbStateChangeListener.ERROR_INTERNAL);
    
public voidtestRemountObb()
Tests remounting a single OBB that has already been mounted.

        mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1);
        String filePath = mFile.getAbsolutePath();
        mountObb(filePath);
        verifyObb1Contents(filePath);
        mountObb(filePath, null, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED);
        verifyObb1Contents(filePath);
        unmountObb(filePath, DONT_FORCE);
    
public voidtestUnmount_DontForce()
Tests that we can not force unmount when a file is currently open on the OBB.

        mFile = createObbFile(OBB_FILE_1, R.raw.obb_file1);
        String obbFilePath = mFile.getAbsolutePath();

        MountingObbThread mountingThread = new MountingObbThread(obbFilePath,
                OBB_FILE_1_CONTENTS_1);

        try {
            mountingThread.start();

            long waitTime = 0;
            while (!mountingThread.isFileOpenOnObb()) {
                synchronized (mountingThread) {
                    Log.i(LOG_TAG, "Waiting for file to be opened on OBB...");
                    mountingThread.wait(WAIT_TIME_INCR);
                    waitTime += WAIT_TIME_INCR;
                    if (waitTime > MAX_WAIT_TIME) {
                        fail("Timed out waiting for file file to be opened on OBB!");
                    }
                }
            }

            unmountObb(obbFilePath, DONT_FORCE);

            // verify still mounted
            assertTrue("mounted path should not be null!", obbFilePath != null);
            assertTrue("mounted path should still be mounted!", mSm.isObbMounted(obbFilePath));

            // close the opened file
            mountingThread.doStop();

            // try unmounting again (should succeed this time)
            unmountObb(obbFilePath, DONT_FORCE);
            assertFalse("mounted path should no longer be mounted!",
                    mSm.isObbMounted(obbFilePath));
        } catch (InterruptedException e) {
            fail("Timed out waiting for file on OBB to be opened...");
        }