SamplingProfilerServicepublic class SamplingProfilerService extends android.os.Binder
Fields Summary |
---|
private static final String | TAG | private static final boolean | LOCAL_LOGV | public static final String | SNAPSHOT_DIR | private final android.content.Context | mContext | private android.os.FileObserver | snapshotObserver |
Constructors Summary |
---|
public SamplingProfilerService(android.content.Context context)
mContext = context;
registerSettingObserver(context);
startWorking(context);
|
Methods Summary |
---|
protected void | dump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
pw.println("SamplingProfilerService:");
pw.println("Watching directory: " + SNAPSHOT_DIR);
| private void | handleSnapshotFile(java.io.File file, android.os.DropBoxManager dropbox)
try {
dropbox.addFile(TAG, file, 0);
if (LOCAL_LOGV) Slog.v(TAG, file.getPath() + " added to dropbox");
} catch (IOException e) {
Slog.e(TAG, "Can't add " + file.getPath() + " to dropbox", e);
} finally {
file.delete();
}
| private void | registerSettingObserver(android.content.Context context)
ContentResolver contentResolver = context.getContentResolver();
contentResolver.registerContentObserver(
Settings.Global.getUriFor(Settings.Global.SAMPLING_PROFILER_MS),
false, new SamplingProfilerSettingsObserver(contentResolver));
| private void | startWorking(android.content.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");
|
|