Search in sources :

Example 6 with START_TAG

use of org.xmlpull.v1.XmlPullParser.START_TAG in project android_frameworks_base by ResurrectionRemix.

the class MountService method readSettingsLocked.

private void readSettingsLocked() {
    mRecords.clear();
    mPrimaryStorageUuid = getDefaultPrimaryStorageUuid();
    mForceAdoptable = false;
    FileInputStream fis = null;
    try {
        fis = mSettingsFile.openRead();
        final XmlPullParser in = Xml.newPullParser();
        in.setInput(fis, StandardCharsets.UTF_8.name());
        int type;
        while ((type = in.next()) != END_DOCUMENT) {
            if (type == START_TAG) {
                final String tag = in.getName();
                if (TAG_VOLUMES.equals(tag)) {
                    final int version = readIntAttribute(in, ATTR_VERSION, VERSION_INIT);
                    final boolean primaryPhysical = SystemProperties.getBoolean(StorageManager.PROP_PRIMARY_PHYSICAL, false);
                    final boolean validAttr = (version >= VERSION_FIX_PRIMARY) || (version >= VERSION_ADD_PRIMARY && !primaryPhysical);
                    if (validAttr) {
                        mPrimaryStorageUuid = readStringAttribute(in, ATTR_PRIMARY_STORAGE_UUID);
                    }
                    mForceAdoptable = readBooleanAttribute(in, ATTR_FORCE_ADOPTABLE, false);
                } else if (TAG_VOLUME.equals(tag)) {
                    final VolumeRecord rec = readVolumeRecord(in);
                    mRecords.put(rec.fsUuid, rec);
                }
            }
        }
    } catch (FileNotFoundException e) {
    // Missing metadata is okay, probably first boot
    } catch (IOException e) {
        Slog.wtf(TAG, "Failed reading metadata", e);
    } catch (XmlPullParserException e) {
        Slog.wtf(TAG, "Failed reading metadata", e);
    } finally {
        IoUtils.closeQuietly(fis);
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 7 with START_TAG

use of org.xmlpull.v1.XmlPullParser.START_TAG in project android_frameworks_base by ResurrectionRemix.

the class PackageInstallerService method readSessionsLocked.

private void readSessionsLocked() {
    if (LOGD)
        Slog.v(TAG, "readSessionsLocked()");
    mSessions.clear();
    FileInputStream fis = null;
    try {
        fis = mSessionsFile.openRead();
        final XmlPullParser in = Xml.newPullParser();
        in.setInput(fis, StandardCharsets.UTF_8.name());
        int type;
        while ((type = in.next()) != END_DOCUMENT) {
            if (type == START_TAG) {
                final String tag = in.getName();
                if (TAG_SESSION.equals(tag)) {
                    final PackageInstallerSession session = readSessionLocked(in);
                    final long age = System.currentTimeMillis() - session.createdMillis;
                    final boolean valid;
                    if (age >= MAX_AGE_MILLIS) {
                        Slog.w(TAG, "Abandoning old session first created at " + session.createdMillis);
                        valid = false;
                    } else {
                        valid = true;
                    }
                    if (valid) {
                        mSessions.put(session.sessionId, session);
                    } else {
                        // Since this is early during boot we don't send
                        // any observer events about the session, but we
                        // keep details around for dumpsys.
                        mHistoricalSessions.put(session.sessionId, session);
                    }
                    mAllocatedSessions.put(session.sessionId, true);
                }
            }
        }
    } catch (FileNotFoundException e) {
    // Missing sessions are okay, probably first boot
    } catch (IOException | XmlPullParserException e) {
        Slog.wtf(TAG, "Failed reading install sessions", e);
    } finally {
        IoUtils.closeQuietly(fis);
    }
}
Also used : IPackageInstallerSession(android.content.pm.IPackageInstallerSession) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 8 with START_TAG

use of org.xmlpull.v1.XmlPullParser.START_TAG in project android_frameworks_base by DirtyUnicorns.

the class NetworkPolicyManagerService method readPolicyAL.

private void readPolicyAL() {
    if (LOGV)
        Slog.v(TAG, "readPolicyAL()");
    // clear any existing policy and read from disk
    mNetworkPolicy.clear();
    mUidPolicy.clear();
    FileInputStream fis = null;
    try {
        fis = mPolicyFile.openRead();
        final XmlPullParser in = Xml.newPullParser();
        in.setInput(fis, StandardCharsets.UTF_8.name());
        int type;
        int version = VERSION_INIT;
        boolean insideWhitelist = false;
        while ((type = in.next()) != END_DOCUMENT) {
            final String tag = in.getName();
            if (type == START_TAG) {
                if (TAG_POLICY_LIST.equals(tag)) {
                    final boolean oldValue = mRestrictBackground;
                    version = readIntAttribute(in, ATTR_VERSION);
                    if (version >= VERSION_ADDED_RESTRICT_BACKGROUND) {
                        mRestrictBackground = readBooleanAttribute(in, ATTR_RESTRICT_BACKGROUND);
                    } else {
                        mRestrictBackground = false;
                    }
                    if (mRestrictBackground != oldValue) {
                        // Some early services may have read the default value,
                        // so notify them that it's changed
                        mHandler.obtainMessage(MSG_RESTRICT_BACKGROUND_CHANGED, mRestrictBackground ? 1 : 0, 0).sendToTarget();
                    }
                } else if (TAG_NETWORK_POLICY.equals(tag)) {
                    final int networkTemplate = readIntAttribute(in, ATTR_NETWORK_TEMPLATE);
                    final String subscriberId = in.getAttributeValue(null, ATTR_SUBSCRIBER_ID);
                    final String networkId;
                    if (version >= VERSION_ADDED_NETWORK_ID) {
                        networkId = in.getAttributeValue(null, ATTR_NETWORK_ID);
                    } else {
                        networkId = null;
                    }
                    final int cycleDay = readIntAttribute(in, ATTR_CYCLE_DAY);
                    final String cycleTimezone;
                    if (version >= VERSION_ADDED_TIMEZONE) {
                        cycleTimezone = in.getAttributeValue(null, ATTR_CYCLE_TIMEZONE);
                    } else {
                        cycleTimezone = Time.TIMEZONE_UTC;
                    }
                    final long warningBytes = readLongAttribute(in, ATTR_WARNING_BYTES);
                    final long limitBytes = readLongAttribute(in, ATTR_LIMIT_BYTES);
                    final long lastLimitSnooze;
                    if (version >= VERSION_SPLIT_SNOOZE) {
                        lastLimitSnooze = readLongAttribute(in, ATTR_LAST_LIMIT_SNOOZE);
                    } else if (version >= VERSION_ADDED_SNOOZE) {
                        lastLimitSnooze = readLongAttribute(in, ATTR_LAST_SNOOZE);
                    } else {
                        lastLimitSnooze = SNOOZE_NEVER;
                    }
                    final boolean metered;
                    if (version >= VERSION_ADDED_METERED) {
                        metered = readBooleanAttribute(in, ATTR_METERED);
                    } else {
                        switch(networkTemplate) {
                            case MATCH_MOBILE_3G_LOWER:
                            case MATCH_MOBILE_4G:
                            case MATCH_MOBILE_ALL:
                                metered = true;
                                break;
                            default:
                                metered = false;
                        }
                    }
                    final long lastWarningSnooze;
                    if (version >= VERSION_SPLIT_SNOOZE) {
                        lastWarningSnooze = readLongAttribute(in, ATTR_LAST_WARNING_SNOOZE);
                    } else {
                        lastWarningSnooze = SNOOZE_NEVER;
                    }
                    final boolean inferred;
                    if (version >= VERSION_ADDED_INFERRED) {
                        inferred = readBooleanAttribute(in, ATTR_INFERRED);
                    } else {
                        inferred = false;
                    }
                    final NetworkTemplate template = new NetworkTemplate(networkTemplate, subscriberId, networkId);
                    if (template.isPersistable()) {
                        mNetworkPolicy.put(template, new NetworkPolicy(template, cycleDay, cycleTimezone, warningBytes, limitBytes, lastWarningSnooze, lastLimitSnooze, metered, inferred));
                    }
                } else if (TAG_UID_POLICY.equals(tag)) {
                    final int uid = readIntAttribute(in, ATTR_UID);
                    final int policy = readIntAttribute(in, ATTR_POLICY);
                    if (UserHandle.isApp(uid)) {
                        setUidPolicyUncheckedUL(uid, policy, false);
                    } else {
                        Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
                    }
                } else if (TAG_APP_POLICY.equals(tag)) {
                    final int appId = readIntAttribute(in, ATTR_APP_ID);
                    final int policy = readIntAttribute(in, ATTR_POLICY);
                    // TODO: set for other users during upgrade
                    // app policy is deprecated so this is only used in pre system user split.
                    final int uid = UserHandle.getUid(UserHandle.USER_SYSTEM, appId);
                    if (UserHandle.isApp(uid)) {
                        setUidPolicyUncheckedUL(uid, policy, false);
                    } else {
                        Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
                    }
                } else if (TAG_WHITELIST.equals(tag)) {
                    insideWhitelist = true;
                } else if (TAG_RESTRICT_BACKGROUND.equals(tag) && insideWhitelist) {
                    final int uid = readIntAttribute(in, ATTR_UID);
                    mRestrictBackgroundWhitelistUids.put(uid, true);
                } else if (TAG_REVOKED_RESTRICT_BACKGROUND.equals(tag) && insideWhitelist) {
                    final int uid = readIntAttribute(in, ATTR_UID);
                    mRestrictBackgroundWhitelistRevokedUids.put(uid, true);
                }
            } else if (type == END_TAG) {
                if (TAG_WHITELIST.equals(tag)) {
                    insideWhitelist = false;
                }
            }
        }
    } catch (FileNotFoundException e) {
        // missing policy is okay, probably first boot
        upgradeLegacyBackgroundDataUL();
    } catch (IOException e) {
        Log.wtf(TAG, "problem reading network policy", e);
    } catch (XmlPullParserException e) {
        Log.wtf(TAG, "problem reading network policy", e);
    } finally {
        IoUtils.closeQuietly(fis);
    }
}
Also used : NetworkTemplate(android.net.NetworkTemplate) NetworkPolicy(android.net.NetworkPolicy) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 9 with START_TAG

use of org.xmlpull.v1.XmlPullParser.START_TAG in project android_frameworks_base by AOSPA.

the class ActivityRecord method restoreFromXml.

static ActivityRecord restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor) throws IOException, XmlPullParserException {
    Intent intent = null;
    PersistableBundle persistentState = null;
    int launchedFromUid = 0;
    String launchedFromPackage = null;
    String resolvedType = null;
    boolean componentSpecified = false;
    int userId = 0;
    long createTime = -1;
    final int outerDepth = in.getDepth();
    TaskDescription taskDescription = new TaskDescription();
    for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
        final String attrName = in.getAttributeName(attrNdx);
        final String attrValue = in.getAttributeValue(attrNdx);
        if (TaskPersister.DEBUG)
            Slog.d(TaskPersister.TAG, "ActivityRecord: attribute name=" + attrName + " value=" + attrValue);
        if (ATTR_ID.equals(attrName)) {
            createTime = Long.valueOf(attrValue);
        } else if (ATTR_LAUNCHEDFROMUID.equals(attrName)) {
            launchedFromUid = Integer.parseInt(attrValue);
        } else if (ATTR_LAUNCHEDFROMPACKAGE.equals(attrName)) {
            launchedFromPackage = attrValue;
        } else if (ATTR_RESOLVEDTYPE.equals(attrName)) {
            resolvedType = attrValue;
        } else if (ATTR_COMPONENTSPECIFIED.equals(attrName)) {
            componentSpecified = Boolean.valueOf(attrValue);
        } else if (ATTR_USERID.equals(attrName)) {
            userId = Integer.parseInt(attrValue);
        } else if (attrName.startsWith(TaskDescription.ATTR_TASKDESCRIPTION_PREFIX)) {
            taskDescription.restoreFromXml(attrName, attrValue);
        } else {
            Log.d(TAG, "Unknown ActivityRecord attribute=" + attrName);
        }
    }
    int event;
    while (((event = in.next()) != XmlPullParser.END_DOCUMENT) && (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
        if (event == XmlPullParser.START_TAG) {
            final String name = in.getName();
            if (TaskPersister.DEBUG)
                Slog.d(TaskPersister.TAG, "ActivityRecord: START_TAG name=" + name);
            if (TAG_INTENT.equals(name)) {
                intent = Intent.restoreFromXml(in);
                if (TaskPersister.DEBUG)
                    Slog.d(TaskPersister.TAG, "ActivityRecord: intent=" + intent);
            } else if (TAG_PERSISTABLEBUNDLE.equals(name)) {
                persistentState = PersistableBundle.restoreFromXml(in);
                if (TaskPersister.DEBUG)
                    Slog.d(TaskPersister.TAG, "ActivityRecord: persistentState=" + persistentState);
            } else {
                Slog.w(TAG, "restoreActivity: unexpected name=" + name);
                XmlUtils.skipCurrentTag(in);
            }
        }
    }
    if (intent == null) {
        throw new XmlPullParserException("restoreActivity error intent=" + intent);
    }
    final ActivityManagerService service = stackSupervisor.mService;
    final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, userId);
    if (aInfo == null) {
        throw new XmlPullParserException("restoreActivity resolver error. Intent=" + intent + " resolvedType=" + resolvedType);
    }
    final ActivityRecord r = new ActivityRecord(service, /*caller*/
    null, launchedFromUid, launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(), null, null, 0, componentSpecified, false, stackSupervisor, null, null, null);
    r.persistentState = persistentState;
    r.taskDescription = taskDescription;
    r.createTime = createTime;
    return r;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PersistableBundle(android.os.PersistableBundle) TaskDescription(android.app.ActivityManager.TaskDescription) PendingIntent(android.app.PendingIntent) ReferrerIntent(com.android.internal.content.ReferrerIntent) Intent(android.content.Intent) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 10 with START_TAG

use of org.xmlpull.v1.XmlPullParser.START_TAG in project android by JetBrains.

the class LayoutPsiPullParserTest method compareParsers.

private void compareParsers(PsiFile file, NextEventType nextEventType) throws Exception {
    assertTrue(file instanceof XmlFile);
    XmlFile xmlFile = (XmlFile) file;
    KXmlParser referenceParser = createReferenceParser(file);
    LayoutPsiPullParser parser = LayoutPsiPullParser.create(xmlFile, new RenderLogger("test", myModule));
    assertEquals("Expected " + name(referenceParser.getEventType()) + " but was " + name(parser.getEventType()) + " (at line:column " + describePosition(referenceParser) + ")", referenceParser.getEventType(), parser.getEventType());
    while (true) {
        int expected, next;
        switch(nextEventType) {
            case NEXT:
                expected = referenceParser.next();
                next = parser.next();
                break;
            case NEXT_TOKEN:
                expected = referenceParser.nextToken();
                next = parser.nextToken();
                break;
            case NEXT_TAG:
                {
                    try {
                        expected = referenceParser.nextTag();
                    } catch (Exception e) {
                        expected = referenceParser.getEventType();
                    }
                    try {
                        next = parser.nextTag();
                    } catch (Exception e) {
                        next = parser.getEventType();
                    }
                    break;
                }
            default:
                throw new AssertionError("Unexpected type");
        }
        PsiElement element = null;
        if (expected == START_TAG) {
            assertNotNull(parser.getViewCookie());
            assertTrue(parser.getViewCookie() instanceof TagSnapshot);
            element = ((TagSnapshot) parser.getViewCookie()).tag;
        }
        if (expected == START_TAG) {
            assertEquals(referenceParser.getName(), parser.getName());
            if (element != xmlFile.getRootTag()) {
                // KXmlParser seems to not include xmlns: attributes on the root tag!{
                SortedSet<String> referenceAttributes = new TreeSet<>();
                SortedSet<String> attributes = new TreeSet<>();
                for (int i = 0; i < referenceParser.getAttributeCount(); i++) {
                    String s = referenceParser.getAttributePrefix(i) + ':' + referenceParser.getAttributeName(i) + '=' + referenceParser.getAttributeValue(i);
                    referenceAttributes.add(s);
                }
                for (int i = 0; i < parser.getAttributeCount(); i++) {
                    String s = parser.getAttributePrefix(i) + ':' + parser.getAttributeName(i) + '=' + parser.getAttributeValue(i);
                    attributes.add(s);
                    if (parser.getAttributeNamespace(i) != null) {
                        //noinspection ConstantConditions
                        assertEquals(normalizeValue(parser.getAttributeValue(i)), normalizeValue(parser.getAttributeValue(parser.getAttributeNamespace(i), parser.getAttributeName(i))));
                    }
                }
                assertEquals(referenceAttributes, attributes);
            }
            if (element instanceof XmlTag) {
                XmlTag tag = (XmlTag) element;
                for (XmlAttribute attribute : tag.getAttributes()) {
                    String namespace = attribute.getNamespace();
                    String name = attribute.getLocalName();
                    if (namespace.isEmpty()) {
                        String prefix = attribute.getNamespacePrefix();
                        if (!prefix.isEmpty()) {
                            name = prefix + ":" + prefix;
                        }
                    }
                    //noinspection ConstantConditions
                    assertEquals(namespace + ':' + name + " in element " + parser.getName(), normalizeValue(referenceParser.getAttributeValue(namespace, name)), normalizeValue(parser.getAttributeValue(namespace, name)));
                }
            }
        } else if (expected == XmlPullParser.TEXT || expected == XmlPullParser.COMMENT) {
            assertEquals(StringUtil.notNullize(referenceParser.getText()).trim(), StringUtil.notNullize(parser.getText()).trim());
        }
        if (expected != next) {
            assertEquals("Expected " + name(expected) + " but was " + name(next) + "(At " + describePosition(referenceParser) + ")", expected, next);
        }
        if (expected == XmlPullParser.END_DOCUMENT) {
            break;
        }
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) KXmlParser(org.kxml2.io.KXmlParser) TreeSet(java.util.TreeSet) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlPullParserException (org.xmlpull.v1.XmlPullParserException)41 XmlPullParser (org.xmlpull.v1.XmlPullParser)28 IOException (java.io.IOException)25 FileNotFoundException (java.io.FileNotFoundException)24 FileInputStream (java.io.FileInputStream)19 NetworkPolicy (android.net.NetworkPolicy)6 NetworkTemplate (android.net.NetworkTemplate)6 TaskDescription (android.app.ActivityManager.TaskDescription)5 PendingIntent (android.app.PendingIntent)5 Intent (android.content.Intent)5 ActivityInfo (android.content.pm.ActivityInfo)5 IPackageInstallerSession (android.content.pm.IPackageInstallerSession)5 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)5 PersistableBundle (android.os.PersistableBundle)5 VolumeRecord (android.os.storage.VolumeRecord)5 ArraySet (android.util.ArraySet)5 AtomicFile (android.util.AtomicFile)5 ReferrerIntent (com.android.internal.content.ReferrerIntent)5 BufferedReader (java.io.BufferedReader)5 File (java.io.File)5