Adds a menu item for additional battery info to battery settings.
Bug: 33352540 Test: No additional test failures. Change-Id: Ibfc1a9463c93d3c087ed712fe45d3d0717472c6a
This commit is contained in:
@@ -6985,6 +6985,9 @@
|
|||||||
<!-- Label for list to control apps that ignore battery saving restrictions [CHAR LIMIT=27]-->
|
<!-- Label for list to control apps that ignore battery saving restrictions [CHAR LIMIT=27]-->
|
||||||
<string name="high_power_apps">Battery optimization</string>
|
<string name="high_power_apps">Battery optimization</string>
|
||||||
|
|
||||||
|
<!-- Label for menu to launch additional battery info -->
|
||||||
|
<string name="additional_battery_info" translatable="false">Additional battery info</string>
|
||||||
|
|
||||||
<!-- Filter for apps allowed to use a lot of power [CHAR LIMIT=25] -->
|
<!-- Filter for apps allowed to use a lot of power [CHAR LIMIT=25] -->
|
||||||
<string name="high_power_filter_on">Not optimized</string>
|
<string name="high_power_filter_on">Not optimized</string>
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -39,7 +40,8 @@ import com.android.settings.SettingsPreferenceFragment;
|
|||||||
public abstract class PowerUsageBase extends SettingsPreferenceFragment {
|
public abstract class PowerUsageBase extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
// +1 to allow ordering for PowerUsageSummary.
|
// +1 to allow ordering for PowerUsageSummary.
|
||||||
private static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
|
@VisibleForTesting
|
||||||
|
static final int MENU_STATS_REFRESH = Menu.FIRST + 1;
|
||||||
|
|
||||||
protected BatteryStatsHelper mStatsHelper;
|
protected BatteryStatsHelper mStatsHelper;
|
||||||
protected UserManager mUm;
|
protected UserManager mUm;
|
||||||
|
@@ -350,8 +350,10 @@ public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickLi
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
mPm = getActivity().getPackageManager();
|
|
||||||
mDpm = (DevicePolicyManager)getActivity().getSystemService(Context.DEVICE_POLICY_SERVICE);
|
Activity activity = getActivity();
|
||||||
|
mPm = activity.getPackageManager();
|
||||||
|
mDpm = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.power_usage_details);
|
addPreferencesFromResource(R.xml.power_usage_details);
|
||||||
mDetailsParent = (PreferenceCategory) findPreference(KEY_DETAILS_PARENT);
|
mDetailsParent = (PreferenceCategory) findPreference(KEY_DETAILS_PARENT);
|
||||||
@@ -360,7 +362,7 @@ public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickLi
|
|||||||
mPackagesParent = (PreferenceCategory) findPreference(KEY_PACKAGES_PARENT);
|
mPackagesParent = (PreferenceCategory) findPreference(KEY_PACKAGES_PARENT);
|
||||||
|
|
||||||
mPowerUsageFeatureProvider =
|
mPowerUsageFeatureProvider =
|
||||||
FeatureFactory.getFactory(getActivity()).getPowerUsageFeatureProvider();
|
FeatureFactory.getFactory(activity).getPowerUsageFeatureProvider(activity);
|
||||||
|
|
||||||
createDetails();
|
createDetails();
|
||||||
}
|
}
|
||||||
|
@@ -24,4 +24,6 @@ public interface PowerUsageFeatureProvider {
|
|||||||
* Check whether location setting is enabled
|
* Check whether location setting is enabled
|
||||||
*/
|
*/
|
||||||
boolean isLocationSettingEnabled(String[] packages);
|
boolean isLocationSettingEnabled(String[] packages);
|
||||||
|
|
||||||
|
boolean isAdditionalBatteryInfoEnabled();
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ import android.os.Handler;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -43,6 +44,7 @@ import com.android.settings.Settings.HighPowerApplicationsActivity;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.applications.ManageApplications;
|
import com.android.settings.applications.ManageApplications;
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.BatteryInfo;
|
import com.android.settingslib.BatteryInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -67,7 +69,9 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
|
|
||||||
private static final int MENU_STATS_TYPE = Menu.FIRST;
|
private static final int MENU_STATS_TYPE = Menu.FIRST;
|
||||||
private static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
|
private static final int MENU_HIGH_POWER_APPS = Menu.FIRST + 3;
|
||||||
private static final int MENU_HELP = Menu.FIRST + 4;
|
@VisibleForTesting
|
||||||
|
static final int MENU_ADDITIONAL_BATTERY_INFO = Menu.FIRST + 4;
|
||||||
|
private static final int MENU_HELP = Menu.FIRST + 5;
|
||||||
|
|
||||||
private BatteryHistoryPreference mHistPref;
|
private BatteryHistoryPreference mHistPref;
|
||||||
private PreferenceGroup mAppListGroup;
|
private PreferenceGroup mAppListGroup;
|
||||||
@@ -130,12 +134,20 @@ public class PowerUsageSummary extends PowerUsageBase {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
menu.add(0, MENU_STATS_TYPE, 0, R.string.menu_stats_total)
|
menu.add(Menu.NONE, MENU_STATS_TYPE, Menu.NONE, R.string.menu_stats_total)
|
||||||
.setIcon(com.android.internal.R.drawable.ic_menu_info_details)
|
.setIcon(com.android.internal.R.drawable.ic_menu_info_details)
|
||||||
.setAlphabeticShortcut('t');
|
.setAlphabeticShortcut('t');
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.add(0, MENU_HIGH_POWER_APPS, 0, R.string.high_power_apps);
|
menu.add(Menu.NONE, MENU_HIGH_POWER_APPS, Menu.NONE, R.string.high_power_apps);
|
||||||
|
|
||||||
|
PowerUsageFeatureProvider powerUsageFeatureProvider =
|
||||||
|
FeatureFactory.getFactory(getContext()).getPowerUsageFeatureProvider(getContext());
|
||||||
|
if (powerUsageFeatureProvider != null &&
|
||||||
|
powerUsageFeatureProvider.isAdditionalBatteryInfoEnabled()) {
|
||||||
|
menu.add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
|
||||||
|
Menu.NONE, R.string.additional_battery_info);
|
||||||
|
}
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -70,7 +70,7 @@ public abstract class FeatureFactory {
|
|||||||
|
|
||||||
public abstract MetricsFeatureProvider getMetricsFeatureProvider();
|
public abstract MetricsFeatureProvider getMetricsFeatureProvider();
|
||||||
|
|
||||||
public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider();
|
public abstract PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context);
|
||||||
|
|
||||||
public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
|
public abstract DashboardFeatureProvider getDashboardFeatureProvider(Context context);
|
||||||
|
|
||||||
|
@@ -63,7 +63,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PowerUsageFeatureProvider getPowerUsageFeatureProvider() {
|
public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,94 @@
|
|||||||
|
package com.android.settings.fuelgauge;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static com.android.settings.fuelgauge.PowerUsageBase.MENU_STATS_REFRESH;
|
||||||
|
import static com.android.settings.fuelgauge.PowerUsageSummary.MENU_ADDITIONAL_BATTERY_INFO;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for {@link PowerUsageSummary}.
|
||||||
|
*/
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class PowerUsageSummaryTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Menu mMenu;
|
||||||
|
@Mock
|
||||||
|
private MenuItem mRefresh;
|
||||||
|
@Mock
|
||||||
|
private MenuInflater mMenuInflater;
|
||||||
|
|
||||||
|
private TestFragment mFragment;
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
|
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
|
|
||||||
|
mFragment = new TestFragment(mContext);
|
||||||
|
|
||||||
|
when(mMenu.add(Menu.NONE, PowerUsageBase.MENU_STATS_REFRESH, Menu.NONE,
|
||||||
|
R.string.menu_stats_refresh)
|
||||||
|
.setIcon(com.android.internal.R.drawable.ic_menu_refresh)
|
||||||
|
.setAlphabeticShortcut('r'))
|
||||||
|
.thenReturn(mRefresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnCreateOptionsMenu_additionalBatteryInfoEnabled() {
|
||||||
|
when(mFeatureFactory.powerUsageFeatureProvider.isAdditionalBatteryInfoEnabled())
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
|
mFragment.onCreateOptionsMenu(mMenu, mMenuInflater);
|
||||||
|
|
||||||
|
verify(mMenu).add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
|
||||||
|
Menu.NONE, R.string.additional_battery_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnCreateOptionsMenu_additionalBatteryInfoDisabled() {
|
||||||
|
when(mFeatureFactory.powerUsageFeatureProvider.isAdditionalBatteryInfoEnabled())
|
||||||
|
.thenReturn(false);
|
||||||
|
|
||||||
|
mFragment.onCreateOptionsMenu(mMenu, mMenuInflater);
|
||||||
|
|
||||||
|
verify(mMenu, never()).add(Menu.NONE, MENU_ADDITIONAL_BATTERY_INFO,
|
||||||
|
Menu.NONE, R.string.additional_battery_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestFragment extends PowerUsageSummary {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
public TestFragment(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Context getContext() {
|
||||||
|
return mContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -91,7 +91,7 @@ public class FakeFeatureFactory extends FeatureFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PowerUsageFeatureProvider getPowerUsageFeatureProvider() {
|
public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
|
||||||
return powerUsageFeatureProvider;
|
return powerUsageFeatureProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user