Java Code Examples for android.util.AtomicFile#exists()

The following examples show how to use android.util.AtomicFile#exists() . 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: BrightnessTracker.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void readEvents() {
    synchronized (mEventsLock) {
        // Read might prune events so mark as dirty.
        mEventsDirty = true;
        mEvents.clear();
        final AtomicFile readFrom = mInjector.getFile(EVENTS_FILE);
        if (readFrom != null && readFrom.exists()) {
            FileInputStream input = null;
            try {
                input = readFrom.openRead();
                readEventsLocked(input);
            } catch (IOException e) {
                readFrom.delete();
                Slog.e(TAG, "Failed to read change mEvents.", e);
            } finally {
                IoUtils.closeQuietly(input);
            }
        }
    }
}
 
Example 2
Source File: BrightnessTracker.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void readAmbientBrightnessStats() {
    mAmbientBrightnessStatsTracker = new AmbientBrightnessStatsTracker(mUserManager, null);
    final AtomicFile readFrom = mInjector.getFile(AMBIENT_BRIGHTNESS_STATS_FILE);
    if (readFrom != null && readFrom.exists()) {
        FileInputStream input = null;
        try {
            input = readFrom.openRead();
            mAmbientBrightnessStatsTracker.readStats(input);
        } catch (IOException e) {
            readFrom.delete();
            Slog.e(TAG, "Failed to read ambient brightness stats.", e);
        } finally {
            IoUtils.closeQuietly(input);
        }
    }
}
 
Example 3
Source File: BrightnessTracker.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void writeEvents() {
    synchronized (mEventsLock) {
        if (!mEventsDirty) {
            // Nothing to write
            return;
        }

        final AtomicFile writeTo = mInjector.getFile(EVENTS_FILE);
        if (writeTo == null) {
            return;
        }
        if (mEvents.isEmpty()) {
            if (writeTo.exists()) {
                writeTo.delete();
            }
            mEventsDirty = false;
        } else {
            FileOutputStream output = null;
            try {
                output = writeTo.startWrite();
                writeEventsLocked(output);
                writeTo.finishWrite(output);
                mEventsDirty = false;
            } catch (IOException e) {
                writeTo.failWrite(output);
                Slog.e(TAG, "Failed to write change mEvents.", e);
            }
        }
    }
}