use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class AccountManagerBackupHelper method restoreAccountAccessPermissions.
public void restoreAccountAccessPermissions(byte[] data, int userId) {
try {
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
XmlPullParser parser = Xml.newPullParser();
parser.setInput(dataStream, StandardCharsets.UTF_8.name());
PackageManager packageManager = mAccountManagerService.mContext.getPackageManager();
final int permissionsOuterDepth = parser.getDepth();
while (XmlUtils.nextElementWithin(parser, permissionsOuterDepth)) {
if (!TAG_PERMISSIONS.equals(parser.getName())) {
continue;
}
final int permissionOuterDepth = parser.getDepth();
while (XmlUtils.nextElementWithin(parser, permissionOuterDepth)) {
if (!TAG_PERMISSION.equals(parser.getName())) {
continue;
}
String accountDigest = parser.getAttributeValue(null, ATTR_ACCOUNT_SHA_256);
if (TextUtils.isEmpty(accountDigest)) {
XmlUtils.skipCurrentTag(parser);
}
String packageName = parser.getAttributeValue(null, ATTR_PACKAGE);
if (TextUtils.isEmpty(packageName)) {
XmlUtils.skipCurrentTag(parser);
}
String digest = parser.getAttributeValue(null, ATTR_DIGEST);
if (TextUtils.isEmpty(digest)) {
XmlUtils.skipCurrentTag(parser);
}
PendingAppPermission pendingAppPermission = new PendingAppPermission(accountDigest, packageName, digest, userId);
if (!pendingAppPermission.apply(packageManager)) {
synchronized (mLock) {
// Start watching before add pending to avoid a missed signal
if (mRestorePackageMonitor == null) {
mRestorePackageMonitor = new RestorePackageMonitor();
mRestorePackageMonitor.register(mAccountManagerService.mContext, mAccountManagerService.mMessageHandler.getLooper(), true);
}
if (mRestorePendingAppPermissions == null) {
mRestorePendingAppPermissions = new ArrayList<>();
}
mRestorePendingAppPermissions.add(pendingAppPermission);
}
}
}
}
// Make sure we eventually prune the in-memory pending restores
synchronized (mLock) {
mRestoreCancelCommand = new CancelRestoreCommand();
}
mAccountManagerService.mMessageHandler.postDelayed(mRestoreCancelCommand, PENDING_RESTORE_TIMEOUT_MILLIS);
} catch (XmlPullParserException | IOException e) {
Log.e(TAG, "Error restoring app permissions", e);
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class TextServicesManagerService method buildSpellCheckerMapLocked.
private static void buildSpellCheckerMapLocked(Context context, ArrayList<SpellCheckerInfo> list, HashMap<String, SpellCheckerInfo> map, TextServicesSettings settings) {
list.clear();
map.clear();
final PackageManager pm = context.getPackageManager();
// Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default
// behavior of PackageManager is exactly what we want. It by default picks up appropriate
// services depending on the unlock state for the specified user.
final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(SpellCheckerService.SERVICE_INTERFACE), PackageManager.GET_META_DATA, settings.getCurrentUserId());
final int N = services.size();
for (int i = 0; i < N; ++i) {
final ResolveInfo ri = services.get(i);
final ServiceInfo si = ri.serviceInfo;
final ComponentName compName = new ComponentName(si.packageName, si.name);
if (!android.Manifest.permission.BIND_TEXT_SERVICE.equals(si.permission)) {
Slog.w(TAG, "Skipping text service " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_TEXT_SERVICE);
continue;
}
if (DBG)
Slog.d(TAG, "Add: " + compName);
try {
final SpellCheckerInfo sci = new SpellCheckerInfo(context, ri);
if (sci.getSubtypeCount() <= 0) {
Slog.w(TAG, "Skipping text service " + compName + ": it does not contain subtypes.");
continue;
}
list.add(sci);
map.put(sci.getId(), sci);
} catch (XmlPullParserException e) {
Slog.w(TAG, "Unable to load the spell checker " + compName, e);
} catch (IOException e) {
Slog.w(TAG, "Unable to load the spell checker " + compName, e);
}
}
if (DBG) {
Slog.d(TAG, "buildSpellCheckerMapLocked: " + list.size() + "," + map.size());
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class TimeUtils method getTimeZones.
/**
* Returns the time zones for the country, which is the code
* attribute of the timezone element in time_zones_by_country.xml. Do not modify.
*
* @param country is a two character country code.
* @return TimeZone list, maybe empty but never null. Do not modify.
* @hide
*/
public static ArrayList<TimeZone> getTimeZones(String country) {
synchronized (sLastLockObj) {
if ((country != null) && country.equals(sLastCountry)) {
if (DBG)
Log.d(TAG, "getTimeZones(" + country + "): return cached version");
return sLastZones;
}
}
ArrayList<TimeZone> tzs = new ArrayList<TimeZone>();
if (country == null) {
if (DBG)
Log.d(TAG, "getTimeZones(null): return empty list");
return tzs;
}
Resources r = Resources.getSystem();
XmlResourceParser parser = r.getXml(com.android.internal.R.xml.time_zones_by_country);
try {
XmlUtils.beginDocument(parser, "timezones");
while (true) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null || !(element.equals("timezone"))) {
break;
}
String code = parser.getAttributeValue(null, "code");
if (country.equals(code)) {
if (parser.next() == XmlPullParser.TEXT) {
String zoneIdString = parser.getText();
TimeZone tz = TimeZone.getTimeZone(zoneIdString);
if (tz.getID().startsWith("GMT") == false) {
// tz.getID doesn't start not "GMT" so its valid
tzs.add(tz);
if (DBG) {
Log.d(TAG, "getTimeZone('" + country + "'): found tz.getID==" + ((tz != null) ? tz.getID() : "<no tz>"));
}
}
}
}
}
} catch (XmlPullParserException e) {
Log.e(TAG, "Got xml parser exception getTimeZone('" + country + "'): e=", e);
} catch (IOException e) {
Log.e(TAG, "Got IO exception getTimeZone('" + country + "'): e=", e);
} finally {
parser.close();
}
synchronized (sLastLockObj) {
// Cache the last result;
sLastZones = tzs;
sLastCountry = country;
return sLastZones;
}
}
use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.
the class Xml method newPullParser.
/**
* Returns a new pull parser with namespace support.
*/
public static XmlPullParser newPullParser() {
try {
KXmlParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
return parser;
} catch (XmlPullParserException e) {
throw new AssertionError();
}
}
use of org.xmlpull.v1.XmlPullParserException in project AsmackService by rtreffer.
the class FeatureNegotiationEngine method open.
/*
* From RFC 3920-bis-13#page-26
* 4.2.7. Flow Chart
*
* +------------+
* | open TCP |
* | connection |
* +------------+
* |
* | <------------ open() starts here
* |
* v
* +---------------+
* | send initial |<-------------------------+
* | stream header | ^
* +---------------+ |
* | |
* v |
* +------------------+ |
* | receive response | |
* | stream header | |
* +------------------+ |
* | |
* v |
* +----------------+ |
* | receive stream | |
* +------------------>| features | |
* ^ +----------------+ |
* | | |
* | v |
* | +<-----------------+ |
* | | |
* | {empty?} ----> {all voluntary?} ----> {some mandatory?} |
* | | no | no | |
* | | yes | yes | yes |
* | | v v |
* | | +---------------+ +----------------+ |
* | | | MAY negotiate | | MUST negotiate | |
* | | | any or none | | one feature | |
* | | +---------------+ +----------------+ |
* | | | | |
* | v v | |
* | +----------+ +-----------+ | |
* | | process |<-----| negotiate | | |
* | | complete | no | a feature | | |
* | +----------+ +-----------+ | |
* | | | |
* | yes | | |
* | v v |
* | +--------->+<---------+ |
* | | |
* | v |
* +<-------------------------- {restart mandatory?} ------------>+
* no yes
*
* The "open" method starts directly after opening the TCP streams,
* negotiates the connection and returns true if the xmpp stream is ready
* for a bind.
*
* The usual way to bind is
* if (streamEngine.open(account)) {
* String resource = streamEngine.bind(account.getResource);
* }
*
* Interresting and available features that require restarts:
* - SASL
* - TLS
* - Compression
*/
/**
* <p>Open a connection for a given account. This will run the full
* negotiation with the following precedence:
* <ol>
* <li>TLS (if available)</li>
* <li>Compression (if available)</li>
* <li>SASL</li>
* <ol></p>
*
* <p><b>Note:</b> Servers should not offer compression befor SASL is
* completed. This is not violated by the rule, mobile devices love xml
* compression, thus a higher preference. Everything will work as expected
* when compression is offered after SASL.</p>
*
* <p>This method requires a call to bind (if you wish to bind) afterwards.
* </p>
*
* @param account XmppAccount The account used for negotiation.
* @throws XmppException In case of an error.
*/
public void open(XmppAccount account) throws XmppException {
boolean rerun = true;
boolean canBind = false;
while (rerun) {
try {
rerun = false;
xmppOutput.open(XMPPUtils.getDomain(account.getJid()), null);
xmppInput.readOpening();
Node features = null;
do {
Node stanza = xmppInput.nextStanza().getDocumentNode();
if (XMLUtils.isInstance(stanza, "http://etherx.jabber.org/streams", "features")) {
features = stanza;
}
} while (features == null);
// check basic stream features
rosterVersioningSupported |= XMLUtils.hasChild(features, "urn:xmpp:features:rosterver", "ver");
sessionsSupported |= XMLUtils.hasChild(features, "urn:ietf:params:xml:ns:xmpp-session", "session");
canBind |= XMLUtils.hasChild(features, "urn:ietf:params:xml:ns:xmpp-bind", "bind");
hasTLS = XMLUtils.hasChild(features, "urn:ietf:params:xml:ns:xmpp-tls", "starttls");
Node compression = XMLUtils.getFirstChild(features, "http://jabber.org/features/compress", "compression");
if (compression != null) {
NodeList methods = compression.getChildNodes();
for (int i = 0, l = methods.getLength(); i < l; i++) {
Node method = methods.item(i);
if (method.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
if (!"method".equals(method.getNodeName())) {
continue;
}
String methodName = method.getFirstChild().getNodeValue();
methodName = methodName.trim();
compressionSupported |= "zlib".equals(methodName);
}
}
Node saslMechanisms = XMLUtils.getFirstChild(features, "urn:ietf:params:xml:ns:xmpp-sasl", "mechanisms");
SASLSupported |= saslMechanisms != null;
if (hasTLS && !secure) {
// enable tls
xmppOutput.sendUnchecked("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
boolean startTLS = XMLUtils.isInstance(xmppInput.nextStanza().getDocumentNode(), "urn:ietf:params:xml:ns:xmpp-tls", "proceed");
if (startTLS) {
startTLS();
secure = true;
rerun = true;
continue;
}
}
if (compressionSupported && !compressed && ZLibOutputStream.SUPPORTED) {
startCompress();
rerun = true;
continue;
}
if (SASLSupported && !authenticated) {
if (saslLogin(saslMechanisms, account)) {
authenticated = true;
rerun = true;
continue;
}
}
} catch (IllegalArgumentException e) {
throw new XmppMalformedException("Can't negotiate features", e);
} catch (IllegalStateException e) {
throw new XmppMalformedException("Can't negotiate features", e);
} catch (IOException e) {
throw new XmppTransportException("Can't negotiate features", e);
} catch (XmlPullParserException e) {
throw new XmppMalformedException("Can't negotiate features", e);
} catch (NoSuchAlgorithmException e) {
// Should never happen - TLS not available?
throw new XmppTransportException("Can't enable tls", e);
} catch (KeyManagementException e) {
throw new XmppTransportException("Can't trust server", e);
}
}
if (!canBind) {
throw new XmppTransportException("Couldn't reach bind state.");
}
}
Aggregations