Test fixes:

- testBaseApkInvalidSignatureAdbInstall was copying idsig to the wrong
folder and never tested it
- testBaseApkMissingSignatureAdbInstall was relying on outdated
assumption which never got fixed

Bug: 163543633
Bug: 165886059
Test: atest IncrementalInstallTest
Change-Id: Ibbd86df73a3db6d4a10274f6fc2de118e3f764e0
Merged-Id: Ibbd86df73a3db6d4a10274f6fc2de118e3f764e0
(cherry picked from commit b4c7b87d9cbbe7791b324d1b8c3885877b343e3b)
diff --git a/hostsidetests/incrementalinstall/src/android/incrementalinstall/cts/IncrementalInstallTest.java b/hostsidetests/incrementalinstall/src/android/incrementalinstall/cts/IncrementalInstallTest.java
index d847e3c..6e7adc6 100644
--- a/hostsidetests/incrementalinstall/src/android/incrementalinstall/cts/IncrementalInstallTest.java
+++ b/hostsidetests/incrementalinstall/src/android/incrementalinstall/cts/IncrementalInstallTest.java
@@ -135,11 +135,14 @@
     public void testBaseApkMissingSignatureAdbInstall() throws Exception {
         String newApkName = String.format("base%d.apk", new Random().nextInt());
         // Create a copy of original apk but not its idsig.
-        copyTestFile(TEST_APP_BASE_APK_NAME, newApkName);
-        String output = installWithAdbInstaller(newApkName);
-        verifyInstallCommandFailure(output);
-        assertTrue(output.contains(String.format("Failed to stat signature file %s",
-                getFilePathFromBuildInfo(newApkName) + SIG_SUFFIX)));
+        copyTestFile(TEST_APP_BASE_APK_NAME, null, newApkName);
+        // Make sure it installs.
+        assertTrue(
+                installWithAdbInstaller(TEST_APP_BASE_APK_NAME).contains(INSTALL_SUCCESS_OUTPUT));
+        verifyPackageInstalled(TEST_APP_PACKAGE_NAME);
+        verifyInstallationTypeAndVersion(TEST_APP_PACKAGE_NAME, /* isIncfs= */ true,
+                TEST_APP_V1_VERSION);
+        validateAppLaunch(TEST_APP_PACKAGE_NAME, ON_CREATE_COMPONENT);
 
     }
 
@@ -147,8 +150,9 @@
     public void testBaseApkInvalidSignatureAdbInstall() throws Exception {
         String newApkName = String.format("base%d.apk", new Random().nextInt());
         String sigSuffix = ".idsig";
-        copyTestFile(TEST_APP_BASE_APK_NAME, newApkName);
-        copyTestFile(TEST_APP_BASE_APK_NAME + sigSuffix, newApkName + sigSuffix);
+        File destApk = copyTestFile(TEST_APP_BASE_APK_NAME, null, newApkName);
+        copyTestFile(TEST_APP_BASE_APK_NAME + sigSuffix, destApk.getParentFile(),
+                newApkName + sigSuffix);
         try (RandomAccessFile raf = new RandomAccessFile(
                 getFilePathFromBuildInfo(newApkName + sigSuffix), "rw")) {
             // Contaminate signature by complementing a random byte.
@@ -351,10 +355,11 @@
         return mBuildHelper.getTestFile(filename).getAbsolutePath();
     }
 
-    private void copyTestFile(String sourceFilename, String destFilename) throws IOException {
+    private File copyTestFile(String sourceFilename, File destPath, String destFilename) throws IOException {
         File source = new File(getFilePathFromBuildInfo(sourceFilename));
-        File dest = new File(source.getParentFile(), destFilename);
+        File dest = new File(destPath != null ? destPath : source.getParentFile(), destFilename);
         FileUtil.copyFile(source, dest);
+        return dest;
     }
 
     private void uninstallApp(String packageName) throws Exception {