use of android.util.AtomicFile in project android_frameworks_base by crdroidandroid.
the class ProcessStatsService method performWriteState.
void performWriteState() {
if (DEBUG)
Slog.d(TAG, "Performing write to " + mFile.getBaseFile());
Parcel data;
AtomicFile file;
synchronized (mPendingWriteLock) {
data = mPendingWrite;
file = mPendingWriteFile;
mPendingWriteCommitted = false;
if (data == null) {
return;
}
mPendingWrite = null;
mPendingWriteFile = null;
mWriteLock.lock();
}
FileOutputStream stream = null;
try {
stream = file.startWrite();
stream.write(data.marshall());
stream.flush();
file.finishWrite(stream);
if (DEBUG)
Slog.d(TAG, "Write completed successfully!");
} catch (IOException e) {
Slog.w(TAG, "Error writing process statistics", e);
file.failWrite(stream);
} finally {
data.recycle();
trimHistoricStatesWriteLocked();
mWriteLock.unlock();
}
}
use of android.util.AtomicFile in project android_frameworks_base by crdroidandroid.
the class ProcessStatsService method updateFile.
private void updateFile() {
mFile = new AtomicFile(new File(mBaseDir, STATE_FILE_PREFIX + mProcessStats.mTimePeriodStartClockStr + STATE_FILE_SUFFIX));
mLastWriteTime = SystemClock.uptimeMillis();
}
use of android.util.AtomicFile in project android_frameworks_base by crdroidandroid.
the class SettingsState method readStateSyncLocked.
private void readStateSyncLocked() {
FileInputStream in;
if (!mStatePersistFile.exists()) {
Slog.i(LOG_TAG, "No settings state " + mStatePersistFile);
addHistoricalOperationLocked(HISTORICAL_OPERATION_INITIALIZE, null);
return;
}
try {
in = new AtomicFile(mStatePersistFile).openRead();
} catch (FileNotFoundException fnfe) {
String message = "No settings state " + mStatePersistFile;
Slog.wtf(LOG_TAG, message);
Slog.i(LOG_TAG, message);
return;
}
try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, StandardCharsets.UTF_8.name());
parseStateLocked(parser);
} catch (XmlPullParserException | IOException e) {
String message = "Failed parsing settings file: " + mStatePersistFile;
Slog.wtf(LOG_TAG, message);
throw new IllegalStateException(message, e);
} finally {
IoUtils.closeQuietly(in);
}
}
use of android.util.AtomicFile in project android_frameworks_base by crdroidandroid.
the class CompilerStats method writeInternal.
@Override
protected void writeInternal(Void data) {
AtomicFile file = getFile();
FileOutputStream f = null;
try {
f = file.startWrite();
OutputStreamWriter osw = new OutputStreamWriter(f);
write(osw);
osw.flush();
file.finishWrite(f);
} catch (IOException e) {
if (f != null) {
file.failWrite(f);
}
Log.e(PackageManagerService.TAG, "Failed to write compiler stats", e);
}
}
use of android.util.AtomicFile in project android_frameworks_base by crdroidandroid.
the class AppWidgetServiceImpl method loadGroupStateLocked.
// only call from initialization -- it assumes that the data structures are all empty
private void loadGroupStateLocked(int[] profileIds) {
// We can bind the widgets to host and providers only after
// reading the host and providers for all users since a widget
// can have a host and a provider in different users.
List<LoadedWidgetState> loadedWidgets = new ArrayList<>();
int version = 0;
final int profileIdCount = profileIds.length;
for (int i = 0; i < profileIdCount; i++) {
final int profileId = profileIds[i];
// No file written for this user - nothing to do.
AtomicFile file = getSavedStateFile(profileId);
try {
FileInputStream stream = file.openRead();
version = readProfileStateFromFileLocked(stream, profileId, loadedWidgets);
IoUtils.closeQuietly(stream);
} catch (FileNotFoundException e) {
Slog.w(TAG, "Failed to read state: " + e);
}
}
if (version >= 0) {
// Hooke'm up...
bindLoadedWidgetsLocked(loadedWidgets);
// upgrade the database if needed
performUpgradeLocked(version);
} else {
// failed reading, clean up
Slog.w(TAG, "Failed to read state, clearing widgets and hosts.");
clearWidgetsLocked();
mHosts.clear();
final int N = mProviders.size();
for (int i = 0; i < N; i++) {
mProviders.get(i).widgets.clear();
}
}
}
Aggregations