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

Commit f0135418 authored by YK Hung's avatar YK Hung Committed by Android (Google) Code Review
Browse files

Merge "Fix uninstalled app original uid should not be 0" into main

parents 9a437cb6 28088dc6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import java.util.List;
 * Utils for battery operation
 */
public class BatteryUtils {
    public static final int UID_ZERO = 0;
    public static final int UID_NULL = -1;
    public static final int SDK_NULL = -1;
    /** Special UID value for data usage by removed apps. */
+3 −1
Original line number Diff line number Diff line
@@ -283,7 +283,9 @@ public class BatteryDiffEntry {
    /** Whether the current BatteryDiffEntry is uninstalled app or not. */
    public boolean isUninstalledEntry() {
        final String packageName = getPackageName();
        if (TextUtils.isEmpty(packageName) || isSystemEntry()) {
        if (TextUtils.isEmpty(packageName) || isSystemEntry()
                // Some special package UIDs could be 0. Those packages are not installed by users.
                || mUid == BatteryUtils.UID_ZERO) {
            return false;
        }

+17 −0
Original line number Diff line number Diff line
@@ -62,6 +62,8 @@ public final class BatteryDiffEntryTest {
    private static final int UNINSTALLED_UID = 101;
    private static final String PACKAGE_NAME = "com.android.testing";
    private static final String UNINSTALLED_PACKAGE_NAME = "com.android.testing.uninstalled";
    private static final String UID_ZERO_PACKAGE_NAME = "com.android.testing.uid.zero";


    private Context mContext;

@@ -89,6 +91,9 @@ public final class BatteryDiffEntryTest {
        doReturn(BatteryUtils.UID_NULL)
                .when(mMockPackageManager)
                .getPackageUid(UNINSTALLED_PACKAGE_NAME, PackageManager.GET_META_DATA);
        doReturn(BatteryUtils.UID_ZERO)
                .when(mMockPackageManager)
                .getPackageUid(UID_ZERO_PACKAGE_NAME, PackageManager.GET_META_DATA);
        BatteryDiffEntry.clearCache();
    }

@@ -442,6 +447,18 @@ public final class BatteryDiffEntryTest {
        assertThat(entry.isUninstalledEntry()).isFalse();
    }

    @Test
    public void testIsUninstalledEntry_uidZero_returnFalse() throws Exception {
        final ContentValues values =
                getContentValuesWithType(ConvertUtils.CONSUMER_TYPE_UID_BATTERY);
        values.put(BatteryHistEntry.KEY_UID, BatteryUtils.UID_ZERO);
        values.put(BatteryHistEntry.KEY_PACKAGE_NAME, PACKAGE_NAME);
        final BatteryDiffEntry entry = createBatteryDiffEntry(10, new BatteryHistEntry(values));

        assertThat(entry.isSystemEntry()).isFalse();
        assertThat(entry.isUninstalledEntry()).isFalse();
    }

    @Test
    public void testIsUninstalledEntry_uninstalledApp_returnTrue() throws Exception {
        doReturn(BatteryUtils.UID_NULL)