Remove useless optimization mode backup for FULL_POWER_LIST am: 2c125d29a3

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23240822

Change-Id: I4fb700f5e002d69abf4d8acf68fdcce6a18a20d8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
ykhung
2023-05-15 17:36:02 +00:00
committed by Automerger Merge Worker
2 changed files with 4 additions and 36 deletions

View File

@@ -55,7 +55,6 @@ public final class BatteryBackupHelper implements BackupHelper {
static final String DELIMITER = ","; static final String DELIMITER = ",";
static final String DELIMITER_MODE = ":"; static final String DELIMITER_MODE = ":";
static final String KEY_FULL_POWER_LIST = "full_power_list";
static final String KEY_OPTIMIZATION_LIST = "optimization_mode_list"; static final String KEY_OPTIMIZATION_LIST = "optimization_mode_list";
@VisibleForTesting @VisibleForTesting
@@ -83,7 +82,7 @@ public final class BatteryBackupHelper implements BackupHelper {
Log.w(TAG, "ignore performBackup() for non-owner or empty data"); Log.w(TAG, "ignore performBackup() for non-owner or empty data");
return; return;
} }
final List<String> allowlistedApps = backupFullPowerList(data); final List<String> allowlistedApps = getFullPowerList();
if (allowlistedApps != null) { if (allowlistedApps != null) {
backupOptimizationMode(data, allowlistedApps); backupOptimizationMode(data, allowlistedApps);
} }
@@ -117,7 +116,7 @@ public final class BatteryBackupHelper implements BackupHelper {
public void writeNewStateDescription(ParcelFileDescriptor newState) { public void writeNewStateDescription(ParcelFileDescriptor newState) {
} }
private List<String> backupFullPowerList(BackupDataOutput data) { private List<String> getFullPowerList() {
final long timestamp = System.currentTimeMillis(); final long timestamp = System.currentTimeMillis();
String[] allowlistedApps; String[] allowlistedApps;
try { try {
@@ -131,10 +130,7 @@ public final class BatteryBackupHelper implements BackupHelper {
Log.w(TAG, "no data found in the getFullPowerList()"); Log.w(TAG, "no data found in the getFullPowerList()");
return new ArrayList<>(); return new ArrayList<>();
} }
Log.d(TAG, String.format("getFullPowerList() size=%d in %d/ms",
final String allowedApps = String.join(DELIMITER, allowlistedApps);
writeBackupData(data, KEY_FULL_POWER_LIST, allowedApps);
Log.d(TAG, String.format("backup getFullPowerList() size=%d in %d/ms",
allowlistedApps.length, (System.currentTimeMillis() - timestamp))); allowlistedApps.length, (System.currentTimeMillis() - timestamp)));
return Arrays.asList(allowlistedApps); return Arrays.asList(allowlistedApps);
} }

View File

@@ -159,34 +159,6 @@ public final class BatteryBackupHelperTest {
verify(mBackupDataOutput, never()).writeEntityHeader(anyString(), anyInt()); verify(mBackupDataOutput, never()).writeEntityHeader(anyString(), anyInt());
} }
@Test
public void performBackup_oneFullPowerListElement_backupFullPowerListData()
throws Exception {
final String[] fullPowerList = {"com.android.package"};
doReturn(fullPowerList).when(mDeviceController).getFullPowerWhitelist();
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
final byte[] expectedBytes = fullPowerList[0].getBytes();
verify(mBackupDataOutput).writeEntityHeader(
BatteryBackupHelper.KEY_FULL_POWER_LIST, expectedBytes.length);
verify(mBackupDataOutput).writeEntityData(expectedBytes, expectedBytes.length);
}
@Test
public void performBackup_backupFullPowerListData() throws Exception {
final String[] fullPowerList = {"com.android.package1", "com.android.package2"};
doReturn(fullPowerList).when(mDeviceController).getFullPowerWhitelist();
mBatteryBackupHelper.performBackup(null, mBackupDataOutput, null);
final String expectedResult = fullPowerList[0] + DELIMITER + fullPowerList[1];
final byte[] expectedBytes = expectedResult.getBytes();
verify(mBackupDataOutput).writeEntityHeader(
BatteryBackupHelper.KEY_FULL_POWER_LIST, expectedBytes.length);
verify(mBackupDataOutput).writeEntityData(expectedBytes, expectedBytes.length);
}
@Test @Test
public void performBackup_nonOwner_ignoreAllBackupAction() throws Exception { public void performBackup_nonOwner_ignoreAllBackupAction() throws Exception {
ShadowUserHandle.setUid(1); ShadowUserHandle.setUid(1);
@@ -283,7 +255,7 @@ public final class BatteryBackupHelperTest {
@Test @Test
public void restoreEntity_incorrectDataKey_notReadBackupData() throws Exception { public void restoreEntity_incorrectDataKey_notReadBackupData() throws Exception {
final String incorrectDataKey = BatteryBackupHelper.KEY_FULL_POWER_LIST; final String incorrectDataKey = "incorrect_data_key";
mockBackupData(30 /*dataSize*/, incorrectDataKey); mockBackupData(30 /*dataSize*/, incorrectDataKey);
mBatteryBackupHelper.restoreEntity(mBackupDataInputStream); mBatteryBackupHelper.restoreEntity(mBackupDataInputStream);