Loading src/com/android/settings/fuelgauge/PowerUsageSummary.java +2 −32 Original line number Diff line number Diff line Loading @@ -93,13 +93,9 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList private static final int MENU_STATS_TYPE = Menu.FIRST; @VisibleForTesting static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3; @VisibleForTesting static final int MENU_TOGGLE_APPS = Menu.FIRST + 4; private static final int MENU_HELP = Menu.FIRST + 5; public static final int DEBUG_INFO_LOADER = 3; @VisibleForTesting boolean mShowAllApps = false; @VisibleForTesting PowerGaugePreference mScreenUsagePref; @VisibleForTesting Loading Loading @@ -221,7 +217,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList mAnomalySparseArray = new SparseArray<>(); restartBatteryInfoLoader(); restoreSavedInstance(icicle); } @Override Loading @@ -229,12 +224,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY_V2; } @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 @@ -284,11 +273,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList menu.add(Menu.NONE, MENU_HIGH_POWER_APPS, Menu.NONE, R.string.high_power_apps); if (mPowerFeatureProvider.isPowerAccountingToggleEnabled()) { menu.add(Menu.NONE, MENU_TOGGLE_APPS, Menu.NONE, mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps); } super.onCreateOptionsMenu(menu, inflater); } Loading Loading @@ -322,25 +306,11 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList metricsFeatureProvider.action(context, MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION); return true; case MENU_TOGGLE_APPS: mShowAllApps = !mShowAllApps; item.setTitle(mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps); metricsFeatureProvider.action(context, MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE, mShowAllApps); restartBatteryStatsLoader(false /* clearHeader */); return true; default: return super.onOptionsItemSelected(item); } } @VisibleForTesting void restoreSavedInstance(Bundle savedInstance) { if (savedInstance != null) { mShowAllApps = savedInstance.getBoolean(KEY_SHOW_ALL_APPS, false); } } private void performBatteryHeaderClick() { if (mPowerFeatureProvider.isAdvancedUiEnabled()) { Utils.startWithFragment(getContext(), PowerUsageAdvanced.class.getName(), null, Loading Loading @@ -375,8 +345,8 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList final CharSequence timeSequence = Utils.formatRelativeTime(context, lastFullChargeTime, false); mBatteryAppListPreferenceController.refreshAppListGroup(mStatsHelper, mShowAllApps, timeSequence); mBatteryAppListPreferenceController.refreshAppListGroup(mStatsHelper, false /* showAllApps */, timeSequence); } @VisibleForTesting Loading tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ */ package com.android.settings.fuelgauge; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_HIGH_POWER_APPS; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_TOGGLE_APPS; import static com.android.settings.fuelgauge.PowerUsageSummaryLegacy.MENU_HIGH_POWER_APPS; import static com.android.settings.fuelgauge.PowerUsageSummaryLegacy.MENU_TOGGLE_APPS; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; Loading tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +0 −47 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.settings.fuelgauge; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_HIGH_POWER_APPS; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_TOGGLE_APPS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -170,7 +169,6 @@ public class PowerUsageSummaryTest { doReturn(mock(LoaderManager.class)).when(mFragment).getLoaderManager(); when(mFragment.getActivity()).thenReturn(mSettingsActivity); when(mToggleAppsMenu.getItemId()).thenReturn(MENU_TOGGLE_APPS); when(mHighPowerMenu.getItemId()).thenReturn(MENU_HIGH_POWER_APPS); when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent()) .thenReturn(sAdditionalBatteryInfoIntent); Loading Loading @@ -214,39 +212,6 @@ public class PowerUsageSummaryTest { MetricsProto.MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION); } @Test public void testOptionsMenu_menuAppToggle_metricEventInvoked() { mFragment.onOptionsItemSelected(mToggleAppsMenu); mFragment.mShowAllApps = false; verify(mFeatureFactory.metricsFeatureProvider).action(mContext, MetricsProto.MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE, true); } @Test public void testOptionsMenu_toggleAppsEnabled() { when(mFeatureFactory.powerUsageFeatureProvider.isPowerAccountingToggleEnabled()) .thenReturn(true); mFragment.mShowAllApps = false; mFragment.onCreateOptionsMenu(mMenu, mMenuInflater); verify(mMenu).add(Menu.NONE, MENU_TOGGLE_APPS, Menu.NONE, R.string.show_all_apps); } @Test public void testOptionsMenu_clickToggleAppsMenu_dataChanged() { testToggleAllApps(true); testToggleAllApps(false); } private void testToggleAllApps(final boolean isShowApps) { mFragment.mShowAllApps = isShowApps; mFragment.onOptionsItemSelected(mToggleAppsMenu); assertThat(mFragment.mShowAllApps).isEqualTo(!isShowApps); } @Test public void testUpdateLastFullChargePreference_showCorrectSummary() { doReturn(mRealContext).when(mFragment).getContext(); Loading Loading @@ -323,18 +288,6 @@ public class PowerUsageSummaryTest { assertThat(summary1.getText().toString().contains(OLD_EST_SUFFIX)); } @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(); } @Test public void testDebugMode() { doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isEstimateDebugEnabled(); Loading Loading
src/com/android/settings/fuelgauge/PowerUsageSummary.java +2 −32 Original line number Diff line number Diff line Loading @@ -93,13 +93,9 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList private static final int MENU_STATS_TYPE = Menu.FIRST; @VisibleForTesting static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3; @VisibleForTesting static final int MENU_TOGGLE_APPS = Menu.FIRST + 4; private static final int MENU_HELP = Menu.FIRST + 5; public static final int DEBUG_INFO_LOADER = 3; @VisibleForTesting boolean mShowAllApps = false; @VisibleForTesting PowerGaugePreference mScreenUsagePref; @VisibleForTesting Loading Loading @@ -221,7 +217,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList mAnomalySparseArray = new SparseArray<>(); restartBatteryInfoLoader(); restoreSavedInstance(icicle); } @Override Loading @@ -229,12 +224,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY_V2; } @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 @@ -284,11 +273,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList menu.add(Menu.NONE, MENU_HIGH_POWER_APPS, Menu.NONE, R.string.high_power_apps); if (mPowerFeatureProvider.isPowerAccountingToggleEnabled()) { menu.add(Menu.NONE, MENU_TOGGLE_APPS, Menu.NONE, mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps); } super.onCreateOptionsMenu(menu, inflater); } Loading Loading @@ -322,25 +306,11 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList metricsFeatureProvider.action(context, MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION); return true; case MENU_TOGGLE_APPS: mShowAllApps = !mShowAllApps; item.setTitle(mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps); metricsFeatureProvider.action(context, MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE, mShowAllApps); restartBatteryStatsLoader(false /* clearHeader */); return true; default: return super.onOptionsItemSelected(item); } } @VisibleForTesting void restoreSavedInstance(Bundle savedInstance) { if (savedInstance != null) { mShowAllApps = savedInstance.getBoolean(KEY_SHOW_ALL_APPS, false); } } private void performBatteryHeaderClick() { if (mPowerFeatureProvider.isAdvancedUiEnabled()) { Utils.startWithFragment(getContext(), PowerUsageAdvanced.class.getName(), null, Loading Loading @@ -375,8 +345,8 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList final CharSequence timeSequence = Utils.formatRelativeTime(context, lastFullChargeTime, false); mBatteryAppListPreferenceController.refreshAppListGroup(mStatsHelper, mShowAllApps, timeSequence); mBatteryAppListPreferenceController.refreshAppListGroup(mStatsHelper, false /* showAllApps */, timeSequence); } @VisibleForTesting Loading
tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ */ package com.android.settings.fuelgauge; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_HIGH_POWER_APPS; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_TOGGLE_APPS; import static com.android.settings.fuelgauge.PowerUsageSummaryLegacy.MENU_HIGH_POWER_APPS; import static com.android.settings.fuelgauge.PowerUsageSummaryLegacy.MENU_TOGGLE_APPS; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; Loading
tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +0 −47 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.settings.fuelgauge; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_HIGH_POWER_APPS; import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_TOGGLE_APPS; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -170,7 +169,6 @@ public class PowerUsageSummaryTest { doReturn(mock(LoaderManager.class)).when(mFragment).getLoaderManager(); when(mFragment.getActivity()).thenReturn(mSettingsActivity); when(mToggleAppsMenu.getItemId()).thenReturn(MENU_TOGGLE_APPS); when(mHighPowerMenu.getItemId()).thenReturn(MENU_HIGH_POWER_APPS); when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent()) .thenReturn(sAdditionalBatteryInfoIntent); Loading Loading @@ -214,39 +212,6 @@ public class PowerUsageSummaryTest { MetricsProto.MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION); } @Test public void testOptionsMenu_menuAppToggle_metricEventInvoked() { mFragment.onOptionsItemSelected(mToggleAppsMenu); mFragment.mShowAllApps = false; verify(mFeatureFactory.metricsFeatureProvider).action(mContext, MetricsProto.MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_APPS_TOGGLE, true); } @Test public void testOptionsMenu_toggleAppsEnabled() { when(mFeatureFactory.powerUsageFeatureProvider.isPowerAccountingToggleEnabled()) .thenReturn(true); mFragment.mShowAllApps = false; mFragment.onCreateOptionsMenu(mMenu, mMenuInflater); verify(mMenu).add(Menu.NONE, MENU_TOGGLE_APPS, Menu.NONE, R.string.show_all_apps); } @Test public void testOptionsMenu_clickToggleAppsMenu_dataChanged() { testToggleAllApps(true); testToggleAllApps(false); } private void testToggleAllApps(final boolean isShowApps) { mFragment.mShowAllApps = isShowApps; mFragment.onOptionsItemSelected(mToggleAppsMenu); assertThat(mFragment.mShowAllApps).isEqualTo(!isShowApps); } @Test public void testUpdateLastFullChargePreference_showCorrectSummary() { doReturn(mRealContext).when(mFragment).getContext(); Loading Loading @@ -323,18 +288,6 @@ public class PowerUsageSummaryTest { assertThat(summary1.getText().toString().contains(OLD_EST_SUFFIX)); } @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(); } @Test public void testDebugMode() { doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isEstimateDebugEnabled(); Loading