Search in sources :

Example 56 with DropBoxManager

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

the class DropBoxTest method testAddData.

public void testAddData() throws Exception {
    File dir = getEmptyDir("testAddData");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    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) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File)

Example 57 with DropBoxManager

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

the class DropBoxTest method testGetNextEntry.

public void testGetNextEntry() throws Exception {
    File dir = getEmptyDir("testGetNextEntry");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    long before = System.currentTimeMillis();
    dropbox.addText("DropBoxTest.A", "A0");
    dropbox.addText("DropBoxTest.B", "B0");
    dropbox.addText("DropBoxTest.A", "A1");
    DropBoxManager.Entry a0 = dropbox.getNextEntry("DropBoxTest.A", before);
    DropBoxManager.Entry a1 = dropbox.getNextEntry("DropBoxTest.A", a0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry("DropBoxTest.A", a1.getTimeMillis()));
    DropBoxManager.Entry b0 = dropbox.getNextEntry("DropBoxTest.B", before);
    assertTrue(null == dropbox.getNextEntry("DropBoxTest.B", b0.getTimeMillis()));
    DropBoxManager.Entry x0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry x1 = dropbox.getNextEntry(null, x0.getTimeMillis());
    DropBoxManager.Entry x2 = dropbox.getNextEntry(null, x1.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, x2.getTimeMillis()));
    assertEquals("DropBoxTest.A", a0.getTag());
    assertEquals("DropBoxTest.A", a1.getTag());
    assertEquals("A0", a0.getText(80));
    assertEquals("A1", a1.getText(80));
    assertEquals("DropBoxTest.B", b0.getTag());
    assertEquals("B0", b0.getText(80));
    assertEquals("DropBoxTest.A", x0.getTag());
    assertEquals("DropBoxTest.B", x1.getTag());
    assertEquals("DropBoxTest.A", x2.getTag());
    assertEquals("A0", x0.getText(80));
    assertEquals("B0", x1.getText(80));
    assertEquals("A1", x2.getText(80));
    a0.close();
    a1.close();
    b0.close();
    x0.close();
    x1.close();
    x2.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File)

Example 58 with DropBoxManager

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

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

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

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)

Example 60 with DropBoxManager

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

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