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);
}
Aggregations