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

The following examples show how to use android.util.AtomicFile#delete() . 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);
            }
        }
    }
}
 
Example 4
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void removeUserState(final int userHandle) {
    try {
        mContext.getSystemService(StorageManager.class).destroyUserKey(userHandle);
    } catch (IllegalStateException e) {
        // This may be simply because the user was partially created.
        Slog.i(LOG_TAG,
            "Destroying key for user " + userHandle + " failed, continuing anyway", e);
    }

    // Cleanup gatekeeper secure user id
    try {
        final IGateKeeperService gk = GateKeeper.getService();
        if (gk != null) {
            gk.clearSecureUserId(userHandle);
        }
    } catch (Exception ex) {
        Slog.w(LOG_TAG, "unable to clear GK secure user id");
    }

    // Cleanup package manager settings
    mPm.cleanUpUser(this, userHandle);

    // Clean up all data before removing metadata
    mUserDataPreparer.destroyUserData(userHandle,
            StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE);

    // Remove this user from the list
    synchronized (mUsersLock) {
        mUsers.remove(userHandle);
        mIsUserManaged.delete(userHandle);
    }
    synchronized (mUserStates) {
        mUserStates.delete(userHandle);
    }
    synchronized (mRestrictionsLock) {
        mBaseUserRestrictions.remove(userHandle);
        mAppliedUserRestrictions.remove(userHandle);
        mCachedEffectiveUserRestrictions.remove(userHandle);
        mDevicePolicyLocalUserRestrictions.remove(userHandle);
        if (mDevicePolicyGlobalUserRestrictions.get(userHandle) != null) {
            mDevicePolicyGlobalUserRestrictions.remove(userHandle);
            applyUserRestrictionsForAllUsersLR();
        }
    }
    // Update the user list
    synchronized (mPackagesLock) {
        writeUserListLP();
    }
    // Remove user file
    AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + XML_SUFFIX));
    userFile.delete();
    updateUserIds();
    if (RELEASE_DELETED_USER_ID) {
        synchronized (mUsers) {
            mRemovingUserIds.delete(userHandle);
        }
    }
}