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

Commit 8359e40c authored by Winson's avatar Winson
Browse files

Fix PackageSetting isUpdatedSystemApp and SYSTEM_EXT rescan

When updating a PackageSetting, the existing one was not
being considered, causing them to be assigned incorrectly
on re-scan/re-install.

The updatedSystemApp state was also being toggled incorrectly,
as the previous code relied on the fact that a new Package
object was created, implicitly resetting the fields as it
was a new Java object with re-initialized fields.

This disables the field explicitly when re-enabling a system app,
as this action re-uses the existing PackageSetting that was
previously associated with the /data copy.

Also fixes scanning as SYSTEM_EXT when the disabled system
package was also SYSTEM_EXT.

Bug: 135203078
Bug: 149994952

Test: atest NexusLauncherTests:com.android.quickstep.StartLauncherViaGestureTests

Merged-In: I81d126efc144725cac8af6810d33952295b375e1
Change-Id: I81d126efc144725cac8af6810d33952295b375e1
parent b629d69d
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -10969,10 +10969,10 @@ public class PackageManagerService extends IPackageManager.Stub
            // to null here, only to reset them at a later point.
            Settings.updatePackageSetting(pkgSetting, disabledPkgSetting, sharedUserSetting,
                    destCodeFile, destResourceFile, parsedPackage.getNativeLibraryDir(),
                    AndroidPackageUtils.getRawPrimaryCpuAbi(parsedPackage),
                    AndroidPackageUtils.getRawSecondaryCpuAbi(parsedPackage),
                    PackageInfoWithoutStateUtils.appInfoFlags(parsedPackage),
                    PackageInfoWithoutStateUtils.appInfoPrivateFlags(parsedPackage),
                    AndroidPackageUtils.getPrimaryCpuAbi(parsedPackage, pkgSetting),
                    AndroidPackageUtils.getSecondaryCpuAbi(parsedPackage, pkgSetting),
                    PackageInfoUtils.appInfoFlags(parsedPackage, pkgSetting),
                    PackageInfoUtils.appInfoPrivateFlags(parsedPackage, pkgSetting),
                    UserManagerService.getInstance(),
                    usesStaticLibraries, parsedPackage.getUsesStaticLibrariesVersions(),
                    parsedPackage.getMimeGroups());
@@ -11164,6 +11164,8 @@ public class PackageManagerService extends IPackageManager.Stub
        // TODO(b/135203078): Remove, move to constructor
        pkgSetting.pkg = parsedPackage;
        pkgSetting.pkgFlags = PackageInfoUtils.appInfoFlags(parsedPackage, pkgSetting);
        pkgSetting.pkgPrivateFlags =
                PackageInfoUtils.appInfoPrivateFlags(parsedPackage, pkgSetting);
        if (parsedPackage.getLongVersionCode() != pkgSetting.versionCode) {
            pkgSetting.versionCode = parsedPackage.getLongVersionCode();
        }
@@ -16954,6 +16956,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    final boolean vendor = oldPackage.isVendor();
                    final boolean product = oldPackage.isProduct();
                    final boolean odm = oldPackage.isOdm();
                    final boolean systemExt = oldPackage.isSystemExt();
                    final @ParseFlags int systemParseFlags = parseFlags;
                    final @ScanFlags int systemScanFlags = scanFlags
                            | SCAN_AS_SYSTEM
@@ -16961,14 +16964,14 @@ public class PackageManagerService extends IPackageManager.Stub
                            | (oem ? SCAN_AS_OEM : 0)
                            | (vendor ? SCAN_AS_VENDOR : 0)
                            | (product ? SCAN_AS_PRODUCT : 0)
                            | (odm ? SCAN_AS_ODM : 0);
                            | (odm ? SCAN_AS_ODM : 0)
                            | (systemExt ? SCAN_AS_SYSTEM_EXT : 0);
                    if (DEBUG_INSTALL) {
                        Slog.d(TAG, "replaceSystemPackageLI: new=" + parsedPackage
                                + ", old=" + oldPackage);
                    }
                    res.setReturnCode(PackageManager.INSTALL_SUCCEEDED);
                    ps.getPkgState().setUpdatedSystemApp(true);
                    targetParseFlags = systemParseFlags;
                    targetScanFlags = systemScanFlags;
                } else { // non system replace
+3 −0
Original line number Diff line number Diff line
@@ -521,6 +521,9 @@ public final class Settings {
                p.secondaryCpuAbiString, p.cpuAbiOverrideString,
                p.appId, p.versionCode, p.pkgFlags, p.pkgPrivateFlags,
                p.usesStaticLibraries, p.usesStaticLibrariesVersions, p.mimeGroups);
        if (ret != null) {
            ret.getPkgState().setUpdatedSystemApp(false);
        }
        mDisabledSysPackages.remove(name);
        return ret;
    }
+1 −1
Original line number Diff line number Diff line
@@ -2794,7 +2794,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
            }

            if ((changedInstallPermission || replace) && !ps.areInstallPermissionsFixed() &&
                    !ps.isSystem() || !ps.getPkgState().isUpdatedSystemApp()) {
                    !ps.isSystem() || ps.getPkgState().isUpdatedSystemApp()) {
                // This is the first that we have heard about this package, so the
                // permissions we have now selected are fixed until explicitly
                // changed.
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ import java.util.List;
 *
 * It is assumed that anything inside the package was not cached or written to disk, so none of
 * these fields are either. They must be set on every boot from other state on the device.
 *
 * These fields are also not copied into any cloned PackageSetting, to preserve the old behavior
 * where they would be lost implicitly by re-generating the package object.
 */
@DataClass(genSetters = true, genConstructor = false, genBuilder = false)
public class PackageStateUnserialized {