Fixes incorrect system app deletion logic

This change corrects a bad boolean check made in a recent refactor that
was causing non-child system packages to be treated as system packages.
It also bypasses the may delete check for replacing system apps as these
are not deleted the same as non-system.

Change-Id: If43a6d019deb0f203a5cfd2c33e02679b05899f3
Fixes: 120213570
Fixes: 120186133
Test: system updates are successful
(cherry picked from commit f7e31e6de78eae1841c589d7e64339c2ae6e64dd)
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c708b0a..72bebbd 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -15246,7 +15246,8 @@
                         "inputs not balanced; missing argument for " + installPackageName);
             }
             final DeletePackageAction deletePackageAction;
-            if (prepareResult.replace) {
+            // we only want to try to delete for non system apps
+            if (prepareResult.replace && !prepareResult.system) {
                 deletePackageAction = mayDeletePackageLocked(res.removedInfo,
                         prepareResult.originalPs, prepareResult.disabledPs,
                         prepareResult.childPackageSettings);
@@ -17818,7 +17819,7 @@
             return null;
         }
         if (isSystemApp(ps)) {
-            if (ps.parentPackageName == null) {
+            if (ps.parentPackageName != null) {
                 Slog.w(TAG, "Attempt to delete child system package " + ps.pkg.packageName);
                 return null;
             }