Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/RestrictedLockUtilsTest.java +90 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.app.admin.EnforcingAdmin; import android.app.admin.RoleAuthority; import android.app.admin.SystemAuthority; import android.app.admin.UnknownAuthority; import android.app.admin.flags.Flags; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading @@ -53,6 +54,7 @@ import android.platform.test.annotations.RequiresFlagsDisabled; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.provider.Settings; import org.junit.Before; import org.junit.Rule; Loading Loading @@ -495,6 +497,94 @@ public class RestrictedLockUtilsTest { .isNull(); } private static final ComponentName ENFORCING_ADMIN_COMPONENT = new ComponentName("test.pkg", "test.class"); private static final UserHandle ENFORCING_ADMIN_USER_HANDLE = UserHandle.of(10); private static final EnforcingAdmin ENFORCING_ADMIN = new EnforcingAdmin( ENFORCING_ADMIN_COMPONENT.getPackageName(), UnknownAuthority.UNKNOWN_AUTHORITY, ENFORCING_ADMIN_USER_HANDLE, ENFORCING_ADMIN_COMPONENT); private static final EnforcingAdmin ENFORCING_ADMIN_NO_COMPONENT = new EnforcingAdmin( ENFORCING_ADMIN_COMPONENT.getPackageName(), UnknownAuthority.UNKNOWN_AUTHORITY, ENFORCING_ADMIN_USER_HANDLE, /* componentName= */ null); @Test public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_nullAdmin() { // Call the method with a null admin Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent((EnforcingAdmin) null); // Verify the intent action is correct assertThat(intent.getAction()).isEqualTo(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS); // Verify no extras are added assertThat(intent.getExtras()).isNull(); } @Test @RequiresFlagsEnabled(Flags.FLAG_ENFORCING_ADMIN_EXTRA_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_extraFlagEnabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent contains the EXTRA_ENFORCING_ADMIN extra assertThat(intent.getParcelableExtra(DevicePolicyManager.EXTRA_ENFORCING_ADMIN, EnforcingAdmin.class)).isEqualTo(ENFORCING_ADMIN); } @Test @RequiresFlagsDisabled(Flags.FLAG_ENFORCING_ADMIN_EXTRA_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_extraFlagDisabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent does not contain the EXTRA_ENFORCING_ADMIN extra assertThat(intent.hasExtra(DevicePolicyManager.EXTRA_ENFORCING_ADMIN)).isFalse(); } @Test @RequiresFlagsEnabled(Flags.FLAG_ENFORCING_ADMIN_GET_COMPONENT_NAME_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_componentNameFlagEnabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent contains the EXTRA_DEVICE_ADMIN extra assertThat(intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, ComponentName.class)).isEqualTo(ENFORCING_ADMIN_COMPONENT); } @Test @RequiresFlagsEnabled(Flags.FLAG_ENFORCING_ADMIN_GET_COMPONENT_NAME_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_componentNameNull_flagEnabled() { // Call the method with an admin that has no component name Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( ENFORCING_ADMIN_NO_COMPONENT); // Verify the intent does not contain the EXTRA_DEVICE_ADMIN extra assertThat(intent.hasExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN)).isFalse(); } @Test @RequiresFlagsDisabled(Flags.FLAG_ENFORCING_ADMIN_GET_COMPONENT_NAME_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_componentNameFlagDisabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent does not contain the EXTRA_DEVICE_ADMIN extra assertThat(intent.hasExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN)).isFalse(); } @Test public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_alwaysHasUserExtra() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent always contains the user handle extra assertThat(intent.getParcelableExtra(Intent.EXTRA_USER, UserHandle.class)) .isEqualTo(ENFORCING_ADMIN_USER_HANDLE); } private UserInfo setUpUser(int userId, ComponentName[] admins) { UserInfo userInfo = new UserInfo(userId, "primary", 0); when(mUserManager.getUserInfo(userId)).thenReturn(userInfo); Loading Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/RestrictedLockUtilsTest.java +90 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.app.admin.EnforcingAdmin; import android.app.admin.RoleAuthority; import android.app.admin.SystemAuthority; import android.app.admin.UnknownAuthority; import android.app.admin.flags.Flags; import android.content.ComponentName; import android.content.Context; import android.content.Intent; Loading @@ -53,6 +54,7 @@ import android.platform.test.annotations.RequiresFlagsDisabled; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.provider.Settings; import org.junit.Before; import org.junit.Rule; Loading Loading @@ -495,6 +497,94 @@ public class RestrictedLockUtilsTest { .isNull(); } private static final ComponentName ENFORCING_ADMIN_COMPONENT = new ComponentName("test.pkg", "test.class"); private static final UserHandle ENFORCING_ADMIN_USER_HANDLE = UserHandle.of(10); private static final EnforcingAdmin ENFORCING_ADMIN = new EnforcingAdmin( ENFORCING_ADMIN_COMPONENT.getPackageName(), UnknownAuthority.UNKNOWN_AUTHORITY, ENFORCING_ADMIN_USER_HANDLE, ENFORCING_ADMIN_COMPONENT); private static final EnforcingAdmin ENFORCING_ADMIN_NO_COMPONENT = new EnforcingAdmin( ENFORCING_ADMIN_COMPONENT.getPackageName(), UnknownAuthority.UNKNOWN_AUTHORITY, ENFORCING_ADMIN_USER_HANDLE, /* componentName= */ null); @Test public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_nullAdmin() { // Call the method with a null admin Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent((EnforcingAdmin) null); // Verify the intent action is correct assertThat(intent.getAction()).isEqualTo(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS); // Verify no extras are added assertThat(intent.getExtras()).isNull(); } @Test @RequiresFlagsEnabled(Flags.FLAG_ENFORCING_ADMIN_EXTRA_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_extraFlagEnabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent contains the EXTRA_ENFORCING_ADMIN extra assertThat(intent.getParcelableExtra(DevicePolicyManager.EXTRA_ENFORCING_ADMIN, EnforcingAdmin.class)).isEqualTo(ENFORCING_ADMIN); } @Test @RequiresFlagsDisabled(Flags.FLAG_ENFORCING_ADMIN_EXTRA_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_extraFlagDisabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent does not contain the EXTRA_ENFORCING_ADMIN extra assertThat(intent.hasExtra(DevicePolicyManager.EXTRA_ENFORCING_ADMIN)).isFalse(); } @Test @RequiresFlagsEnabled(Flags.FLAG_ENFORCING_ADMIN_GET_COMPONENT_NAME_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_componentNameFlagEnabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent contains the EXTRA_DEVICE_ADMIN extra assertThat(intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, ComponentName.class)).isEqualTo(ENFORCING_ADMIN_COMPONENT); } @Test @RequiresFlagsEnabled(Flags.FLAG_ENFORCING_ADMIN_GET_COMPONENT_NAME_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_componentNameNull_flagEnabled() { // Call the method with an admin that has no component name Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( ENFORCING_ADMIN_NO_COMPONENT); // Verify the intent does not contain the EXTRA_DEVICE_ADMIN extra assertThat(intent.hasExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN)).isFalse(); } @Test @RequiresFlagsDisabled(Flags.FLAG_ENFORCING_ADMIN_GET_COMPONENT_NAME_ENABLED) public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_componentNameFlagDisabled() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent does not contain the EXTRA_DEVICE_ADMIN extra assertThat(intent.hasExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN)).isFalse(); } @Test public void getShowAdminSupportDetailsIntent_withEnforcingAdmin_alwaysHasUserExtra() { // Call the method Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(ENFORCING_ADMIN); // Verify the intent always contains the user handle extra assertThat(intent.getParcelableExtra(Intent.EXTRA_USER, UserHandle.class)) .isEqualTo(ENFORCING_ADMIN_USER_HANDLE); } private UserInfo setUpUser(int userId, ComponentName[] admins) { UserInfo userInfo = new UserInfo(userId, "primary", 0); when(mUserManager.getUserInfo(userId)).thenReturn(userInfo); Loading