Add title and summary for "High usage" pref.
The logic for this pref lives in AnomalyPreferenceController. Bug: 36924669 Test: RunSettingsRoboTest Change-Id: Ib88d8e76e1af8a2270fcb671baf55e9f6564b96e
This commit is contained in:
@@ -7410,11 +7410,11 @@
|
|||||||
<!-- Title for high usage item, which means power high usage [CHAR LIMIT=30] -->
|
<!-- Title for high usage item, which means power high usage [CHAR LIMIT=30] -->
|
||||||
<string name="power_high_usage_title">High usage</string>
|
<string name="power_high_usage_title">High usage</string>
|
||||||
|
|
||||||
<!-- Summary for high usage item, showing one app is behaving abnormally [CHAR LIMIT=80] -->
|
<!-- Summary for high usage item, showing app/apps are behaving abnormally [CHAR LIMIT=80] -->
|
||||||
<string name="power_high_usage_summary"><xliff:g id="app">%1$s</xliff:g> behaving abnormally</string>
|
<plurals name="power_high_usage_summary">
|
||||||
|
<item quantity="one"><xliff:g id="app">%1$s</xliff:g> behaving abnormally</item>
|
||||||
<!-- Summary for high usage item, showing several apps are behaving abnormally [CHAR LIMIT=80] -->
|
<item quantity="other"><xliff:g id="number">%2$d</xliff:g> apps behaving abnormally</item>
|
||||||
<string name="power_high_usage_multiple_apps_summary"><xliff:g id="number">%1$d</xliff:g> apps behaving abnormally</string>
|
</plurals>
|
||||||
|
|
||||||
<!-- 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>
|
||||||
|
@@ -26,7 +26,8 @@
|
|||||||
android:layout="@layout/battery_header"/>
|
android:layout="@layout/battery_header"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="high_usage"/>
|
android:key="high_usage"
|
||||||
|
android:title="@string/power_high_usage_title"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="device_usage_list">
|
android:key="device_usage_list">
|
||||||
|
@@ -139,7 +139,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
|
|||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<List<Anomaly>> loader, List<Anomaly> data) {
|
public void onLoadFinished(Loader<List<Anomaly>> loader, List<Anomaly> data) {
|
||||||
// show high usage preference if possible
|
// show high usage preference if possible
|
||||||
mAnomalySummaryPreferenceController.updateHighUsagePreference(data);
|
mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
package com.android.settings.fuelgauge.anomaly;
|
package com.android.settings.fuelgauge.anomaly;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v14.preference.PreferenceFragment;
|
import android.support.v14.preference.PreferenceFragment;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.fuelgauge.PowerUsageAnomalyDetails;
|
import com.android.settings.fuelgauge.PowerUsageAnomalyDetails;
|
||||||
|
|
||||||
@@ -70,12 +72,18 @@ public class AnomalySummaryPreferenceController {
|
|||||||
*
|
*
|
||||||
* @param anomalies used to update the summary, this method will store a reference of it
|
* @param anomalies used to update the summary, this method will store a reference of it
|
||||||
*/
|
*/
|
||||||
public void updateHighUsagePreference(List<Anomaly> anomalies) {
|
public void updateAnomalySummaryPreference(List<Anomaly> anomalies) {
|
||||||
|
final Context context = mFragment.getContext();
|
||||||
mAnomalies = anomalies;
|
mAnomalies = anomalies;
|
||||||
|
|
||||||
if (!mAnomalies.isEmpty()) {
|
if (!mAnomalies.isEmpty()) {
|
||||||
mAnomalyPreference.setVisible(true);
|
mAnomalyPreference.setVisible(true);
|
||||||
//TODO(b/36924669): update summary for anomaly preference
|
final int count = mAnomalies.size();
|
||||||
|
final String summary = context.getResources().getQuantityString(
|
||||||
|
R.plurals.power_high_usage_summary, count,
|
||||||
|
mAnomalies.get(0).displayName, count);
|
||||||
|
|
||||||
|
mAnomalyPreference.setSummary(summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,6 +53,7 @@ public class AnomalySummaryPreferenceControllerTest {
|
|||||||
@Anomaly.AnomalyType
|
@Anomaly.AnomalyType
|
||||||
private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
|
private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
|
||||||
private static final String PACKAGE_NAME = "com.android.app";
|
private static final String PACKAGE_NAME = "com.android.app";
|
||||||
|
private static final String DISPLAY_NAME = "app";
|
||||||
private static final int UID = 111;
|
private static final int UID = 111;
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
@@ -75,32 +76,47 @@ public class AnomalySummaryPreferenceControllerTest {
|
|||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mPreference = new Preference(mContext);
|
mPreference = new Preference(mContext);
|
||||||
mPreference.setKey(AnomalySummaryPreferenceController.ANOMALY_KEY);
|
mPreference.setKey(AnomalySummaryPreferenceController.ANOMALY_KEY);
|
||||||
when(mFragment.getPreferenceManager().findPreference(any())).thenReturn(mPreference);
|
when(mFragment.getPreferenceScreen().findPreference(any())).thenReturn(mPreference);
|
||||||
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
|
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
|
||||||
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
|
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
|
||||||
|
when(mFragment.getContext()).thenReturn(mContext);
|
||||||
|
|
||||||
mAnomalyList = new ArrayList<>();
|
mAnomalyList = new ArrayList<>();
|
||||||
Anomaly anomaly = new Anomaly.Builder()
|
|
||||||
.setType(ANOMALY_TYPE)
|
|
||||||
.setUid(UID)
|
|
||||||
.setPackageName(PACKAGE_NAME)
|
|
||||||
.build();
|
|
||||||
mAnomalyList.add(anomaly);
|
|
||||||
|
|
||||||
mAnomalySummaryPreferenceController = new AnomalySummaryPreferenceController(
|
mAnomalySummaryPreferenceController = new AnomalySummaryPreferenceController(
|
||||||
mSettingsActivity, mFragment);
|
mSettingsActivity, mFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateHighUsagePreference_hasCorrectData() {
|
public void testUpdateHighUsageSummaryPreference_hasCorrectData() {
|
||||||
mAnomalySummaryPreferenceController.updateHighUsagePreference(mAnomalyList);
|
mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);
|
||||||
|
|
||||||
//add more test when this method is complete
|
|
||||||
assertThat(mAnomalySummaryPreferenceController.mAnomalies).isEqualTo(mAnomalyList);
|
assertThat(mAnomalySummaryPreferenceController.mAnomalies).isEqualTo(mAnomalyList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAnomalySummaryPreference_oneAnomaly_showCorrectSummary() {
|
||||||
|
mAnomalyList.add(createTestAnomaly());
|
||||||
|
|
||||||
|
mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo("app behaving abnormally");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateAnomalySummaryPreference_multipleAnomalies_showCorrectSummary() {
|
||||||
|
mAnomalyList.add(createTestAnomaly());
|
||||||
|
mAnomalyList.add(createTestAnomaly());
|
||||||
|
|
||||||
|
mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo("2 apps behaving abnormally");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnPreferenceTreeClick_oneAnomaly_showDialog() {
|
public void testOnPreferenceTreeClick_oneAnomaly_showDialog() {
|
||||||
|
|
||||||
|
mAnomalyList.add(createTestAnomaly());
|
||||||
mAnomalySummaryPreferenceController.mAnomalies = mAnomalyList;
|
mAnomalySummaryPreferenceController.mAnomalies = mAnomalyList;
|
||||||
|
|
||||||
mAnomalySummaryPreferenceController.onPreferenceTreeClick(mPreference);
|
mAnomalySummaryPreferenceController.onPreferenceTreeClick(mPreference);
|
||||||
@@ -110,4 +126,13 @@ public class AnomalySummaryPreferenceControllerTest {
|
|||||||
verify(mFragmentTransaction).commit();
|
verify(mFragmentTransaction).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Anomaly createTestAnomaly() {
|
||||||
|
return new Anomaly.Builder()
|
||||||
|
.setType(ANOMALY_TYPE)
|
||||||
|
.setUid(UID)
|
||||||
|
.setPackageName(PACKAGE_NAME)
|
||||||
|
.setDisplayName(DISPLAY_NAME)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user