use of android.util.AtomicFile in project platform_frameworks_base by android.
the class ShortcutService method getBaseStateFile.
/** Return the base state file name */
private AtomicFile getBaseStateFile() {
final File path = new File(injectSystemDataPath(), FILENAME_BASE_STATE);
path.mkdirs();
return new AtomicFile(path);
}
use of android.util.AtomicFile in project platform_frameworks_base by android.
the class ShortcutService method loadUserLocked.
@Nullable
private ShortcutUser loadUserLocked(@UserIdInt int userId) {
final File path = getUserFile(userId);
if (DEBUG) {
Slog.d(TAG, "Loading from " + path);
}
final AtomicFile file = new AtomicFile(path);
final FileInputStream in;
try {
in = file.openRead();
} catch (FileNotFoundException e) {
if (DEBUG) {
Slog.d(TAG, "Not found " + path);
}
return null;
}
try {
final ShortcutUser ret = loadUserInternal(userId, in, /* forBackup= */
false);
return ret;
} catch (IOException | XmlPullParserException | InvalidFileFormatException e) {
Slog.e(TAG, "Failed to read file " + file.getBaseFile(), e);
return null;
} finally {
IoUtils.closeQuietly(in);
}
}
use of android.util.AtomicFile in project platform_frameworks_base by android.
the class UserManagerService method writeApplicationRestrictionsLP.
private void writeApplicationRestrictionsLP(String packageName, Bundle restrictions, int userId) {
AtomicFile restrictionsFile = new AtomicFile(new File(Environment.getUserSystemDirectory(userId), packageToRestrictionsFileName(packageName)));
writeApplicationRestrictionsLP(restrictions, restrictionsFile);
}
use of android.util.AtomicFile in project platform_frameworks_base by android.
the class UsageStatsDatabase method init.
/**
* Initialize any directories required and index what stats are available.
*/
public void init(long currentTimeMillis) {
synchronized (mLock) {
for (File f : mIntervalDirs) {
f.mkdirs();
if (!f.exists()) {
throw new IllegalStateException("Failed to create directory " + f.getAbsolutePath());
}
}
checkVersionAndBuildLocked();
indexFilesLocked();
// Delete files that are in the future.
for (TimeSparseArray<AtomicFile> files : mSortedStatFiles) {
final int startIndex = files.closestIndexOnOrAfter(currentTimeMillis);
if (startIndex < 0) {
continue;
}
final int fileCount = files.size();
for (int i = startIndex; i < fileCount; i++) {
files.valueAt(i).delete();
}
// will cause a gc in the SparseArray and mess up the order.
for (int i = startIndex; i < fileCount; i++) {
files.removeAt(i);
}
}
}
}
use of android.util.AtomicFile in project platform_frameworks_base by android.
the class AppIdleHistory method readAppIdleTimesLocked.
private void readAppIdleTimesLocked(int userId, ArrayMap<String, PackageHistory> userHistory) {
FileInputStream fis = null;
try {
AtomicFile appIdleFile = new AtomicFile(getUserFile(userId));
fis = appIdleFile.openRead();
XmlPullParser parser = Xml.newPullParser();
parser.setInput(fis, StandardCharsets.UTF_8.name());
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Skip
}
if (type != XmlPullParser.START_TAG) {
Slog.e(TAG, "Unable to read app idle file for user " + userId);
return;
}
if (!parser.getName().equals(TAG_PACKAGES)) {
return;
}
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (type == XmlPullParser.START_TAG) {
final String name = parser.getName();
if (name.equals(TAG_PACKAGE)) {
final String packageName = parser.getAttributeValue(null, ATTR_NAME);
PackageHistory packageHistory = new PackageHistory();
packageHistory.lastUsedElapsedTime = Long.parseLong(parser.getAttributeValue(null, ATTR_ELAPSED_IDLE));
packageHistory.lastUsedScreenTime = Long.parseLong(parser.getAttributeValue(null, ATTR_SCREEN_IDLE));
userHistory.put(packageName, packageHistory);
}
}
}
} catch (IOException | XmlPullParserException e) {
Slog.e(TAG, "Unable to read app idle file for user " + userId);
} finally {
IoUtils.closeQuietly(fis);
}
}
Aggregations