Java Code Examples for android.os.FileObserver#stopWatching()

The following examples show how to use android.os.FileObserver#stopWatching() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
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);
        onProfilesChanged();
    }
}
 
Example 2
Source File: FileSystemScanner.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
public void stopObservers() {
    synchronized (observers) {
        for (final FileObserver o : observers.values()) {
            o.stopWatching();
        }
        observers.clear();
    }
}
 
Example 3
Source File: OomAdjOverrider.java    From mockgeofix with Apache License 2.0 4 votes vote down vote up
public void stop() {
    for (FileObserver o : observers) {
        o.stopWatching();
    }
    observers.clear();
}
 
Example 4
Source File: ConversationsFileObserver.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void stopWatchingInternal() {
    for (FileObserver observer : mObservers) {
        observer.stopWatching();
    }
    mObservers.clear();
}
 
Example 5
Source File: ConversationsFileObserver.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private synchronized void stopWatchingInternal() {
    for(FileObserver observer : mObservers) {
        observer.stopWatching();
    }
    mObservers.clear();
}
 
Example 6
Source File: FileSystemScanner.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
void scanDir(final File dir) {
    // Checks if scan should be continued
    if (!inScan.get()) {
        return;
    }

    if (dir == null || !dir.isDirectory()) {
        return;
    }

    if (dir.getAbsolutePath().startsWith("/sys")) {
        LCTX.d("Skip system dir: " + dir);
        return;
    }

    try {
        final File cd = CacheManager.getCacheDir();
        if (cd != null && dir.getCanonicalPath().equals(cd.getCanonicalPath())) {
            LCTX.d("Skip file cache: " + dir);
            return;
        }
    } catch (final IOException ex) {
        ex.printStackTrace();
    }

    if (LCTX.isDebugEnabled()) {
        LCTX.d("Scan dir: " + dir);
    }

    // Retrieves file observer for scanning folder
    final FileObserver observer = getObserver(dir);
    // Stop watching
    observer.stopWatching();

    // Retrieves listener
    final Listener l = listeners.getListener();

    // Retrieves file list
    final File[] files = dir.listFiles((FilenameFilter) filter);
    // Sort file list
    if (LengthUtils.isNotEmpty(files)) {
        Arrays.sort(files, StringUtils.NFC);
    }
    // Call the file scan callback
    l.onFileScan(dir, files);

    // Retrieves files from current directory
    final File[] childDirs = dir.listFiles(DirectoryFilter.ALL);
    // Immediately starts folder watching
    getObserver(dir).startWatching();

    if (LengthUtils.isNotEmpty(childDirs)) {
        // Sort child dir list
        Arrays.sort(childDirs, StringUtils.NFC);
        // Add children for deep ordered scanning
        synchronized (this) {
            for (int i = childDirs.length - 1; i >= 0; i--) {
                this.paths.addFirst(childDirs[i]);
            }
        }
    }
}