From 8d430de5d5c87175d39c1ed52055d8d2a80ec5f5 Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Mon, 16 Mar 2020 09:31:39 +0000 Subject: [PATCH] Fix AppButtonPreferenceControllerTest * isSystem was not being mocked. * The tests where isSystem should return true were not being tested properly. Bug: 151569506 Test: atest com.android.settings.applications.appinfo.AppButtonsPreferenceControllerTest Change-Id: Ib4249bca8f3c0321d0b64b4dbd4c4e5fc29586e1 --- .../appinfo/AppButtonsPreferenceController.java | 2 +- .../appinfo/AppButtonsPreferenceControllerTest.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java index 19627ffcb43..590384ceebb 100644 --- a/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java +++ b/src/com/android/settings/applications/appinfo/AppButtonsPreferenceController.java @@ -396,7 +396,7 @@ public class AppButtonsPreferenceController extends BasePreferenceController imp // We don't allow uninstalling DO/PO on *any* users if it's a system app, because // "uninstall" is actually "downgrade to the system version + disable", and "downgrade" // will clear data on all users. - if (Utils.isSystemPackage(mActivity.getResources(), mPm, mPackageInfo)) { + if (isSystemPackage(mActivity.getResources(), mPm, mPackageInfo)) { if (Utils.isProfileOrDeviceOwner(mUserManager, mDpm, mPackageInfo.packageName)) { enabled = false; } diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java index 044b6982424..7304fc20d9f 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppButtonsPreferenceControllerTest.java @@ -275,7 +275,7 @@ public class AppButtonsPreferenceControllerTest { @Test public void updateUninstallButton_isSystemAndIsProfileOrDeviceOwner_setButtonDisable() { - mAppInfo.flags |= ApplicationInfo.FLAG_SYSTEM; + doReturn(true).when(mController).isSystemPackage(any(), any(), any()); doReturn(true).when(mDpm).isDeviceOwnerAppOnAnyUser(anyString()); mController.updateUninstallButton(); @@ -285,7 +285,7 @@ public class AppButtonsPreferenceControllerTest { @Test public void updateUninstallButton_isSystemAndIsNotProfileOrDeviceOwner_setButtonEnabled() { - mAppInfo.flags |= ApplicationInfo.FLAG_SYSTEM; + doReturn(true).when(mController).isSystemPackage(any(), any(), any()); doReturn(false).when(mDpm).isDeviceOwnerAppOnAnyUser(anyString()); mController.updateUninstallButton(); @@ -295,6 +295,7 @@ public class AppButtonsPreferenceControllerTest { @Test public void updateUninstallButton_isNotSystemAndIsProfileOrDeviceOwner_setButtonDisable() { + doReturn(false).when(mController).isSystemPackage(any(), any(), any()); doReturn(0).when(mDpm).getDeviceOwnerUserId(); doReturn(true).when(mDpm).isDeviceOwnerApp(anyString()); @@ -305,6 +306,7 @@ public class AppButtonsPreferenceControllerTest { @Test public void updateUninstallButton_isNotSystemAndIsNotProfileOrDeviceOwner_setButtonEnabled() { + doReturn(false).when(mController).isSystemPackage(any(), any(), any()); doReturn(10).when(mDpm).getDeviceOwnerUserId(); doReturn(false).when(mDpm).isDeviceOwnerApp(anyString());