Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9de5fe15 authored by ykhung's avatar ykhung
Browse files

[B&R] avoid to backup & restore app which is in the PowerSaveWhitelistExceptIdle

BYPASS_INCLUSIVE_LANGUAGE_REASON=legacy method name

Test command for backup manager:
adb shell bmgr backupnow com.android.settings
adb shell dumpsys backup | grep Current
adb shell bmgr restore 3e9867a7660315b8 com.android.settings

Bug: 192523697
Test: make SettingsRoboTests
Change-Id: I78f34870af3146698e6d1b9fbc5ec4385a8d5384
parent 8ab5c92a
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -263,7 +263,9 @@ public final class BatteryBackupHelper implements BackupHelper {
    private boolean isSystemOrDefaultApp(String packageName) {
        final PowerAllowlistBackend powerAllowlistBackend = getPowerAllowlistBackend();
        return powerAllowlistBackend.isSysAllowlisted(packageName)
                || powerAllowlistBackend.isDefaultActiveApp(packageName);
                || powerAllowlistBackend.isDefaultActiveApp(packageName)
                // Optimize mode only for app which is in the allow list not idle app.
                || powerAllowlistBackend.isAllowlistedExceptIdle(packageName);
    }

    private List<ApplicationInfo> getInstalledApplications() {
+18 −2
Original line number Diff line number Diff line
@@ -114,6 +114,9 @@ public final class BatteryBackupHelperTest {
        mockUid(1001 /*fake uid*/, PACKAGE_NAME1);
        mockUid(1002 /*fake uid*/, PACKAGE_NAME2);
        mockUid(BatteryUtils.UID_NULL, PACKAGE_NAME3);
        doReturn(false).when(mPowerAllowlistBackend).isDefaultActiveApp(anyString());
        doReturn(false).when(mPowerAllowlistBackend).isDefaultActiveApp(anyString());
        doReturn(false).when(mPowerAllowlistBackend).isAllowlistedExceptIdle(anyString());
    }

    @After
@@ -218,7 +221,6 @@ public final class BatteryBackupHelperTest {
        createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
        // Sets "com.android.testing.1" as system app.
        doReturn(true).when(mPowerAllowlistBackend).isSysAllowlisted(PACKAGE_NAME1);
        doReturn(false).when(mPowerAllowlistBackend).isDefaultActiveApp(anyString());

        mBatteryBackupHelper.backupOptimizationMode(mBackupDataOutput, allowlistedApps);

@@ -234,7 +236,21 @@ public final class BatteryBackupHelperTest {
        createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
        // Sets "com.android.testing.1" as device default app.
        doReturn(true).when(mPowerAllowlistBackend).isDefaultActiveApp(PACKAGE_NAME1);
        doReturn(false).when(mPowerAllowlistBackend).isSysAllowlisted(anyString());

        mBatteryBackupHelper.backupOptimizationMode(mBackupDataOutput, allowlistedApps);

        // "com.android.testing.2" for RESTRICTED mode.
        final String expectedResult = PACKAGE_NAME2 + ":1,";
        verifyBackupData(expectedResult);
    }

    @Test
    public void backupOptimizationMode_backupOptimizationAndIgnoreAppInTheAllowlist()
            throws Exception {
        final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
        createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
        // Sets "com.android.testing.1" in the allowlist.
        doReturn(true).when(mPowerAllowlistBackend).isAllowlistedExceptIdle(PACKAGE_NAME1);

        mBatteryBackupHelper.backupOptimizationMode(mBackupDataOutput, allowlistedApps);