use of android.os.FileObserver 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();
}
use of android.os.FileObserver in project android_frameworks_base by crdroidandroid.
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");
}
Aggregations