Search in sources :

Example 76 with DropBoxManager

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

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

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

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

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

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

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

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

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

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)

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