Limit the optimization mode restore mechanism for specific conditions

Limit the app optimization mode restore mechanism is enabled by checking
the isValidToRestoreOptimizationMode() method (default false)

Bug: 280192659
Test: make test RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.fuelgauge.BatteryBackupHelperTest
Change-Id: I90a438a15905578336bc46ec7cd92d3bbe2858b7
This commit is contained in:
ykhung
2023-05-16 15:45:23 +08:00
parent cad41681d6
commit 24cbb2c0aa
4 changed files with 104 additions and 24 deletions

View File

@@ -283,6 +283,20 @@ public final class BatteryBackupHelperTest {
assertThat(TestUtils.getScheduledLevel(mContext)).isNotEqualTo(invalidScheduledLevel);
}
@Test
public void restoreEntity_verifyConfigurationOneTimeOnly() {
final int invalidScheduledLevel = 5;
TestUtils.setScheduledLevel(mContext, invalidScheduledLevel);
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);
TestUtils.setScheduledLevel(mContext, invalidScheduledLevel);
// Invoke the restoreEntity() method 2nd time.
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);
assertThat(TestUtils.getScheduledLevel(mContext))
.isEqualTo(invalidScheduledLevel);
}
@Test
public void restoreOptimizationMode_nullBytesData_skipRestore() throws Exception {
mBatteryBackupHelper.restoreOptimizationMode(new byte[0]);