Fix the wrong test fixture setup regarding downgrade.
The storage threshold is now controlled by a constant rather than a
sysprop. This change removes the setup for the sysprop that no longer
exsits and adds a test case to catch such wrong setup.
Also fixes a wrong comment.
Bug: 255565888
Test: atest ArtServiceTests
Ignore-AOSP-First: ART Services.
Change-Id: Ib902e643a528a47ec5d0c3a3b1751d3d9d6f6d90
diff --git a/libartservice/service/java/com/android/server/art/ArtManagerLocal.java b/libartservice/service/java/com/android/server/art/ArtManagerLocal.java
index 6f5818a..baaf622 100644
--- a/libartservice/service/java/com/android/server/art/ArtManagerLocal.java
+++ b/libartservice/service/java/com/android/server/art/ArtManagerLocal.java
@@ -101,7 +101,9 @@
private static final String TAG = "ArtService";
private static final String[] CLASSPATHS_FOR_BOOT_IMAGE_PROFILE = {
"BOOTCLASSPATH", "SYSTEMSERVERCLASSPATH", "STANDALONE_SYSTEMSERVER_JARS"};
- private static final long DOWNGRADE_THRESHOLD_ABOVE_LOW_BYTES = 500_000_000;
+
+ /** @hide */
+ @VisibleForTesting public static final long DOWNGRADE_THRESHOLD_ABOVE_LOW_BYTES = 500_000_000;
@NonNull private final Injector mInjector;
@@ -407,7 +409,7 @@
* pm.dexopt.downgrade_after_inactive_days} is set. The space threshold to trigger this feature
* is the Storage Manager's low space threshold plus {@link
* #DOWNGRADE_THRESHOLD_ABOVE_LOW_BYTES}. The concurrency can be configured by system property
- * {@code pm.dexopt.inactive.concurrency}. The packages in the list provided by
+ * {@code pm.dexopt.bg-dexopt.concurrency}. The packages in the list provided by
* {@link BatchDexoptStartCallback} for {@link ReasonMapping#REASON_BG_DEXOPT} are never
* downgraded.
*
diff --git a/libartservice/service/javatests/com/android/server/art/ArtManagerLocalTest.java b/libartservice/service/javatests/com/android/server/art/ArtManagerLocalTest.java
index 1f294be..54a6a77 100644
--- a/libartservice/service/javatests/com/android/server/art/ArtManagerLocalTest.java
+++ b/libartservice/service/javatests/com/android/server/art/ArtManagerLocalTest.java
@@ -171,10 +171,6 @@
.when(SystemProperties.getInt(
eq("pm.dexopt.downgrade_after_inactive_days"), anyInt()))
.thenReturn(INACTIVE_DAYS);
- lenient()
- .when(SystemProperties.getLong(
- eq("pm.dexopt.storage_threshold_above_low_bytes"), anyLong()))
- .thenReturn(1000l);
// No ISA translation.
lenient()
@@ -197,7 +193,7 @@
List<? extends SecondaryDexInfo> secondaryDexInfo = createSecondaryDexInfo();
lenient().doReturn(secondaryDexInfo).when(mDexUseManager).getSecondaryDexInfo(eq(PKG_NAME));
- lenient().when(mStorageManager.getAllocatableBytes(any())).thenReturn(1000l);
+ simulateStorageNotLow();
lenient().when(mPackageManagerLocal.withFilteredSnapshot()).thenReturn(mSnapshot);
List<PackageState> pkgStates = createPackageStates();
@@ -438,7 +434,7 @@
var dexoptResult = mock(DexoptResult.class);
var cancellationSignal = new CancellationSignal();
when(mDexUseManager.getPackageLastUsedAtMs(PKG_NAME_SYS_UI)).thenReturn(CURRENT_TIME_MS);
- when(mStorageManager.getAllocatableBytes(any())).thenReturn(999l);
+ simulateStorageLow();
// It should use the default package list and params. The list is sorted by last active
// time in descending order.
@@ -464,7 +460,7 @@
PackageUserState userState = mPkgState.getStateForUser(UserHandle.of(1));
when(userState.getFirstInstallTimeMillis()).thenReturn(RECENT_TIME_MS);
when(mDexUseManager.getPackageLastUsedAtMs(PKG_NAME)).thenReturn(0l);
- when(mStorageManager.getAllocatableBytes(any())).thenReturn(999l);
+ simulateStorageLow();
var result = mock(DexoptResult.class);
var cancellationSignal = new CancellationSignal();
@@ -491,7 +487,7 @@
PackageUserState userState = mPkgState.getStateForUser(UserHandle.of(1));
when(userState.getFirstInstallTimeMillis()).thenReturn(NOT_RECENT_TIME_MS);
when(mDexUseManager.getPackageLastUsedAtMs(PKG_NAME)).thenReturn(NOT_RECENT_TIME_MS);
- when(mStorageManager.getAllocatableBytes(any())).thenReturn(999l);
+ simulateStorageLow();
var result = mock(DexoptResult.class);
var cancellationSignal = new CancellationSignal();
@@ -515,10 +511,36 @@
}
@Test
+ public void testDexoptPackagesInactiveStorageNotLow() throws Exception {
+ // PKG_NAME is neither recently installed nor recently used.
+ PackageUserState userState = mPkgState.getStateForUser(UserHandle.of(1));
+ when(userState.getFirstInstallTimeMillis()).thenReturn(NOT_RECENT_TIME_MS);
+ when(mDexUseManager.getPackageLastUsedAtMs(PKG_NAME)).thenReturn(NOT_RECENT_TIME_MS);
+
+ var result = mock(DexoptResult.class);
+ var cancellationSignal = new CancellationSignal();
+
+ // PKG_NAME should not be dexopted.
+ doReturn(result)
+ .when(mDexoptHelper)
+ .dexopt(any(), deepEq(List.of(PKG_NAME_SYS_UI)),
+ argThat(params -> params.getReason().equals("bg-dexopt")), any(), any(),
+ any(), any());
+
+ mArtManagerLocal.dexoptPackages(mSnapshot, "bg-dexopt", cancellationSignal,
+ null /* processCallbackExecutor */, null /* processCallback */);
+
+ // PKG_NAME should not be downgraded because the storage is not low.
+ verify(mDexoptHelper, never())
+ .dexopt(any(), any(), argThat(params -> params.getReason().equals("inactive")),
+ any(), any(), any(), any());
+ }
+
+ @Test
public void testDexoptPackagesBootAfterMainlineUpdate() throws Exception {
var result = mock(DexoptResult.class);
var cancellationSignal = new CancellationSignal();
- lenient().when(mStorageManager.getAllocatableBytes(any())).thenReturn(999l);
+ simulateStorageLow();
// It should only dexopt system UI.
when(mDexoptHelper.dexopt(
@@ -542,7 +564,7 @@
PackageUserState userState = mPkgState.getStateForUser(UserHandle.of(1));
when(userState.getFirstInstallTimeMillis()).thenReturn(NOT_RECENT_TIME_MS);
when(mDexUseManager.getPackageLastUsedAtMs(PKG_NAME)).thenReturn(NOT_RECENT_TIME_MS);
- when(mStorageManager.getAllocatableBytes(any())).thenReturn(999l);
+ simulateStorageLow();
var params = new DexoptParams.Builder("bg-dexopt").build();
var result = mock(DexoptResult.class);
@@ -867,4 +889,16 @@
lenient().when(dexInfo.classLoaderContext()).thenReturn("CLC");
return List.of(dexInfo);
}
+
+ private void simulateStorageLow() throws Exception {
+ lenient()
+ .when(mStorageManager.getAllocatableBytes(any()))
+ .thenReturn(ArtManagerLocal.DOWNGRADE_THRESHOLD_ABOVE_LOW_BYTES - 1);
+ }
+
+ private void simulateStorageNotLow() throws Exception {
+ lenient()
+ .when(mStorageManager.getAllocatableBytes(any()))
+ .thenReturn(ArtManagerLocal.DOWNGRADE_THRESHOLD_ABOVE_LOW_BYTES);
+ }
}