Search in sources :

Example 11 with FileObserver

use of android.os.FileObserver in project android by cSploit.

the class Sniffer method startMonitoringPcapFile.

/**
   * Monitor a pcap file for changes, in order to let the user know that the capture is running.
   */
private void startMonitoringPcapFile() {
    final String str_address = (System.getCurrentTarget().getType() == Target.Type.NETWORK) ? System.getCurrentTarget().getDisplayAddress().split("/")[0] : System.getCurrentTarget().getDisplayAddress();
    final File pcapfile = new File(mPcapFileName);
    try {
        pcapfile.createNewFile();
    } catch (IOException io) {
        Toast.makeText(this, "File not created: " + io.getLocalizedMessage(), Toast.LENGTH_LONG).show();
        return;
    }
    mFileActivity = new FileObserver(mPcapFileName) {

        @Override
        public void onEvent(int event, String s) {
            switch(event) {
                case FileObserver.CLOSE_WRITE:
                    showMessage(getString(R.string.saved) + ":\n" + mPcapFileName);
                    break;
                case FileObserver.MODIFY:
                    AddressStats stats = mAdapter.getStats(str_address);
                    updateStats(stats, pcapfile.length());
                    break;
                case FileObserver.OPEN:
                    showMessage(getString(R.string.dumping_traffic_to) + mPcapFileName);
                    break;
                default:
                    break;
            }
        }
    };
    final AddressStats stats = new AddressStats(str_address);
    stats.mBytes = 0;
    stats.mSampledTime = java.lang.System.currentTimeMillis();
    addNewTarget(stats);
    // android docs: The monitored file or directory must exist at this time,or else no events will be reported
    mFileActivity.startWatching();
}
Also used : FileObserver(android.os.FileObserver)

Example 12 with FileObserver

use of android.os.FileObserver in project android_frameworks_base by ParanoidAndroid.

the class SettingsProvider method onUserRemoved.

void onUserRemoved(int userHandle) {
    synchronized (this) {
        // the db file itself will be deleted automatically, but we need to tear down
        // our caches and other internal bookkeeping.
        FileObserver observer = sObserverInstances.get(userHandle);
        if (observer != null) {
            observer.stopWatching();
            sObserverInstances.delete(userHandle);
        }
        mOpenHelpers.delete(userHandle);
        sSystemCaches.delete(userHandle);
        sSecureCaches.delete(userHandle);
        sKnownMutationsInFlight.delete(userHandle);
    }
}
Also used : FileObserver(android.os.FileObserver)

Example 13 with FileObserver

use of android.os.FileObserver in project android_frameworks_base by ParanoidAndroid.

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 14 with FileObserver

use of android.os.FileObserver in project storymaker by StoryMaker.

the class AudioActivity method addObserver.

private void addObserver() {
    this.mFileObserver = new FileObserver("/sdcard/Sounds/") {

        @Override
        public void onEvent(int event, String path) {
            if (event == FileObserver.CREATE) {
                if (path != null) {
                    int index = path.indexOf("tmp");
                    String tempFileName = (String) path.subSequence(0, index - 1);
                    audioFileNames.add(tempFileName);
                }
            } else if (event == FileObserver.DELETE) {
                if (path != null) {
                    int index = path.indexOf("tmp");
                    String tempFileName = (String) path.subSequence(0, index - 1);
                    if (audioFileNames.contains(tempFileName)) {
                        audioFileNames.remove(tempFileName);
                    }
                }
            }
        }
    };
}
Also used : FileObserver(android.os.FileObserver)

Example 15 with FileObserver

use of android.os.FileObserver in project platform_frameworks_base by android.

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();
}
Also used : DropBoxManager(android.os.DropBoxManager) HashMap(java.util.HashMap) IOException(java.io.IOException) AtomicFile(android.util.AtomicFile) File(java.io.File) FileObserver(android.os.FileObserver)

Aggregations

FileObserver (android.os.FileObserver)22 File (java.io.File)15 DropBoxManager (android.os.DropBoxManager)12 IOException (java.io.IOException)7 AtomicFile (android.util.AtomicFile)5 HashMap (java.util.HashMap)5 ProcessStats (com.android.internal.os.ProcessStats)3 Point (android.graphics.Point)2 ProcessCpuTracker (com.android.internal.os.ProcessCpuTracker)2 SharedPreferences (android.content.SharedPreferences)1 Stack (java.util.Stack)1