Search in sources :

Example 11 with START_TAG

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

the class LayoutPullParser method nextText.

@Override
public String nextText() throws XmlPullParserException {
    if (getEventType() != START_TAG) {
        throw new XmlPullParserException("parser must be on START_TAG to read next text", this, null);
    }
    int eventType = next();
    if (eventType == TEXT) {
        String result = getText();
        eventType = next();
        if (eventType != END_TAG) {
            throw new XmlPullParserException("event TEXT it must be immediately followed by END_TAG", this, null);
        }
        return result;
    } else if (eventType == END_TAG) {
        return "";
    } else {
        throw new XmlPullParserException("parser must be on START_TAG or TEXT to read text", this, null);
    }
}
Also used : XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 12 with START_TAG

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

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 13 with START_TAG

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

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 14 with START_TAG

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

the class BridgeXmlBlockParser method nextText.

@Override
public String nextText() throws XmlPullParserException, IOException {
    if (getEventType() != START_TAG) {
        throw new XmlPullParserException(getPositionDescription() + ": parser must be on START_TAG to read next text", this, null);
    }
    int eventType = next();
    if (eventType == TEXT) {
        String result = getText();
        eventType = next();
        if (eventType != END_TAG) {
            throw new XmlPullParserException(getPositionDescription() + ": event TEXT it must be immediately followed by END_TAG", this, null);
        }
        return result;
    } else if (eventType == END_TAG) {
        return "";
    } else {
        throw new XmlPullParserException(getPositionDescription() + ": parser must be on START_TAG or TEXT to read text", this, null);
    }
}
Also used : XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 15 with START_TAG

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

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)

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