Search in sources :

Example 31 with DropBoxManager

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

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

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

the class ActivityManagerService method logStrictModeViolationToDropBox.

// Depending on the policy in effect, there could be a bunch of
// these in quick succession so we try to batch these together to
// minimize disk writes, number of dropbox entries, and maximize
// compression, by having more fewer, larger records.
private void logStrictModeViolationToDropBox(ProcessRecord process, StrictMode.ViolationInfo info) {
    if (info == null) {
        return;
    }
    final boolean isSystemApp = process == null || (process.info.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
    final String processName = process == null ? "unknown" : process.processName;
    final String dropboxTag = isSystemApp ? "system_app_strictmode" : "data_app_strictmode";
    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;
    boolean bufferWasEmpty;
    boolean needsFlush;
    final StringBuilder sb = isSystemApp ? mStrictModeBuffer : new StringBuilder(1024);
    synchronized (sb) {
        bufferWasEmpty = sb.length() == 0;
        appendDropBoxProcessHeaders(process, processName, sb);
        sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
        sb.append("System-App: ").append(isSystemApp).append("\n");
        sb.append("Uptime-Millis: ").append(info.violationUptimeMillis).append("\n");
        if (info.violationNumThisLoop != 0) {
            sb.append("Loop-Violation-Number: ").append(info.violationNumThisLoop).append("\n");
        }
        if (info.numAnimationsRunning != 0) {
            sb.append("Animations-Running: ").append(info.numAnimationsRunning).append("\n");
        }
        if (info.broadcastIntentAction != null) {
            sb.append("Broadcast-Intent-Action: ").append(info.broadcastIntentAction).append("\n");
        }
        if (info.durationMillis != -1) {
            sb.append("Duration-Millis: ").append(info.durationMillis).append("\n");
        }
        if (info.numInstances != -1) {
            sb.append("Instance-Count: ").append(info.numInstances).append("\n");
        }
        if (info.tags != null) {
            for (String tag : info.tags) {
                sb.append("Span-Tag: ").append(tag).append("\n");
            }
        }
        sb.append("\n");
        if (info.crashInfo != null && info.crashInfo.stackTrace != null) {
            sb.append(info.crashInfo.stackTrace);
            sb.append("\n");
        }
        if (info.message != null) {
            sb.append(info.message);
            sb.append("\n");
        }
        // Only buffer up to ~64k.  Various logging bits truncate
        // things at 128k.
        needsFlush = (sb.length() > 64 * 1024);
    }
    // thousands of separate files could be created on boot.
    if (!isSystemApp || needsFlush) {
        new Thread("Error dump: " + dropboxTag) {

            @Override
            public void run() {
                String report;
                synchronized (sb) {
                    report = sb.toString();
                    sb.delete(0, sb.length());
                    sb.trimToSize();
                }
                if (report.length() != 0) {
                    dbox.addText(dropboxTag, report);
                }
            }
        }.start();
        return;
    }
    // System app batching:
    if (!bufferWasEmpty) {
        // catch the buffer appends we just did.
        return;
    }
    // Worker thread to both batch writes and to avoid blocking the caller on I/O.
    // (After this point, we shouldn't access AMS internal data structures.)
    new Thread("Error dump: " + dropboxTag) {

        @Override
        public void run() {
            // 5 second sleep to let stacks arrive and be batched together
            try {
                // 5 seconds
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            String errorReport;
            synchronized (mStrictModeBuffer) {
                errorReport = mStrictModeBuffer.toString();
                if (errorReport.length() == 0) {
                    return;
                }
                mStrictModeBuffer.delete(0, mStrictModeBuffer.length());
                mStrictModeBuffer.trimToSize();
            }
            dbox.addText(dropboxTag, errorReport);
        }
    }.start();
}
Also used : DropBoxManager(android.os.DropBoxManager) IApplicationThread(android.app.IApplicationThread) BackgroundThread(com.android.internal.os.BackgroundThread) ServiceThread(com.android.server.ServiceThread) ActivityThread(android.app.ActivityThread)

Example 33 with DropBoxManager

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

the class ActivityManagerService method logStrictModeViolationToDropBox.

// Depending on the policy in effect, there could be a bunch of
// these in quick succession so we try to batch these together to
// minimize disk writes, number of dropbox entries, and maximize
// compression, by having more fewer, larger records.
private void logStrictModeViolationToDropBox(ProcessRecord process, StrictMode.ViolationInfo info) {
    if (info == null) {
        return;
    }
    final boolean isSystemApp = process == null || (process.info.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
    final String processName = process == null ? "unknown" : process.processName;
    final String dropboxTag = isSystemApp ? "system_app_strictmode" : "data_app_strictmode";
    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;
    boolean bufferWasEmpty;
    boolean needsFlush;
    final StringBuilder sb = isSystemApp ? mStrictModeBuffer : new StringBuilder(1024);
    synchronized (sb) {
        bufferWasEmpty = sb.length() == 0;
        appendDropBoxProcessHeaders(process, processName, sb);
        sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
        sb.append("System-App: ").append(isSystemApp).append("\n");
        sb.append("Uptime-Millis: ").append(info.violationUptimeMillis).append("\n");
        if (info.violationNumThisLoop != 0) {
            sb.append("Loop-Violation-Number: ").append(info.violationNumThisLoop).append("\n");
        }
        if (info.numAnimationsRunning != 0) {
            sb.append("Animations-Running: ").append(info.numAnimationsRunning).append("\n");
        }
        if (info.broadcastIntentAction != null) {
            sb.append("Broadcast-Intent-Action: ").append(info.broadcastIntentAction).append("\n");
        }
        if (info.durationMillis != -1) {
            sb.append("Duration-Millis: ").append(info.durationMillis).append("\n");
        }
        if (info.numInstances != -1) {
            sb.append("Instance-Count: ").append(info.numInstances).append("\n");
        }
        if (info.tags != null) {
            for (String tag : info.tags) {
                sb.append("Span-Tag: ").append(tag).append("\n");
            }
        }
        sb.append("\n");
        if (info.crashInfo != null && info.crashInfo.stackTrace != null) {
            sb.append(info.crashInfo.stackTrace);
        }
        sb.append("\n");
        // Only buffer up to ~64k.  Various logging bits truncate
        // things at 128k.
        needsFlush = (sb.length() > 64 * 1024);
    }
    // thousands of separate files could be created on boot.
    if (!isSystemApp || needsFlush) {
        new Thread("Error dump: " + dropboxTag) {

            @Override
            public void run() {
                String report;
                synchronized (sb) {
                    report = sb.toString();
                    sb.delete(0, sb.length());
                    sb.trimToSize();
                }
                if (report.length() != 0) {
                    dbox.addText(dropboxTag, report);
                }
            }
        }.start();
        return;
    }
    // System app batching:
    if (!bufferWasEmpty) {
        // catch the buffer appends we just did.
        return;
    }
    // Worker thread to both batch writes and to avoid blocking the caller on I/O.
    // (After this point, we shouldn't access AMS internal data structures.)
    new Thread("Error dump: " + dropboxTag) {

        @Override
        public void run() {
            // 5 second sleep to let stacks arrive and be batched together
            try {
                // 5 seconds
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            String errorReport;
            synchronized (mStrictModeBuffer) {
                errorReport = mStrictModeBuffer.toString();
                if (errorReport.length() == 0) {
                    return;
                }
                mStrictModeBuffer.delete(0, mStrictModeBuffer.length());
                mStrictModeBuffer.trimToSize();
            }
            dbox.addText(dropboxTag, errorReport);
        }
    }.start();
}
Also used : DropBoxManager(android.os.DropBoxManager) IApplicationThread(android.app.IApplicationThread) ActivityThread(android.app.ActivityThread)

Example 34 with DropBoxManager

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

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

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

the class DropBoxTest method testAgeLimits.

public void testAgeLimits() throws Exception {
    File dir = getEmptyDir("testAgeLimits");
    int blockSize = new StatFs(dir.getPath()).getBlockSize();
    // Limit storage to 10 blocks with an expiration of 1 second
    int kb = blockSize * 10 / 1024;
    ContentResolver cr = getContext().getContentResolver();
    Settings.Global.putString(cr, Settings.Global.DROPBOX_AGE_SECONDS, "1");
    Settings.Global.putString(cr, Settings.Global.DROPBOX_QUOTA_KB, Integer.toString(kb));
    // Write one normal entry and another so big that it is instantly tombstoned
    long before = System.currentTimeMillis();
    DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
    DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
    dropbox.addText("DropBoxTest", "TEST");
    addRandomEntry(dropbox, "DropBoxTest", blockSize * 20);
    // Verify that things are as expected
    DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
    DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
    assertTrue(null == dropbox.getNextEntry(null, e1.getTimeMillis()));
    assertEquals("TEST", e0.getText(80));
    assertEquals(null, e1.getText(80));
    assertEquals(-1, getEntrySize(e1));
    e0.close();
    e1.close();
    // Wait a second and write another entry -- old ones should be expunged
    Thread.sleep(2000);
    dropbox.addText("DropBoxTest", "TEST1");
    e0 = dropbox.getNextEntry(null, before);
    assertTrue(null == dropbox.getNextEntry(null, e0.getTimeMillis()));
    assertEquals("TEST1", e0.getText(80));
    e0.close();
}
Also used : DropBoxManager(android.os.DropBoxManager) StatFs(android.os.StatFs) DropBoxManagerService(com.android.server.DropBoxManagerService) File(java.io.File) ContentResolver(android.content.ContentResolver)

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