Search in sources :

Example 71 with DropBoxManager

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

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

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

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

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

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

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

the class BatteryService method logBatteryStatsLocked.

private void logBatteryStatsLocked() {
    IBinder batteryInfoService = ServiceManager.getService(BatteryStats.SERVICE_NAME);
    if (batteryInfoService == null)
        return;
    DropBoxManager db = (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
    if (db == null || !db.isTagEnabled("BATTERY_DISCHARGE_INFO"))
        return;
    File dumpFile = null;
    FileOutputStream dumpStream = null;
    try {
        // dump the service to a file
        dumpFile = new File(DUMPSYS_DATA_PATH + BatteryStats.SERVICE_NAME + ".dump");
        dumpStream = new FileOutputStream(dumpFile);
        batteryInfoService.dump(dumpStream.getFD(), DUMPSYS_ARGS);
        FileUtils.sync(dumpStream);
        // add dump file to drop box
        db.addFile("BATTERY_DISCHARGE_INFO", dumpFile, DropBoxManager.IS_TEXT);
    } catch (RemoteException e) {
        Slog.e(TAG, "failed to dump battery service", e);
    } catch (IOException e) {
        Slog.e(TAG, "failed to write dumpsys file", e);
    } finally {
        // make sure we clean up
        if (dumpStream != null) {
            try {
                dumpStream.close();
            } catch (IOException e) {
                Slog.e(TAG, "failed to close dumpsys output stream");
            }
        }
        if (dumpFile != null && !dumpFile.delete()) {
            Slog.e(TAG, "failed to delete temporary dumpsys file: " + dumpFile.getAbsolutePath());
        }
    }
}
Also used : DropBoxManager(android.os.DropBoxManager) IBinder(android.os.IBinder) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RemoteException(android.os.RemoteException) File(java.io.File)

Example 75 with DropBoxManager

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

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)

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