Add power management settings into Settings->Battery
The items been added to group are: Adaptive brightness, Sleep. Battery saver has been moved into this group as well. Also refactor the code a little bit to make it fit the preferenceController. Whole refactor of PowerUsageSummary and PowerUsageDetail will be tracked in b/34386721 Bug: 34279051 Test: runSettingsRoboTests & Screenshot Change-Id: I702d8479d1b80f7e9cf1a46752c75bf5d189e0f6
This commit is contained in:
@@ -6996,6 +6996,9 @@
|
||||
<!-- Summary of power usage for an app [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_summary"><xliff:g id="percentage" example="2">%1$d</xliff:g>%% use since last full charge</string>
|
||||
|
||||
<!-- Title of a group of settings that let you manage settings that affect battery life [CHAR LIMIT=60] -->
|
||||
<string name="battery_power_management">Power management</string>
|
||||
|
||||
<!-- Summary for app with no battery usage [CHAR LIMIT=NONE] -->
|
||||
<string name="no_battery_summary">No battery use since last full charge</string>
|
||||
|
||||
|
@@ -14,20 +14,42 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/power_usage_summary_title"
|
||||
settings:keywords="@string/keywords_battery">
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
||||
android:title="@string/power_usage_summary_title"
|
||||
settings:keywords="@string/keywords_battery">
|
||||
|
||||
<com.android.settings.fuelgauge.BatteryHistoryPreference
|
||||
android:key="battery_history"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="power_management"
|
||||
android:title="@string/battery_power_management">
|
||||
|
||||
<com.android.settings.fuelgauge.BatterySaverPreference
|
||||
android:title="@string/battery_saver"
|
||||
android:fragment="com.android.settings.fuelgauge.BatterySaverSettings" />
|
||||
android:fragment="com.android.settings.fuelgauge.BatterySaverSettings"/>
|
||||
|
||||
<com.android.settings.fuelgauge.BatteryHistoryPreference
|
||||
android:key="battery_history" />
|
||||
<!-- Cross-listed item, if you change this, also change it in ia_display_settings.xml -->
|
||||
<SwitchPreference
|
||||
android:key="auto_brightness"
|
||||
android:title="@string/auto_brightness_title"
|
||||
android:summary="@string/auto_brightness_summary"
|
||||
settings:keywords="@string/keywords_display_auto_brightness"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="app_list"
|
||||
android:title="@string/power_usage_list_summary" />
|
||||
<!-- Cross-listed item, if you change this, also change it in ia_display_settings.xml -->
|
||||
<com.android.settings.TimeoutListPreference
|
||||
android:key="screen_timeout"
|
||||
android:title="@string/screen_timeout"
|
||||
android:summary="@string/screen_timeout_summary"
|
||||
android:entries="@array/screen_timeout_entries"
|
||||
android:entryValues="@array/screen_timeout_values"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="app_list"
|
||||
android:title="@string/power_usage_list_summary"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@@ -32,12 +32,12 @@ import android.view.MenuItem;
|
||||
|
||||
import com.android.internal.os.BatteryStatsHelper;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
|
||||
/**
|
||||
* Common base class for things that need to show the battery usage graph.
|
||||
*/
|
||||
public abstract class PowerUsageBase extends SettingsPreferenceFragment {
|
||||
public abstract class PowerUsageBase extends DashboardFragment {
|
||||
|
||||
// +1 to allow ordering for PowerUsageSummary.
|
||||
@VisibleForTesting
|
||||
|
@@ -34,6 +34,7 @@ import android.os.BatteryStats;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
@@ -42,7 +43,6 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.os.BatterySipper;
|
||||
import com.android.internal.os.BatterySipper.DrainType;
|
||||
@@ -58,13 +58,17 @@ import com.android.settings.applications.AppHeaderController;
|
||||
import com.android.settings.applications.InstalledAppDetails;
|
||||
import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.bluetooth.BluetoothSettings;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.location.LocationSettings;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.wifi.WifiSettings;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickListener {
|
||||
|
||||
@@ -355,7 +359,6 @@ public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickLi
|
||||
mPm = activity.getPackageManager();
|
||||
mDpm = (DevicePolicyManager) activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||
|
||||
addPreferencesFromResource(R.xml.power_usage_details);
|
||||
mDetailsParent = (PreferenceCategory) findPreference(KEY_DETAILS_PARENT);
|
||||
mControlsParent = (PreferenceCategory) findPreference(KEY_CONTROLS_PARENT);
|
||||
mMessagesParent = (PreferenceCategory) findPreference(KEY_MESSAGES_PARENT);
|
||||
@@ -384,6 +387,26 @@ public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickLi
|
||||
setupHeader();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCategoryKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.power_usage_details;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
@@ -810,4 +833,19 @@ public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickLi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
|
||||
.isEnabled()) {
|
||||
return null;
|
||||
}
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.power_usage_details;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -26,6 +26,7 @@ import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Process;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
@@ -44,11 +45,17 @@ import com.android.settings.R;
|
||||
import com.android.settings.Settings.HighPowerApplicationsActivity;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.applications.ManageApplications;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.display.AutoBrightnessPreferenceController;
|
||||
import com.android.settings.display.TimeoutPreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.BatteryInfo;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -89,7 +96,6 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
super.onCreate(icicle);
|
||||
setAnimationAllowed(true);
|
||||
|
||||
addPreferencesFromResource(R.xml.power_usage_summary);
|
||||
mHistPref = (BatteryHistoryPreference) findPreference(KEY_BATTERY_HISTORY);
|
||||
mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
|
||||
}
|
||||
@@ -132,6 +138,29 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCategoryKey() {
|
||||
return CategoryKey.CATEGORY_BATTERY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.power_usage_summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new AutoBrightnessPreferenceController(context));
|
||||
controllers.add(new TimeoutPreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
if (DEBUG) {
|
||||
@@ -209,6 +238,7 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
* We want to coalesce some UIDs. For example, dex2oat runs under a shared gid that
|
||||
* exists for all users of the same app. We detect this case and merge the power use
|
||||
* for dex2oat to the device OWNER's use of the app.
|
||||
*
|
||||
* @return A sorted list of apps using power.
|
||||
*/
|
||||
private static List<BatterySipper> getCoalescedUsageList(final List<BatterySipper> sippers) {
|
||||
@@ -331,7 +361,7 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
if (sipper.drainType == BatterySipper.DrainType.OVERCOUNTED) {
|
||||
// Don't show over-counted unless it is at least 2/3 the size of
|
||||
// the largest real entry, and its percent of total is more significant
|
||||
if (sipper.totalPowerMah < ((mStatsHelper.getMaxRealPower()*2)/3)) {
|
||||
if (sipper.totalPowerMah < ((mStatsHelper.getMaxRealPower() * 2) / 3)) {
|
||||
continue;
|
||||
}
|
||||
if (percentOfTotal < 10) {
|
||||
@@ -344,7 +374,7 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
if (sipper.drainType == BatterySipper.DrainType.UNACCOUNTED) {
|
||||
// Don't show over-counted unless it is at least 1/2 the size of
|
||||
// the largest real entry, and its percent of total is more significant
|
||||
if (sipper.totalPowerMah < (mStatsHelper.getMaxRealPower()/2)) {
|
||||
if (sipper.totalPowerMah < (mStatsHelper.getMaxRealPower() / 2)) {
|
||||
continue;
|
||||
}
|
||||
if (percentOfTotal < 5) {
|
||||
@@ -508,6 +538,21 @@ public class PowerUsageSummary extends PowerUsageBase {
|
||||
}
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
|
||||
.isEnabled()) {
|
||||
return null;
|
||||
}
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.power_usage_summary;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
||||
= new SummaryLoader.SummaryProviderFactory() {
|
||||
@Override
|
||||
|
@@ -20,7 +20,6 @@ import android.provider.SearchIndexableResource;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.annotation.XmlRes;
|
||||
|
||||
import com.android.settings.DateTimeSettings;
|
||||
import com.android.settings.DevelopmentSettings;
|
||||
import com.android.settings.DeviceInfoSettings;
|
||||
@@ -47,6 +46,7 @@ import com.android.settings.deviceinfo.StorageSettings;
|
||||
import com.android.settings.display.ScreenZoomSettings;
|
||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||
import com.android.settings.fuelgauge.BatterySaverSettings;
|
||||
import com.android.settings.fuelgauge.PowerUsageDetail;
|
||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||
import com.android.settings.gestures.DoubleTapPowerSettings;
|
||||
import com.android.settings.gestures.DoubleTapScreenSettings;
|
||||
@@ -124,6 +124,7 @@ public final class SearchIndexableResources {
|
||||
addIndex(StorageSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_storage);
|
||||
addIndex(PowerUsageSummary.class,
|
||||
R.xml.power_usage_summary, R.drawable.ic_settings_battery);
|
||||
addIndex(PowerUsageDetail.class, NO_DATA_RES_ID, R.drawable.ic_settings_battery);
|
||||
addIndex(BatterySaverSettings.class,
|
||||
R.xml.battery_saver_settings, R.drawable.ic_settings_battery);
|
||||
addIndex(AdvancedAppSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_applications);
|
||||
|
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
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.annotation.Config;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class AutoBrightnessPreferenceControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private AutoBrightnessPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mController = new AutoBrightnessPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_TurnOnAuto_ReturnAuto() {
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
assertThat(mode).isEqualTo(SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_TurnOffAuto_ReturnManual() {
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
|
||||
assertThat(mode).isEqualTo(SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.TimeoutListPreference;
|
||||
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.annotation.Config;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class TimeoutPreferenceControllerTest {
|
||||
private static final int TIMEOUT = 30;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private TimeoutListPreference mPreference;
|
||||
private TimeoutPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mController = new TimeoutPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPreferenceChange_SetTimeout_ReturnCorrectTimeout() {
|
||||
mController.onPreferenceChange(mPreference, Integer.toString(TIMEOUT));
|
||||
|
||||
final int mode = Settings.System.getInt(mContext.getContentResolver(),
|
||||
SCREEN_OFF_TIMEOUT, 0);
|
||||
assertThat(mode).isEqualTo(TIMEOUT);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user