Search in sources :

Example 31 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.

the class InputManagerService method getExcludedDeviceNames.

// Native callback.
private String[] getExcludedDeviceNames() {
    ArrayList<String> names = new ArrayList<String>();
    // Read partner-provided list of excluded input devices
    XmlPullParser parser = null;
    // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
    File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
    FileReader confreader = null;
    try {
        confreader = new FileReader(confFile);
        parser = Xml.newPullParser();
        parser.setInput(confreader);
        XmlUtils.beginDocument(parser, "devices");
        while (true) {
            XmlUtils.nextElement(parser);
            if (!"device".equals(parser.getName())) {
                break;
            }
            String name = parser.getAttributeValue(null, "name");
            if (name != null) {
                names.add(name);
            }
        }
    } catch (FileNotFoundException e) {
    // It's ok if the file does not exist.
    } catch (Exception e) {
        Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
    } finally {
        try {
            if (confreader != null)
                confreader.close();
        } catch (IOException e) {
        }
    }
    return names.toArray(new String[names.size()]);
}
Also used : ArrayList(java.util.ArrayList) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 32 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.

the class PackageManagerService method restorePreferredActivities.

@Override
public void restorePreferredActivities(byte[] backup, int userId) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        throw new SecurityException("Only the system may call restorePreferredActivities()");
    }
    try {
        final XmlPullParser parser = Xml.newPullParser();
        parser.setInput(new ByteArrayInputStream(backup), StandardCharsets.UTF_8.name());
        restoreFromXml(parser, userId, TAG_PREFERRED_BACKUP, new BlobXmlRestorer() {

            @Override
            public void apply(XmlPullParser parser, int userId) throws XmlPullParserException, IOException {
                synchronized (mPackages) {
                    mSettings.readPreferredActivitiesLPw(parser, userId);
                }
            }
        });
    } catch (Exception e) {
        if (DEBUG_BACKUP) {
            Slog.e(TAG, "Exception restoring preferred activities: " + e.getMessage());
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) CertificateEncodingException(java.security.cert.CertificateEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PackageParserException(android.content.pm.PackageParser.PackageParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InstallerException(com.android.server.pm.Installer.InstallerException) SendIntentException(android.content.IntentSender.SendIntentException) FileNotFoundException(java.io.FileNotFoundException) CertificateException(java.security.cert.CertificateException)

Example 33 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.

the class PackageManagerService method restorePermissionGrants.

@Override
public void restorePermissionGrants(byte[] backup, int userId) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        throw new SecurityException("Only the system may call restorePermissionGrants()");
    }
    try {
        final XmlPullParser parser = Xml.newPullParser();
        parser.setInput(new ByteArrayInputStream(backup), StandardCharsets.UTF_8.name());
        restoreFromXml(parser, userId, TAG_PERMISSION_BACKUP, new BlobXmlRestorer() {

            @Override
            public void apply(XmlPullParser parser, int userId) throws XmlPullParserException, IOException {
                synchronized (mPackages) {
                    processRestoredPermissionGrantsLPr(parser, userId);
                }
            }
        });
    } catch (Exception e) {
        if (DEBUG_BACKUP) {
            Slog.e(TAG, "Exception restoring preferred activities: " + e.getMessage());
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) CertificateEncodingException(java.security.cert.CertificateEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PackageParserException(android.content.pm.PackageParser.PackageParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InstallerException(com.android.server.pm.Installer.InstallerException) SendIntentException(android.content.IntentSender.SendIntentException) FileNotFoundException(java.io.FileNotFoundException) CertificateException(java.security.cert.CertificateException)

Example 34 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.

the class BootReceiver method readTimestamps.

private static HashMap<String, Long> readTimestamps() {
    synchronized (sFile) {
        HashMap<String, Long> timestamps = new HashMap<String, Long>();
        boolean success = false;
        try (final FileInputStream stream = sFile.openRead()) {
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(stream, StandardCharsets.UTF_8.name());
            int type;
            while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                ;
            }
            if (type != XmlPullParser.START_TAG) {
                throw new IllegalStateException("no start tag found");
            }
            // Skip the outer <log-files> tag.
            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("log")) {
                    final String filename = parser.getAttributeValue(null, "filename");
                    final long timestamp = Long.valueOf(parser.getAttributeValue(null, "timestamp"));
                    timestamps.put(filename, timestamp);
                } else {
                    Slog.w(TAG, "Unknown tag: " + parser.getName());
                    XmlUtils.skipCurrentTag(parser);
                }
            }
            success = true;
        } catch (FileNotFoundException e) {
            Slog.i(TAG, "No existing last log timestamp file " + sFile.getBaseFile() + "; starting empty");
        } catch (IOException e) {
            Slog.w(TAG, "Failed parsing " + e);
        } catch (IllegalStateException e) {
            Slog.w(TAG, "Failed parsing " + e);
        } catch (NullPointerException e) {
            Slog.w(TAG, "Failed parsing " + e);
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Failed parsing " + e);
        } finally {
            if (!success) {
                timestamps.clear();
            }
        }
        return timestamps;
    }
}
Also used : HashMap(java.util.HashMap) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 35 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project platform_frameworks_base by android.

the class SettingsState method readStateSyncLocked.

private void readStateSyncLocked() {
    FileInputStream in;
    if (!mStatePersistFile.exists()) {
        Slog.i(LOG_TAG, "No settings state " + mStatePersistFile);
        addHistoricalOperationLocked(HISTORICAL_OPERATION_INITIALIZE, null);
        return;
    }
    try {
        in = new AtomicFile(mStatePersistFile).openRead();
    } catch (FileNotFoundException fnfe) {
        String message = "No settings state " + mStatePersistFile;
        Slog.wtf(LOG_TAG, message);
        Slog.i(LOG_TAG, message);
        return;
    }
    try {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(in, StandardCharsets.UTF_8.name());
        parseStateLocked(parser);
    } catch (XmlPullParserException | IOException e) {
        String message = "Failed parsing settings file: " + mStatePersistFile;
        Slog.wtf(LOG_TAG, message);
        throw new IllegalStateException(message, e);
    } finally {
        IoUtils.closeQuietly(in);
    }
}
Also used : AtomicFile(android.util.AtomicFile) FileNotFoundException(java.io.FileNotFoundException) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)673 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)623 IOException (java.io.IOException)377 FileInputStream (java.io.FileInputStream)185 FileNotFoundException (java.io.FileNotFoundException)185 File (java.io.File)107 ArrayList (java.util.ArrayList)77 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)45 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)30 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28