Search in sources :

Example 1 with UserCache

use of com.android.launcher3.pm.UserCache in project android_packages_apps_Launcher3 by crdroidandroid.

the class PersistedItemArray method write.

/**
 * Writes the provided list of items on the disk
 */
@WorkerThread
public void write(Context context, List<T> items) {
    AtomicFile file = getFile(context);
    FileOutputStream fos;
    try {
        fos = file.startWrite();
    } catch (IOException e) {
        Log.e(TAG, "Unable to persist items in " + mFileName, e);
        return;
    }
    UserCache userCache = UserCache.INSTANCE.get(context);
    try {
        XmlSerializer out = Xml.newSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_ROOT);
        for (T item : items) {
            Intent intent = item.getIntent();
            if (intent == null) {
                continue;
            }
            out.startTag(null, TAG_ENTRY);
            out.attribute(null, Favorites.ITEM_TYPE, Integer.toString(item.itemType));
            out.attribute(null, Favorites.PROFILE_ID, Long.toString(userCache.getSerialNumberForUser(item.user)));
            out.attribute(null, Favorites.INTENT, intent.toUri(0));
            out.endTag(null, TAG_ENTRY);
        }
        out.endTag(null, TAG_ROOT);
        out.endDocument();
    } catch (IOException e) {
        file.failWrite(fos);
        Log.e(TAG, "Unable to persist items in " + mFileName, e);
        return;
    }
    file.finishWrite(fos);
}
Also used : AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) Intent(android.content.Intent) IOException(java.io.IOException) UserCache(com.android.launcher3.pm.UserCache) XmlSerializer(org.xmlpull.v1.XmlSerializer) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

Intent (android.content.Intent)1 AtomicFile (android.util.AtomicFile)1 WorkerThread (androidx.annotation.WorkerThread)1 UserCache (com.android.launcher3.pm.UserCache)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 XmlSerializer (org.xmlpull.v1.XmlSerializer)1