If freeCache deletes APK, give out of space error

After DownloadManager has downloaded an application to cache to install
during low memory condition, we try to free cache to fit the new
application. The free cache function deletes older files first, but it
will also delete the downloaded application (since it's in cache) as a
last resort since installd has no context about it.

This just changes the error code returned in this case so that we'll
give something more meaningful to the user. A later fix should actually
make this more sane. For instance: know which file to avoid deleting,
not even trying to delete anything if it won't arrive at the desired
free space.

Bug: 7684538
Change-Id: Ide77320fc51a4f692ef8042cb0eafe17b5cd279d
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
index fd649a1..2238f17 100644
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ b/services/java/com/android/server/pm/PackageManagerService.java
@@ -6353,6 +6353,18 @@
                                 pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath,
                                         flags, lowThreshold);
                             }
+                            /*
+                             * The cache free must have deleted the file we
+                             * downloaded to install.
+                             *
+                             * TODO: fix the "freeCache" call to not delete
+                             *       the file we care about.
+                             */
+                            if (pkgLite.recommendedInstallLocation
+                                    == PackageHelper.RECOMMEND_FAILED_INVALID_URI) {
+                                pkgLite.recommendedInstallLocation
+                                    = PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE;
+                            }
                         }
                     }
                 } finally {