DPC can be uninstalled in personal profile in New COPE

* For an organization-owned device, the DPC should be able to
  be uninstalled in the personal profile. Previously, the
  observed behaviour was that the uninstall button in the App
  Info Screen was being greyed out.
* This was because the previous logic did not allow for
  uninstalling any app which has a profile owner or device
  owner on *any* user.
* This CL updates this logic, such that, for non-system apps
  uninstalling is blocked only if the app has a profile owner
  or device owner for the current calling user.

Bug: 149381804
Test: Manual testing
      atest com.android.settings.applications.appinfo.AppButtonsPreferenceControllerTest
Change-Id: Ifaf03daa41724dbbd869c7e1371a77cc39d15ac7
This commit is contained in:
Alex Johnston
2020-02-26 15:54:11 +00:00
parent 8ee5045d68
commit 341f995971
3 changed files with 65 additions and 8 deletions

View File

@@ -36,7 +36,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.app.Application;
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
@@ -51,8 +50,6 @@ import android.os.UserManager;
import android.util.ArraySet;
import android.view.View;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
@@ -277,7 +274,8 @@ public class AppButtonsPreferenceControllerTest {
}
@Test
public void updateUninstallButton_isProfileOrDeviceOwner_setButtonDisable() {
public void updateUninstallButton_isSystemAndIsProfileOrDeviceOwner_setButtonDisable() {
mAppInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
doReturn(true).when(mDpm).isDeviceOwnerAppOnAnyUser(anyString());
mController.updateUninstallButton();
@@ -285,6 +283,36 @@ public class AppButtonsPreferenceControllerTest {
verify(mButtonPrefs).setButton2Enabled(false);
}
@Test
public void updateUninstallButton_isSystemAndIsNotProfileOrDeviceOwner_setButtonEnabled() {
mAppInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
doReturn(false).when(mDpm).isDeviceOwnerAppOnAnyUser(anyString());
mController.updateUninstallButton();
verify(mButtonPrefs).setButton2Enabled(true);
}
@Test
public void updateUninstallButton_isNotSystemAndIsProfileOrDeviceOwner_setButtonDisable() {
doReturn(0).when(mDpm).getDeviceOwnerUserId();
doReturn(true).when(mDpm).isDeviceOwnerApp(anyString());
mController.updateUninstallButton();
verify(mButtonPrefs).setButton2Enabled(false);
}
@Test
public void updateUninstallButton_isNotSystemAndIsNotProfileOrDeviceOwner_setButtonEnabled() {
doReturn(10).when(mDpm).getDeviceOwnerUserId();
doReturn(false).when(mDpm).isDeviceOwnerApp(anyString());
mController.updateUninstallButton();
verify(mButtonPrefs).setButton2Enabled(true);
}
@Test
public void updateUninstallButton_isDeviceProvisioningApp_setButtonDisable() {
doReturn(true).when(mDpm).isDeviceOwnerAppOnAnyUser(anyString());