use of android.util.AtomicFile in project android_frameworks_base by ParanoidAndroid.
the class AppWidgetServiceImpl method loadStateLocked.
// only call from initialization -- it assumes that the data structures are all empty
void loadStateLocked() {
AtomicFile file = savedStateFile();
try {
FileInputStream stream = file.openRead();
readStateFromFileLocked(stream);
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
Slog.w(TAG, "Failed to close state FileInputStream " + e);
}
}
} catch (FileNotFoundException e) {
Slog.w(TAG, "Failed to read state: " + e);
}
}
use of android.util.AtomicFile in project android_frameworks_base by ParanoidAndroid.
the class NotificationManagerService method loadBlockDb.
private void loadBlockDb() {
synchronized (mBlockedPackages) {
if (mPolicyFile == null) {
mPolicyFile = new AtomicFile(new File("/data/system", "notification_policy.xml"));
mBlockedPackages.clear();
readPolicy(mPolicyFile, TAG_BLOCKED_PKGS, mBlockedPackages, null, 0);
}
}
}
use of android.util.AtomicFile in project android_frameworks_base by ParanoidAndroid.
the class NetworkStatsCollection method readLegacyNetwork.
@Deprecated
public void readLegacyNetwork(File file) throws IOException {
final AtomicFile inputFile = new AtomicFile(file);
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
// verify file magic header intact
final int magic = in.readInt();
if (magic != FILE_MAGIC) {
throw new ProtocolException("unexpected magic: " + magic);
}
final int version = in.readInt();
switch(version) {
case VERSION_NETWORK_INIT:
{
// network := size *(NetworkIdentitySet NetworkStatsHistory)
final int size = in.readInt();
for (int i = 0; i < size; i++) {
final NetworkIdentitySet ident = new NetworkIdentitySet(in);
final NetworkStatsHistory history = new NetworkStatsHistory(in);
final Key key = new Key(ident, UID_ALL, SET_ALL, TAG_NONE);
recordHistory(key, history);
}
break;
}
default:
{
throw new ProtocolException("unexpected version: " + version);
}
}
} catch (FileNotFoundException e) {
// missing stats is okay, probably first boot
} finally {
IoUtils.closeQuietly(in);
}
}
use of android.util.AtomicFile in project android_frameworks_base by ParanoidAndroid.
the class UserManagerService method removeUserStateLocked.
private void removeUserStateLocked(final int userHandle) {
// Cleanup package manager settings
mPm.cleanUpUserLILPw(userHandle);
// Remove this user from the list
mUsers.remove(userHandle);
// Have user ID linger for several seconds to let external storage VFS
// cache entries expire. This must be greater than the 'entry_valid'
// timeout used by the FUSE daemon.
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
synchronized (mPackagesLock) {
mRemovingUserIds.delete(userHandle);
}
}
}, MINUTE_IN_MILLIS);
// Remove user file
AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml"));
userFile.delete();
// Update the user list
writeUserListLocked();
updateUserIdsLocked();
removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle));
}
use of android.util.AtomicFile in project android_frameworks_base by ParanoidAndroid.
the class UserManagerService method writeApplicationRestrictionsLocked.
private void writeApplicationRestrictionsLocked(String packageName, Bundle restrictions, int userId) {
FileOutputStream fos = null;
AtomicFile restrictionsFile = new AtomicFile(new File(Environment.getUserSystemDirectory(userId), RESTRICTIONS_FILE_PREFIX + packageName + ".xml"));
try {
fos = restrictionsFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos);
// XmlSerializer serializer = XmlUtils.serializerInstance();
final XmlSerializer serializer = new FastXmlSerializer();
serializer.setOutput(bos, "utf-8");
serializer.startDocument(null, true);
serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
serializer.startTag(null, TAG_RESTRICTIONS);
for (String key : restrictions.keySet()) {
Object value = restrictions.get(key);
serializer.startTag(null, TAG_ENTRY);
serializer.attribute(null, ATTR_KEY, key);
if (value instanceof Boolean) {
serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_BOOLEAN);
serializer.text(value.toString());
} else if (value == null || value instanceof String) {
serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_STRING);
serializer.text(value != null ? (String) value : "");
} else {
serializer.attribute(null, ATTR_VALUE_TYPE, ATTR_TYPE_STRING_ARRAY);
String[] values = (String[]) value;
serializer.attribute(null, ATTR_MULTIPLE, Integer.toString(values.length));
for (String choice : values) {
serializer.startTag(null, TAG_VALUE);
serializer.text(choice != null ? choice : "");
serializer.endTag(null, TAG_VALUE);
}
}
serializer.endTag(null, TAG_ENTRY);
}
serializer.endTag(null, TAG_RESTRICTIONS);
serializer.endDocument();
restrictionsFile.finishWrite(fos);
} catch (Exception e) {
restrictionsFile.failWrite(fos);
Slog.e(LOG_TAG, "Error writing application restrictions list");
}
}
Aggregations