Search in sources :

Example 1 with DropBoxManagerService

use of com.android.server.DropBoxManagerService in project android_frameworks_base by ParanoidAndroid.

the class DropBoxTest method testFileCountLimits.

public void testFileCountLimits() throws Exception {
    File dir = getEmptyDir("testFileCountLimits");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(service);
    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)

Example 2 with DropBoxManagerService

use of com.android.server.DropBoxManagerService in project android_frameworks_base by ParanoidAndroid.

the class DropBoxTest method testCreateDropBoxManagerWithInvalidDirectory.

public void testCreateDropBoxManagerWithInvalidDirectory() throws Exception {
    // If created with an invalid directory, the DropBoxManager should suffer quietly
    // and fail all operations (this is how it survives a full disk).
    // Once the directory becomes possible to create, it will start working.
    File dir = new File(getEmptyDir("testCreateDropBoxManagerWith"), "InvalidDirectory");
    // Create an empty file
    new FileOutputStream(dir).close();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(service);
    dropbox.addText("DropBoxTest", "should be ignored");
    dropbox.addData("DropBoxTest", "should be ignored".getBytes(), 0);
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", 0));
    // Remove the file so a directory can be created
    dir.delete();
    dropbox.addText("DropBoxTest", "TEST");
    DropBoxManager.Entry e = dropbox.getNextEntry("DropBoxTest", 0);
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
    assertEquals("DropBoxTest", e.getTag());
    assertEquals("TEST", e.getText(80));
    e.close();
    service.stop();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 3 with DropBoxManagerService

use of com.android.server.DropBoxManagerService in project android_frameworks_base by ParanoidAndroid.

the class DropBoxTest method testAddEntriesInTheFuture.

public void testAddEntriesInTheFuture() throws Exception {
    File dir = getEmptyDir("testAddEntriesInTheFuture");
    long before = System.currentTimeMillis();
    // Near future: should be allowed to persist
    FileWriter w0 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 5000) + ".txt"));
    w0.write("FUTURE0");
    w0.close();
    // Far future: should be collapsed
    FileWriter w1 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 100000) + ".txt"));
    w1.write("FUTURE1");
    w1.close();
    // Another far future item, this one gzipped
    File f2 = new File(dir, "DropBoxTest@" + (before + 100001) + ".txt.gz");
    GZIPOutputStream gz2 = new GZIPOutputStream(new FileOutputStream(f2));
    gz2.write("FUTURE2".getBytes());
    gz2.close();
    // Tombstone in the far future
    new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(service);
    // Until a write, the timestamps are taken at face value
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
    DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e3.getTimeMillis()));
    assertEquals("FUTURE0", e0.getText(80));
    assertEquals("FUTURE1", e1.getText(80));
    assertEquals("FUTURE2", e2.getText(80));
    assertEquals(null, e3.getText(80));
    assertEquals(before + 5000, e0.getTimeMillis());
    assertEquals(before + 100000, e1.getTimeMillis());
    assertEquals(before + 100001, e2.getTimeMillis());
    assertEquals(before + 100002, e3.getTimeMillis());
    e0.close();
    e1.close();
    e2.close();
    e3.close();
    // Write something to force a collapse
    dropbox.addText("NotDropBoxTest", "FUTURE");
    e0 = dropbox.getNextEntry(null, before);
    e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
    e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
    assertEquals("FUTURE0", e0.getText(80));
    assertEquals("FUTURE1", e1.getText(80));
    assertEquals("FUTURE2", e2.getText(80));
    assertEquals(null, e3.getText(80));
    assertEquals(before + 5000, e0.getTimeMillis());
    assertEquals(before + 5001, e1.getTimeMillis());
    assertEquals(before + 5002, e2.getTimeMillis());
    assertEquals(before + 5003, e3.getTimeMillis());
    e0.close();
    e1.close();
    e2.close();
    e3.close();
    service.stop();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 4 with DropBoxManagerService

use of com.android.server.DropBoxManagerService in project android_frameworks_base by ParanoidAndroid.

the class DropBoxTest method testAgeLimits.

public void testAgeLimits() throws Exception {
    File dir = getEmptyDir("testAgeLimits");
    int blockSize = new StatFs(dir.getPath()).getBlockSize();
    // Limit storage to 10 blocks with an expiration of 1 second
    int kb = blockSize * 10 / 1024;
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_AGE_SECONDS, "1");
    Settings.Global.putString(cr, Settings.Global.DROPBOX_QUOTA_KB, Integer.toString(kb));
    // Write one normal entry and another so big that it is instantly tombstoned
    long before = System.currentTimeMillis();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(service);
    dropbox.addText("DropBoxTest", "TEST");
    addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
    // Verify that things are as expected
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
    assertEquals("TEST", e0.getText(80));
    assertEquals(null, e1.getText(80));
    assertEquals(-1, getEntrySize(e1));
    e0.close();
    e1.close();
    // Wait a second and write another entry -- old ones should be expunged
    Thread.sleep(2000);
    dropbox.addText("DropBoxTest", "TEST1");
    e0 = dropbox.getNextEntry(null, before);
    assertTrue(null == dropbox.getNextEntry(null, e0.getTimeMillis()));
    assertEquals("TEST1", e0.getText(80));
    e0.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) StatFs(android.os.StatFs) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

Example 5 with DropBoxManagerService

use of com.android.server.DropBoxManagerService in project platform_frameworks_base by android.

the class DropBoxTest method testAgeLimits.

public void testAgeLimits() throws Exception {
    File dir = getEmptyDir("testAgeLimits");
    int blockSize = new StatFs(dir.getPath()).getBlockSize();
    // Limit storage to 10 blocks with an expiration of 1 second
    int kb = blockSize * 10 / 1024;
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_AGE_SECONDS, "1");
    Settings.Global.putString(cr, Settings.Global.DROPBOX_QUOTA_KB, Integer.toString(kb));
    // Write one normal entry and another so big that it is instantly tombstoned
    long before = System.currentTimeMillis();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    dropbox.addText("DropBoxTest", "TEST");
    addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
    // Verify that things are as expected
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
    assertEquals("TEST", e0.getText(80));
    assertEquals(null, e1.getText(80));
    assertEquals(-1, getEntrySize(e1));
    e0.close();
    e1.close();
    // Wait a second and write another entry -- old ones should be expunged
    Thread.sleep(2000);
    dropbox.addText("DropBoxTest", "TEST1");
    e0 = dropbox.getNextEntry(null, before);
    assertTrue(null == dropbox.getNextEntry(null, e0.getTimeMillis()));
    assertEquals("TEST1", e0.getText(80));
    e0.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) StatFs(android.os.StatFs) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

Aggregations

DropBoxManager (android.os.DropBoxManager)46 DropBoxManagerService (com.android.server.DropBoxManagerService)46 File (java.io.File)46 ContentResolver (android.content.ContentResolver)19 FileOutputStream (java.io.FileOutputStream)14 StatFs (android.os.StatFs)10 FileWriter (java.io.FileWriter)9 GZIPOutputStream (java.util.zip.GZIPOutputStream)9