use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class DatabaseHelper method loadBookmarks.
/**
* Loads the default set of bookmarked shortcuts from an xml file.
*
* @param db The database to write the values into
*/
private void loadBookmarks(SQLiteDatabase db) {
ContentValues values = new ContentValues();
PackageManager packageManager = mContext.getPackageManager();
try {
XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
XmlUtils.beginDocument(parser, "bookmarks");
final int depth = parser.getDepth();
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (!"bookmark".equals(name)) {
break;
}
String pkg = parser.getAttributeValue(null, "package");
String cls = parser.getAttributeValue(null, "class");
String shortcutStr = parser.getAttributeValue(null, "shortcut");
String category = parser.getAttributeValue(null, "category");
int shortcutValue = shortcutStr.charAt(0);
if (TextUtils.isEmpty(shortcutStr)) {
Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
continue;
}
final Intent intent;
final String title;
if (pkg != null && cls != null) {
ActivityInfo info = null;
ComponentName cn = new ComponentName(pkg, cls);
try {
info = packageManager.getActivityInfo(cn, 0);
} catch (PackageManager.NameNotFoundException e) {
String[] packages = packageManager.canonicalToCurrentPackageNames(new String[] { pkg });
cn = new ComponentName(packages[0], cls);
try {
info = packageManager.getActivityInfo(cn, 0);
} catch (PackageManager.NameNotFoundException e1) {
Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
continue;
}
}
intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(cn);
title = info.loadLabel(packageManager).toString();
} else if (category != null) {
intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
title = "";
} else {
Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr + ": missing package/class or category attributes");
continue;
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
values.put(Settings.Bookmarks.TITLE, title);
values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
db.delete("bookmarks", "shortcut = ?", new String[] { Integer.toString(shortcutValue) });
db.insert("bookmarks", null, values);
}
} catch (XmlPullParserException e) {
Log.w(TAG, "Got execption parsing bookmarks.", e);
} catch (IOException e) {
Log.w(TAG, "Got execption parsing bookmarks.", e);
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class SettingsState method readStateSyncLocked.
private void readStateSyncLocked() {
FileInputStream in;
if (!mStatePersistFile.exists()) {
Slog.i(LOG_TAG, "No settings state " + mStatePersistFile);
addHistoricalOperationLocked(HISTORICAL_OPERATION_INITIALIZE, null);
return;
}
try {
in = new AtomicFile(mStatePersistFile).openRead();
} catch (FileNotFoundException fnfe) {
String message = "No settings state " + mStatePersistFile;
Slog.wtf(LOG_TAG, message);
Slog.i(LOG_TAG, message);
return;
}
try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, StandardCharsets.UTF_8.name());
parseStateLocked(parser);
} catch (XmlPullParserException | IOException e) {
String message = "Failed parsing settings file: " + mStatePersistFile;
Slog.wtf(LOG_TAG, message);
throw new IllegalStateException(message, e);
} finally {
IoUtils.closeQuietly(in);
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class AppWidgetServiceImpl method readProfileStateFromFileLocked.
private int readProfileStateFromFileLocked(FileInputStream stream, int userId, List<LoadedWidgetState> outLoadedWidgets) {
int version = -1;
try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(stream, StandardCharsets.UTF_8.name());
int legacyProviderIndex = -1;
int legacyHostIndex = -1;
int type;
do {
type = parser.next();
if (type == XmlPullParser.START_TAG) {
String tag = parser.getName();
if ("gs".equals(tag)) {
String attributeValue = parser.getAttributeValue(null, "version");
try {
version = Integer.parseInt(attributeValue);
} catch (NumberFormatException e) {
version = 0;
}
} else if ("p".equals(tag)) {
legacyProviderIndex++;
// TODO: do we need to check that this package has the same signature
// as before?
String pkg = parser.getAttributeValue(null, "pkg");
String cl = parser.getAttributeValue(null, "cl");
pkg = getCanonicalPackageName(pkg, cl, userId);
if (pkg == null) {
continue;
}
final int uid = getUidForPackage(pkg, userId);
if (uid < 0) {
continue;
}
ComponentName componentName = new ComponentName(pkg, cl);
ActivityInfo providerInfo = getProviderInfo(componentName, userId);
if (providerInfo == null) {
continue;
}
ProviderId providerId = new ProviderId(uid, componentName);
Provider provider = lookupProviderLocked(providerId);
if (provider == null && mSafeMode) {
// if we're in safe mode, make a temporary one
provider = new Provider();
provider.info = new AppWidgetProviderInfo();
provider.info.provider = providerId.componentName;
provider.info.providerInfo = providerInfo;
provider.zombie = true;
provider.id = providerId;
mProviders.add(provider);
}
String tagAttribute = parser.getAttributeValue(null, "tag");
final int providerTag = !TextUtils.isEmpty(tagAttribute) ? Integer.parseInt(tagAttribute, 16) : legacyProviderIndex;
provider.tag = providerTag;
} else if ("h".equals(tag)) {
legacyHostIndex++;
Host host = new Host();
// TODO: do we need to check that this package has the same signature
// as before?
String pkg = parser.getAttributeValue(null, "pkg");
final int uid = getUidForPackage(pkg, userId);
if (uid < 0) {
host.zombie = true;
}
if (!host.zombie || mSafeMode) {
// In safe mode, we don't discard the hosts we don't recognize
// so that they're not pruned from our list. Otherwise, we do.
final int hostId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
String tagAttribute = parser.getAttributeValue(null, "tag");
final int hostTag = !TextUtils.isEmpty(tagAttribute) ? Integer.parseInt(tagAttribute, 16) : legacyHostIndex;
host.tag = hostTag;
host.id = new HostId(uid, hostId, pkg);
mHosts.add(host);
}
} else if ("b".equals(tag)) {
String packageName = parser.getAttributeValue(null, "packageName");
final int uid = getUidForPackage(packageName, userId);
if (uid >= 0) {
Pair<Integer, String> packageId = Pair.create(userId, packageName);
mPackagesWithBindWidgetPermission.add(packageId);
}
} else if ("g".equals(tag)) {
Widget widget = new Widget();
widget.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
setMinAppWidgetIdLocked(userId, widget.appWidgetId + 1);
// restored ID is allowed to be absent
String restoredIdString = parser.getAttributeValue(null, "rid");
widget.restoredId = (restoredIdString == null) ? 0 : Integer.parseInt(restoredIdString, 16);
Bundle options = new Bundle();
String minWidthString = parser.getAttributeValue(null, "min_width");
if (minWidthString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, Integer.parseInt(minWidthString, 16));
}
String minHeightString = parser.getAttributeValue(null, "min_height");
if (minHeightString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, Integer.parseInt(minHeightString, 16));
}
String maxWidthString = parser.getAttributeValue(null, "max_width");
if (maxWidthString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, Integer.parseInt(maxWidthString, 16));
}
String maxHeightString = parser.getAttributeValue(null, "max_height");
if (maxHeightString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, Integer.parseInt(maxHeightString, 16));
}
String categoryString = parser.getAttributeValue(null, "host_category");
if (categoryString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, Integer.parseInt(categoryString, 16));
}
widget.options = options;
final int hostTag = Integer.parseInt(parser.getAttributeValue(null, "h"), 16);
String providerString = parser.getAttributeValue(null, "p");
final int providerTag = (providerString != null) ? Integer.parseInt(parser.getAttributeValue(null, "p"), 16) : TAG_UNDEFINED;
// We can match widgets with hosts and providers only after hosts
// and providers for all users have been loaded since the widget
// host and provider can be in different user profiles.
LoadedWidgetState loadedWidgets = new LoadedWidgetState(widget, hostTag, providerTag);
outLoadedWidgets.add(loadedWidgets);
}
}
} while (type != XmlPullParser.END_DOCUMENT);
} catch (NullPointerException | NumberFormatException | XmlPullParserException | IOException | IndexOutOfBoundsException e) {
Slog.w(TAG, "failed parsing " + e);
return -1;
}
return version;
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class ActivityManagerService method readGrantedUriPermissionsLocked.
private void readGrantedUriPermissionsLocked() {
if (DEBUG_URI_PERMISSION)
Slog.v(TAG_URI_PERMISSION, "readGrantedUriPermissions()");
final long now = System.currentTimeMillis();
FileInputStream fis = null;
try {
fis = mGrantFile.openRead();
final XmlPullParser in = Xml.newPullParser();
in.setInput(fis, StandardCharsets.UTF_8.name());
int type;
while ((type = in.next()) != END_DOCUMENT) {
final String tag = in.getName();
if (type == START_TAG) {
if (TAG_URI_GRANT.equals(tag)) {
final int sourceUserId;
final int targetUserId;
final int userHandle = readIntAttribute(in, ATTR_USER_HANDLE, UserHandle.USER_NULL);
if (userHandle != UserHandle.USER_NULL) {
// For backwards compatibility.
sourceUserId = userHandle;
targetUserId = userHandle;
} else {
sourceUserId = readIntAttribute(in, ATTR_SOURCE_USER_ID);
targetUserId = readIntAttribute(in, ATTR_TARGET_USER_ID);
}
final String sourcePkg = in.getAttributeValue(null, ATTR_SOURCE_PKG);
final String targetPkg = in.getAttributeValue(null, ATTR_TARGET_PKG);
final Uri uri = Uri.parse(in.getAttributeValue(null, ATTR_URI));
final boolean prefix = readBooleanAttribute(in, ATTR_PREFIX);
final int modeFlags = readIntAttribute(in, ATTR_MODE_FLAGS);
final long createdTime = readLongAttribute(in, ATTR_CREATED_TIME, now);
// Sanity check that provider still belongs to source package
// Both direct boot aware and unaware packages are fine as we
// will do filtering at query time to avoid multiple parsing.
final ProviderInfo pi = getProviderInfoLocked(uri.getAuthority(), sourceUserId, MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE);
if (pi != null && sourcePkg.equals(pi.packageName)) {
int targetUid = -1;
try {
targetUid = AppGlobals.getPackageManager().getPackageUid(targetPkg, MATCH_UNINSTALLED_PACKAGES, targetUserId);
} catch (RemoteException e) {
}
if (targetUid != -1) {
final UriPermission perm = findOrCreateUriPermissionLocked(sourcePkg, targetPkg, targetUid, new GrantUri(sourceUserId, uri, prefix));
perm.initPersistedModes(modeFlags, createdTime);
}
} else {
Slog.w(TAG, "Persisted grant for " + uri + " had source " + sourcePkg + " but instead found " + pi);
}
}
}
}
} catch (FileNotFoundException e) {
// Missing grants is okay
} catch (IOException e) {
Slog.wtf(TAG, "Failed reading Uri grants", e);
} catch (XmlPullParserException e) {
Slog.wtf(TAG, "Failed reading Uri grants", e);
} finally {
IoUtils.closeQuietly(fis);
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class FullBackupTest method testParseBackupSchemeFromXml_invalidXmlFails.
public void testParseBackupSchemeFromXml_invalidXmlFails() throws Exception {
// Invalid root tag.
mXpp.setInput(new StringReader("<full-weird-tag>" + "<exclude path=\"invalidRootTag.txt\" domain=\"file\"/>" + "</ffull-weird-tag>"));
try {
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
fail("Invalid root xml tag should throw an XmlPullParserException");
} catch (XmlPullParserException expected) {
}
// Invalid exclude tag.
mXpp.setInput(new StringReader("<full-backup-content>" + "<excluded path=\"invalidExcludeTag.txt\" domain=\"file\"/>" + "</full-backup-conten>t"));
try {
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
fail("Misspelled xml exclude tag should throw an XmlPullParserException");
} catch (XmlPullParserException expected) {
}
// Just for good measure - invalid include tag.
mXpp.setInput(new StringReader("<full-backup-content>" + "<yinclude path=\"invalidIncludeTag.txt\" domain=\"file\"/>" + "</full-backup-conten>t"));
try {
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
fail("Misspelled xml exclude tag should throw an XmlPullParserException");
} catch (XmlPullParserException expected) {
}
}
Aggregations