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

Commit fd62af57 authored by Lei Yu's avatar Lei Yu
Browse files

Fix crash in Monkey test.

When battery page is launched, BatteryTipLoader will start running.
If we rotate the screen before loader is finished, it will store null
to Bundle and will crash when restoring from that Bundle.

In this cl, we add null pointer check for tip list to avoid the crash.

Also remove a TODO since it is obsolete.

Change-Id: Ic59bc20c633f3a7467f7b5e95da062160bcb4e93
Fixes: 77534165
Test: RunSettingsRoboTests
parent cf60ff7e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -91,6 +91,9 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
    }

    public void updateBatteryTips(List<BatteryTip> batteryTips) {
        if (batteryTips == null) {
            return;
        }
        if (mBatteryTips == null) {
            mBatteryTips = batteryTips;
        } else {
@@ -100,7 +103,6 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
            }
        }

        //TODO(b/70570352): try to reuse the existing preference rather than remove and add.
        mPreferenceGroup.removeAll();
        for (int i = 0, size = batteryTips.size(); i < size; i++) {
            final BatteryTip batteryTip = mBatteryTips.get(i);
+13 −0
Original line number Diff line number Diff line
@@ -149,6 +149,19 @@ public class BatteryTipPreferenceControllerTest {
        assertOnlyContainsSummaryTip(mPreferenceGroup);
    }

    @Test
    public void testRestoreFromNull_shouldNotCrash() {
        final Bundle bundle = new Bundle();
        // Battery tip list is null at this time
        mBatteryTipPreferenceController.saveInstanceState(bundle);

        final BatteryTipPreferenceController controller = new BatteryTipPreferenceController(
                mContext, KEY_PREF, mSettingsActivity, mFragment, mBatteryTipListener);

        // Should not crash
        controller.restoreInstanceState(bundle);
    }

    @Test
    public void testHandlePreferenceTreeClick_noDialog_invokeCallback() {
        when(mBatteryTip.getType()).thenReturn(SMART_BATTERY_MANAGER);