Fix uninstalled app original uid should not be 0
Context: some special packages have uid but 0. Those packages should not be part of uninstalled apps. Test: manual Bug: 264339271 Fix: 264339271 Change-Id: I86874691b0a837335c2e5352d1d0c6be8df8a2e4
This commit is contained in:
@@ -74,6 +74,7 @@ import java.util.List;
|
|||||||
* Utils for battery operation
|
* Utils for battery operation
|
||||||
*/
|
*/
|
||||||
public class BatteryUtils {
|
public class BatteryUtils {
|
||||||
|
public static final int UID_ZERO = 0;
|
||||||
public static final int UID_NULL = -1;
|
public static final int UID_NULL = -1;
|
||||||
public static final int SDK_NULL = -1;
|
public static final int SDK_NULL = -1;
|
||||||
/** Special UID value for data usage by removed apps. */
|
/** Special UID value for data usage by removed apps. */
|
||||||
|
|||||||
@@ -283,7 +283,9 @@ public class BatteryDiffEntry {
|
|||||||
/** Whether the current BatteryDiffEntry is uninstalled app or not. */
|
/** Whether the current BatteryDiffEntry is uninstalled app or not. */
|
||||||
public boolean isUninstalledEntry() {
|
public boolean isUninstalledEntry() {
|
||||||
final String packageName = getPackageName();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ public final class BatteryDiffEntryTest {
|
|||||||
private static final int UNINSTALLED_UID = 101;
|
private static final int UNINSTALLED_UID = 101;
|
||||||
private static final String PACKAGE_NAME = "com.android.testing";
|
private static final String PACKAGE_NAME = "com.android.testing";
|
||||||
private static final String UNINSTALLED_PACKAGE_NAME = "com.android.testing.uninstalled";
|
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;
|
private Context mContext;
|
||||||
|
|
||||||
@@ -89,6 +91,9 @@ public final class BatteryDiffEntryTest {
|
|||||||
doReturn(BatteryUtils.UID_NULL)
|
doReturn(BatteryUtils.UID_NULL)
|
||||||
.when(mMockPackageManager)
|
.when(mMockPackageManager)
|
||||||
.getPackageUid(UNINSTALLED_PACKAGE_NAME, PackageManager.GET_META_DATA);
|
.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();
|
BatteryDiffEntry.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,6 +447,18 @@ public final class BatteryDiffEntryTest {
|
|||||||
assertThat(entry.isUninstalledEntry()).isFalse();
|
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
|
@Test
|
||||||
public void testIsUninstalledEntry_uninstalledApp_returnTrue() throws Exception {
|
public void testIsUninstalledEntry_uninstalledApp_returnTrue() throws Exception {
|
||||||
doReturn(BatteryUtils.UID_NULL)
|
doReturn(BatteryUtils.UID_NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user