[cts] test that ArchiveState is cleared on package update

BUG: 297352898
BUG: 310027113

Test: adb shell device_config set_sync_disabled_for_tests persistent
Test: adb shell device_config put package_manager_service android.content.pm.archiving true
android.content.pm.cts.PackageInstallerArchiveTest#archiveApp_archiveStateClearedAfterUpdate
Test: atest android.content.pm.cts.PackageInstallerArchiveTest#archiveApp_archiveStateClearedAfterUpdate

Change-Id: I7ead8e6e18674990f1c724162e23646cf6217b3d
diff --git a/tests/tests/content/src/android/content/pm/cts/PackageInstallerArchiveTest.java b/tests/tests/content/src/android/content/pm/cts/PackageInstallerArchiveTest.java
index 2aa6a7f..319e3ac 100644
--- a/tests/tests/content/src/android/content/pm/cts/PackageInstallerArchiveTest.java
+++ b/tests/tests/content/src/android/content/pm/cts/PackageInstallerArchiveTest.java
@@ -340,7 +340,7 @@
 
     @Test
     @RequiresFlagsEnabled(Flags.FLAG_ARCHIVING)
-    public void testGetArchiveTimeMillis() throws Exception {
+    public void archiveApp_getArchiveTimeMillis() throws Exception {
         installPackage(PACKAGE_NAME, APK_PATH);
         final long timestampBeforeArchive = System.currentTimeMillis();
         runWithShellPermissionIdentity(
@@ -361,6 +361,32 @@
 
     @Test
     @RequiresFlagsEnabled(Flags.FLAG_ARCHIVING)
+    public void archiveApp_archiveStateClearedAfterUpdate() throws Exception {
+        installPackage(PACKAGE_NAME, APK_PATH);
+        runWithShellPermissionIdentity(
+                () -> mPackageInstaller.requestArchive(PACKAGE_NAME,
+                        new IntentSender((IIntentSender) mArchiveIntentSender)),
+                Manifest.permission.DELETE_PACKAGES);
+
+        assertThat(mArchiveIntentSender.mStatus.get()).isEqualTo(PackageInstaller.STATUS_SUCCESS);
+
+        // Test that the archiveTimeMillis field is valid
+        PackageInfo pi = mPackageManager.getPackageInfo(PACKAGE_NAME,
+                PackageInfoFlags.of(MATCH_ARCHIVED_PACKAGES));
+        assertThat(pi).isNotNull();
+        assertThat(pi.getArchiveTimeMillis()).isGreaterThan(0);
+        assertThat(pi.applicationInfo.isArchived).isTrue();
+
+        // reinstall the app
+        installPackage(PACKAGE_NAME, APK_PATH);
+        pi = mPackageManager.getPackageInfo(PACKAGE_NAME, PackageInfoFlags.of(0));
+        assertThat(pi).isNotNull();
+        assertThat(pi.getArchiveTimeMillis()).isEqualTo(0);
+        assertThat(pi.applicationInfo.isArchived).isFalse();
+    }
+
+    @Test
+    @RequiresFlagsEnabled(Flags.FLAG_ARCHIVING)
     public void unarchiveApp() throws Exception {
         installPackage(PACKAGE_NAME, APK_PATH);
         runWithShellPermissionIdentity(