Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4282924e authored by Alan Treadway's avatar Alan Treadway
Browse files

Fix for managed-profile users needing to "install" packages twice.

Fix ensures that the users requesting package installation have the
package marked as installed and enabled for them. This appears to be
the intent of the existing code, but without this change in certain
cases the user has to effectively request "installation" twice.

Bug: 17445378
Change-Id: Ic17399e493125e631b381b89615336be17c9d1ee
parent f3ece365
Loading
Loading
Loading
Loading
+20 −11
Original line number Diff line number Diff line
@@ -9956,7 +9956,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags, scanFlags,
                    System.currentTimeMillis(), user);
            updateSettingsLI(newPackage, installerPackageName, null, null, res);
            updateSettingsLI(newPackage, installerPackageName, null, null, res, user);
            // delete the partially installed application. the data directory will have to be
            // restored if it was already existing
            if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) {
@@ -10078,7 +10078,8 @@ public class PackageManagerService extends IPackageManager.Stub {
            try {
                final PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags,
                        scanFlags | SCAN_UPDATE_TIME, System.currentTimeMillis(), user);
                updateSettingsLI(newPackage, installerPackageName, allUsers, perUserInstalled, res);
                updateSettingsLI(newPackage, installerPackageName, allUsers, perUserInstalled, res,
                        user);
                updatedSettings = true;
            } catch (PackageManagerException e) {
                res.setError("Package couldn't be installed in " + pkg.codePath, e);
@@ -10208,7 +10209,8 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
            if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) {
                updateSettingsLI(newPackage, installerPackageName, allUsers, perUserInstalled, res);
                updateSettingsLI(newPackage, installerPackageName, allUsers, perUserInstalled, res,
                        user);
                updatedSettings = true;
            }
@@ -10244,7 +10246,7 @@ public class PackageManagerService extends IPackageManager.Stub {
    private void updateSettingsLI(PackageParser.Package newPackage, String installerPackageName,
            int[] allUsers, boolean[] perUserInstalled,
            PackageInstalledInfo res) {
            PackageInstalledInfo res, UserHandle user) {
        String pkgName = newPackage.packageName;
        synchronized (mPackages) {
            //write settings. the installStatus will be incomplete at this stage.
@@ -10263,13 +10265,13 @@ public class PackageManagerService extends IPackageManager.Stub {
            // For system-bundled packages, we assume that installing an upgraded version
            // of the package implies that the user actually wants to run that new code,
            // so we enable the package.
            PackageSetting ps = mSettings.mPackages.get(pkgName);
            if (ps != null) {
                if (isSystemApp(newPackage)) {
                    // NB: implicit assumption that system package upgrades apply to all users
                    if (DEBUG_INSTALL) {
                        Slog.d(TAG, "Implicitly enabling system package on upgrade: " + pkgName);
                    }
                PackageSetting ps = mSettings.mPackages.get(pkgName);
                if (ps != null) {
                    if (res.origUsers != null) {
                        for (int userHandle : res.origUsers) {
                            ps.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT,
@@ -10289,6 +10291,13 @@ public class PackageManagerService extends IPackageManager.Stub {
                        // upcoming call to mSettings.writeLPr().
                    }
                }
                // It's implied that when a user requests installation, they want the app to be
                // installed and enabled.
                int userId = user.getIdentifier();
                if (userId != UserHandle.USER_ALL) {
                    ps.setInstalled(true, userId);
                    ps.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, userId, installerPackageName);
                }
            }
            res.name = pkgName;
            res.uid = newPackage.applicationInfo.uid;