Don't install package if it's required to be known

During package scaning, we can require packages to be known. This
allows us to determine if an install was interrupted by checking
the previously known path with the current scanned path. However,
if the package wasn't known at all, we allowed the newly scanned
package to be installed. Instead, these completely unknown
packages should be removed as incomplete installs.

One side effect of the existing code is when new apps randomly
appear on /data/app, they will be installed. This is not behaviour
we want to support. Instead, applications should always be
installed through "adb install".

Change-Id: I3169482ab9ead252c0e91b415fa4da056abeed4a
Fixes: 65162907
Test: Manual
Test: cherry-pick ag/2863255
Test: adb install Foo.apk
Test: adb shell setprop fw.poke com.android.foo
Test: adb shell stop && adb shell start
Test: see entries in persistent package manager logs for removing app & data [adb shell dumpsys package messages]
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index bafcad4..71d3d9a 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -11394,6 +11394,10 @@
                                     + " but expected at " + known.codePathString
                                     + "; ignoring.");
                         }
+                    } else {
+                        throw new PackageManagerException(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
+                                "Application package " + pkg.packageName
+                                + " not found; ignoring.");
                     }
                 }
             }