Search in sources :

Example 1 with AtomicFile

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);
    }
}
Also used : AtomicFile(android.util.AtomicFile) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 2 with AtomicFile

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);
        }
    }
}
Also used : AtomicFile(android.util.AtomicFile) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 3 with AtomicFile

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);
    }
}
Also used : ProtocolException(java.net.ProtocolException) AtomicFile(android.util.AtomicFile) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) NetworkStatsHistory(android.net.NetworkStatsHistory) DataInputStream(java.io.DataInputStream)

Example 4 with AtomicFile

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));
}
Also used : AtomicFile(android.util.AtomicFile) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 5 with AtomicFile

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");
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) AtomicFile(android.util.AtomicFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Aggregations

AtomicFile (android.util.AtomicFile)231 IOException (java.io.IOException)135 File (java.io.File)106 FileOutputStream (java.io.FileOutputStream)73 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)70 FileNotFoundException (java.io.FileNotFoundException)61 FileInputStream (java.io.FileInputStream)39 XmlSerializer (org.xmlpull.v1.XmlSerializer)35 XmlPullParser (org.xmlpull.v1.XmlPullParser)33 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)25 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)24 BufferedOutputStream (java.io.BufferedOutputStream)19 BufferedInputStream (java.io.BufferedInputStream)16 UserInfo (android.content.pm.UserInfo)15 Bundle (android.os.Bundle)15 RemoteException (android.os.RemoteException)15 ArrayList (java.util.ArrayList)15 InputStream (java.io.InputStream)14 NetworkStatsHistory (android.net.NetworkStatsHistory)12 ErrnoException (android.system.ErrnoException)12