Search in sources :

Example 26 with XmlPullParserException

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

the class UserManagerService method readUserLP.

private UserData readUserLP(int id) {
    int flags = 0;
    int serialNumber = id;
    String name = null;
    String account = null;
    String iconPath = null;
    long creationTime = 0L;
    long lastLoggedInTime = 0L;
    String lastLoggedInFingerprint = null;
    int profileGroupId = UserInfo.NO_PROFILE_GROUP_ID;
    int restrictedProfileParentId = UserInfo.NO_PROFILE_GROUP_ID;
    boolean partial = false;
    boolean guestToRemove = false;
    boolean persistSeedData = false;
    String seedAccountName = null;
    String seedAccountType = null;
    PersistableBundle seedAccountOptions = null;
    Bundle baseRestrictions = new Bundle();
    Bundle localRestrictions = new Bundle();
    FileInputStream fis = null;
    try {
        AtomicFile userFile = new AtomicFile(new File(mUsersDir, Integer.toString(id) + XML_SUFFIX));
        fis = userFile.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(LOG_TAG, "Unable to read user " + id);
            return null;
        }
        if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_USER)) {
            int storedId = readIntAttribute(parser, ATTR_ID, -1);
            if (storedId != id) {
                Slog.e(LOG_TAG, "User id does not match the file name");
                return null;
            }
            serialNumber = readIntAttribute(parser, ATTR_SERIAL_NO, id);
            flags = readIntAttribute(parser, ATTR_FLAGS, 0);
            iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH);
            creationTime = readLongAttribute(parser, ATTR_CREATION_TIME, 0);
            lastLoggedInTime = readLongAttribute(parser, ATTR_LAST_LOGGED_IN_TIME, 0);
            lastLoggedInFingerprint = parser.getAttributeValue(null, ATTR_LAST_LOGGED_IN_FINGERPRINT);
            profileGroupId = readIntAttribute(parser, ATTR_PROFILE_GROUP_ID, UserInfo.NO_PROFILE_GROUP_ID);
            restrictedProfileParentId = readIntAttribute(parser, ATTR_RESTRICTED_PROFILE_PARENT_ID, UserInfo.NO_PROFILE_GROUP_ID);
            String valueString = parser.getAttributeValue(null, ATTR_PARTIAL);
            if ("true".equals(valueString)) {
                partial = true;
            }
            valueString = parser.getAttributeValue(null, ATTR_GUEST_TO_REMOVE);
            if ("true".equals(valueString)) {
                guestToRemove = true;
            }
            seedAccountName = parser.getAttributeValue(null, ATTR_SEED_ACCOUNT_NAME);
            seedAccountType = parser.getAttributeValue(null, ATTR_SEED_ACCOUNT_TYPE);
            if (seedAccountName != null || seedAccountType != null) {
                persistSeedData = true;
            }
            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 tag = parser.getName();
                if (TAG_NAME.equals(tag)) {
                    type = parser.next();
                    if (type == XmlPullParser.TEXT) {
                        name = parser.getText();
                    }
                } else if (TAG_RESTRICTIONS.equals(tag)) {
                    UserRestrictionsUtils.readRestrictions(parser, baseRestrictions);
                } else if (TAG_DEVICE_POLICY_RESTRICTIONS.equals(tag)) {
                    UserRestrictionsUtils.readRestrictions(parser, localRestrictions);
                } else if (TAG_ACCOUNT.equals(tag)) {
                    type = parser.next();
                    if (type == XmlPullParser.TEXT) {
                        account = parser.getText();
                    }
                } else if (TAG_SEED_ACCOUNT_OPTIONS.equals(tag)) {
                    seedAccountOptions = PersistableBundle.restoreFromXml(parser);
                    persistSeedData = true;
                }
            }
        }
        // Create the UserInfo object that gets passed around
        UserInfo userInfo = new UserInfo(id, name, iconPath, flags);
        userInfo.serialNumber = serialNumber;
        userInfo.creationTime = creationTime;
        userInfo.lastLoggedInTime = lastLoggedInTime;
        userInfo.lastLoggedInFingerprint = lastLoggedInFingerprint;
        userInfo.partial = partial;
        userInfo.guestToRemove = guestToRemove;
        userInfo.profileGroupId = profileGroupId;
        userInfo.restrictedProfileParentId = restrictedProfileParentId;
        // Create the UserData object that's internal to this class
        UserData userData = new UserData();
        userData.info = userInfo;
        userData.account = account;
        userData.seedAccountName = seedAccountName;
        userData.seedAccountType = seedAccountType;
        userData.persistSeedData = persistSeedData;
        userData.seedAccountOptions = seedAccountOptions;
        synchronized (mRestrictionsLock) {
            mBaseUserRestrictions.put(id, baseRestrictions);
            mDevicePolicyLocalUserRestrictions.put(id, localRestrictions);
        }
        return userData;
    } catch (IOException ioe) {
    } catch (XmlPullParserException pe) {
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
            }
        }
    }
    return null;
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) XmlPullParser(org.xmlpull.v1.XmlPullParser) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PersistableBundle(android.os.PersistableBundle) AtomicFile(android.util.AtomicFile) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 27 with XmlPullParserException

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

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);
        Slog.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);
        Slog.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 28 with XmlPullParserException

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

the class ShortcutService method loadUserInternal.

private ShortcutUser loadUserInternal(@UserIdInt int userId, InputStream is, boolean fromBackup) throws XmlPullParserException, IOException, InvalidFileFormatException {
    final BufferedInputStream bis = new BufferedInputStream(is);
    ShortcutUser ret = null;
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(bis, StandardCharsets.UTF_8.name());
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        final int depth = parser.getDepth();
        final String tag = parser.getName();
        if (DEBUG_LOAD) {
            Slog.d(TAG, String.format("depth=%d type=%d name=%s", depth, type, tag));
        }
        if ((depth == 1) && ShortcutUser.TAG_ROOT.equals(tag)) {
            ret = ShortcutUser.loadFromXml(this, parser, userId, fromBackup);
            continue;
        }
        throwForInvalidTag(depth, tag);
    }
    return ret;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 29 with XmlPullParserException

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

the class ShortcutService method getBackupPayload.

@Override
public byte[] getBackupPayload(@UserIdInt int userId) {
    enforceSystem();
    if (DEBUG) {
        Slog.d(TAG, "Backing up user " + userId);
    }
    synchronized (mLock) {
        if (!isUserUnlockedL(userId)) {
            wtf("Can't backup: user " + userId + " is locked or not running");
            return null;
        }
        final ShortcutUser user = getUserShortcutsLocked(userId);
        if (user == null) {
            wtf("Can't backup: user not found: id=" + userId);
            return null;
        }
        // Update the signatures for all packages.
        user.forAllPackageItems(spi -> spi.refreshPackageSignatureAndSave());
        // Set the version code for the launchers.
        // We shouldn't do this for publisher packages, because we don't want to update the
        // version code without rescanning the manifest.
        user.forAllLaunchers(launcher -> launcher.ensureVersionInfo());
        // Save to the filesystem.
        scheduleSaveUser(userId);
        saveDirtyInfo();
        // Then create the backup payload.
        final ByteArrayOutputStream os = new ByteArrayOutputStream(32 * 1024);
        try {
            saveUserInternalLocked(userId, os, /* forBackup */
            true);
        } catch (XmlPullParserException | IOException e) {
            // Shouldn't happen.
            Slog.w(TAG, "Backup failed.", e);
            return null;
        }
        return os.toByteArray();
    }
}
Also used : XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 30 with XmlPullParserException

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

the class ShortcutService method loadBaseStateLocked.

private void loadBaseStateLocked() {
    mRawLastResetTime = 0;
    final AtomicFile file = getBaseStateFile();
    if (DEBUG) {
        Slog.d(TAG, "Loading from " + file.getBaseFile());
    }
    try (FileInputStream in = file.openRead()) {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(in, StandardCharsets.UTF_8.name());
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT) {
            if (type != XmlPullParser.START_TAG) {
                continue;
            }
            final int depth = parser.getDepth();
            // Check the root tag
            final String tag = parser.getName();
            if (depth == 1) {
                if (!TAG_ROOT.equals(tag)) {
                    Slog.e(TAG, "Invalid root tag: " + tag);
                    return;
                }
                continue;
            }
            // Assume depth == 2
            switch(tag) {
                case TAG_LAST_RESET_TIME:
                    mRawLastResetTime = parseLongAttribute(parser, ATTR_VALUE);
                    break;
                default:
                    Slog.e(TAG, "Invalid tag: " + tag);
                    break;
            }
        }
    } catch (FileNotFoundException e) {
    // Use the default
    } catch (IOException | XmlPullParserException e) {
        Slog.e(TAG, "Failed to read file " + file.getBaseFile(), e);
        mRawLastResetTime = 0;
    }
    // Adjust the last reset time.
    getLastResetTimeLocked();
}
Also used : AtomicFile(android.util.AtomicFile) 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)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