com.android.internal.util.XmlUtils Java Examples
The following examples show how to use
com.android.internal.util.XmlUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OverlayManagerSettings.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public static void restore(@NonNull final ArrayList<SettingsItem> table, @NonNull final InputStream is) throws IOException, XmlPullParserException { try (InputStreamReader reader = new InputStreamReader(is)) { table.clear(); final XmlPullParser parser = Xml.newPullParser(); parser.setInput(reader); XmlUtils.beginDocument(parser, TAG_OVERLAYS); int version = XmlUtils.readIntAttribute(parser, ATTR_VERSION); if (version != CURRENT_VERSION) { upgrade(version); } int depth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, depth)) { switch (parser.getName()) { case TAG_ITEM: final SettingsItem item = restoreRow(parser, depth + 1); table.add(item); break; } } } }
Example #2
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void loadFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { XmlUtils.beginDocument(parser, TAG_DISPLAY_MANAGER_STATE); final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals(TAG_REMEMBERED_WIFI_DISPLAYS)) { loadRememberedWifiDisplaysFromXml(parser); } if (parser.getName().equals(TAG_DISPLAY_STATES)) { loadDisplaysFromXml(parser); } if (parser.getName().equals(TAG_STABLE_DEVICE_VALUES)) { mStableDeviceValues.loadFromXml(parser); } if (parser.getName().equals(TAG_BRIGHTNESS_CONFIGURATIONS)) { mBrightnessConfigurations.loadFromXml(parser); } } }
Example #3
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void loadRememberedWifiDisplaysFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals(TAG_WIFI_DISPLAY)) { String deviceAddress = parser.getAttributeValue(null, ATTR_DEVICE_ADDRESS); String deviceName = parser.getAttributeValue(null, ATTR_DEVICE_NAME); String deviceAlias = parser.getAttributeValue(null, ATTR_DEVICE_ALIAS); if (deviceAddress == null || deviceName == null) { throw new XmlPullParserException( "Missing deviceAddress or deviceName attribute on wifi-display."); } if (findRememberedWifiDisplay(deviceAddress) >= 0) { throw new XmlPullParserException( "Found duplicate wifi display device address."); } mRememberedWifiDisplays.add( new WifiDisplay(deviceAddress, deviceName, deviceAlias, false, false, false)); } } }
Example #4
Source File: TypedArray.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Retrieve the boolean value for the attribute at <var>index</var>. * <p> * If the attribute is an integer value, this method will return whether * it is equal to zero. If the attribute is not a boolean or integer value, * this method will attempt to coerce it to an integer using * {@link Integer#decode(String)} and return whether it is equal to zero. * * @param index Index of attribute to retrieve. * @param defValue Value to return if the attribute is not defined or * cannot be coerced to an integer. * * @return Boolean value of the attribute, or defValue if the attribute was * not defined or could not be coerced to an integer. * @throws RuntimeException if the TypedArray has already been recycled. */ public boolean getBoolean(@StyleableRes int index, boolean defValue) { if (mRecycled) { throw new RuntimeException("Cannot make calls to a recycled instance!"); } index *= STYLE_NUM_ENTRIES; final int[] data = mData; final int type = data[index + STYLE_TYPE]; if (type == TypedValue.TYPE_NULL) { return defValue; } else if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { return data[index + STYLE_DATA] != 0; } final TypedValue v = mValue; if (getValueAt(index, v)) { StrictMode.noteResourceMismatch(v); return XmlUtils.convertValueToBoolean(v.coerceToString(), defValue); } // We already checked for TYPE_NULL. This should never happen. throw new RuntimeException("getBoolean of bad type: 0x" + Integer.toHexString(type)); }
Example #5
Source File: TypedArray.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Retrieve the integer value for the attribute at <var>index</var>. * <p> * If the attribute is not an integer, this method will attempt to coerce * it to an integer using {@link Integer#decode(String)}. * * @param index Index of attribute to retrieve. * @param defValue Value to return if the attribute is not defined or * cannot be coerced to an integer. * * @return Integer value of the attribute, or defValue if the attribute was * not defined or could not be coerced to an integer. * @throws RuntimeException if the TypedArray has already been recycled. */ public int getInt(@StyleableRes int index, int defValue) { if (mRecycled) { throw new RuntimeException("Cannot make calls to a recycled instance!"); } index *= STYLE_NUM_ENTRIES; final int[] data = mData; final int type = data[index + STYLE_TYPE]; if (type == TypedValue.TYPE_NULL) { return defValue; } else if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) { return data[index + STYLE_DATA]; } final TypedValue v = mValue; if (getValueAt(index, v)) { StrictMode.noteResourceMismatch(v); return XmlUtils.convertValueToInt(v.coerceToString(), defValue); } // We already checked for TYPE_NULL. This should never happen. throw new RuntimeException("getInt of bad type: 0x" + Integer.toHexString(type)); }
Example #6
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void loadDisplaysFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals(TAG_DISPLAY)) { String uniqueId = parser.getAttributeValue(null, ATTR_UNIQUE_ID); if (uniqueId == null) { throw new XmlPullParserException( "Missing unique-id attribute on display."); } if (mDisplayStates.containsKey(uniqueId)) { throw new XmlPullParserException("Found duplicate display."); } DisplayState state = new DisplayState(); state.loadFromXml(parser); mDisplayStates.put(uniqueId, state); } } }
Example #7
Source File: Resources.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Parse a series of {@link android.R.styleable#Extra <extra>} tags from * an XML file. You call this when you are at the parent tag of the * extra tags, and it will return once all of the child tags have been parsed. * This will call {@link #parseBundleExtra} for each extra tag encountered. * * @param parser The parser from which to retrieve the extras. * @param outBundle A Bundle in which to place all parsed extras. * @throws XmlPullParserException * @throws IOException */ public void parseBundleExtras(XmlResourceParser parser, Bundle outBundle) throws XmlPullParserException, IOException { int outerDepth = parser.getDepth(); int type; while ((type=parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } String nodeName = parser.getName(); if (nodeName.equals("extra")) { parseBundleExtra("extra", parser, outBundle); XmlUtils.skipCurrentTag(parser); } else { XmlUtils.skipCurrentTag(parser); } } }
Example #8
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static BrightnessConfiguration loadConfigurationFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { final int outerDepth = parser.getDepth(); String description = null; Pair<float[], float[]> curve = null; while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (TAG_BRIGHTNESS_CURVE.equals(parser.getName())) { description = parser.getAttributeValue(null, ATTR_DESCRIPTION); curve = loadCurveFromXml(parser); } } if (curve == null) { return null; } final BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder( curve.first, curve.second); builder.setDescription(description); return builder.build(); }
Example #9
Source File: PersistableBundle.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** @hide */ public static PersistableBundle restoreFromXml(XmlPullParser in) throws IOException, XmlPullParserException { final int outerDepth = in.getDepth(); final String startTag = in.getName(); final String[] tagName = new String[1]; int event; while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && (event != XmlPullParser.END_TAG || in.getDepth() < outerDepth)) { if (event == XmlPullParser.START_TAG) { return new PersistableBundle((ArrayMap<String, Object>) XmlUtils.readThisArrayMapXml(in, startTag, tagName, new MyReadMapCallback())); } } return EMPTY; }
Example #10
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static Pair<float[], float[]> loadCurveFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { final int outerDepth = parser.getDepth(); List<Float> luxLevels = new ArrayList<>(); List<Float> nitLevels = new ArrayList<>(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (TAG_BRIGHTNESS_POINT.equals(parser.getName())) { luxLevels.add(loadFloat(parser.getAttributeValue(null, ATTR_LUX))); nitLevels.add(loadFloat(parser.getAttributeValue(null, ATTR_NITS))); } } final int N = luxLevels.size(); float[] lux = new float[N]; float[] nits = new float[N]; for (int i = 0; i < N; i++) { lux[i] = luxLevels.get(i); nits[i] = nitLevels.get(i); } return Pair.create(lux, nits); }
Example #11
Source File: SystemImpl.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Reads all signatures at the current depth (within the current provider) from the XML parser. */ private static String[] readSignatures(XmlResourceParser parser) throws IOException, XmlPullParserException { List<String> signatures = new ArrayList<String>(); int outerDepth = parser.getDepth(); while(XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals(TAG_SIGNATURE)) { // Parse the value within the signature tag String signature = parser.nextText(); signatures.add(signature); } else { Log.e(TAG, "Found an element in a webview provider that is not a signature"); } } return signatures.toArray(new String[signatures.size()]); }
Example #12
Source File: AppOpsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void readPackage(XmlPullParser parser) throws NumberFormatException, XmlPullParserException, IOException { String pkgName = parser.getAttributeValue(null, "n"); int outerDepth = parser.getDepth(); int type; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } String tagName = parser.getName(); if (tagName.equals("uid")) { readUid(parser, pkgName); } else { Slog.w(TAG, "Unknown element under <pkg>: " + parser.getName()); XmlUtils.skipCurrentTag(parser); } } }
Example #13
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void loadFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { XmlUtils.beginDocument(parser, TAG_TV_INPUT_MANAGER_STATE); final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals(TAG_BLOCKED_RATINGS)) { loadBlockedRatingsFromXml(parser); } else if (parser.getName().equals(TAG_PARENTAL_CONTROLS)) { String enabled = parser.getAttributeValue(null, ATTR_ENABLED); if (TextUtils.isEmpty(enabled)) { throw new XmlPullParserException( "Missing " + ATTR_ENABLED + " attribute on " + TAG_PARENTAL_CONTROLS); } mParentalControlsEnabled = Boolean.parseBoolean(enabled); } } }
Example #14
Source File: PreferredActivity.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public boolean onReadTag(String tagName, XmlPullParser parser) throws XmlPullParserException, IOException { if (tagName.equals("filter")) { if (DEBUG_FILTERS) { Log.i(TAG, "Starting to parse filter..."); } readFromXml(parser); if (DEBUG_FILTERS) { Log.i(TAG, "Finished filter: depth=" + parser.getDepth() + " tag=" + parser.getName()); } } else { PackageManagerService.reportSettingsProblem(Log.WARN, "Unknown element under <preferred-activities>: " + parser.getName()); XmlUtils.skipCurrentTag(parser); } return true; }
Example #15
Source File: OverlayManagerSettings.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static SettingsItem restoreRow(@NonNull final XmlPullParser parser, final int depth) throws IOException { final String packageName = XmlUtils.readStringAttribute(parser, ATTR_PACKAGE_NAME); final int userId = XmlUtils.readIntAttribute(parser, ATTR_USER_ID); final String targetPackageName = XmlUtils.readStringAttribute(parser, ATTR_TARGET_PACKAGE_NAME); final String baseCodePath = XmlUtils.readStringAttribute(parser, ATTR_BASE_CODE_PATH); final int state = XmlUtils.readIntAttribute(parser, ATTR_STATE); final boolean isEnabled = XmlUtils.readBooleanAttribute(parser, ATTR_IS_ENABLED); final boolean isStatic = XmlUtils.readBooleanAttribute(parser, ATTR_IS_STATIC); final int priority = XmlUtils.readIntAttribute(parser, ATTR_PRIORITY); final String category = XmlUtils.readStringAttribute(parser, ATTR_CATEGORY); return new SettingsItem(packageName, userId, targetPackageName, baseCodePath, state, isEnabled, isStatic, priority, category); }
Example #16
Source File: InstantAppRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static InstantAppInfo parsePackage(@NonNull XmlPullParser parser, @NonNull String packageName) throws IOException, XmlPullParserException { String label = parser.getAttributeValue(null, ATTR_LABEL); List<String> outRequestedPermissions = new ArrayList<>(); List<String> outGrantedPermissions = new ArrayList<>(); final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (TAG_PERMISSIONS.equals(parser.getName())) { parsePermissions(parser, outRequestedPermissions, outGrantedPermissions); } } String[] requestedPermissions = new String[outRequestedPermissions.size()]; outRequestedPermissions.toArray(requestedPermissions); String[] grantedPermissions = new String[outGrantedPermissions.size()]; outGrantedPermissions.toArray(grantedPermissions); return new InstantAppInfo(packageName, label, requestedPermissions, grantedPermissions); }
Example #17
Source File: WatchlistSettings.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void reloadSettings() { if (!mXmlFile.exists()) { // No settings config return; } try (FileInputStream stream = mXmlFile.openRead()){ XmlPullParser parser = Xml.newPullParser(); parser.setInput(stream, StandardCharsets.UTF_8.name()); XmlUtils.beginDocument(parser, "network-watchlist-settings"); final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals("secret-key")) { mPrivacySecretKey = parseSecretKey(parser); } } Slog.i(TAG, "Reload watchlist settings done"); } catch (IllegalStateException | NullPointerException | NumberFormatException | XmlPullParserException | IOException | IndexOutOfBoundsException e) { Slog.e(TAG, "Failed parsing xml", e); } }
Example #18
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void loadInputDevicesFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals("input-device")) { String descriptor = parser.getAttributeValue(null, "descriptor"); if (descriptor == null) { throw new XmlPullParserException( "Missing descriptor attribute on input-device."); } if (mInputDevices.containsKey(descriptor)) { throw new XmlPullParserException("Found duplicate input device."); } InputDeviceState state = new InputDeviceState(); state.loadFromXml(parser); mInputDevices.put(descriptor, state); } } }
Example #19
Source File: PermissionSettings.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public static void readPermissions(ArrayMap<String, BasePermission> out, XmlPullParser parser) throws IOException, XmlPullParserException { int outerDepth = parser.getDepth(); int type; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } if (!BasePermission.readLPw(out, parser)) { PackageManagerService.reportSettingsProblem(Log.WARN, "Unknown element reading permissions: " + parser.getName() + " at " + parser.getPositionDescription()); } XmlUtils.skipCurrentTag(parser); } }
Example #20
Source File: NotFilter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public Filter newFilter(XmlPullParser parser) throws IOException, XmlPullParserException { Filter child = null; int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { Filter filter = IntentFirewall.parseFilter(parser); if (child == null) { child = filter; } else { throw new XmlPullParserException( "<not> tag can only contain a single child filter.", parser, null); } } return new NotFilter(child); }
Example #21
Source File: XmlConfigSource.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private CertificatesEntryRef parseCertificatesEntry(XmlResourceParser parser, boolean defaultOverridePins) throws IOException, XmlPullParserException, ParserException { boolean overridePins = parser.getAttributeBooleanValue(null, "overridePins", defaultOverridePins); int sourceId = parser.getAttributeResourceValue(null, "src", -1); String sourceString = parser.getAttributeValue(null, "src"); CertificateSource source = null; if (sourceString == null) { throw new ParserException(parser, "certificates element missing src attribute"); } if (sourceId != -1) { // TODO: Cache ResourceCertificateSources by sourceId source = new ResourceCertificateSource(sourceId, mContext); } else if ("system".equals(sourceString)) { source = SystemCertificateSource.getInstance(); } else if ("user".equals(sourceString)) { source = UserCertificateSource.getInstance(); } else { throw new ParserException(parser, "Unknown certificates src. " + "Should be one of system|user|@resourceVal"); } XmlUtils.skipCurrentTag(parser); return new CertificatesEntryRef(source, overridePins); }
Example #22
Source File: OverlayManagerSettings.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public static void persist(@NonNull final ArrayList<SettingsItem> table, @NonNull final OutputStream os) throws IOException, XmlPullParserException { final FastXmlSerializer xml = new FastXmlSerializer(); xml.setOutput(os, "utf-8"); xml.startDocument(null, true); xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); xml.startTag(null, TAG_OVERLAYS); XmlUtils.writeIntAttribute(xml, ATTR_VERSION, CURRENT_VERSION); final int N = table.size(); for (int i = 0; i < N; i++) { final SettingsItem item = table.get(i); persistRow(xml, item); } xml.endTag(null, TAG_OVERLAYS); xml.endDocument(); }
Example #23
Source File: OverlayManagerSettings.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void persistRow(@NonNull final FastXmlSerializer xml, @NonNull final SettingsItem item) throws IOException { xml.startTag(null, TAG_ITEM); XmlUtils.writeStringAttribute(xml, ATTR_PACKAGE_NAME, item.mPackageName); XmlUtils.writeIntAttribute(xml, ATTR_USER_ID, item.mUserId); XmlUtils.writeStringAttribute(xml, ATTR_TARGET_PACKAGE_NAME, item.mTargetPackageName); XmlUtils.writeStringAttribute(xml, ATTR_BASE_CODE_PATH, item.mBaseCodePath); XmlUtils.writeIntAttribute(xml, ATTR_STATE, item.mState); XmlUtils.writeBooleanAttribute(xml, ATTR_IS_ENABLED, item.mIsEnabled); XmlUtils.writeBooleanAttribute(xml, ATTR_IS_STATIC, item.mIsStatic); XmlUtils.writeIntAttribute(xml, ATTR_PRIORITY, item.mPriority); XmlUtils.writeStringAttribute(xml, ATTR_CATEGORY, item.mCategory); xml.endTag(null, TAG_ITEM); }
Example #24
Source File: XmlBlock.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public int getAttributeListValue(int idx, String[] options, int defaultValue) { int t = nativeGetAttributeDataType(mParseState, idx); int v = nativeGetAttributeData(mParseState, idx); if (t == TypedValue.TYPE_STRING) { return XmlUtils.convertValueToList( mStrings.get(v), options, defaultValue); } return v; }
Example #25
Source File: XmlConfigSource.java From cwac-netsecurity with Apache License 2.0 | 5 votes |
private PinSet parsePinSet(XmlResourceParser parser) throws IOException, XmlPullParserException, ParserException { String expirationDate = parser.getAttributeValue(null, "expiration"); long expirationTimestampMilis = Long.MAX_VALUE; if (expirationDate != null) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setLenient(false); Date date = sdf.parse(expirationDate); if (date == null) { throw new ParserException(parser, "Invalid expiration date in pin-set"); } expirationTimestampMilis = date.getTime(); } catch (ParseException e) { throw new ParserException(parser, "Invalid expiration date in pin-set", e); } } int outerDepth = parser.getDepth(); Set<Pin> pins = new HashSet<>(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { String tagName = parser.getName(); if (tagName.equals("pin")) { pins.add(parsePin(parser)); } else { XmlUtils.skipCurrentTag(parser); } } return new PinSet(pins, expirationTimestampMilis); }
Example #26
Source File: PersistentDataStore.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void loadFromXml(XmlPullParser parser) throws IOException, XmlPullParserException { XmlUtils.beginDocument(parser, "input-manager-state"); final int outerDepth = parser.getDepth(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { if (parser.getName().equals("input-devices")) { loadInputDevicesFromXml(parser); } } }
Example #27
Source File: XmlConfigSource.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private Collection<CertificatesEntryRef> parseTrustAnchors(XmlResourceParser parser, boolean defaultOverridePins) throws IOException, XmlPullParserException, ParserException { int outerDepth = parser.getDepth(); List<CertificatesEntryRef> anchors = new ArrayList<>(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { String tagName = parser.getName(); if (tagName.equals("certificates")) { anchors.add(parseCertificatesEntry(parser, defaultOverridePins)); } else { XmlUtils.skipCurrentTag(parser); } } return anchors; }
Example #28
Source File: AliasActivity.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private Intent parseAlias(XmlPullParser parser) throws XmlPullParserException, IOException { AttributeSet attrs = Xml.asAttributeSet(parser); Intent intent = null; int type; while ((type=parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) { } String nodeName = parser.getName(); if (!"alias".equals(nodeName)) { throw new RuntimeException( "Alias meta-data must start with <alias> tag; found" + nodeName + " at " + parser.getPositionDescription()); } int outerDepth = parser.getDepth(); while ((type=parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { continue; } nodeName = parser.getName(); if ("intent".equals(nodeName)) { Intent gotIntent = Intent.parseIntent(getResources(), parser, attrs); if (intent == null) intent = gotIntent; } else { XmlUtils.skipCurrentTag(parser); } } return intent; }
Example #29
Source File: XmlConfigSource.java From cwac-netsecurity with Apache License 2.0 | 5 votes |
private Collection<CertificatesEntryRef> parseTrustAnchors(XmlResourceParser parser, boolean defaultOverridePins) throws IOException, XmlPullParserException, ParserException { int outerDepth = parser.getDepth(); List<CertificatesEntryRef> anchors = new ArrayList<>(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { String tagName = parser.getName(); if (tagName.equals("certificates")) { anchors.add(parseCertificatesEntry(parser, defaultOverridePins)); } else { XmlUtils.skipCurrentTag(parser); } } return anchors; }
Example #30
Source File: XmlConfigSource.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private PinSet parsePinSet(XmlResourceParser parser) throws IOException, XmlPullParserException, ParserException { String expirationDate = parser.getAttributeValue(null, "expiration"); long expirationTimestampMilis = Long.MAX_VALUE; if (expirationDate != null) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setLenient(false); Date date = sdf.parse(expirationDate); if (date == null) { throw new ParserException(parser, "Invalid expiration date in pin-set"); } expirationTimestampMilis = date.getTime(); } catch (ParseException e) { throw new ParserException(parser, "Invalid expiration date in pin-set", e); } } int outerDepth = parser.getDepth(); Set<Pin> pins = new ArraySet<>(); while (XmlUtils.nextElementWithin(parser, outerDepth)) { String tagName = parser.getName(); if (tagName.equals("pin")) { pins.add(parsePin(parser)); } else { XmlUtils.skipCurrentTag(parser); } } return new PinSet(pins, expirationTimestampMilis); }