FileDocCategorySizeDatePackage
PackageHelperTests.javaAPI DocAndroid 5.1 API4230Thu Mar 12 22:22:12 GMT 2015android.content.pm

PackageHelperTests

public class PackageHelperTests extends android.test.AndroidTestCase

Fields Summary
private static final boolean
localLOGV
public static final String
TAG
protected final String
PREFIX
private android.os.storage.IMountService
mMs
private String
fullId
private String
fullId2
Constructors Summary
Methods Summary
private voidcleanupContainers()

        Log.d(TAG,"cleanUp");
        IMountService ms = getMs();
        String[] containers = ms.getSecureContainerList();
        for (int i = 0; i < containers.length; i++) {
            if (containers[i].startsWith(PREFIX)) {
                Log.d(TAG,"cleaing up "+containers[i]);
                ms.destroySecureContainer(containers[i], true);
            }
        }
    
voidfailStr(java.lang.String errMsg)

        Log.w(TAG, "errMsg=" + errMsg);
        fail(errMsg);
    
voidfailStr(java.lang.Exception e)

        failStr(e.getMessage());
    
public java.lang.RunnablegetDestroyRunnable()

        Runnable r = new Runnable () {
            public void run () {
                try {
                    PackageHelper.destroySdDir(fullId);
                    Log.e(TAG, "destroy done: " + fullId);
                } catch (Throwable t) {
                    Log.e(TAG, "destroy failed", t);
                }
            }
        };
        return r;
    
public java.lang.RunnablegetMountRunnable()

        Runnable r = new Runnable () {
            public void run () {
                try {
                    Thread.sleep(5);
                    String path = PackageHelper.mountSdDir(fullId, "none",
                            android.os.Process.myUid());
                    Log.e(TAG, "mount done " + path);
                } catch (IllegalArgumentException iae) {
                    throw iae;
                } catch (Throwable t) {
                    Log.e(TAG, "mount failed", t);
                }
            }
        };
        return r;
    
private android.os.storage.IMountServicegetMs()


       
        IBinder service = ServiceManager.getService("mount");
        if (service != null) {
            return IMountService.Stub.asInterface(service);
        } else {
            Log.e(TAG, "Can't get mount service");
        }
        return null;
    
protected voidsetUp()

        super.setUp();
        if (localLOGV) Log.i(TAG, "Cleaning out old test containers");
        cleanupContainers();
    
protected voidtearDown()

        super.tearDown();
        if (localLOGV) Log.i(TAG, "Cleaning out old test containers");
        cleanupContainers();
    
public voidtestMountAndPullSdCard()

        try {
            fullId = PREFIX;
            fullId2 = PackageHelper.createSdDir(1024 * MB_IN_BYTES, fullId, "none",
                    android.os.Process.myUid(), true);

            Log.d(TAG,PackageHelper.getSdDir(fullId));
            PackageHelper.unMountSdDir(fullId);

            Runnable r1 = getMountRunnable();
            Runnable r2 = getDestroyRunnable();
            Thread thread = new Thread(r1);
            Thread thread2 = new Thread(r2);
            thread2.start();
            thread.start();
        } catch (Exception e) {
            failStr(e);
        }