Loading src/com/android/settings/fuelgauge/PowerUsageSummary.java +15 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ public class PowerUsageSummary extends PowerUsageBase { private static final boolean USE_FAKE_DATA = false; private static final String KEY_APP_LIST = "app_list"; private static final String KEY_BATTERY_HEADER = "battery_header"; private static final String KEY_SHOW_ALL_APPS = "show_all_apps"; private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10; private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10; Loading Loading @@ -131,6 +132,7 @@ public class PowerUsageSummary extends PowerUsageBase { mBatteryUtils = BatteryUtils.getInstance(getContext()); restoreSavedInstance(icicle); initFeatureProvider(); } Loading @@ -154,6 +156,12 @@ public class PowerUsageSummary extends PowerUsageBase { } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(KEY_SHOW_ALL_APPS, mShowAllApps); } @Override public boolean onPreferenceTreeClick(Preference preference) { if (KEY_BATTERY_HEADER.equals(preference.getKey())) { Loading Loading @@ -262,6 +270,13 @@ public class PowerUsageSummary extends PowerUsageBase { } } @VisibleForTesting void restoreSavedInstance(Bundle savedInstance) { if (savedInstance != null) { mShowAllApps = savedInstance.getBoolean(KEY_SHOW_ALL_APPS, false); } } private void addNotAvailableMessage() { final String NOT_AVAILABLE = "not_available"; Preference notAvailable = getCachedPreference(NOT_AVAILABLE); Loading tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +17 −4 Original line number Diff line number Diff line Loading @@ -15,10 +15,12 @@ */ package com.android.settings.fuelgauge; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.os.Process; import android.support.v7.preference.PreferenceScreen; import android.text.TextUtils; import android.text.format.DateUtils; import android.view.Menu; Loading @@ -41,13 +43,11 @@ import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor; import com.android.settings.testutils.XmlTestUtils; import com.android.settingslib.BatteryInfo; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; Loading @@ -65,7 +65,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; Loading Loading @@ -135,6 +134,8 @@ public class PowerUsageSummaryTest { private PowerManager mPowerManager; @Mock private SettingsActivity mSettingsActivity; @Mock private PreferenceScreen mPreferenceScreen; private List<BatterySipper> mUsageList; private Context mRealContext; Loading Loading @@ -432,6 +433,18 @@ public class PowerUsageSummaryTest { assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys); } @Test public void testSaveInstanceState_showAllAppsRestored() { Bundle bundle = new Bundle(); mFragment.mShowAllApps = true; doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen(); mFragment.onSaveInstanceState(bundle); mFragment.restoreSavedInstance(bundle); assertThat(mFragment.mShowAllApps).isTrue(); } public static class TestFragment extends PowerUsageSummary { private Context mContext; Loading Loading
src/com/android/settings/fuelgauge/PowerUsageSummary.java +15 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ public class PowerUsageSummary extends PowerUsageBase { private static final boolean USE_FAKE_DATA = false; private static final String KEY_APP_LIST = "app_list"; private static final String KEY_BATTERY_HEADER = "battery_header"; private static final String KEY_SHOW_ALL_APPS = "show_all_apps"; private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10; private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10; Loading Loading @@ -131,6 +132,7 @@ public class PowerUsageSummary extends PowerUsageBase { mBatteryUtils = BatteryUtils.getInstance(getContext()); restoreSavedInstance(icicle); initFeatureProvider(); } Loading @@ -154,6 +156,12 @@ public class PowerUsageSummary extends PowerUsageBase { } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(KEY_SHOW_ALL_APPS, mShowAllApps); } @Override public boolean onPreferenceTreeClick(Preference preference) { if (KEY_BATTERY_HEADER.equals(preference.getKey())) { Loading Loading @@ -262,6 +270,13 @@ public class PowerUsageSummary extends PowerUsageBase { } } @VisibleForTesting void restoreSavedInstance(Bundle savedInstance) { if (savedInstance != null) { mShowAllApps = savedInstance.getBoolean(KEY_SHOW_ALL_APPS, false); } } private void addNotAvailableMessage() { final String NOT_AVAILABLE = "not_available"; Preference notAvailable = getCachedPreference(NOT_AVAILABLE); Loading
tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +17 −4 Original line number Diff line number Diff line Loading @@ -15,10 +15,12 @@ */ package com.android.settings.fuelgauge; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.PowerManager; import android.os.Process; import android.support.v7.preference.PreferenceScreen; import android.text.TextUtils; import android.text.format.DateUtils; import android.view.Menu; Loading @@ -41,13 +43,11 @@ import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor; import com.android.settings.testutils.XmlTestUtils; import com.android.settingslib.BatteryInfo; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; Loading @@ -65,7 +65,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; Loading Loading @@ -135,6 +134,8 @@ public class PowerUsageSummaryTest { private PowerManager mPowerManager; @Mock private SettingsActivity mSettingsActivity; @Mock private PreferenceScreen mPreferenceScreen; private List<BatterySipper> mUsageList; private Context mRealContext; Loading Loading @@ -432,6 +433,18 @@ public class PowerUsageSummaryTest { assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys); } @Test public void testSaveInstanceState_showAllAppsRestored() { Bundle bundle = new Bundle(); mFragment.mShowAllApps = true; doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen(); mFragment.onSaveInstanceState(bundle); mFragment.restoreSavedInstance(bundle); assertThat(mFragment.mShowAllApps).isTrue(); } public static class TestFragment extends PowerUsageSummary { private Context mContext; Loading