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

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

Merge "Combine system apps to one item in the battery usage app list."

parents 476bb204 e756675e
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -603,9 +603,6 @@
    <!-- Whether to show communal settings at the top level. -->
    <bool name="config_show_communal_settings">false</bool>

    <!-- Whether to put the apps with system UID into system component bucket or not -->
    <bool name="config_battery_combine_system_components">false</bool>

    <!-- The extra value for battery tip -->
    <integer name="config_battery_extra_tip_value">12</integer>

+2 −0
Original line number Diff line number Diff line
@@ -5065,6 +5065,8 @@
    <string name="battery_not_usage_24hr">No usage for past 24 hr</string>
    <!-- Description for no usage time but have battery usage [CHAR LIMIT=120] -->
    <string name="battery_usage_without_time"></string>
   <!-- Description for system apps aggregated battery usage data [CHAR LIMIT=120] -->
    <string name="battery_usage_system_apps">System apps</string>
    <!-- Description for battery time left, i.e. 50min Estimated time left. [CHAR LIMIT=80]-->
    <string name="estimated_time_left">Estimated time left</string>
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.util.SparseIntArray;

import com.android.settingslib.fuelgauge.Estimate;

import java.util.List;
import java.util.Set;

/**
@@ -34,6 +35,11 @@ public interface PowerUsageFeatureProvider {
     */
    boolean isBatteryUsageEnabled(Context context);

    /**
     * Returns an allowlist of app names combined into the system-apps item
     */
    List<String> getSystemAppsAllowlist(Context context);

    /**
     * Check whether location setting is enabled
     */
+6 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.util.SparseIntArray;
import com.android.internal.util.ArrayUtils;
import com.android.settingslib.fuelgauge.Estimate;

import java.util.List;
import java.util.Set;

/** Implementation of {@code PowerUsageFeatureProvider} */
@@ -70,6 +71,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
        return true;
    }

    @Override
    public List<String> getSystemAppsAllowlist(Context context) {
        return null;
    }

    @Override
    public boolean isLocationSettingEnabled(String[] packages) {
        return false;
+52 −17
Original line number Diff line number Diff line
@@ -15,12 +15,12 @@
 */
package com.android.settings.fuelgauge.batteryusage;

import android.content.ContentValues;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
@@ -62,10 +62,10 @@ public class BatteryDiffEntry {
    // A BatteryHistEntry corresponding to this diff usage data.
    public final BatteryHistEntry mBatteryHistEntry;

    protected Context mContext;

    private double mTotalConsumePower;
    private double mPercentOfTotal;

    private Context mContext;
    private UserManager mUserManager;
    private String mDefaultPackageName = null;

@@ -111,6 +111,11 @@ public class BatteryDiffEntry {
                ? 0 : (mConsumePower / mTotalConsumePower) * 100.0;
    }

    /** Gets the total consumed power in a specific time slot. */
    public double getTotalConsumePower() {
        return mTotalConsumePower;
    }

    /** Gets the percentage of total consumed power. */
    public double getPercentOfTotal() {
        return mPercentOfTotal;
@@ -176,24 +181,18 @@ public class BatteryDiffEntry {

    /** Whether the current BatteryDiffEntry is system component or not. */
    public boolean isSystemEntry() {
        if (mBatteryHistEntry.mIsHidden) {
            return false;
        }
        switch (mBatteryHistEntry.mConsumerType) {
            case ConvertUtils.CONSUMER_TYPE_USER_BATTERY:
            case ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY:
                return true;
            case ConvertUtils.CONSUMER_TYPE_UID_BATTERY:
                final int uid = (int) mBatteryHistEntry.mUid;
                if (mBatteryHistEntry.mIsHidden
                        || uid == BatteryUtils.UID_REMOVED_APPS
                        || uid == BatteryUtils.UID_TETHERING) {
                    return true;
                }
                final boolean combineSystemComponents =
                        mContext.getResources().getBoolean(
                                R.bool.config_battery_combine_system_components);
                return combineSystemComponents && isSystemUid(uid);
        }
            default:
                return false;
        }
    }

    void loadLabelAndIcon() {
        if (mIsLoaded) {
@@ -396,8 +395,44 @@ public class BatteryDiffEntry {
                mUserManager.getBadgedIconForUser(icon, new UserHandle(userId));
    }

    private static boolean isSystemUid(int uid) {
        final int appUid = UserHandle.getAppId(uid);
        return appUid >= Process.SYSTEM_UID && appUid < Process.FIRST_APPLICATION_UID;
    /** Specific battery diff entry for system apps. */
    static class SystemAppsBatteryDiffEntry extends BatteryDiffEntry {
        SystemAppsBatteryDiffEntry(Context context) {
            super(context,
                    /*foregroundUsageTimeInMs=*/ 0,
                    /*backgroundUsageTimeInMs=*/ 0,
                    /*screenOnTimeInMs=*/ 0,
                    /*consumePower=*/ 0,
                    /*foregroundUsageConsumePower=*/ 0,
                    /*foregroundServiceUsageConsumePower=*/ 0,
                    /*backgroundUsageConsumePower=*/ 0,
                    /*cachedUsageConsumePower=*/ 0,
                    new BatteryHistEntry(new ContentValues()));
        }

        @Override
        public String getKey() {
            return "A|SystemApps";
        }

        @Override
        public String getAppLabel() {
            return mContext.getString(R.string.battery_usage_system_apps);
        }

        @Override
        public Drawable getAppIcon() {
            return mContext.getDrawable(R.drawable.ic_power_system);
        }

        @Override
        public boolean validForRestriction() {
            return false;
        }

        @Override
        public boolean isSystemEntry() {
            return false;
        }
    }
}
Loading