Merge "[AAPM] Add advanced protection dialog according to API feedback" into main

This commit is contained in:
Azhara Assanova
2024-12-19 09:41:27 -08:00
committed by Android (Google) Code Review
7 changed files with 100 additions and 22 deletions

View File

@@ -20,9 +20,14 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.security.advancedprotection.AdvancedProtectionManager.ACTION_SHOW_ADVANCED_PROTECTION_SUPPORT_DIALOG;
import static android.security.advancedprotection.AdvancedProtectionManager.ADVANCED_PROTECTION_SYSTEM_ENTITY;
import static android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_FEATURE;
import static android.security.advancedprotection.AdvancedProtectionManager.EXTRA_SUPPORT_DIALOG_TYPE;
import static android.security.advancedprotection.AdvancedProtectionManager.FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES;
import static android.security.advancedprotection.AdvancedProtectionManager.SUPPORT_DIALOG_TYPE_UNKNOWN;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
@@ -40,7 +45,6 @@ import android.os.UserManager;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.security.advancedprotection.AdvancedProtectionManager;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -48,6 +52,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -59,8 +64,6 @@ public class ActionDisabledByAdminDialogTest {
@Mock
private DevicePolicyManager mDevicePolicyManager;
@Mock
private AdvancedProtectionManager mAdvancedProtectionManager;
private ActionDisabledByAdminDialog mDialog;
private final ComponentName mAdminComponent = new ComponentName("admin", "adminclass");
@@ -70,8 +73,6 @@ public class ActionDisabledByAdminDialogTest {
MockitoAnnotations.initMocks(this);
mDialog = spy(new ActionDisabledByAdminDialog());
doReturn(mDevicePolicyManager).when(mDialog).getSystemService(DevicePolicyManager.class);
doReturn(mAdvancedProtectionManager).when(mDialog).getSystemService(
AdvancedProtectionManager.class);
}
@Test
@@ -118,24 +119,28 @@ public class ActionDisabledByAdminDialogTest {
advancedProtectionAuthority, UserHandle.of(userId), mAdminComponent);
final String userRestriction = UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY;
final Intent apmIntent = new Intent(ACTION_SHOW_ADVANCED_PROTECTION_SUPPORT_DIALOG);
apmIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
apmIntent.putExtra(EXTRA_SUPPORT_DIALOG_FEATURE, "featureId");
final Intent dialogIntent = new Intent();
dialogIntent.putExtra(Intent.EXTRA_USER_ID, userId);
dialogIntent.putExtra(DevicePolicyManager.EXTRA_RESTRICTION, userRestriction);
when(mDevicePolicyManager.getEnforcingAdmin(userId, userRestriction))
.thenReturn(advancedProtectionEnforcingAdmin);
when(mAdvancedProtectionManager.createSupportIntentForPolicyIdentifierOrRestriction(
userRestriction, /* type */ null)).thenReturn(apmIntent);
doNothing().when(mDialog).startActivityAsUser(apmIntent, UserHandle.of(userId));
doNothing().when(mDialog).startActivityAsUser(any(), eq(UserHandle.of(userId)));
mDialog.getAdminDetailsFromIntent(dialogIntent);
verify(mDialog).startActivityAsUser(apmIntent, UserHandle.of(userId));
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mDialog).startActivityAsUser(intentCaptor.capture(), eq(UserHandle.of(userId)));
assertTrue(mDialog.isFinishing());
Intent launchedIntent = intentCaptor.getValue();
assertEquals("Intent action is incorrect", ACTION_SHOW_ADVANCED_PROTECTION_SUPPORT_DIALOG,
launchedIntent.getAction());
assertEquals("Feature ID extra is incorrect", FEATURE_ID_DISALLOW_INSTALL_UNKNOWN_SOURCES,
launchedIntent.getIntExtra(EXTRA_SUPPORT_DIALOG_FEATURE, -1));
assertEquals("Type is incorrect", SUPPORT_DIALOG_TYPE_UNKNOWN,
launchedIntent.getIntExtra(EXTRA_SUPPORT_DIALOG_TYPE, -1));
assertEquals(FLAG_ACTIVITY_NEW_TASK, launchedIntent.getFlags());
}
@RequiresFlagsEnabled(android.security.Flags.FLAG_AAPM_API)