Search in sources :

Example 16 with PackageCleanItem

use of android.content.pm.PackageCleanItem in project android_frameworks_base by ResurrectionRemix.

the class Settings method readLPw.

boolean readLPw(@NonNull List<UserInfo> users) {
    FileInputStream str = null;
    if (mBackupSettingsFilename.exists()) {
        try {
            str = new FileInputStream(mBackupSettingsFilename);
            mReadMessages.append("Reading from backup settings file\n");
            PackageManagerService.reportSettingsProblem(Log.INFO, "Need to read from backup settings file");
            if (mSettingsFilename.exists()) {
                // If both the backup and settings file exist, we
                // ignore the settings since it might have been
                // corrupted.
                Slog.w(PackageManagerService.TAG, "Cleaning up settings file " + mSettingsFilename);
                mSettingsFilename.delete();
            }
        } catch (java.io.IOException e) {
        // We'll try for the normal settings file.
        }
    }
    mPendingPackages.clear();
    mPastSignatures.clear();
    mKeySetRefs.clear();
    mInstallerPackages.clear();
    try {
        if (str == null) {
            if (!mSettingsFilename.exists()) {
                mReadMessages.append("No settings file found\n");
                PackageManagerService.reportSettingsProblem(Log.INFO, "No settings file; creating initial state");
                // It's enough to just touch version details to create them
                // with default values
                findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL);
                findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL);
                return false;
            }
            str = new FileInputStream(mSettingsFilename);
        }
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(str, StandardCharsets.UTF_8.name());
        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 settings file\n");
            PackageManagerService.reportSettingsProblem(Log.WARN, "No start tag found in package manager settings");
            Slog.wtf(PackageManagerService.TAG, "No start tag found in package manager settings");
            return false;
        }
        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("package")) {
                readPackageLPw(parser);
            } else if (tagName.equals("permissions")) {
                readPermissionsLPw(mPermissions, parser);
            } else if (tagName.equals("permission-trees")) {
                readPermissionsLPw(mPermissionTrees, parser);
            } else if (tagName.equals("shared-user")) {
                readSharedUserLPw(parser);
            } else if (tagName.equals("preferred-packages")) {
            // no longer used.
            } else if (tagName.equals("preferred-activities")) {
                // Upgrading from old single-user implementation;
                // these are the preferred activities for user 0.
                readPreferredActivitiesLPw(parser, 0);
            } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) {
                // TODO: check whether this is okay! as it is very
                // similar to how preferred-activities are treated
                readPersistentPreferredActivitiesLPw(parser, 0);
            } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) {
                // TODO: check whether this is okay! as it is very
                // similar to how preferred-activities are treated
                readCrossProfileIntentFiltersLPw(parser, 0);
            } else if (tagName.equals(TAG_DEFAULT_BROWSER)) {
                readDefaultAppsLPw(parser, 0);
            } else if (tagName.equals("updated-package")) {
                readDisabledSysPackageLPw(parser);
            } else if (tagName.equals("cleaning-package")) {
                String name = parser.getAttributeValue(null, ATTR_NAME);
                String userStr = parser.getAttributeValue(null, ATTR_USER);
                String codeStr = parser.getAttributeValue(null, ATTR_CODE);
                if (name != null) {
                    int userId = UserHandle.USER_SYSTEM;
                    boolean andCode = true;
                    try {
                        if (userStr != null) {
                            userId = Integer.parseInt(userStr);
                        }
                    } catch (NumberFormatException e) {
                    }
                    if (codeStr != null) {
                        andCode = Boolean.parseBoolean(codeStr);
                    }
                    addPackageToCleanLPw(new PackageCleanItem(userId, name, andCode));
                }
            } else if (tagName.equals("renamed-package")) {
                String nname = parser.getAttributeValue(null, "new");
                String oname = parser.getAttributeValue(null, "old");
                if (nname != null && oname != null) {
                    mRenamedPackages.put(nname, oname);
                }
            } else if (tagName.equals("restored-ivi")) {
                readRestoredIntentFilterVerifications(parser);
            } else if (tagName.equals("last-platform-version")) {
                // Upgrade from older XML schema
                final VersionInfo internal = findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL);
                final VersionInfo external = findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL);
                internal.sdkVersion = XmlUtils.readIntAttribute(parser, "internal", 0);
                external.sdkVersion = XmlUtils.readIntAttribute(parser, "external", 0);
                internal.fingerprint = external.fingerprint = XmlUtils.readStringAttribute(parser, "fingerprint");
            } else if (tagName.equals("database-version")) {
                // Upgrade from older XML schema
                final VersionInfo internal = findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL);
                final VersionInfo external = findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL);
                internal.databaseVersion = XmlUtils.readIntAttribute(parser, "internal", 0);
                external.databaseVersion = XmlUtils.readIntAttribute(parser, "external", 0);
            } else if (tagName.equals("verifier")) {
                final String deviceIdentity = parser.getAttributeValue(null, "device");
                try {
                    mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity);
                } catch (IllegalArgumentException e) {
                    Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: " + e.getMessage());
                }
            } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) {
                final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT);
                mReadExternalStorageEnforced = "1".equals(enforcement);
            } else if (tagName.equals("keyset-settings")) {
                mKeySetManagerService.readKeySetsLPw(parser, mKeySetRefs);
            } else if (TAG_VERSION.equals(tagName)) {
                final String volumeUuid = XmlUtils.readStringAttribute(parser, ATTR_VOLUME_UUID);
                final VersionInfo ver = findOrCreateVersion(volumeUuid);
                ver.sdkVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION);
                ver.databaseVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION);
                ver.fingerprint = XmlUtils.readStringAttribute(parser, ATTR_FINGERPRINT);
            } else {
                Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: " + parser.getName());
                XmlUtils.skipCurrentTag(parser);
            }
        }
        str.close();
    } catch (XmlPullParserException e) {
        mReadMessages.append("Error reading: " + e.toString());
        PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
        Slog.wtf(PackageManagerService.TAG, "Error reading package manager settings", 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 settings", e);
    }
    // on update drop the files before loading them.
    if (PackageManagerService.CLEAR_RUNTIME_PERMISSIONS_ON_UPGRADE) {
        final VersionInfo internal = getInternalVersion();
        if (!Build.FINGERPRINT.equals(internal.fingerprint)) {
            for (UserInfo user : users) {
                mRuntimePermissionsPersistence.deleteUserRuntimePermissionsFile(user.id);
            }
        }
    }
    final int N = mPendingPackages.size();
    for (int i = 0; i < N; i++) {
        final PendingPackage pp = mPendingPackages.get(i);
        Object idObj = getUserIdLPr(pp.sharedId);
        if (idObj != null && idObj instanceof SharedUserSetting) {
            PackageSetting p = getPackageLPw(pp.name, null, pp.realName, (SharedUserSetting) idObj, pp.codePath, pp.resourcePath, pp.legacyNativeLibraryPathString, pp.primaryCpuAbiString, pp.secondaryCpuAbiString, pp.versionCode, pp.pkgFlags, pp.pkgPrivateFlags, null, true, /* add */
            false, /* allowInstall */
            pp.parentPackageName, pp.childPackageNames);
            if (p == null) {
                PackageManagerService.reportSettingsProblem(Log.WARN, "Unable to create application package for " + pp.name);
                continue;
            }
            p.copyFrom(pp);
        } else if (idObj != null) {
            String msg = "Bad package setting: package " + pp.name + " has shared uid " + pp.sharedId + " that is not a shared uid\n";
            mReadMessages.append(msg);
            PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
        } else {
            String msg = "Bad package setting: package " + pp.name + " has shared uid " + pp.sharedId + " that is not defined\n";
            mReadMessages.append(msg);
            PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
        }
    }
    mPendingPackages.clear();
    if (mBackupStoppedPackagesFilename.exists() || mStoppedPackagesFilename.exists()) {
        // Read old file
        readStoppedLPw();
        mBackupStoppedPackagesFilename.delete();
        mStoppedPackagesFilename.delete();
        // Migrate to new file format
        writePackageRestrictionsLPr(UserHandle.USER_SYSTEM);
    } else {
        for (UserInfo user : users) {
            readPackageRestrictionsLPr(user.id);
        }
    }
    for (UserInfo user : users) {
        mRuntimePermissionsPersistence.readStateForUserSyncLPr(user.id);
    }
    /*
         * Make sure all the updated system packages have their shared users
         * associated with them.
         */
    final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator();
    while (disabledIt.hasNext()) {
        final PackageSetting disabledPs = disabledIt.next();
        final Object id = getUserIdLPr(disabledPs.appId);
        if (id != null && id instanceof SharedUserSetting) {
            disabledPs.sharedUser = (SharedUserSetting) id;
        }
    }
    mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, " + mSharedUsers.size() + " shared uids\n");
    writeKernelMappingLPr();
    return true;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) UserInfo(android.content.pm.UserInfo) FileInputStream(java.io.FileInputStream) PackageCleanItem(android.content.pm.PackageCleanItem) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 17 with PackageCleanItem

use of android.content.pm.PackageCleanItem in project android_frameworks_base by crdroidandroid.

the class Settings method writeLPr.

void writeLPr() {
    // been successfully written.
    if (mSettingsFilename.exists()) {
        // might have been corrupted.
        if (!mBackupSettingsFilename.exists()) {
            if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
                Slog.wtf(PackageManagerService.TAG, "Unable to backup package manager settings, " + " current changes will be lost at reboot");
                return;
            }
        } else {
            mSettingsFilename.delete();
            Slog.w(PackageManagerService.TAG, "Preserving older settings backup");
        }
    }
    mPastSignatures.clear();
    try {
        FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
        BufferedOutputStream str = new BufferedOutputStream(fstr);
        //XmlSerializer serializer = XmlUtils.serializerInstance();
        XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(str, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.startTag(null, "packages");
        for (int i = 0; i < mVersion.size(); i++) {
            final String volumeUuid = mVersion.keyAt(i);
            final VersionInfo ver = mVersion.valueAt(i);
            serializer.startTag(null, TAG_VERSION);
            XmlUtils.writeStringAttribute(serializer, ATTR_VOLUME_UUID, volumeUuid);
            XmlUtils.writeIntAttribute(serializer, ATTR_SDK_VERSION, ver.sdkVersion);
            XmlUtils.writeIntAttribute(serializer, ATTR_DATABASE_VERSION, ver.databaseVersion);
            XmlUtils.writeStringAttribute(serializer, ATTR_FINGERPRINT, ver.fingerprint);
            serializer.endTag(null, TAG_VERSION);
        }
        if (mVerifierDeviceIdentity != null) {
            serializer.startTag(null, "verifier");
            serializer.attribute(null, "device", mVerifierDeviceIdentity.toString());
            serializer.endTag(null, "verifier");
        }
        if (mReadExternalStorageEnforced != null) {
            serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE);
            serializer.attribute(null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0");
            serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE);
        }
        serializer.startTag(null, "permission-trees");
        for (BasePermission bp : mPermissionTrees.values()) {
            writePermissionLPr(serializer, bp);
        }
        serializer.endTag(null, "permission-trees");
        serializer.startTag(null, "permissions");
        for (BasePermission bp : mPermissions.values()) {
            writePermissionLPr(serializer, bp);
        }
        serializer.endTag(null, "permissions");
        for (final PackageSetting pkg : mPackages.values()) {
            writePackageLPr(serializer, pkg);
        }
        for (final PackageSetting pkg : mDisabledSysPackages.values()) {
            writeDisabledSysPackageLPr(serializer, pkg);
        }
        for (final SharedUserSetting usr : mSharedUsers.values()) {
            serializer.startTag(null, "shared-user");
            serializer.attribute(null, ATTR_NAME, usr.name);
            serializer.attribute(null, "userId", Integer.toString(usr.userId));
            usr.signatures.writeXml(serializer, "sigs", mPastSignatures);
            writePermissionsLPr(serializer, usr.getPermissionsState().getInstallPermissionStates());
            serializer.endTag(null, "shared-user");
        }
        if (mPackagesToBeCleaned.size() > 0) {
            for (PackageCleanItem item : mPackagesToBeCleaned) {
                final String userStr = Integer.toString(item.userId);
                serializer.startTag(null, "cleaning-package");
                serializer.attribute(null, ATTR_NAME, item.packageName);
                serializer.attribute(null, ATTR_CODE, item.andCode ? "true" : "false");
                serializer.attribute(null, ATTR_USER, userStr);
                serializer.endTag(null, "cleaning-package");
            }
        }
        if (mRenamedPackages.size() > 0) {
            for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
                serializer.startTag(null, "renamed-package");
                serializer.attribute(null, "new", e.getKey());
                serializer.attribute(null, "old", e.getValue());
                serializer.endTag(null, "renamed-package");
            }
        }
        final int numIVIs = mRestoredIntentFilterVerifications.size();
        if (numIVIs > 0) {
            if (DEBUG_DOMAIN_VERIFICATION) {
                Slog.i(TAG, "Writing restored-ivi entries to packages.xml");
            }
            serializer.startTag(null, "restored-ivi");
            for (int i = 0; i < numIVIs; i++) {
                IntentFilterVerificationInfo ivi = mRestoredIntentFilterVerifications.valueAt(i);
                writeDomainVerificationsLPr(serializer, ivi);
            }
            serializer.endTag(null, "restored-ivi");
        } else {
            if (DEBUG_DOMAIN_VERIFICATION) {
                Slog.i(TAG, "  no restored IVI entries to write");
            }
        }
        mKeySetManagerService.writeKeySetManagerServiceLPr(serializer);
        serializer.endTag(null, "packages");
        serializer.endDocument();
        str.flush();
        FileUtils.sync(fstr);
        str.close();
        // New settings successfully written, old ones are no longer
        // needed.
        mBackupSettingsFilename.delete();
        FileUtils.setPermissions(mSettingsFilename.toString(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IWGRP, -1, -1);
        writeKernelMappingLPr();
        writePackageListLPr();
        writeAllUsersPackageRestrictionsLPr();
        writeAllRuntimePermissionsLPr();
        return;
    } catch (XmlPullParserException | java.io.IOException e) {
        Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, " + "current changes will be lost at reboot", e);
    }
    // Clean up partially written files
    if (mSettingsFilename.exists()) {
        if (!mSettingsFilename.delete()) {
            Slog.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: " + mSettingsFilename);
        }
    }
//Debug.stopMethodTracing();
}
Also used : IOException(java.io.IOException) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) PackageCleanItem(android.content.pm.PackageCleanItem) FileOutputStream(java.io.FileOutputStream) IntentFilterVerificationInfo(android.content.pm.IntentFilterVerificationInfo) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) BufferedOutputStream(java.io.BufferedOutputStream) Map(java.util.Map) ArrayMap(android.util.ArrayMap) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 18 with PackageCleanItem

use of android.content.pm.PackageCleanItem in project android_frameworks_base by crdroidandroid.

the class Settings method readLPw.

boolean readLPw(@NonNull List<UserInfo> users) {
    FileInputStream str = null;
    if (mBackupSettingsFilename.exists()) {
        try {
            str = new FileInputStream(mBackupSettingsFilename);
            mReadMessages.append("Reading from backup settings file\n");
            PackageManagerService.reportSettingsProblem(Log.INFO, "Need to read from backup settings file");
            if (mSettingsFilename.exists()) {
                // If both the backup and settings file exist, we
                // ignore the settings since it might have been
                // corrupted.
                Slog.w(PackageManagerService.TAG, "Cleaning up settings file " + mSettingsFilename);
                mSettingsFilename.delete();
            }
        } catch (java.io.IOException e) {
        // We'll try for the normal settings file.
        }
    }
    mPendingPackages.clear();
    mPastSignatures.clear();
    mKeySetRefs.clear();
    mInstallerPackages.clear();
    try {
        if (str == null) {
            if (!mSettingsFilename.exists()) {
                mReadMessages.append("No settings file found\n");
                PackageManagerService.reportSettingsProblem(Log.INFO, "No settings file; creating initial state");
                // It's enough to just touch version details to create them
                // with default values
                findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL);
                findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL);
                return false;
            }
            str = new FileInputStream(mSettingsFilename);
        }
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(str, StandardCharsets.UTF_8.name());
        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 settings file\n");
            PackageManagerService.reportSettingsProblem(Log.WARN, "No start tag found in package manager settings");
            Slog.wtf(PackageManagerService.TAG, "No start tag found in package manager settings");
            return false;
        }
        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("package")) {
                readPackageLPw(parser);
            } else if (tagName.equals("permissions")) {
                readPermissionsLPw(mPermissions, parser);
            } else if (tagName.equals("permission-trees")) {
                readPermissionsLPw(mPermissionTrees, parser);
            } else if (tagName.equals("shared-user")) {
                readSharedUserLPw(parser);
            } else if (tagName.equals("preferred-packages")) {
            // no longer used.
            } else if (tagName.equals("preferred-activities")) {
                // Upgrading from old single-user implementation;
                // these are the preferred activities for user 0.
                readPreferredActivitiesLPw(parser, 0);
            } else if (tagName.equals(TAG_PERSISTENT_PREFERRED_ACTIVITIES)) {
                // TODO: check whether this is okay! as it is very
                // similar to how preferred-activities are treated
                readPersistentPreferredActivitiesLPw(parser, 0);
            } else if (tagName.equals(TAG_CROSS_PROFILE_INTENT_FILTERS)) {
                // TODO: check whether this is okay! as it is very
                // similar to how preferred-activities are treated
                readCrossProfileIntentFiltersLPw(parser, 0);
            } else if (tagName.equals(TAG_DEFAULT_BROWSER)) {
                readDefaultAppsLPw(parser, 0);
            } else if (tagName.equals("updated-package")) {
                readDisabledSysPackageLPw(parser);
            } else if (tagName.equals("cleaning-package")) {
                String name = parser.getAttributeValue(null, ATTR_NAME);
                String userStr = parser.getAttributeValue(null, ATTR_USER);
                String codeStr = parser.getAttributeValue(null, ATTR_CODE);
                if (name != null) {
                    int userId = UserHandle.USER_SYSTEM;
                    boolean andCode = true;
                    try {
                        if (userStr != null) {
                            userId = Integer.parseInt(userStr);
                        }
                    } catch (NumberFormatException e) {
                    }
                    if (codeStr != null) {
                        andCode = Boolean.parseBoolean(codeStr);
                    }
                    addPackageToCleanLPw(new PackageCleanItem(userId, name, andCode));
                }
            } else if (tagName.equals("renamed-package")) {
                String nname = parser.getAttributeValue(null, "new");
                String oname = parser.getAttributeValue(null, "old");
                if (nname != null && oname != null) {
                    mRenamedPackages.put(nname, oname);
                }
            } else if (tagName.equals("restored-ivi")) {
                readRestoredIntentFilterVerifications(parser);
            } else if (tagName.equals("last-platform-version")) {
                // Upgrade from older XML schema
                final VersionInfo internal = findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL);
                final VersionInfo external = findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL);
                internal.sdkVersion = XmlUtils.readIntAttribute(parser, "internal", 0);
                external.sdkVersion = XmlUtils.readIntAttribute(parser, "external", 0);
                internal.fingerprint = external.fingerprint = XmlUtils.readStringAttribute(parser, "fingerprint");
            } else if (tagName.equals("database-version")) {
                // Upgrade from older XML schema
                final VersionInfo internal = findOrCreateVersion(StorageManager.UUID_PRIVATE_INTERNAL);
                final VersionInfo external = findOrCreateVersion(StorageManager.UUID_PRIMARY_PHYSICAL);
                internal.databaseVersion = XmlUtils.readIntAttribute(parser, "internal", 0);
                external.databaseVersion = XmlUtils.readIntAttribute(parser, "external", 0);
            } else if (tagName.equals("verifier")) {
                final String deviceIdentity = parser.getAttributeValue(null, "device");
                try {
                    mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity);
                } catch (IllegalArgumentException e) {
                    Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: " + e.getMessage());
                }
            } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) {
                final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT);
                mReadExternalStorageEnforced = "1".equals(enforcement);
            } else if (tagName.equals("keyset-settings")) {
                mKeySetManagerService.readKeySetsLPw(parser, mKeySetRefs);
            } else if (TAG_VERSION.equals(tagName)) {
                final String volumeUuid = XmlUtils.readStringAttribute(parser, ATTR_VOLUME_UUID);
                final VersionInfo ver = findOrCreateVersion(volumeUuid);
                ver.sdkVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION);
                ver.databaseVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION);
                ver.fingerprint = XmlUtils.readStringAttribute(parser, ATTR_FINGERPRINT);
            } else {
                Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: " + parser.getName());
                XmlUtils.skipCurrentTag(parser);
            }
        }
    } catch (XmlPullParserException | 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 settings", e);
    } finally {
        IoUtils.closeQuietly(str);
    }
    // on update drop the files before loading them.
    if (PackageManagerService.CLEAR_RUNTIME_PERMISSIONS_ON_UPGRADE) {
        final VersionInfo internal = getInternalVersion();
        if (!Build.FINGERPRINT.equals(internal.fingerprint)) {
            for (UserInfo user : users) {
                mRuntimePermissionsPersistence.deleteUserRuntimePermissionsFile(user.id);
            }
        }
    }
    final int N = mPendingPackages.size();
    for (int i = 0; i < N; i++) {
        final PendingPackage pp = mPendingPackages.get(i);
        Object idObj = getUserIdLPr(pp.sharedId);
        if (idObj != null && idObj instanceof SharedUserSetting) {
            PackageSetting p = getPackageLPw(pp.name, null, pp.realName, (SharedUserSetting) idObj, pp.codePath, pp.resourcePath, pp.legacyNativeLibraryPathString, pp.primaryCpuAbiString, pp.secondaryCpuAbiString, pp.versionCode, pp.pkgFlags, pp.pkgPrivateFlags, null, true, /* add */
            false, /* allowInstall */
            pp.parentPackageName, pp.childPackageNames);
            if (p == null) {
                PackageManagerService.reportSettingsProblem(Log.WARN, "Unable to create application package for " + pp.name);
                continue;
            }
            p.copyFrom(pp);
        } else if (idObj != null) {
            String msg = "Bad package setting: package " + pp.name + " has shared uid " + pp.sharedId + " that is not a shared uid\n";
            mReadMessages.append(msg);
            PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
        } else {
            String msg = "Bad package setting: package " + pp.name + " has shared uid " + pp.sharedId + " that is not defined\n";
            mReadMessages.append(msg);
            PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
        }
    }
    mPendingPackages.clear();
    if (mBackupStoppedPackagesFilename.exists() || mStoppedPackagesFilename.exists()) {
        // Read old file
        readStoppedLPw();
        mBackupStoppedPackagesFilename.delete();
        mStoppedPackagesFilename.delete();
        // Migrate to new file format
        writePackageRestrictionsLPr(UserHandle.USER_SYSTEM);
    } else {
        for (UserInfo user : users) {
            readPackageRestrictionsLPr(user.id);
        }
    }
    for (UserInfo user : users) {
        mRuntimePermissionsPersistence.readStateForUserSyncLPr(user.id);
    }
    /*
         * Make sure all the updated system packages have their shared users
         * associated with them.
         */
    final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator();
    while (disabledIt.hasNext()) {
        final PackageSetting disabledPs = disabledIt.next();
        final Object id = getUserIdLPr(disabledPs.appId);
        if (id != null && id instanceof SharedUserSetting) {
            disabledPs.sharedUser = (SharedUserSetting) id;
        }
    }
    mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, " + mSharedUsers.size() + " shared uids\n");
    writeKernelMappingLPr();
    return true;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) PackageCleanItem(android.content.pm.PackageCleanItem) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 19 with PackageCleanItem

use of android.content.pm.PackageCleanItem in project android_frameworks_base by crdroidandroid.

the class DefaultContainerService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE.equals(intent.getAction())) {
        final IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
        PackageCleanItem item = null;
        try {
            while ((item = pm.nextPackageToClean(item)) != null) {
                final UserEnvironment userEnv = new UserEnvironment(item.userId);
                eraseFiles(userEnv.buildExternalStorageAppDataDirs(item.packageName));
                eraseFiles(userEnv.buildExternalStorageAppMediaDirs(item.packageName));
                if (item.andCode) {
                    eraseFiles(userEnv.buildExternalStorageAppObbDirs(item.packageName));
                }
            }
        } catch (RemoteException e) {
        }
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) PackageCleanItem(android.content.pm.PackageCleanItem) UserEnvironment(android.os.Environment.UserEnvironment) RemoteException(android.os.RemoteException)

Aggregations

PackageCleanItem (android.content.pm.PackageCleanItem)19 IOException (java.io.IOException)11 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)10 IPackageManager (android.content.pm.IPackageManager)6 UserEnvironment (android.os.Environment.UserEnvironment)6 RemoteException (android.os.RemoteException)6 UserInfo (android.content.pm.UserInfo)5 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)5 BufferedOutputStream (java.io.BufferedOutputStream)5 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 Map (java.util.Map)5 XmlPullParser (org.xmlpull.v1.XmlPullParser)5 XmlSerializer (org.xmlpull.v1.XmlSerializer)5 IntentFilterVerificationInfo (android.content.pm.IntentFilterVerificationInfo)4 ArrayMap (android.util.ArrayMap)4 File (java.io.File)4 ComponentName (android.content.ComponentName)3 PackageParser (android.content.pm.PackageParser)3 ResolverActivity (com.android.internal.app.ResolverActivity)3