Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2f6a7c2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add title and summary for "High usage" pref."

parents c43b09a2 59bc0cc7
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -7410,11 +7410,11 @@
    <!-- Title for high usage item, which means power high usage [CHAR LIMIT=30] -->
    <string name="power_high_usage_title">High usage</string>
    <!-- Summary for high usage item, showing one app is behaving abnormally [CHAR LIMIT=80] -->
    <string name="power_high_usage_summary"><xliff:g id="app">%1$s</xliff:g> behaving abnormally</string>
    <!-- Summary for high usage item, showing several apps are behaving abnormally [CHAR LIMIT=80] -->
    <string name="power_high_usage_multiple_apps_summary"><xliff:g id="number">%1$d</xliff:g> apps behaving abnormally</string>
    <!-- Summary for high usage item, showing app/apps are behaving abnormally [CHAR LIMIT=80] -->
    <plurals name="power_high_usage_summary">
        <item quantity="one"><xliff:g id="app">%1$s</xliff:g> behaving abnormally</item>
        <item quantity="other"><xliff:g id="number">%2$d</xliff:g> apps behaving abnormally</item>
    </plurals>
    <!-- Filter for apps allowed to use a lot of power [CHAR LIMIT=25] -->
    <string name="high_power_filter_on">Not optimized</string>
+2 −1
Original line number Diff line number Diff line
@@ -26,7 +26,8 @@
        android:layout="@layout/battery_header"/>

    <Preference
        android:key="high_usage"/>
        android:key="high_usage"
        android:title="@string/power_high_usage_title"/>

    <PreferenceCategory
        android:key="device_usage_list">
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
                @Override
                public void onLoadFinished(Loader<List<Anomaly>> loader, List<Anomaly> data) {
                    // show high usage preference if possible
                    mAnomalySummaryPreferenceController.updateHighUsagePreference(data);
                    mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(data);
                }

                @Override
+10 −2
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package com.android.settings.fuelgauge.anomaly;

import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;

import com.android.settings.R;
import com.android.settings.SettingsActivity;
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
     */
    public void updateHighUsagePreference(List<Anomaly> anomalies) {
    public void updateAnomalySummaryPreference(List<Anomaly> anomalies) {
        final Context context = mFragment.getContext();
        mAnomalies = anomalies;

        if (!mAnomalies.isEmpty()) {
            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);
        }
    }

+35 −10
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ public class AnomalySummaryPreferenceControllerTest {
    @Anomaly.AnomalyType
    private static final int ANOMALY_TYPE = Anomaly.AnomalyType.WAKE_LOCK;
    private static final String PACKAGE_NAME = "com.android.app";
    private static final String DISPLAY_NAME = "app";
    private static final int UID = 111;

    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -75,32 +76,47 @@ public class AnomalySummaryPreferenceControllerTest {
        mContext = RuntimeEnvironment.application;
        mPreference = new Preference(mContext);
        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(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
        when(mFragment.getContext()).thenReturn(mContext);

        mAnomalyList = new ArrayList<>();
        Anomaly anomaly = new Anomaly.Builder()
                .setType(ANOMALY_TYPE)
                .setUid(UID)
                .setPackageName(PACKAGE_NAME)
                .build();
        mAnomalyList.add(anomaly);

        mAnomalySummaryPreferenceController = new AnomalySummaryPreferenceController(
                mSettingsActivity, mFragment);
    }

    @Test
    public void testUpdateHighUsagePreference_hasCorrectData() {
        mAnomalySummaryPreferenceController.updateHighUsagePreference(mAnomalyList);
    public void testUpdateHighUsageSummaryPreference_hasCorrectData() {
        mAnomalySummaryPreferenceController.updateAnomalySummaryPreference(mAnomalyList);

        //add more test when this method is complete
        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
    public void testOnPreferenceTreeClick_oneAnomaly_showDialog() {

        mAnomalyList.add(createTestAnomaly());
        mAnomalySummaryPreferenceController.mAnomalies = mAnomalyList;

        mAnomalySummaryPreferenceController.onPreferenceTreeClick(mPreference);
@@ -110,4 +126,13 @@ public class AnomalySummaryPreferenceControllerTest {
        verify(mFragmentTransaction).commit();
    }

    private Anomaly createTestAnomaly() {
        return new Anomaly.Builder()
                .setType(ANOMALY_TYPE)
                .setUid(UID)
                .setPackageName(PACKAGE_NAME)
                .setDisplayName(DISPLAY_NAME)
                .build();
    }

}