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

Commit 551a1a01 authored by Lei Yu's avatar Lei Yu
Browse files

Refine update process for restrict tip.

When restrict tip update, we should also update app list unless it goes
from NEW to INVISIBLE. After that it won't show "0 apps been
restricted".

Change-Id: Iedf4288fcddfe632a9ba8c16afdfb5bc044bce2e
Fix: 79890132
Test: RunSettingsRoboTests
parent cd28a977
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ public class RestrictAppTip extends BatteryTip {
        } else {
            mState = tip.getState();
            mShowDialog = tip.shouldShowDialog();
            mRestrictAppList = ((RestrictAppTip) tip).mRestrictAppList;
        }
    }

+13 −4
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class RestrictAppTipTest {
    private RestrictAppTip mHandledBatteryTip;
    private RestrictAppTip mInvisibleBatteryTip;
    private List<AppInfo> mUsageAppList;
    private AppInfo mAppInfo;
    @Mock
    private ApplicationInfo mApplicationInfo;
    @Mock
@@ -77,15 +78,16 @@ public class RestrictAppTipTest {
                PackageManager.MATCH_DISABLED_COMPONENTS | PackageManager.MATCH_ANY_USER);
        doReturn(DISPLAY_NAME).when(mApplicationInfo).loadLabel(mPackageManager);

        mUsageAppList = new ArrayList<>();
        mUsageAppList.add(new AppInfo.Builder()
        mAppInfo = new AppInfo.Builder()
                .setPackageName(PACKAGE_NAME)
                .addAnomalyType(ANOMALY_WAKEUP)
                .addAnomalyType(ANOMALY_WAKELOCK)
                .build());
                .build();
        mUsageAppList = new ArrayList<>();
        mUsageAppList.add(mAppInfo);
        mNewBatteryTip = new RestrictAppTip(BatteryTip.StateType.NEW, mUsageAppList);
        mHandledBatteryTip = new RestrictAppTip(BatteryTip.StateType.HANDLED, mUsageAppList);
        mInvisibleBatteryTip = new RestrictAppTip(BatteryTip.StateType.INVISIBLE, mUsageAppList);
        mInvisibleBatteryTip = new RestrictAppTip(BatteryTip.StateType.INVISIBLE, new ArrayList<>());
    }

    @Test
@@ -164,6 +166,13 @@ public class RestrictAppTipTest {
        assertThat(mHandledBatteryTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
    }

    @Test
    public void update_newHandledAnomalyComes_containHandledAnomaly() {
        mInvisibleBatteryTip.updateState(mHandledBatteryTip);
        assertThat(mInvisibleBatteryTip.getState()).isEqualTo(BatteryTip.StateType.HANDLED);
        assertThat(mInvisibleBatteryTip.getRestrictAppList()).containsExactly(mAppInfo);
    }

    @Test
    public void toString_containsAppData() {
        assertThat(mNewBatteryTip.toString()).isEqualTo(