use of android.os.DropBoxManager in project android_frameworks_base by DirtyUnicorns.
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();
}
use of android.os.DropBoxManager in project android_frameworks_base by DirtyUnicorns.
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();
}
use of android.os.DropBoxManager in project android_frameworks_base by DirtyUnicorns.
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();
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
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();
}
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");
}
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();
}
Aggregations