Add a flag to protect overwrite app optimization mode to restricted mode.
- Skip set app optimization mode to restricted if the flag disabled. Bug: 348192536 Fix: 348192536 Test: atest Flag: EXEMPT bug fix Change-Id: I92d320ce1edfe9b7044afdcd058651b0d54bd6bd
This commit is contained in:
@@ -83,8 +83,17 @@ class AppOptModeSharedPreferencesUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateAppOptModeExpirationInternal_withExpirationTime_verifyData() {
|
||||
insertAppOptModeEventForTest(expirationTime = 1000L)
|
||||
fun updateAppOptModeExpirationInternal_withoutExpirationTime_verifyEmptyList() {
|
||||
insertAppOptModeEventForTest(expirationTime = UNLIMITED_EXPIRE_TIME)
|
||||
|
||||
assertThat(AppOptModeSharedPreferencesUtils.getAllEvents(context)).isEmpty()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateAppOptModeExpirationInternal_setOptimizedModeWithFlagEnabled_verifyData() {
|
||||
whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
|
||||
.thenReturn(true)
|
||||
insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_OPTIMIZED)
|
||||
|
||||
val events = AppOptModeSharedPreferencesUtils.getAllEvents(context)
|
||||
|
||||
@@ -99,8 +108,46 @@ class AppOptModeSharedPreferencesUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateAppOptModeExpirationInternal_withoutExpirationTime_verifyEmptyList() {
|
||||
insertAppOptModeEventForTest(expirationTime = UNLIMITED_EXPIRE_TIME)
|
||||
fun updateAppOptModeExpirationInternal_setOptimizedModeWithFlagDisabled_verifyData() {
|
||||
whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
|
||||
.thenReturn(false)
|
||||
insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_OPTIMIZED)
|
||||
|
||||
val events = AppOptModeSharedPreferencesUtils.getAllEvents(context)
|
||||
|
||||
assertThat(events).hasSize(1)
|
||||
assertAppOptimizationModeEventInfo(
|
||||
events[0],
|
||||
UID,
|
||||
PACKAGE_NAME,
|
||||
MODE_OPTIMIZED,
|
||||
expirationTime = 1000L
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateAppOptModeExpirationInternal_setRestrictedModeWithFlagEnabled_verifyData() {
|
||||
whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
|
||||
.thenReturn(true)
|
||||
insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_RESTRICTED)
|
||||
|
||||
val events = AppOptModeSharedPreferencesUtils.getAllEvents(context)
|
||||
|
||||
assertThat(events).hasSize(1)
|
||||
assertAppOptimizationModeEventInfo(
|
||||
events[0],
|
||||
UID,
|
||||
PACKAGE_NAME,
|
||||
MODE_RESTRICTED,
|
||||
expirationTime = 1000L
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateAppOptModeExpirationInternal_setRestrictedModeWithFlagDisabled_verifyEmptyList() {
|
||||
whenever(featureFactory.powerUsageFeatureProvider.isRestrictedModeOverwriteEnabled)
|
||||
.thenReturn(false)
|
||||
insertAppOptModeEventForTest(expirationTime = 1000L, mode = MODE_RESTRICTED)
|
||||
|
||||
assertThat(AppOptModeSharedPreferencesUtils.getAllEvents(context)).isEmpty()
|
||||
}
|
||||
@@ -237,14 +284,14 @@ class AppOptModeSharedPreferencesUtilsTest {
|
||||
assertThat(currentOptMode).isEqualTo(MODE_RESTRICTED)
|
||||
}
|
||||
|
||||
private fun insertAppOptModeEventForTest(expirationTime: Long) {
|
||||
private fun insertAppOptModeEventForTest(expirationTime: Long, mode: Int = MODE_OPTIMIZED) {
|
||||
whenever(testBatteryOptimizeUtils?.isOptimizeModeMutable).thenReturn(true)
|
||||
whenever(testBatteryOptimizeUtils?.getAppOptimizationMode(true)).thenReturn(MODE_OPTIMIZED)
|
||||
whenever(testBatteryOptimizeUtils?.getAppOptimizationMode(true)).thenReturn(mode)
|
||||
AppOptModeSharedPreferencesUtils.updateAppOptModeExpirationInternal(
|
||||
context,
|
||||
mutableListOf(UID),
|
||||
mutableListOf(PACKAGE_NAME),
|
||||
mutableListOf(MODE_OPTIMIZED),
|
||||
mutableListOf(mode),
|
||||
longArrayOf(expirationTime),
|
||||
) { _: Int, _: String ->
|
||||
testBatteryOptimizeUtils
|
||||
|
Reference in New Issue
Block a user