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

Commit c52d6fd0 authored by Kenny Root's avatar Kenny Root
Browse files

Prune hidden system apps when removed via OTA

System applications which had an update applied to them at some point
were in a semi-broken state when removed via an OTA. The
"updated-package" setting would stay around forever and permissions
wouldn't be revoked.

Change-Id: I908e813b5de59c0f777d9b051253b28255a1c694
parent 775bcac6
Loading
Loading
Loading
Loading
+27 −7
Original line number Diff line number Diff line
@@ -1063,19 +1063,25 @@ public class PackageManagerService extends IPackageManager.Stub {
            mInstaller.moveFiles();

            // Prune any system packages that no longer exist.
            final List<String> possiblyDeletedSystemApps = new ArrayList<String>();
            if (!mOnlyCore) {
                Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator();
                while (psit.hasNext()) {
                    PackageSetting ps = psit.next();
                    if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0
                            && !mPackages.containsKey(ps.name)
                            && !mSettings.mDisabledSysPackages.containsKey(ps.name)) {
                    if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0
                            || mPackages.containsKey(ps.name)) {
                        continue;
                    }

                    if (!mSettings.isDisabledSystemPackageLPr(ps.name)) {
                        psit.remove();
                        String msg = "System package " + ps.name
                                + " no longer exists; wiping its data";
                        reportSettingsProblem(Log.WARN, msg);
                        mInstaller.remove(ps.name, 0);
                        sUserManager.removePackageForAllUsers(ps.name);
                    } else {
                        possiblyDeletedSystemApps.add(ps.name);
                    }
                }
            }
@@ -1104,6 +1110,21 @@ public class PackageManagerService extends IPackageManager.Stub {
                mDrmAppInstallObserver.startWatching();
                scanDirLI(mDrmAppPrivateInstallDir, PackageParser.PARSE_FORWARD_LOCK,
                        scanMode, 0);

                /**
                 * Remove disable package settings for any system apps
                 * that were removed via an OTA.
                 */
                for (String deletedAppName : possiblyDeletedSystemApps) {
                    PackageParser.Package deletedPkg = mPackages.get(deletedAppName);
                    if (deletedPkg != null) {
                        mSettings.removeDisabledSystemPackageLPw(deletedAppName);
                        deletedPkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM;

                        PackageSetting deletedPs = mSettings.mPackages.get(deletedAppName);
                        deletedPs.pkgFlags &= ~ApplicationInfo.FLAG_SYSTEM;
                    }
                }
            } else {
                mAppInstallObserver = null;
                mDrmAppInstallObserver = null;
@@ -3043,8 +3064,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            // Check to see if this package could be hiding/updating a system
            // package.  Must look for it either under the original or real
            // package name depending on our state.
            updatedPkg = mSettings.mDisabledSysPackages.get(
                    ps != null ? ps.name : pkg.packageName);
            updatedPkg = mSettings.getDisabledSystemPkgLPr(ps != null ? ps.name : pkg.packageName);
        }
        // First check if this is a system package that may involve an update
        if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) {
@@ -3523,7 +3543,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                mTransferedPackages.add(pkg.packageName);
            }
            
            if (mSettings.mDisabledSysPackages.get(pkg.packageName) != null) {
            if (mSettings.isDisabledSystemPackageLPr(pkg.packageName)) {
                pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
            }

+9 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ final class Settings {
    final HashMap<String, PackageSetting> mPackages =
            new HashMap<String, PackageSetting>();
    // List of replaced system applications
    final HashMap<String, PackageSetting> mDisabledSysPackages =
    private final HashMap<String, PackageSetting> mDisabledSysPackages =
        new HashMap<String, PackageSetting>();

    // These are the last platform API version we were using for
@@ -280,6 +280,14 @@ final class Settings {
        return ret;
    }

    boolean isDisabledSystemPackageLPr(String name) {
        return mDisabledSysPackages.containsKey(name);
    }

    void removeDisabledSystemPackageLPw(String name) {
        mDisabledSysPackages.remove(name);
    }

    PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath,
            String nativeLibraryPathString, int uid, int vc, int pkgFlags) {
        PackageSetting p = mPackages.get(name);