Search in sources :

Example 46 with PackageUserState

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

the class EphemeralApplicationRegistry method createEphemeralAppInfoForPackage.

private EphemeralApplicationInfo createEphemeralAppInfoForPackage(PackageParser.Package pkg, int userId) {
    PackageSetting ps = (PackageSetting) pkg.mExtras;
    if (ps == null) {
        return null;
    }
    PackageUserState userState = ps.readUserState(userId);
    if (userState == null || !userState.installed || userState.hidden) {
        return null;
    }
    String[] requestedPermissions = new String[pkg.requestedPermissions.size()];
    pkg.requestedPermissions.toArray(requestedPermissions);
    Set<String> permissions = ps.getPermissionsState().getPermissions(userId);
    String[] grantedPermissions = new String[permissions.size()];
    permissions.toArray(grantedPermissions);
    return new EphemeralApplicationInfo(pkg.applicationInfo, requestedPermissions, grantedPermissions);
}
Also used : PackageUserState(android.content.pm.PackageUserState) EphemeralApplicationInfo(android.content.pm.EphemeralApplicationInfo)

Example 47 with PackageUserState

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

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);
            }
            if (!ArrayUtils.isEmpty(ustate.protectedComponents)) {
                serializer.startTag(null, TAG_PROTECTED_COMPONENTS);
                for (final String name : ustate.protectedComponents) {
                    serializer.startTag(null, TAG_ITEM);
                    serializer.attribute(null, ATTR_NAME, name);
                    serializer.endTag(null, TAG_ITEM);
                }
                serializer.endTag(null, TAG_PROTECTED_COMPONENTS);
            }
            if (!ArrayUtils.isEmpty(ustate.visibleComponents)) {
                serializer.startTag(null, TAG_VISIBLE_COMPONENTS);
                for (final String name : ustate.visibleComponents) {
                    serializer.startTag(null, TAG_ITEM);
                    serializer.attribute(null, ATTR_NAME, name);
                    serializer.endTag(null, TAG_ITEM);
                }
                serializer.endTag(null, TAG_VISIBLE_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 48 with PackageUserState

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

the class PackageSettingBase method modifyUserState.

private PackageUserState modifyUserState(int userId) {
    PackageUserState state = userState.get(userId);
    if (state == null) {
        state = new PackageUserState();
        userState.put(userId, state);
    }
    return state;
}
Also used : PackageUserState(android.content.pm.PackageUserState)

Example 49 with PackageUserState

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

the class PackageSettingBase method protectComponentLPw.

boolean protectComponentLPw(String componentClassName, boolean protect, int userId) {
    PackageUserState state = modifyUserStateComponents(userId);
    boolean changed = false;
    if (protect == COMPONENT_VISIBLE_STATUS) {
        changed = state.protectedComponents != null ? state.protectedComponents.remove(componentClassName) : false;
        changed |= state.visibleComponents.add(componentClassName);
    } else {
        changed = state.visibleComponents != null ? state.visibleComponents.remove(componentClassName) : false;
        changed |= state.protectedComponents.add(componentClassName);
    }
    return changed;
}
Also used : PackageUserState(android.content.pm.PackageUserState)

Example 50 with PackageUserState

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

the class PackageSettingBase method setEnabled.

void setEnabled(int state, int userId, String callingPackage) {
    PackageUserState st = modifyUserState(userId);
    st.enabled = state;
    st.lastDisableAppCaller = callingPackage;
}
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