diff --git a/res/values/strings.xml b/res/values/strings.xml index ed6aa0774d6..8f5bbf1c8e8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -6996,6 +6996,9 @@ %1$d%% use since last full charge + + Power management + No battery use since last full charge diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml index 1ae0a445155..4607c482462 100644 --- a/res/xml/power_usage_summary.xml +++ b/res/xml/power_usage_summary.xml @@ -14,20 +14,42 @@ limitations under the License. --> - + + + + + + android:fragment="com.android.settings.fuelgauge.BatterySaverSettings"/> - + + - + + + + + + diff --git a/src/com/android/settings/fuelgauge/PowerUsageBase.java b/src/com/android/settings/fuelgauge/PowerUsageBase.java index 1af9df1d372..60d1ecd4f1b 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageBase.java +++ b/src/com/android/settings/fuelgauge/PowerUsageBase.java @@ -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 diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java index 5f9a305bc86..dbc53601cdc 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java +++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java @@ -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 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 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); + } + }; } diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index bc5322461da..c4a780f3954 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -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 getPreferenceControllers(Context context) { + final List 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) { @@ -531,6 +560,21 @@ public class PowerUsageSummary extends PowerUsageBase { } } + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider() { + @Override + public List 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 diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index cb848d8c657..4f9f92cda45 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -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); diff --git a/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java new file mode 100644 index 00000000000..10a8b0b6e89 --- /dev/null +++ b/tests/robotests/src/com/android/settings/display/AutoBrightnessPreferenceControllerTest.java @@ -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); + } +} diff --git a/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java new file mode 100644 index 00000000000..ec142c251a1 --- /dev/null +++ b/tests/robotests/src/com/android/settings/display/TimeoutPreferenceControllerTest.java @@ -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); + } +}