Search in sources :

Example 11 with DropBoxManagerService

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

the class DropBoxTest method testAddFile.

public void testAddFile() throws Exception {
    File dir = getEmptyDir("testAddFile");
    long before = System.currentTimeMillis();
    File f0 = new File(dir, "f0.txt");
    File f1 = new File(dir, "f1.txt.gz");
    File f2 = new File(dir, "f2.dat");
    File f3 = new File(dir, "f2.dat.gz");
    FileWriter w0 = new FileWriter(f0);
    GZIPOutputStream gz1 = new GZIPOutputStream(new FileOutputStream(f1));
    FileOutputStream os2 = new FileOutputStream(f2);
    GZIPOutputStream gz3 = new GZIPOutputStream(new FileOutputStream(f3));
    w0.write("FILE0");
    gz1.write("FILE1".getBytes());
    os2.write("DATA2".getBytes());
    gz3.write("DATA3".getBytes());
    w0.close();
    gz1.close();
    os2.close();
    gz3.close();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    dropbox.addFile("DropBoxTest", f0, DropBoxManager.IS_TEXT);
    dropbox.addFile("DropBoxTest", f1, DropBoxManager.IS_TEXT | DropBoxManager.IS_GZIPPED);
    dropbox.addFile("DropBoxTest", f2, 0);
    dropbox.addFile("DropBoxTest", f3, DropBoxManager.IS_GZIPPED);
    DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
    DropBoxManager.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
    DropBoxManager.Entry e3 = dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
    assertTrue(e0.getTimeMillis() > before);
    assertTrue(e1.getTimeMillis() > e0.getTimeMillis());
    assertTrue(e2.getTimeMillis() > e1.getTimeMillis());
    assertTrue(e3.getTimeMillis() > e2.getTimeMillis());
    assertEquals(DropBoxManager.IS_TEXT, e0.getFlags());
    assertEquals(DropBoxManager.IS_TEXT, e1.getFlags());
    assertEquals(0, e2.getFlags());
    assertEquals(0, e3.getFlags());
    assertEquals("FILE0", e0.getText(80));
    byte[] buf1 = new byte[80];
    assertEquals("FILE1", new String(buf1, 0, e1.getInputStream().read(buf1)));
    assertTrue(null == e2.getText(80));
    byte[] buf2 = new byte[80];
    assertEquals("DATA2", new String(buf2, 0, e2.getInputStream().read(buf2)));
    assertTrue(null == e3.getText(80));
    byte[] buf3 = new byte[80];
    assertEquals("DATA3", new String(buf3, 0, e3.getInputStream().read(buf3)));
    e0.close();
    e1.close();
    e2.close();
    e3.close();
}
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 12 with DropBoxManagerService

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

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)

Example 13 with DropBoxManagerService

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

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(getContext(), service.getServiceStub());
    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();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 14 with DropBoxManagerService

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

the class DropBoxTest method testIsTagEnabled.

public void testIsTagEnabled() throws Exception {
    File dir = getEmptyDir("testIsTagEnabled");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    long before = System.currentTimeMillis();
    dropbox.addText("DropBoxTest", "TEST-ENABLED");
    assertTrue(dropbox.isTagEnabled("DropBoxTest"));
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_TAG_PREFIX + "DropBoxTest", "disabled");
    dropbox.addText("DropBoxTest", "TEST-DISABLED");
    assertFalse(dropbox.isTagEnabled("DropBoxTest"));
    Settings.Global.putString(cr, Settings.Global.DROPBOX_TAG_PREFIX + "DropBoxTest", "");
    dropbox.addText("DropBoxTest", "TEST-ENABLED-AGAIN");
    assertTrue(dropbox.isTagEnabled("DropBoxTest"));
    DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis()));
    assertEquals("TEST-ENABLED", e0.getText(80));
    assertEquals("TEST-ENABLED-AGAIN", e1.getText(80));
    e0.close();
    e1.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

Example 15 with DropBoxManagerService

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

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