Search in sources :

Example 46 with XmlPullParserException

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

the class ParserFactory method readAndClose.

@NonNull
private static InputStream readAndClose(@NonNull InputStream stream, @Nullable String name, long size) throws XmlPullParserException {
    // just a sanity check. It's doubtful we'll have such big files!
    if (size > Integer.MAX_VALUE) {
        throw new XmlPullParserException("File " + name + " is too big to be parsed");
    }
    int intSize = (int) size;
    // create a buffered reader to facilitate reading.
    BufferedInputStream bufferedStream = new BufferedInputStream(stream);
    try {
        int avail;
        if (intSize != -1) {
            avail = intSize;
        } else {
            // get the size to read.
            avail = bufferedStream.available();
        }
        // create the initial buffer and read it.
        byte[] buffer = new byte[avail];
        int read = stream.read(buffer);
        // this is the easy case.
        if (read == intSize) {
            return new ByteArrayInputStream(buffer);
        }
        // available() returned!)
        while ((avail = bufferedStream.available()) > 0) {
            if (read + avail > buffer.length) {
                // just allocate what is needed. We're mostly reading small files
                // so it shouldn't be too problematic.
                byte[] moreBuffer = new byte[read + avail];
                System.arraycopy(buffer, 0, moreBuffer, 0, read);
                buffer = moreBuffer;
            }
            read += stream.read(buffer, read, avail);
        }
        // return a new stream encapsulating this buffer.
        return new ByteArrayInputStream(buffer);
    } catch (IOException e) {
        throw new XmlPullParserException("Failed to read " + name, null, e);
    } finally {
        try {
            bufferedStream.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) NonNull(android.annotation.NonNull)

Example 47 with XmlPullParserException

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

the class PersistentDataStore method load.

private void load() {
    clearState();
    final InputStream is;
    try {
        is = mAtomicFile.openRead();
    } catch (FileNotFoundException ex) {
        return;
    }
    XmlPullParser parser;
    try {
        parser = Xml.newPullParser();
        parser.setInput(new BufferedInputStream(is), StandardCharsets.UTF_8.name());
        loadFromXml(parser);
    } catch (IOException ex) {
        Slog.w(InputManagerService.TAG, "Failed to load input manager persistent store data.", ex);
        clearState();
    } catch (XmlPullParserException ex) {
        Slog.w(InputManagerService.TAG, "Failed to load input manager persistent store data.", ex);
        clearState();
    } finally {
        IoUtils.closeQuietly(is);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 48 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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 49 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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 50 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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)

Aggregations

XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1071 IOException (java.io.IOException)630 XmlPullParser (org.xmlpull.v1.XmlPullParser)440 FileNotFoundException (java.io.FileNotFoundException)187 XmlResourceParser (android.content.res.XmlResourceParser)186 FileInputStream (java.io.FileInputStream)182 AttributeSet (android.util.AttributeSet)159 TypedArray (android.content.res.TypedArray)156 Resources (android.content.res.Resources)101 File (java.io.File)101 ArrayList (java.util.ArrayList)99 PackageManager (android.content.pm.PackageManager)62 HashMap (java.util.HashMap)58 ComponentName (android.content.ComponentName)57 InputStream (java.io.InputStream)57 Intent (android.content.Intent)54 XmlSerializer (org.xmlpull.v1.XmlSerializer)54 AtomicFile (android.util.AtomicFile)50 BufferedInputStream (java.io.BufferedInputStream)44 TypedValue (android.util.TypedValue)43