From d4838ac4d916104531735712cf3af2fff7432ac1 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Thu, 12 May 2022 00:24:28 +0000 Subject: [PATCH] Populate activeApexChanged in ActiveApexInfo PackageManager and ART wants to know whether a different version of an APEX was activated during this boot compared to the last boot. This change populates this field from binder call to apexd. In a follow up CL PackageManager will use that information to drop apk-in-apex cache on APEX updates. Test: atest ApexManagerTest Bug: 225435110 Change-Id: I0ecdf758567fb8677a676d7c39f6b35cdc1208ac Merged-In: I0ecdf758567fb8677a676d7c39f6b35cdc1208ac (cherry picked from commit fdef4b6afdefa66ef222464d6c5c6f87d10238de) --- .../core/java/com/android/server/pm/ApexManager.java | 9 ++++++--- .../src/com/android/server/pm/ApexManagerTest.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/pm/ApexManager.java b/services/core/java/com/android/server/pm/ApexManager.java index beca71486899c..1a6155b43f6b9 100644 --- a/services/core/java/com/android/server/pm/ApexManager.java +++ b/services/core/java/com/android/server/pm/ApexManager.java @@ -121,17 +121,19 @@ public abstract class ApexManager { public final File apexDirectory; public final File preInstalledApexPath; public final File apexFile; + public final boolean activeApexChanged; private ActiveApexInfo(File apexDirectory, File preInstalledApexPath, File apexFile) { - this(null, apexDirectory, preInstalledApexPath, apexFile); + this(null, apexDirectory, preInstalledApexPath, apexFile, false); } private ActiveApexInfo(@Nullable String apexModuleName, File apexDirectory, - File preInstalledApexPath, File apexFile) { + File preInstalledApexPath, File apexFile, boolean activeApexChanged) { this.apexModuleName = apexModuleName; this.apexDirectory = apexDirectory; this.preInstalledApexPath = preInstalledApexPath; this.apexFile = apexFile; + this.activeApexChanged = activeApexChanged; } private ActiveApexInfo(ApexInfo apexInfo) { @@ -140,7 +142,8 @@ public abstract class ApexManager { new File(Environment.getApexDirectory() + File.separator + apexInfo.moduleName), new File(apexInfo.preinstalledModulePath), - new File(apexInfo.modulePath)); + new File(apexInfo.modulePath), + apexInfo.activeApexChanged); } } diff --git a/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java index 8f5b0e19f07ed..ab292ab5381e9 100644 --- a/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java @@ -546,6 +546,18 @@ public class ApexManagerTest { assertThat(backingApexFile).isNull(); } + @Test + public void testActiveApexChanged() throws RemoteException { + ApexInfo apex1 = createApexInfo( + "com.apex1", 37, true, true, new File("/data/apex/active/com.apex@37.apex")); + apex1.activeApexChanged = true; + apex1.preinstalledModulePath = apex1.modulePath; + when(mApexService.getActivePackages()).thenReturn(new ApexInfo[]{apex1}); + final ApexManager.ActiveApexInfo activeApex = mApexManager.getActiveApexInfos().get(0); + assertThat(activeApex.apexModuleName).isEqualTo("com.apex1"); + assertThat(activeApex.activeApexChanged).isTrue(); + } + private ApexInfo createApexInfoForTestPkg(boolean isActive, boolean isFactory, int version) { File apexFile = extractResource(TEST_APEX_PKG, TEST_APEX_FILE_NAME); ApexInfo apexInfo = new ApexInfo();