Search in sources :

Example 66 with DropBoxManager

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

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)

Example 67 with DropBoxManager

use of android.os.DropBoxManager in project cornerstone by Onskreen.

the class ActivityManagerService method addErrorToDropBox.

/**
     * Write a description of an error (crash, WTF, ANR) to the drop box.
     * @param eventType to include in the drop box tag ("crash", "wtf", etc.)
     * @param process which caused the error, null means the system server
     * @param activity which triggered the error, null if unknown
     * @param parent activity related to the error, null if unknown
     * @param subject line related to the error, null if absent
     * @param report in long form describing the error, null if absent
     * @param logFile to include in the report, null if none
     * @param crashInfo giving an application stack trace, null if absent
     */
public void addErrorToDropBox(String eventType, ProcessRecord process, String processName, ActivityRecord activity, ActivityRecord parent, String subject, final String report, final File logFile, final ApplicationErrorReport.CrashInfo crashInfo) {
    // NOTE -- this must never acquire the ActivityManagerService lock,
    // otherwise the watchdog may be prevented from resetting the system.
    final String dropboxTag = processClass(process) + "_" + eventType;
    final DropBoxManager dbox = (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
    // Exit early if the dropbox isn't configured to accept this report type.
    if (dbox == null || !dbox.isTagEnabled(dropboxTag))
        return;
    final StringBuilder sb = new StringBuilder(1024);
    appendDropBoxProcessHeaders(process, processName, sb);
    if (activity != null) {
        sb.append("Activity: ").append(activity.shortComponentName).append("\n");
    }
    if (parent != null && parent.app != null && parent.app.pid != process.pid) {
        sb.append("Parent-Process: ").append(parent.app.processName).append("\n");
    }
    if (parent != null && parent != activity) {
        sb.append("Parent-Activity: ").append(parent.shortComponentName).append("\n");
    }
    if (subject != null) {
        sb.append("Subject: ").append(subject).append("\n");
    }
    sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
    if (Debug.isDebuggerConnected()) {
        sb.append("Debugger: Connected\n");
    }
    sb.append("\n");
    // Do the rest in a worker thread to avoid blocking the caller on I/O
    // (After this point, we shouldn't access AMS internal data structures.)
    Thread worker = new Thread("Error dump: " + dropboxTag) {

        @Override
        public void run() {
            if (report != null) {
                sb.append(report);
            }
            if (logFile != null) {
                try {
                    sb.append(FileUtils.readTextFile(logFile, 128 * 1024, "\n\n[[TRUNCATED]]"));
                } catch (IOException e) {
                    Slog.e(TAG, "Error reading " + logFile, e);
                }
            }
            if (crashInfo != null && crashInfo.stackTrace != null) {
                sb.append(crashInfo.stackTrace);
            }
            String setting = Settings.Secure.ERROR_LOGCAT_PREFIX + dropboxTag;
            int lines = Settings.Secure.getInt(mContext.getContentResolver(), setting, 0);
            if (lines > 0) {
                sb.append("\n");
                // Merge several logcat streams, and take the last N lines
                InputStreamReader input = null;
                try {
                    java.lang.Process logcat = new ProcessBuilder("/system/bin/logcat", "-v", "time", "-b", "events", "-b", "system", "-b", "main", "-t", String.valueOf(lines)).redirectErrorStream(true).start();
                    try {
                        logcat.getOutputStream().close();
                    } catch (IOException e) {
                    }
                    try {
                        logcat.getErrorStream().close();
                    } catch (IOException e) {
                    }
                    input = new InputStreamReader(logcat.getInputStream());
                    int num;
                    char[] buf = new char[8192];
                    while ((num = input.read(buf)) > 0) sb.append(buf, 0, num);
                } catch (IOException e) {
                    Slog.e(TAG, "Error running logcat", e);
                } finally {
                    if (input != null)
                        try {
                            input.close();
                        } catch (IOException e) {
                        }
                }
            }
            dbox.addText(dropboxTag, sb.toString());
        }
    };
    if (process == null) {
        // If process is null, we are being called from some internal code
        // and may be about to die -- run this synchronously.
        worker.run();
    } else {
        worker.start();
    }
}
Also used : DropBoxManager(android.os.DropBoxManager) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IApplicationThread(android.app.IApplicationThread) ActivityThread(android.app.ActivityThread)

Example 68 with DropBoxManager

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

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)

Example 69 with DropBoxManager

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

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

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

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)

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