Add toggle in menu to show/hide hidden apps
In the previous cl we hide unrelated apps and distribute hidden battery usage among other apps. Now we add a toggle in menu to show old power accounting as well. Bug: 35366708 Test: RunSettingsRoboTests Change-Id: I6918b7095cf84d9756ad3972ff50a62aeae1de0e
This commit is contained in:
@@ -7057,6 +7057,12 @@
|
||||
<!-- Label for menu to launch a screen showing usage alerts for battery [CHAR LIMIT=30] -->
|
||||
<string name="additional_battery_info">Usage alerts</string>
|
||||
|
||||
<!-- Label for menu to show all apps in battery settings [CHAR LIMIT=30] -->
|
||||
<string name="show_all_apps">Show all apps</string>
|
||||
|
||||
<!-- Label for menu to hide extra apps in battery settings [CHAR LIMIT=30] -->
|
||||
<string name="hide_extra_apps">Hide extra apps</string>
|
||||
|
||||
<!-- Filter for apps allowed to use a lot of power [CHAR LIMIT=25] -->
|
||||
<string name="high_power_filter_on">Not optimized</string>
|
||||
|
||||
|
@@ -46,4 +46,9 @@ public interface PowerUsageFeatureProvider {
|
||||
* Check whether it is type service
|
||||
*/
|
||||
boolean isTypeService(String[] packages);
|
||||
|
||||
/**
|
||||
* Check whether the toggle for power accounting is enabled
|
||||
*/
|
||||
boolean isPowerAccountingToggleEnabled();
|
||||
}
|
||||
|
@@ -43,4 +43,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
|
||||
public boolean isTypeService(String[] packages) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerAccountingToggleEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -72,31 +72,32 @@ import java.util.List;
|
||||
*/
|
||||
public class PowerUsageSummary extends PowerUsageBase {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final boolean USE_FAKE_DATA = false;
|
||||
|
||||
static final String TAG = "PowerUsageSummary";
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
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 int MIN_POWER_THRESHOLD_MILLI_AMP = 5;
|
||||
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10;
|
||||
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
|
||||
private static final int SECONDS_IN_HOUR = 60 * 60;
|
||||
|
||||
private static final int MENU_STATS_TYPE = Menu.FIRST;
|
||||
private static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
|
||||
@VisibleForTesting
|
||||
static final int MENU_ADDITIONAL_BATTERY_INFO = Menu.FIRST + 4;
|
||||
private static final int MENU_HELP = Menu.FIRST + 5;
|
||||
@VisibleForTesting
|
||||
static final int MENU_TOGGLE_APPS = Menu.FIRST + 5;
|
||||
private static final int MENU_HELP = Menu.FIRST + 6;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mShowAllApps = false;
|
||||
private LayoutPreference mBatteryLayoutPref;
|
||||
private PreferenceGroup mAppListGroup;
|
||||
|
||||
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
|
||||
|
||||
private static final int MIN_POWER_THRESHOLD_MILLI_AMP = 5;
|
||||
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 10;
|
||||
private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
|
||||
private static final int SECONDS_IN_HOUR = 60 * 60;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -183,6 +184,11 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
menu.add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
|
||||
Menu.NONE, R.string.additional_battery_info);
|
||||
}
|
||||
if (powerUsageFeatureProvider.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);
|
||||
}
|
||||
|
||||
@@ -215,6 +221,11 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
.getPowerUsageFeatureProvider(getContext())
|
||||
.getAdditionalBatteryInfoIntent());
|
||||
return true;
|
||||
case MENU_TOGGLE_APPS:
|
||||
mShowAllApps = !mShowAllApps;
|
||||
item.setTitle(mShowAllApps ? R.string.hide_extra_apps : R.string.show_all_apps);
|
||||
refreshStats();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -378,7 +389,7 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
final List<BatterySipper> usageList = getCoalescedUsageList(
|
||||
USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());
|
||||
|
||||
final double hiddenPowerMah = removeHiddenBatterySippers(usageList);
|
||||
double hiddenPowerMah = mShowAllApps ? 0 : removeHiddenBatterySippers(usageList);
|
||||
|
||||
final int dischargeAmount = USE_FAKE_DATA ? 5000
|
||||
: stats != null ? stats.getDischargeAmount(mStatsType) : 0;
|
||||
|
@@ -47,6 +47,7 @@ import java.util.List;
|
||||
|
||||
import static com.android.settings.fuelgauge.PowerUsageBase.MENU_STATS_REFRESH;
|
||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_ADDITIONAL_BATTERY_INFO;
|
||||
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_TOGGLE_APPS;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -81,6 +82,8 @@ public class PowerUsageSummaryTest {
|
||||
@Mock
|
||||
private MenuItem mAdditionalBatteryInfoMenu;
|
||||
@Mock
|
||||
private MenuItem mToggleAppsMenu;
|
||||
@Mock
|
||||
private MenuInflater mMenuInflater;
|
||||
@Mock
|
||||
private BatterySipper mNormalBatterySipper;
|
||||
@@ -123,6 +126,7 @@ public class PowerUsageSummaryTest {
|
||||
.thenReturn(mRefreshMenu);
|
||||
when(mAdditionalBatteryInfoMenu.getItemId())
|
||||
.thenReturn(MENU_ADDITIONAL_BATTERY_INFO);
|
||||
when(mToggleAppsMenu.getItemId()).thenReturn(MENU_TOGGLE_APPS);
|
||||
when(mFeatureFactory.powerUsageFeatureProvider.getAdditionalBatteryInfoIntent())
|
||||
.thenReturn(ADDITIONAL_BATTERY_INFO_INTENT);
|
||||
|
||||
@@ -173,6 +177,23 @@ public class PowerUsageSummaryTest {
|
||||
Menu.NONE, R.string.additional_battery_info);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractKeyFromSipper_TypeAPPUidObjectNull_ReturnPackageNames() {
|
||||
mNormalBatterySipper.uidObj = null;
|
||||
@@ -305,6 +326,13 @@ public class PowerUsageSummaryTest {
|
||||
verify(mSummary1).setText(R.string.estimated_time_left);
|
||||
}
|
||||
|
||||
private void testToggleAllApps(final boolean isShowApps) {
|
||||
mFragment.mShowAllApps = isShowApps;
|
||||
|
||||
mFragment.onOptionsItemSelected(mToggleAppsMenu);
|
||||
assertThat(mFragment.mShowAllApps).isEqualTo(!isShowApps);
|
||||
}
|
||||
|
||||
public static class TestFragment extends PowerUsageSummary {
|
||||
|
||||
private Context mContext;
|
||||
@@ -325,5 +353,10 @@ public class PowerUsageSummaryTest {
|
||||
mStartActivityCalled = true;
|
||||
mStartActivityIntent = intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshStats() {
|
||||
// Leave it empty for toggle apps menu test
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user