Fix 2641875
Initialize the cache path only if the container exists.
This did exist before but was somehow removed.
Fix a known test failure as well.

Change-Id: I63219369b0e7abca4919fbde2a04035a0fea9e35
diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
index 5571341..c1e4d72 100755
--- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
+++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
@@ -1444,7 +1444,7 @@
         int result = PackageManager.MOVE_FAILED_FORWARD_LOCKED;
         sampleMoveFromRawResource(installFlags, moveFlags, fail, result);
     }
-    //TODO: To be reenabled after investigation
+    @MediumTest
     public void testMoveAppFailInternalToExternalDelete() {
         int installFlags = 0;
         int moveFlags = PackageManager.MOVE_EXTERNAL_MEDIA;
@@ -1461,7 +1461,8 @@
             ip = installFromRawResource("install.apk", R.raw.install, installFlags, false,
                     false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED);
             // Delete the package now retaining data.
-            pm.deletePackage(ip.pkg.packageName, null, PackageManager.DONT_DELETE_DATA);
+            GenericReceiver receiver = new DeleteReceiver(ip.pkg.packageName);
+            invokeDeletePackage(ip.pkg.packageName, PackageManager.DONT_DELETE_DATA, receiver);
             assertTrue(invokeMovePackageFail(ip.pkg.packageName, moveFlags, result));
         } catch (Exception e) {
             failStr(e);
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 22becba..5ed19a2 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -5057,7 +5057,8 @@
         }
     }
 
-    private InstallArgs createInstallArgs(Uri packageURI, int flags, String pkgName) {
+    private InstallArgs createInstallArgs(Uri packageURI, int flags,
+            String pkgName) {
         if (installOnSd(flags)) {
             String cid = getNextCodePath(null, pkgName, "/" + SdInstallArgs.RES_FILE_NAME);
             return new SdInstallArgs(packageURI, cid);
@@ -5317,6 +5318,7 @@
         SdInstallArgs(String cid) {
             super(null, null, PackageManager.INSTALL_EXTERNAL, null);
             this.cid = cid;
+            cachePath = PackageHelper.getSdDir(cid);
         }
 
         SdInstallArgs(Uri packageURI, String cid) {