Search in sources :

Example 46 with DropBoxManager

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

the class DropBoxTest method testIsTagEnabled.

public void testIsTagEnabled() throws Exception {
    DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService(Context.DROPBOX_SERVICE);
    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) ContentResolver(android.content.ContentResolver)

Example 47 with DropBoxManager

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

the class DropBoxTest method testSizeLimits.

public void testSizeLimits() throws Exception {
    File dir = getEmptyDir("testSizeLimits");
    int blockSize = new StatFs(dir.getPath()).getBlockSize();
    // Limit storage to 10 blocks
    int kb = blockSize * 10 / 1024;
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_QUOTA_KB, Integer.toString(kb));
    // Three tags using a total of 12 blocks:
    // DropBoxTest0 [ ][ ]
    // DropBoxTest1 [x][ ][    ][ ][xxx(20 blocks)xxx]
    // DropBoxTest2 [xxxxxxxxxx][ ][ ]
    //
    // The blocks marked "x" will be removed due to storage restrictions.
    // Use random fill (so it doesn't compress), subtract a little for gzip overhead
    final int overhead = 64;
    long before = System.currentTimeMillis();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(service);
    addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest0", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize * 2 - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest1", blockSize * 20 - overhead);
    addRandomEntry(dropbox, "DropBoxTest2", blockSize * 4 - overhead);
    addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
    addRandomEntry(dropbox, "DropBoxTest2", blockSize - overhead);
    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());
    DropBoxManager.Entry e4 = dropbox.getNextEntry(null, e3.getTimeMillis());
    DropBoxManager.Entry e5 = dropbox.getNextEntry(null, e4.getTimeMillis());
    DropBoxManager.Entry e6 = dropbox.getNextEntry(null, e5.getTimeMillis());
    DropBoxManager.Entry e7 = dropbox.getNextEntry(null, e6.getTimeMillis());
    DropBoxManager.Entry e8 = dropbox.getNextEntry(null, e7.getTimeMillis());
    DropBoxManager.Entry e9 = dropbox.getNextEntry(null, e8.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e9.getTimeMillis()));
    assertEquals("DropBoxTest0", e0.getTag());
    assertEquals("DropBoxTest0", e1.getTag());
    assertEquals(blockSize - overhead, getEntrySize(e0));
    assertEquals(blockSize - overhead, getEntrySize(e1));
    assertEquals("DropBoxTest1", e2.getTag());
    assertEquals("DropBoxTest1", e3.getTag());
    assertEquals("DropBoxTest1", e4.getTag());
    assertEquals("DropBoxTest1", e5.getTag());
    assertEquals("DropBoxTest1", e6.getTag());
    // Tombstone
    assertEquals(-1, getEntrySize(e2));
    assertEquals(blockSize - overhead, getEntrySize(e3));
    assertEquals(blockSize * 2 - overhead, getEntrySize(e4));
    assertEquals(blockSize - overhead, getEntrySize(e5));
    assertEquals(-1, getEntrySize(e6));
    assertEquals("DropBoxTest2", e7.getTag());
    assertEquals("DropBoxTest2", e8.getTag());
    assertEquals("DropBoxTest2", e9.getTag());
    // Tombstone
    assertEquals(-1, getEntrySize(e7));
    assertEquals(blockSize - overhead, getEntrySize(e8));
    assertEquals(blockSize - overhead, getEntrySize(e9));
    e0.close();
    e1.close();
    e2.close();
    e3.close();
    e4.close();
    e5.close();
    e6.close();
    e7.close();
    e8.close();
    e9.close();
    // Specifying a tag name skips tombstone records.
    DropBoxManager.Entry t0 = dropbox.getNextEntry("DropBoxTest1", before);
    DropBoxManager.Entry t1 = dropbox.getNextEntry("DropBoxTest1", t0.getTimeMillis());
    DropBoxManager.Entry t2 = dropbox.getNextEntry("DropBoxTest1", t1.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest1", t2.getTimeMillis()));
    assertEquals("DropBoxTest1", t0.getTag());
    assertEquals("DropBoxTest1", t1.getTag());
    assertEquals("DropBoxTest1", t2.getTag());
    assertEquals(blockSize - overhead, getEntrySize(t0));
    assertEquals(blockSize * 2 - overhead, getEntrySize(t1));
    assertEquals(blockSize - overhead, getEntrySize(t2));
    t0.close();
    t1.close();
    t2.close();
    service.stop();
}
Also used : DropBoxManager(android.os.DropBoxManager) StatFs(android.os.StatFs) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

Example 48 with DropBoxManager

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

the class DropBoxTest method testAddData.

public void testAddData() throws Exception {
    DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService(Context.DROPBOX_SERVICE);
    long before = System.currentTimeMillis();
    dropbox.addData("DropBoxTest", "TEST".getBytes(), 0);
    long after = System.currentTimeMillis();
    DropBoxManager.Entry e = dropbox.getNextEntry("DropBoxTest", before);
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e.getTimeMillis()));
    assertEquals("DropBoxTest", e.getTag());
    assertTrue(e.getTimeMillis() >= before);
    assertEquals(0, e.getFlags());
    assertTrue(null == e.getText(80));
    byte[] buf = new byte[80];
    assertEquals("TEST", new String(buf, 0, e.getInputStream().read(buf)));
    e.close();
}
Also used : DropBoxManager(android.os.DropBoxManager)

Example 49 with DropBoxManager

use of android.os.DropBoxManager in project platform_frameworks_base by android.

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 50 with DropBoxManager

use of android.os.DropBoxManager in project platform_frameworks_base by android.

the class DropBoxTest method testAddText.

public void testAddText() throws Exception {
    File dir = getEmptyDir("testAddText");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    long before = System.currentTimeMillis();
    Thread.sleep(5);
    dropbox.addText("DropBoxTest", "TEST0");
    Thread.sleep(5);
    long between = System.currentTimeMillis();
    Thread.sleep(5);
    dropbox.addText("DropBoxTest", "TEST1");
    dropbox.addText("DropBoxTest", "TEST2");
    Thread.sleep(5);
    long after = System.currentTimeMillis();
    DropBoxManager.Entry e0 = dropbox.getNextEntry("DropBoxTest", before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry("DropBoxTest", e0.getTimeMillis());
    DropBoxManager.Entry e2 = dropbox.getNextEntry("DropBoxTest", e1.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest", e2.getTimeMillis()));
    assertTrue(e0.getTimeMillis() > before);
    assertTrue(e0.getTimeMillis() < between);
    assertTrue(e1.getTimeMillis() > between);
    assertTrue(e1.getTimeMillis() < e2.getTimeMillis());
    assertTrue(e2.getTimeMillis() < after);
    assertEquals("TEST0", e0.getText(80));
    assertEquals("TEST1", e1.getText(80));
    assertEquals("TES", e2.getText(3));
    e0.close();
    e1.close();
    e2.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File)

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