Search in sources :

Example 1 with DropBoxManager

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

the class BootReceiver method logBootEvents.

private void logBootEvents(Context ctx) throws IOException {
    final DropBoxManager db = (DropBoxManager) ctx.getSystemService(Context.DROPBOX_SERVICE);
    final SharedPreferences prefs = ctx.getSharedPreferences("log_files", Context.MODE_PRIVATE);
    final String headers = new StringBuilder(512).append("Build: ").append(Build.FINGERPRINT).append("\n").append("Hardware: ").append(Build.BOARD).append("\n").append("Revision: ").append(SystemProperties.get("ro.revision", "")).append("\n").append("Bootloader: ").append(Build.BOOTLOADER).append("\n").append("Radio: ").append(Build.RADIO).append("\n").append("Kernel: ").append(FileUtils.readTextFile(new File("/proc/version"), 1024, "...\n")).append("\n").toString();
    String recovery = RecoverySystem.handleAftermath();
    if (recovery != null && db != null) {
        db.addText("SYSTEM_RECOVERY_LOG", headers + recovery);
    }
    if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) {
        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())
        addFileToDropBox(db, prefs, headers, "/proc/last_kmsg", -LOG_SIZE, "SYSTEM_LAST_KMSG");
        addFileToDropBox(db, prefs, headers, "/cache/recovery/log", -LOG_SIZE, "SYSTEM_RECOVERY_LOG");
        addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_console", -LOG_SIZE, "APANIC_CONSOLE");
        addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_threads", -LOG_SIZE, "APANIC_THREADS");
        addAuditErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_AUDIT");
    } 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++) {
        addFileToDropBox(db, prefs, headers, tombstoneFiles[i].getPath(), LOG_SIZE, "SYSTEM_TOMBSTONE");
    }
    // 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) {
            try {
                String filename = new File(TOMBSTONE_DIR, path).getPath();
                addFileToDropBox(db, prefs, headers, filename, LOG_SIZE, "SYSTEM_TOMBSTONE");
            } catch (IOException e) {
                Slog.e(TAG, "Can't log tombstone", e);
            }
        }
    };
    sTombstoneObserver.startWatching();
}
Also used : DropBoxManager(android.os.DropBoxManager) SharedPreferences(android.content.SharedPreferences) IOException(java.io.IOException) File(java.io.File) FileObserver(android.os.FileObserver)

Example 2 with DropBoxManager

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

the class BatteryService method logBatteryStatsLocked.

private void logBatteryStatsLocked() {
    IBinder batteryInfoService = ServiceManager.getService(BATTERY_STATS_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 + BATTERY_STATS_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 3 with DropBoxManager

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

the class DropBoxTest method testFileCountLimits.

public void testFileCountLimits() throws Exception {
    File dir = getEmptyDir("testFileCountLimits");
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(service);
    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)

Example 4 with DropBoxManager

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

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(service);
    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();
    service.stop();
}
Also used : DropBoxManager(android.os.DropBoxManager) DropBoxManagerService(com.android.server.DropBoxManagerService) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 5 with DropBoxManager

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

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();
    DropBoxManager dropbox = (DropBoxManager) getContext().getSystemService(Context.DROPBOX_SERVICE);
    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) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

DropBoxManager (android.os.DropBoxManager)83 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 ContextWrapper (android.content.ContextWrapper)3