Search in sources :

Example 26 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.

the class StackOverflowXmlParser method parse.

// We don't use namespaces
public List<Entry> parse(InputStream in) throws XmlPullParserException, IOException {
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(in, null);
        parser.nextTag();
        return readFeed(parser);
    } finally {
        in.close();
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 27 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.

the class ConnectivityService method getProvisioningUrlBaseFromFile.

private String getProvisioningUrlBaseFromFile(int type) {
    FileReader fileReader = null;
    XmlPullParser parser = null;
    Configuration config = mContext.getResources().getConfiguration();
    String tagType;
    switch(type) {
        case PROVISIONING:
            tagType = TAG_PROVISIONING_URL;
            break;
        case REDIRECTED_PROVISIONING:
            tagType = TAG_REDIRECTED_URL;
            break;
        default:
            throw new RuntimeException("getProvisioningUrlBaseFromFile: Unexpected parameter " + type);
    }
    try {
        fileReader = new FileReader(mProvisioningUrlFile);
        parser = Xml.newPullParser();
        parser.setInput(fileReader);
        XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);
        while (true) {
            XmlUtils.nextElement(parser);
            String element = parser.getName();
            if (element == null)
                break;
            if (element.equals(tagType)) {
                String mcc = parser.getAttributeValue(null, ATTR_MCC);
                try {
                    if (mcc != null && Integer.parseInt(mcc) == config.mcc) {
                        String mnc = parser.getAttributeValue(null, ATTR_MNC);
                        if (mnc != null && Integer.parseInt(mnc) == config.mnc) {
                            parser.next();
                            if (parser.getEventType() == XmlPullParser.TEXT) {
                                return parser.getText();
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                    loge("NumberFormatException in getProvisioningUrlBaseFromFile: " + e);
                }
            }
        }
        return null;
    } catch (FileNotFoundException e) {
        loge("Carrier Provisioning Urls file not found");
    } catch (XmlPullParserException e) {
        loge("Xml parser exception reading Carrier Provisioning Urls file: " + e);
    } catch (IOException e) {
        loge("I/O exception reading Carrier Provisioning Urls file: " + e);
    } finally {
        if (fileReader != null) {
            try {
                fileReader.close();
            } catch (IOException e) {
            }
        }
    }
    return null;
}
Also used : Configuration(android.content.res.Configuration) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 28 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.

the class UsageStatsService method readHistoryStatsFLOCK.

private void readHistoryStatsFLOCK(AtomicFile file) {
    FileInputStream fis = null;
    try {
        fis = mHistoryFile.openRead();
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(fis, null);
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.START_TAG) {
            eventType = parser.next();
        }
        String tagName = parser.getName();
        if ("usage-history".equals(tagName)) {
            String pkg = null;
            do {
                eventType = parser.next();
                if (eventType == XmlPullParser.START_TAG) {
                    tagName = parser.getName();
                    int depth = parser.getDepth();
                    if ("pkg".equals(tagName) && depth == 2) {
                        pkg = parser.getAttributeValue(null, "name");
                    } else if ("comp".equals(tagName) && depth == 3 && pkg != null) {
                        String comp = parser.getAttributeValue(null, "name");
                        String lastResumeTimeStr = parser.getAttributeValue(null, "lrt");
                        if (comp != null && lastResumeTimeStr != null) {
                            try {
                                long lastResumeTime = Long.parseLong(lastResumeTimeStr);
                                synchronized (mStatsLock) {
                                    Map<String, Long> lrt = mLastResumeTimes.get(pkg);
                                    if (lrt == null) {
                                        lrt = new HashMap<String, Long>();
                                        mLastResumeTimes.put(pkg, lrt);
                                    }
                                    lrt.put(comp, lastResumeTime);
                                }
                            } catch (NumberFormatException e) {
                            }
                        }
                    }
                } else if (eventType == XmlPullParser.END_TAG) {
                    if ("pkg".equals(parser.getName())) {
                        pkg = null;
                    }
                }
            } while (eventType != XmlPullParser.END_DOCUMENT);
        }
    } catch (XmlPullParserException e) {
        Slog.w(TAG, "Error reading history stats: " + e);
    } catch (IOException e) {
        Slog.w(TAG, "Error reading history stats: " + e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 29 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.

the class Settings method readStoppedLPw.

// Note: assumed "stopped" field is already cleared in all packages.
// Legacy reader, used to read in the old file format after an upgrade. Not used after that.
void readStoppedLPw() {
    FileInputStream str = null;
    if (mBackupStoppedPackagesFilename.exists()) {
        try {
            str = new FileInputStream(mBackupStoppedPackagesFilename);
            mReadMessages.append("Reading from backup stopped packages file\n");
            PackageManagerService.reportSettingsProblem(Log.INFO, "Need to read from backup stopped packages file");
            if (mSettingsFilename.exists()) {
                // If both the backup and normal file exist, we
                // ignore the normal one since it might have been
                // corrupted.
                Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file " + mStoppedPackagesFilename);
                mStoppedPackagesFilename.delete();
            }
        } catch (java.io.IOException e) {
        // We'll try for the normal settings file.
        }
    }
    try {
        if (str == null) {
            if (!mStoppedPackagesFilename.exists()) {
                mReadMessages.append("No stopped packages file found\n");
                PackageManagerService.reportSettingsProblem(Log.INFO, "No stopped packages file file; assuming all started");
                // in the stopped state, but not at first boot.
                for (PackageSetting pkg : mPackages.values()) {
                    pkg.setStopped(false, 0);
                    pkg.setNotLaunched(false, 0);
                }
                return;
            }
            str = new FileInputStream(mStoppedPackagesFilename);
        }
        final XmlPullParser parser = Xml.newPullParser();
        parser.setInput(str, null);
        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
            ;
        }
        if (type != XmlPullParser.START_TAG) {
            mReadMessages.append("No start tag found in stopped packages file\n");
            PackageManagerService.reportSettingsProblem(Log.WARN, "No start tag found in package manager stopped packages");
            return;
        }
        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;
            }
            String tagName = parser.getName();
            if (tagName.equals(TAG_PACKAGE)) {
                String name = parser.getAttributeValue(null, ATTR_NAME);
                PackageSetting ps = mPackages.get(name);
                if (ps != null) {
                    ps.setStopped(true, 0);
                    if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) {
                        ps.setNotLaunched(true, 0);
                    }
                } else {
                    Slog.w(PackageManagerService.TAG, "No package known for stopped package: " + name);
                }
                XmlUtils.skipCurrentTag(parser);
            } else {
                Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: " + parser.getName());
                XmlUtils.skipCurrentTag(parser);
            }
        }
        str.close();
    } catch (XmlPullParserException e) {
        mReadMessages.append("Error reading: " + e.toString());
        PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading stopped packages: " + e);
        Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
    } catch (java.io.IOException e) {
        mReadMessages.append("Error reading: " + e.toString());
        PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
        Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) FileInputStream(java.io.FileInputStream)

Example 30 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project android_frameworks_base by ParanoidAndroid.

the class Settings method readDefaultPreferredAppsLPw.

void readDefaultPreferredAppsLPw(PackageManagerService service, int userId) {
    // Read preferred apps from .../etc/preferred-apps directory.
    File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps");
    if (!preferredDir.exists() || !preferredDir.isDirectory()) {
        return;
    }
    if (!preferredDir.canRead()) {
        Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
        return;
    }
    // Iterate over the files in the directory and scan .xml files
    for (File f : preferredDir.listFiles()) {
        if (!f.getPath().endsWith(".xml")) {
            Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
            continue;
        }
        if (!f.canRead()) {
            Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
            continue;
        }
        if (PackageManagerService.DEBUG_PREFERRED)
            Log.d(TAG, "Reading default preferred " + f);
        FileInputStream str = null;
        try {
            str = new FileInputStream(f);
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(str, null);
            int type;
            while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                ;
            }
            if (type != XmlPullParser.START_TAG) {
                Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
                continue;
            }
            if (!"preferred-activities".equals(parser.getName())) {
                Slog.w(TAG, "Preferred apps file " + f + " does not start with 'preferred-activities'");
                continue;
            }
            readDefaultPreferredActivitiesLPw(service, parser, userId);
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Error reading apps file " + f, e);
        } catch (IOException e) {
            Slog.w(TAG, "Error reading apps file " + f, e);
        } finally {
            if (str != null) {
                try {
                    str.close();
                } catch (IOException e) {
                }
            }
        }
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) File(java.io.File) JournaledFile(com.android.internal.util.JournaledFile) FileInputStream(java.io.FileInputStream)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)665 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)614 IOException (java.io.IOException)376 FileNotFoundException (java.io.FileNotFoundException)185 FileInputStream (java.io.FileInputStream)184 File (java.io.File)107 ArrayList (java.util.ArrayList)75 StringReader (java.io.StringReader)65 AttributeSet (android.util.AttributeSet)61 Test (org.junit.Test)57 TypedArray (android.content.res.TypedArray)56 InputStream (java.io.InputStream)48 AtomicFile (android.util.AtomicFile)47 HashMap (java.util.HashMap)42 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)29 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28