Search in sources :

Example 36 with DropBoxManager

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

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(getContext(), service.getServiceStub());
    // 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();
}
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 37 with DropBoxManager

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

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

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

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

Example 39 with DropBoxManager

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

the class BootReceiver method logBootEvents.

private void logBootEvents(Context ctx) throws IOException {
    final DropBoxManager db = (DropBoxManager) ctx.getSystemService(Context.DROPBOX_SERVICE);
    final String headers = getBootHeadersToLogAndUpdate();
    final String bootReason = SystemProperties.get("ro.boot.bootreason", null);
    String recovery = RecoverySystem.handleAftermath(ctx);
    if (recovery != null && db != null) {
        db.addText("SYSTEM_RECOVERY_LOG", headers + recovery);
    }
    String lastKmsgFooter = "";
    if (bootReason != null) {
        lastKmsgFooter = new StringBuilder(512).append("\n").append("Boot info:\n").append("Last boot reason: ").append(bootReason).append("\n").toString();
    }
    HashMap<String, Long> timestamps = readTimestamps();
    if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) {
        if (StorageManager.inCryptKeeperBounce()) {
        // Encrypted, first boot to get PIN/pattern/password so data is tmpfs
        // Don't set ro.runtime.firstboot so that we will do this again
        // when data is properly mounted
        } else {
            String now = Long.toString(System.currentTimeMillis());
            SystemProperties.set("ro.runtime.firstboot", now);
        }
        if (db != null)
            db.addText("SYSTEM_BOOT", headers);
        // Negative sizes mean to take the *tail* of the file (see FileUtils.readTextFile())
        addFileWithFootersToDropBox(db, timestamps, headers, lastKmsgFooter, "/proc/last_kmsg", -LOG_SIZE, "SYSTEM_LAST_KMSG");
        addFileWithFootersToDropBox(db, timestamps, headers, lastKmsgFooter, "/sys/fs/pstore/console-ramoops", -LOG_SIZE, "SYSTEM_LAST_KMSG");
        addFileToDropBox(db, timestamps, headers, "/cache/recovery/log", -LOG_SIZE, "SYSTEM_RECOVERY_LOG");
        addFileToDropBox(db, timestamps, headers, "/cache/recovery/last_kmsg", -LOG_SIZE, "SYSTEM_RECOVERY_KMSG");
        addAuditErrorsToDropBox(db, timestamps, headers, -LOG_SIZE, "SYSTEM_AUDIT");
        addFsckErrorsToDropBox(db, timestamps, headers, -LOG_SIZE, "SYSTEM_FSCK");
    } else {
        if (db != null)
            db.addText("SYSTEM_RESTART", headers);
    }
    // Scan existing tombstones (in case any new ones appeared)
    File[] tombstoneFiles = TOMBSTONE_DIR.listFiles();
    for (int i = 0; tombstoneFiles != null && i < tombstoneFiles.length; i++) {
        if (tombstoneFiles[i].isFile()) {
            addFileToDropBox(db, timestamps, headers, tombstoneFiles[i].getPath(), LOG_SIZE, "SYSTEM_TOMBSTONE");
        }
    }
    writeTimestamps(timestamps);
    // Start watching for new tombstone files; will record them as they occur.
    // This gets registered with the singleton file observer thread.
    sTombstoneObserver = new FileObserver(TOMBSTONE_DIR.getPath(), FileObserver.CLOSE_WRITE) {

        @Override
        public void onEvent(int event, String path) {
            HashMap<String, Long> timestamps = readTimestamps();
            try {
                File file = new File(TOMBSTONE_DIR, path);
                if (file.isFile()) {
                    addFileToDropBox(db, timestamps, headers, file.getPath(), LOG_SIZE, "SYSTEM_TOMBSTONE");
                }
            } catch (IOException e) {
                Slog.e(TAG, "Can't log tombstone", e);
            }
            writeTimestamps(timestamps);
        }
    };
    sTombstoneObserver.startWatching();
}
Also used : DropBoxManager(android.os.DropBoxManager) HashMap(java.util.HashMap) IOException(java.io.IOException) AtomicFile(android.util.AtomicFile) File(java.io.File) FileObserver(android.os.FileObserver)

Example 40 with DropBoxManager

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

the class SamplingProfilerService method startWorking.

private void startWorking(Context context) {
    if (LOCAL_LOGV)
        Slog.v(TAG, "starting SamplingProfilerService!");
    final DropBoxManager dropbox = (DropBoxManager) context.getSystemService(Context.DROPBOX_SERVICE);
    // before FileObserver is ready, there could have already been some snapshots
    // in the directory, we don't want to miss them
    File[] snapshotFiles = new File(SNAPSHOT_DIR).listFiles();
    for (int i = 0; snapshotFiles != null && i < snapshotFiles.length; i++) {
        handleSnapshotFile(snapshotFiles[i], dropbox);
    }
    // detect new snapshot and put it in dropbox
    // delete it afterwards no matter what happened before
    // Note: needs listening at event ATTRIB rather than CLOSE_WRITE, because we set the
    // readability of snapshot files after writing them!
    snapshotObserver = new FileObserver(SNAPSHOT_DIR, FileObserver.ATTRIB) {

        @Override
        public void onEvent(int event, String path) {
            handleSnapshotFile(new File(SNAPSHOT_DIR, path), dropbox);
        }
    };
    snapshotObserver.startWatching();
    if (LOCAL_LOGV)
        Slog.v(TAG, "SamplingProfilerService activated");
}
Also used : DropBoxManager(android.os.DropBoxManager) File(java.io.File) FileObserver(android.os.FileObserver)

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