Merge "Remve menu item in battery settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
85fd529cc4
@@ -93,13 +93,9 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
|||||||
private static final int MENU_STATS_TYPE = Menu.FIRST;
|
private static final int MENU_STATS_TYPE = Menu.FIRST;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
|
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;
|
private static final int MENU_HELP = Menu.FIRST + 5;
|
||||||
public static final int DEBUG_INFO_LOADER = 3;
|
public static final int DEBUG_INFO_LOADER = 3;
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
boolean mShowAllApps = false;
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PowerGaugePreference mScreenUsagePref;
|
PowerGaugePreference mScreenUsagePref;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -221,7 +217,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
|||||||
mAnomalySparseArray = new SparseArray<>();
|
mAnomalySparseArray = new SparseArray<>();
|
||||||
|
|
||||||
restartBatteryInfoLoader();
|
restartBatteryInfoLoader();
|
||||||
restoreSavedInstance(icicle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -229,12 +224,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
|||||||
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY_V2;
|
return MetricsEvent.FUELGAUGE_POWER_USAGE_SUMMARY_V2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putBoolean(KEY_SHOW_ALL_APPS, mShowAllApps);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(Preference preference) {
|
public boolean onPreferenceTreeClick(Preference preference) {
|
||||||
if (KEY_BATTERY_HEADER.equals(preference.getKey())) {
|
if (KEY_BATTERY_HEADER.equals(preference.getKey())) {
|
||||||
@@ -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);
|
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);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,25 +306,11 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
|||||||
metricsFeatureProvider.action(context,
|
metricsFeatureProvider.action(context,
|
||||||
MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION);
|
MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION);
|
||||||
return true;
|
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:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void restoreSavedInstance(Bundle savedInstance) {
|
|
||||||
if (savedInstance != null) {
|
|
||||||
mShowAllApps = savedInstance.getBoolean(KEY_SHOW_ALL_APPS, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void performBatteryHeaderClick() {
|
private void performBatteryHeaderClick() {
|
||||||
if (mPowerFeatureProvider.isAdvancedUiEnabled()) {
|
if (mPowerFeatureProvider.isAdvancedUiEnabled()) {
|
||||||
Utils.startWithFragment(getContext(), PowerUsageAdvanced.class.getName(), null,
|
Utils.startWithFragment(getContext(), PowerUsageAdvanced.class.getName(), null,
|
||||||
@@ -375,8 +345,8 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
|||||||
|
|
||||||
final CharSequence timeSequence = Utils.formatRelativeTime(context, lastFullChargeTime,
|
final CharSequence timeSequence = Utils.formatRelativeTime(context, lastFullChargeTime,
|
||||||
false);
|
false);
|
||||||
mBatteryAppListPreferenceController.refreshAppListGroup(mStatsHelper, mShowAllApps,
|
mBatteryAppListPreferenceController.refreshAppListGroup(mStatsHelper,
|
||||||
timeSequence);
|
false /* showAllApps */, timeSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.fuelgauge;
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_HIGH_POWER_APPS;
|
import static com.android.settings.fuelgauge.PowerUsageSummaryLegacy.MENU_HIGH_POWER_APPS;
|
||||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_TOGGLE_APPS;
|
import static com.android.settings.fuelgauge.PowerUsageSummaryLegacy.MENU_TOGGLE_APPS;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
package com.android.settings.fuelgauge;
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_HIGH_POWER_APPS;
|
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;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -170,7 +169,6 @@ public class PowerUsageSummaryTest {
|
|||||||
doReturn(mock(LoaderManager.class)).when(mFragment).getLoaderManager();
|
doReturn(mock(LoaderManager.class)).when(mFragment).getLoaderManager();
|
||||||
|
|
||||||
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
|
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
|
||||||
when(mToggleAppsMenu.getItemId()).thenReturn(MENU_TOGGLE_APPS);
|
|
||||||
when(mHighPowerMenu.getItemId()).thenReturn(MENU_HIGH_POWER_APPS);
|
when(mHighPowerMenu.getItemId()).thenReturn(MENU_HIGH_POWER_APPS);
|
||||||
when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent())
|
when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent())
|
||||||
.thenReturn(sAdditionalBatteryInfoIntent);
|
.thenReturn(sAdditionalBatteryInfoIntent);
|
||||||
@@ -214,39 +212,6 @@ public class PowerUsageSummaryTest {
|
|||||||
MetricsProto.MetricsEvent.ACTION_SETTINGS_MENU_BATTERY_OPTIMIZATION);
|
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
|
@Test
|
||||||
public void testUpdateLastFullChargePreference_showCorrectSummary() {
|
public void testUpdateLastFullChargePreference_showCorrectSummary() {
|
||||||
doReturn(mRealContext).when(mFragment).getContext();
|
doReturn(mRealContext).when(mFragment).getContext();
|
||||||
@@ -323,18 +288,6 @@ public class PowerUsageSummaryTest {
|
|||||||
assertThat(summary1.getText().toString().contains(OLD_EST_SUFFIX));
|
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
|
@Test
|
||||||
public void testDebugMode() {
|
public void testDebugMode() {
|
||||||
doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isEstimateDebugEnabled();
|
doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isEstimateDebugEnabled();
|
||||||
|
Reference in New Issue
Block a user