Search in sources :

Example 1 with PackageUserState

use of android.content.pm.PackageUserState in project platform_frameworks_base by android.

the class Settings method writePackageRestrictionsLPr.

void writePackageRestrictionsLPr(int userId) {
    if (DEBUG_MU) {
        Log.i(TAG, "Writing package restrictions for user=" + userId);
    }
    // Keep the old stopped packages around until we know the new ones have
    // been successfully written.
    File userPackagesStateFile = getUserPackagesStateFile(userId);
    File backupFile = getUserPackagesStateBackupFile(userId);
    new File(userPackagesStateFile.getParent()).mkdirs();
    if (userPackagesStateFile.exists()) {
        // might have been corrupted.
        if (!backupFile.exists()) {
            if (!userPackagesStateFile.renameTo(backupFile)) {
                Slog.wtf(PackageManagerService.TAG, "Unable to backup user packages state file, " + "current changes will be lost at reboot");
                return;
            }
        } else {
            userPackagesStateFile.delete();
            Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup");
        }
    }
    try {
        final FileOutputStream fstr = new FileOutputStream(userPackagesStateFile);
        final BufferedOutputStream str = new BufferedOutputStream(fstr);
        final 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, TAG_PACKAGE_RESTRICTIONS);
        for (final PackageSetting pkg : mPackages.values()) {
            final PackageUserState ustate = pkg.readUserState(userId);
            if (DEBUG_MU)
                Log.i(TAG, "  pkg=" + pkg.name + ", state=" + ustate.enabled);
            serializer.startTag(null, TAG_PACKAGE);
            serializer.attribute(null, ATTR_NAME, pkg.name);
            if (ustate.ceDataInode != 0) {
                XmlUtils.writeLongAttribute(serializer, ATTR_CE_DATA_INODE, ustate.ceDataInode);
            }
            if (!ustate.installed) {
                serializer.attribute(null, ATTR_INSTALLED, "false");
            }
            if (ustate.stopped) {
                serializer.attribute(null, ATTR_STOPPED, "true");
            }
            if (ustate.notLaunched) {
                serializer.attribute(null, ATTR_NOT_LAUNCHED, "true");
            }
            if (ustate.hidden) {
                serializer.attribute(null, ATTR_HIDDEN, "true");
            }
            if (ustate.suspended) {
                serializer.attribute(null, ATTR_SUSPENDED, "true");
            }
            if (ustate.blockUninstall) {
                serializer.attribute(null, ATTR_BLOCK_UNINSTALL, "true");
            }
            if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) {
                serializer.attribute(null, ATTR_ENABLED, Integer.toString(ustate.enabled));
                if (ustate.lastDisableAppCaller != null) {
                    serializer.attribute(null, ATTR_ENABLED_CALLER, ustate.lastDisableAppCaller);
                }
            }
            if (ustate.domainVerificationStatus != PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED) {
                XmlUtils.writeIntAttribute(serializer, ATTR_DOMAIN_VERIFICATON_STATE, ustate.domainVerificationStatus);
            }
            if (ustate.appLinkGeneration != 0) {
                XmlUtils.writeIntAttribute(serializer, ATTR_APP_LINK_GENERATION, ustate.appLinkGeneration);
            }
            if (!ArrayUtils.isEmpty(ustate.enabledComponents)) {
                serializer.startTag(null, TAG_ENABLED_COMPONENTS);
                for (final String name : ustate.enabledComponents) {
                    serializer.startTag(null, TAG_ITEM);
                    serializer.attribute(null, ATTR_NAME, name);
                    serializer.endTag(null, TAG_ITEM);
                }
                serializer.endTag(null, TAG_ENABLED_COMPONENTS);
            }
            if (!ArrayUtils.isEmpty(ustate.disabledComponents)) {
                serializer.startTag(null, TAG_DISABLED_COMPONENTS);
                for (final String name : ustate.disabledComponents) {
                    serializer.startTag(null, TAG_ITEM);
                    serializer.attribute(null, ATTR_NAME, name);
                    serializer.endTag(null, TAG_ITEM);
                }
                serializer.endTag(null, TAG_DISABLED_COMPONENTS);
            }
            serializer.endTag(null, TAG_PACKAGE);
        }
        writePreferredActivitiesLPr(serializer, userId, true);
        writePersistentPreferredActivitiesLPr(serializer, userId);
        writeCrossProfileIntentFiltersLPr(serializer, userId);
        writeDefaultAppsLPr(serializer, userId);
        serializer.endTag(null, TAG_PACKAGE_RESTRICTIONS);
        serializer.endDocument();
        str.flush();
        FileUtils.sync(fstr);
        str.close();
        // New settings successfully written, old ones are no longer
        // needed.
        backupFile.delete();
        FileUtils.setPermissions(userPackagesStateFile.toString(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IWGRP, -1, -1);
        // Done, all is good!
        return;
    } catch (java.io.IOException e) {
        Slog.wtf(PackageManagerService.TAG, "Unable to write package manager user packages state, " + " current changes will be lost at reboot", e);
    }
    // Clean up partially written files
    if (userPackagesStateFile.exists()) {
        if (!userPackagesStateFile.delete()) {
            Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: " + mStoppedPackagesFilename);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) PackageUserState(android.content.pm.PackageUserState) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) AtomicFile(android.util.AtomicFile) File(java.io.File) JournaledFile(com.android.internal.util.JournaledFile) BufferedOutputStream(java.io.BufferedOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 2 with PackageUserState

use of android.content.pm.PackageUserState in project platform_frameworks_base by android.

the class Settings method isEnabledAndMatchLPr.

boolean isEnabledAndMatchLPr(ComponentInfo componentInfo, int flags, int userId) {
    final PackageSetting ps = mPackages.get(componentInfo.packageName);
    if (ps == null)
        return false;
    final PackageUserState userState = ps.readUserState(userId);
    return userState.isMatch(componentInfo, flags);
}
Also used : PackageUserState(android.content.pm.PackageUserState)

Example 3 with PackageUserState

use of android.content.pm.PackageUserState in project platform_frameworks_base by android.

the class PackageManagerService method getActivityInfo.

@Override
public ActivityInfo getActivityInfo(ComponentName component, int flags, int userId) {
    if (!sUserManager.exists(userId))
        return null;
    flags = updateFlagsForComponent(flags, userId, component);
    enforceCrossUserPermission(Binder.getCallingUid(), userId, false, /* requireFullPermission */
    false, /* checkShell */
    "get activity info");
    synchronized (mPackages) {
        PackageParser.Activity a = mActivities.mActivities.get(component);
        if (DEBUG_PACKAGE_INFO)
            Log.v(TAG, "getActivityInfo " + component + ": " + a);
        if (a != null && mSettings.isEnabledAndMatchLPr(a.info, flags, userId)) {
            PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
            if (ps == null)
                return null;
            return PackageParser.generateActivityInfo(a, flags, ps.readUserState(userId), userId);
        }
        if (mResolveComponentName.equals(component)) {
            return PackageParser.generateActivityInfo(mResolveActivity, flags, new PackageUserState(), userId);
        }
    }
    return null;
}
Also used : PackageParser(android.content.pm.PackageParser) PackageUserState(android.content.pm.PackageUserState)

Example 4 with PackageUserState

use of android.content.pm.PackageUserState in project platform_frameworks_base by android.

the class PackageSettingBase method enableComponentLPw.

boolean enableComponentLPw(String componentClassName, int userId) {
    PackageUserState state = modifyUserStateComponents(userId, false, true);
    boolean changed = state.disabledComponents != null ? state.disabledComponents.remove(componentClassName) : false;
    changed |= state.enabledComponents.add(componentClassName);
    return changed;
}
Also used : PackageUserState(android.content.pm.PackageUserState)

Example 5 with PackageUserState

use of android.content.pm.PackageUserState in project platform_frameworks_base by android.

the class PackageSettingBase method getDomainVerificationStatusForUser.

// Returns a packed value as a long:
//
// high 'int'-sized word: link status: undefined/ask/never/always.
// low 'int'-sized word: relative priority among 'always' results.
long getDomainVerificationStatusForUser(int userId) {
    PackageUserState state = readUserState(userId);
    long result = (long) state.appLinkGeneration;
    result |= ((long) state.domainVerificationStatus) << 32;
    return result;
}
Also used : PackageUserState(android.content.pm.PackageUserState)

Aggregations

PackageUserState (android.content.pm.PackageUserState)60 EphemeralApplicationInfo (android.content.pm.EphemeralApplicationInfo)5 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)5 JournaledFile (com.android.internal.util.JournaledFile)5 BufferedOutputStream (java.io.BufferedOutputStream)5 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 XmlSerializer (org.xmlpull.v1.XmlSerializer)5 PackageParser (android.content.pm.PackageParser)4 AtomicFile (android.util.AtomicFile)4 PackageInfo (android.content.pm.PackageInfo)1