Search in sources :

Example 81 with DropBoxManager

use of android.os.DropBoxManager in project android_frameworks_base by crdroidandroid.

the class DropBoxTest method testFileCountLimits.

public void testFileCountLimits() throws Exception {
    File dir = getEmptyDir("testFileCountLimits");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    dropbox.addText("DropBoxTest", "TEST0");
    dropbox.addText("DropBoxTest", "TEST1");
    dropbox.addText("DropBoxTest", "TEST2");
    dropbox.addText("DropBoxTest", "TEST3");
    dropbox.addText("DropBoxTest", "TEST4");
    dropbox.addText("DropBoxTest", "TEST5");
    // Verify 6 files added
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, 0);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
    DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
    DropBoxManager.Entry e4 = dropbox.getNextEntry(null, e3.getTimeMillis());
    DropBoxManager.Entry e5 = dropbox.getNextEntry(null, e4.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e5.getTimeMillis()));
    assertEquals("TEST0", e0.getText(80));
    assertEquals("TEST5", e5.getText(80));
    e0.close();
    e1.close();
    e2.close();
    e3.close();
    e4.close();
    e5.close();
    // Limit to 3 files and add one more entry
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_MAX_FILES, "3");
    dropbox.addText("DropBoxTest", "TEST6");
    // Verify only 3 files left
    DropBoxManager.Entry f0 = dropbox.getNextEntry(null, 0);
    DropBoxManager.Entry f1 = dropbox.getNextEntry(null, f0.getTimeMillis());
    DropBoxManager.Entry f2 = dropbox.getNextEntry(null, f1.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, f2.getTimeMillis()));
    assertEquals("TEST4", f0.getText(80));
    assertEquals("TEST5", f1.getText(80));
    assertEquals("TEST6", f2.getText(80));
    f0.close();
    f1.close();
    f2.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

Aggregations

DropBoxManager (android.os.DropBoxManager)81 File (java.io.File)65 DropBoxManagerService (com.android.server.DropBoxManagerService)46 FileOutputStream (java.io.FileOutputStream)21 ContentResolver (android.content.ContentResolver)20 IOException (java.io.IOException)16 FileObserver (android.os.FileObserver)12 StatFs (android.os.StatFs)10 FileWriter (java.io.FileWriter)10 GZIPOutputStream (java.util.zip.GZIPOutputStream)10 ActivityThread (android.app.ActivityThread)8 IApplicationThread (android.app.IApplicationThread)8 IBinder (android.os.IBinder)8 RemoteException (android.os.RemoteException)6 AtomicFile (android.util.AtomicFile)5 HashMap (java.util.HashMap)5 BackgroundThread (com.android.internal.os.BackgroundThread)4 ServiceThread (com.android.server.ServiceThread)4 InputStreamReader (java.io.InputStreamReader)4 Point (android.graphics.Point)2