Search in sources :

Example 61 with XmlPullParserException

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

the class AppIdleHistory method readAppIdleTimesLocked.

private void readAppIdleTimesLocked(int userId, ArrayMap<String, PackageHistory> userHistory) {
    FileInputStream fis = null;
    try {
        AtomicFile appIdleFile = new AtomicFile(getUserFile(userId));
        fis = appIdleFile.openRead();
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(fis, StandardCharsets.UTF_8.name());
        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
        // Skip
        }
        if (type != XmlPullParser.START_TAG) {
            Slog.e(TAG, "Unable to read app idle file for user " + userId);
            return;
        }
        if (!parser.getName().equals(TAG_PACKAGES)) {
            return;
        }
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
            if (type == XmlPullParser.START_TAG) {
                final String name = parser.getName();
                if (name.equals(TAG_PACKAGE)) {
                    final String packageName = parser.getAttributeValue(null, ATTR_NAME);
                    PackageHistory packageHistory = new PackageHistory();
                    packageHistory.lastUsedElapsedTime = Long.parseLong(parser.getAttributeValue(null, ATTR_ELAPSED_IDLE));
                    packageHistory.lastUsedScreenTime = Long.parseLong(parser.getAttributeValue(null, ATTR_SCREEN_IDLE));
                    userHistory.put(packageName, packageHistory);
                }
            }
        }
    } catch (IOException | XmlPullParserException e) {
        Slog.e(TAG, "Unable to read app idle file for user " + userId);
    } finally {
        IoUtils.closeQuietly(fis);
    }
}
Also used : AtomicFile(android.util.AtomicFile) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 62 with XmlPullParserException

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

the class SimpleInflater method inflate.

public void inflate(int menuRes) {
    XmlResourceParser parser = null;
    try {
        parser = mContext.getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException e) {
        throw new InflateException("Error inflating menu XML", e);
    } catch (IOException e) {
        throw new InflateException("Error inflating menu XML", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 63 with XmlPullParserException

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

the class AudioService method loadTouchSoundAssets.

private void loadTouchSoundAssets() {
    XmlResourceParser parser = null;
    // only load assets once.
    if (!SOUND_EFFECT_FILES.isEmpty()) {
        return;
    }
    loadTouchSoundAssetDefaults();
    try {
        parser = mContext.getResources().getXml(com.android.internal.R.xml.audio_assets);
        XmlUtils.beginDocument(parser, TAG_AUDIO_ASSETS);
        String version = parser.getAttributeValue(null, ATTR_VERSION);
        boolean inTouchSoundsGroup = false;
        if (ASSET_FILE_VERSION.equals(version)) {
            while (true) {
                XmlUtils.nextElement(parser);
                String element = parser.getName();
                if (element == null) {
                    break;
                }
                if (element.equals(TAG_GROUP)) {
                    String name = parser.getAttributeValue(null, ATTR_GROUP_NAME);
                    if (GROUP_TOUCH_SOUNDS.equals(name)) {
                        inTouchSoundsGroup = true;
                        break;
                    }
                }
            }
            while (inTouchSoundsGroup) {
                XmlUtils.nextElement(parser);
                String element = parser.getName();
                if (element == null) {
                    break;
                }
                if (element.equals(TAG_ASSET)) {
                    String id = parser.getAttributeValue(null, ATTR_ASSET_ID);
                    String file = parser.getAttributeValue(null, ATTR_ASSET_FILE);
                    int fx;
                    try {
                        Field field = AudioManager.class.getField(id);
                        fx = field.getInt(null);
                    } catch (Exception e) {
                        Log.w(TAG, "Invalid touch sound ID: " + id);
                        continue;
                    }
                    int i = SOUND_EFFECT_FILES.indexOf(file);
                    if (i == -1) {
                        i = SOUND_EFFECT_FILES.size();
                        SOUND_EFFECT_FILES.add(file);
                    }
                    SOUND_EFFECT_FILES_MAP[fx][0] = i;
                } else {
                    break;
                }
            }
        }
    } catch (Resources.NotFoundException e) {
        Log.w(TAG, "audio assets file not found", e);
    } catch (XmlPullParserException e) {
        Log.w(TAG, "XML parser exception reading touch sound assets", e);
    } catch (IOException e) {
        Log.w(TAG, "I/O exception reading touch sound assets", e);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
Also used : Field(java.lang.reflect.Field) XmlResourceParser(android.content.res.XmlResourceParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) AndroidRuntimeException(android.util.AndroidRuntimeException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NoSuchElementException(java.util.NoSuchElementException)

Example 64 with XmlPullParserException

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

the class NotificationManagerService method readPolicyXml.

private void readPolicyXml(InputStream stream, boolean forRestore) throws XmlPullParserException, NumberFormatException, IOException {
    final XmlPullParser parser = Xml.newPullParser();
    parser.setInput(stream, StandardCharsets.UTF_8.name());
    while (parser.next() != END_DOCUMENT) {
        mZenModeHelper.readXml(parser, forRestore);
        mRankingHelper.readXml(parser, forRestore);
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 65 with XmlPullParserException

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

the class NotificationManagerService method loadPolicyFile.

private void loadPolicyFile() {
    if (DBG)
        Slog.d(TAG, "loadPolicyFile");
    synchronized (mPolicyFile) {
        FileInputStream infile = null;
        try {
            infile = mPolicyFile.openRead();
            readPolicyXml(infile, false);
        } catch (FileNotFoundException e) {
        // No data yet
        } catch (IOException e) {
            Log.wtf(TAG, "Unable to read notification policy", e);
        } catch (NumberFormatException e) {
            Log.wtf(TAG, "Unable to parse notification policy", e);
        } catch (XmlPullParserException e) {
            Log.wtf(TAG, "Unable to parse notification policy", e);
        } finally {
            IoUtils.closeQuietly(infile);
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

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