Verify and reset invalid battery setting in the data restore stage

Verify and reset invalid battery setting configuration in the data
restore stage to avoid resoring invalid configuration from other devices

Bug: 258243197
Test: make RunSettingsRoboTests
Change-Id: I1a0febd2ad527147e4e9e9c77734c4b51963263a
This commit is contained in:
ykhung
2022-11-11 13:46:49 +08:00
committed by YK Hung
parent df25b72044
commit d66fd82c35
5 changed files with 64 additions and 9 deletions

View File

@@ -51,6 +51,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArraySet;
import com.android.settings.TestUtils;
import com.android.settings.fuelgauge.BatteryOptimizeHistoricalLogEntry.Action;
import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
@@ -290,6 +291,16 @@ public final class BatteryBackupHelperTest {
assertThat(captor.getValue().length).isEqualTo(dataSize);
}
@Test
public void restoreEntity_verifyConfiguration() {
final int invalidScheduledLevel = 5;
TestUtils.setScheduledLevel(mContext, invalidScheduledLevel);
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);
assertThat(TestUtils.getScheduledLevel(mContext)).isNotEqualTo(invalidScheduledLevel);
}
@Test
public void restoreOptimizationMode_nullBytesData_skipRestore() throws Exception {
mBatteryBackupHelper.restoreOptimizationMode(new byte[0]);