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

Commit 3d1b6fd0 authored by ykhung's avatar ykhung
Browse files

Add a mechanism to configure whether the summary should be set or not

Add a mechanism to customize whether the summary information in the
battery entry should be set or not. We can consider is as the extension
for the ag/18062824.

Bug: 220717612
Test: make RunSettingsRoboTests -j56 ROBOTEST_FILTER="com.android.settings.fuelgauge"
Change-Id: I3c21148d288f29ce65378f59f9086dab90c14a7b
parent 55d722c2
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1646,4 +1646,8 @@
        <item>1875000</item> <!-- 15Mbps == 1875000/s -->
    </string-array>

    <!-- An allowlist which packages won't show summary in battery usage screen.
         [CHAR LIMIT=NONE] -->
    <string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
    </string-array>
</resources>
+15 −2
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.settingslib.utils.StringUtil;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

/**
 * Controller that update the battery header view
@@ -72,7 +73,6 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
    private static final int MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP = 10;
    private static final String MEDIASERVER_PACKAGE_NAME = "mediaserver";

    private final String mPreferenceKey;
    @VisibleForTesting
    PreferenceGroup mAppListGroup;
    private BatteryUsageStats mBatteryUsageStats;
@@ -83,6 +83,9 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
    private final PackageManager mPackageManager;
    private final SettingsActivity mActivity;
    private final InstrumentedPreferenceFragment mFragment;
    private final Set<CharSequence> mNotAllowShowSummaryPackages;
    private final String mPreferenceKey;

    private Context mPrefContext;

    /**
@@ -159,6 +162,10 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
        mPackageManager = context.getPackageManager();
        mActivity = activity;
        mFragment = fragment;
        mNotAllowShowSummaryPackages = Set.of(
                FeatureFactory.getFactory(context)
                        .getPowerUsageFeatureProvider(context)
                        .getHideApplicationSummary(context));
    }

    @Override
@@ -427,6 +434,12 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
        if (entry.getUid() == Process.SYSTEM_UID) {
            return;
        }
        String packageName = entry.getDefaultPackageName();
        if (packageName != null
                && mNotAllowShowSummaryPackages != null
                && mNotAllowShowSummaryPackages.contains(packageName)) {
            return;
        }
        // Only show summary when usage time is longer than one minute
        final long usageTimeMs = entry.getTimeInForegroundMs();
        if (shouldShowSummary(entry) && usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
+3 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.util.ArraySet;
import android.util.SparseIntArray;

import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settingslib.fuelgauge.Estimate;

import java.util.Map;
@@ -179,6 +180,7 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider

    @Override
    public CharSequence[] getHideApplicationSummary(Context context) {
        return new CharSequence[0];
        return context.getResources().getTextArray(
                R.array.allowlist_hide_summary_in_battery_usage);
    }
}