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

Commit 1e7181cf authored by Kuan Wang's avatar Kuan Wang
Browse files

Remove "Other Users" entry in app usage list.

Don't show the aggregated other user entry in the app usage list to keep
consistent with screen-on time data.

Bug: 260964903
Test: make RunSettingsRoboTests
Change-Id: Id611e7222602f5ad2ea0fe27fb3f9f62fed31ff9
parent 97924455
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -4952,8 +4952,6 @@
    <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 other users aggregated battery usage data [CHAR LIMIT=120] -->
    <string name="battery_usage_other_users">Other users</string>
    <!-- Description for battery time left, i.e. 50min Estimated time left. [CHAR LIMIT=80]-->
    <string name="estimated_time_left">Estimated time left</string>
+0 −2
Original line number Diff line number Diff line
@@ -74,8 +74,6 @@ public class BatteryUtils {
    public static final int UID_REMOVED_APPS = -4;
    /** Special UID value for data usage by tethering. */
    public static final int UID_TETHERING = -5;
    /** Special UID for aggregated other users. */
    public static final long UID_OTHER_USERS = Long.MIN_VALUE;

    /** Flag to check if the dock defender mode has been temporarily bypassed */
    public static final String SETTINGS_GLOBAL_DOCK_DEFENDER_BYPASS = "dock_defender_bypass";
+0 −14
Original line number Diff line number Diff line
@@ -129,9 +129,6 @@ public class BatteryDiffEntry {

    /** Gets the app label name for this entry. */
    public String getAppLabel() {
        if (isOtherUsers()) {
            return mContext.getString(R.string.battery_usage_other_users);
        }
        loadLabelAndIcon();
        // Returns default applicationn label if we cannot find it.
        return mAppLabel == null || mAppLabel.length() == 0
@@ -141,9 +138,6 @@ public class BatteryDiffEntry {

    /** Gets the app icon {@link Drawable} for this entry. */
    public Drawable getAppIcon() {
        if (isOtherUsers()) {
            return mContext.getDrawable(R.drawable.ic_power_system);
        }
        loadLabelAndIcon();
        return mAppIcon != null && mAppIcon.getConstantState() != null
                ? mAppIcon.getConstantState().newDrawable()
@@ -178,9 +172,6 @@ public class BatteryDiffEntry {

    /** Whether the current BatteryDiffEntry is system component or not. */
    public boolean isSystemEntry() {
        if (isOtherUsers()) {
            return true;
        }
        switch (mBatteryHistEntry.mConsumerType) {
            case ConvertUtils.CONSUMER_TYPE_USER_BATTERY:
            case ConvertUtils.CONSUMER_TYPE_SYSTEM_BATTERY:
@@ -200,11 +191,6 @@ public class BatteryDiffEntry {
        return false;
    }

    private boolean isOtherUsers() {
        return mBatteryHistEntry.mConsumerType == ConvertUtils.CONSUMER_TYPE_UID_BATTERY
                && mBatteryHistEntry.mUid == BatteryUtils.UID_OTHER_USERS;
    }

    void loadLabelAndIcon() {
        if (mIsLoaded) {
            return;
+29 −54
Original line number Diff line number Diff line
@@ -589,13 +589,13 @@ public final class DataProcessor {
                userHandle != null ? userHandle.getIdentifier() : Integer.MIN_VALUE;
        final List<BatteryDiffEntry> appEntries = new ArrayList<>();
        final List<BatteryDiffEntry> systemEntries = new ArrayList<>();
        double consumePowerFromOtherUsers = 0f;

        for (BatteryHistEntry entry : batteryHistEntryList) {
            final boolean isFromOtherUsers = isConsumedFromOtherUsers(
                    currentUserId, workProfileUserId, entry);
            // Not show other users' battery usage data.
            if (isFromOtherUsers) {
                consumePowerFromOtherUsers += entry.mConsumePower;
                continue;
            } else {
                final BatteryDiffEntry currentBatteryDiffEntry = new BatteryDiffEntry(
                        context,
@@ -614,9 +614,6 @@ public final class DataProcessor {
                }
            }
        }
        if (consumePowerFromOtherUsers != 0) {
            systemEntries.add(createOtherUsersEntry(context, consumePowerFromOtherUsers));
        }

        // If there is no data, return null instead of empty item.
        if (appEntries.isEmpty() && systemEntries.isEmpty()) {
@@ -1086,7 +1083,6 @@ public final class DataProcessor {
        allBatteryHistEntryKeys.addAll(nextBatteryHistMap.keySet());
        allBatteryHistEntryKeys.addAll(nextTwoBatteryHistMap.keySet());

        double consumePowerFromOtherUsers = 0f;
        // Calculates all packages diff usage data in a specific time slot.
        for (String key : allBatteryHistEntryKeys) {
            final BatteryHistEntry currentEntry =
@@ -1095,6 +1091,20 @@ public final class DataProcessor {
                    nextBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);
            final BatteryHistEntry nextTwoEntry =
                    nextTwoBatteryHistMap.getOrDefault(key, EMPTY_BATTERY_HIST_ENTRY);

            final BatteryHistEntry selectedBatteryEntry =
                    selectBatteryHistEntry(currentEntry, nextEntry, nextTwoEntry);
            if (selectedBatteryEntry == null) {
                continue;
            }

            // Not show other users' battery usage data.
            final boolean isFromOtherUsers = isConsumedFromOtherUsers(
                    currentUserId, workProfileUserId, selectedBatteryEntry);
            if (isFromOtherUsers) {
                continue;
            }

            // Cumulative values is a specific time slot for a specific app.
            long foregroundUsageTimeInMs =
                    getDiffValue(
@@ -1137,11 +1147,6 @@ public final class DataProcessor {
                    && consumePower == 0) {
                continue;
            }
            final BatteryHistEntry selectedBatteryEntry =
                    selectBatteryHistEntry(currentEntry, nextEntry, nextTwoEntry);
            if (selectedBatteryEntry == null) {
                continue;
            }
            // Forces refine the cumulative value since it may introduce deviation error since we
            // will apply the interpolation arithmetic.
            final float totalUsageTimeInMs =
@@ -1165,11 +1170,6 @@ public final class DataProcessor {
                cachedUsageConsumePower = cachedUsageConsumePower * ratio;
            }

            final boolean isFromOtherUsers = isConsumedFromOtherUsers(
                    currentUserId, workProfileUserId, selectedBatteryEntry);
            if (isFromOtherUsers) {
                consumePowerFromOtherUsers += consumePower;
            } else {
            final BatteryDiffEntry currentBatteryDiffEntry = new BatteryDiffEntry(
                    context,
                    foregroundUsageTimeInMs,
@@ -1186,10 +1186,6 @@ public final class DataProcessor {
                appEntries.add(currentBatteryDiffEntry);
            }
        }
        }
        if (consumePowerFromOtherUsers != 0) {
            systemEntries.add(createOtherUsersEntry(context, consumePowerFromOtherUsers));
        }

        // If there is no data, return null instead of empty item.
        if (appEntries.isEmpty() && systemEntries.isEmpty()) {
@@ -1518,27 +1514,6 @@ public final class DataProcessor {
        return null;
    }

    private static BatteryDiffEntry createOtherUsersEntry(
            Context context, final double consumePower) {
        final ContentValues values = new ContentValues();
        values.put(BatteryHistEntry.KEY_UID, BatteryUtils.UID_OTHER_USERS);
        values.put(BatteryHistEntry.KEY_USER_ID, BatteryUtils.UID_OTHER_USERS);
        values.put(BatteryHistEntry.KEY_CONSUMER_TYPE, ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
        // We will show the percentage for the "other users" item only, the aggregated
        // running time information is useless for users to identify individual apps.
        final BatteryDiffEntry batteryDiffEntry = new BatteryDiffEntry(
                context,
                /*foregroundUsageTimeInMs=*/ 0,
                /*backgroundUsageTimeInMs=*/ 0,
                consumePower,
                /*foregroundUsageConsumePower=*/ 0,
                /*foregroundServiceUsageConsumePower=*/ 0,
                /*backgroundUsageConsumePower=*/ 0,
                /*cachedUsageConsumePower=*/ 0,
                new BatteryHistEntry(values));
        return batteryDiffEntry;
    }

    private static long getCurrentTimeMillis() {
        return sFakeCurrentTimeMillis > 0 ? sFakeCurrentTimeMillis : System.currentTimeMillis();
    }
+0 −13
Original line number Diff line number Diff line
@@ -464,19 +464,6 @@ public final class BatteryDiffEntryTest {
        assertThat(entry.getPackageName()).isEqualTo(expectedPackageName);
    }

    @Test
    public void getAppLabel_withOtherUsersUid_returnExpectedLabel() {
        final ContentValues values = getContentValuesWithType(
                ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
        values.put(BatteryHistEntry.KEY_UID, BatteryUtils.UID_OTHER_USERS);

        final BatteryDiffEntry batteryDiffEntry = createBatteryDiffEntry(
                /*consumePower=*/ 0, new BatteryHistEntry(values));

        assertThat(batteryDiffEntry.getAppLabel())
                .isEqualTo(mContext.getString(R.string.battery_usage_other_users));
    }

    private BatteryDiffEntry createBatteryDiffEntry(
            int consumerType, long uid, boolean isHidden) {
        final ContentValues values = getContentValuesWithType(consumerType);
Loading