Fix broken hibernation test

ag/14203210 made isAppHibernationEnabled use a cached value rather than
query device config every time. This happened to break a test that
relied on mocking the DeviceConfig value. We update the static value
directly to ensure the feature is enabled in the test.

Bug: 185730191
Test: atest PackageManagerServiceHibernationTests
Change-Id: Icf7d5bedba69cc5af7df2d38bf5088cb08b5cfb6
This commit is contained in:
Kevin Han
2021-04-19 14:26:11 -07:00
parent d560996d0f
commit 7e56f8dad4
2 changed files with 3 additions and 1 deletions

View File

@@ -109,7 +109,7 @@ public final class AppHibernationService extends SystemService {
private final boolean mOatArtifactDeletionEnabled;
@VisibleForTesting
static boolean sIsServiceEnabled;
public static boolean sIsServiceEnabled;
/**
* Initializes the system service.

View File

@@ -24,6 +24,7 @@ import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.testing.TestableLooper.RunWithLooper
import com.android.server.apphibernation.AppHibernationManagerInternal
import com.android.server.apphibernation.AppHibernationService
import com.android.server.extendedtestutils.wheneverStatic
import com.android.server.testutils.whenever
import org.junit.Assert.assertFalse
@@ -61,6 +62,7 @@ class PackageManagerServiceHibernationTests {
MockitoAnnotations.initMocks(this)
wheneverStatic { DeviceConfig.getBoolean(
NAMESPACE_APP_HIBERNATION, KEY_APP_HIBERNATION_ENABLED, false) }.thenReturn(true)
AppHibernationService.sIsServiceEnabled = true
rule.system().stageNominalSystemState()
whenever(rule.mocks().injector.getLocalService(AppHibernationManagerInternal::class.java))
.thenReturn(appHibernationManager)