Add unit test for createConfirmDeviceCredentialForRemoteValidationIntent

Bug: 273591679
Test: atest frameworks/base/core/tests/coretests/src/android/app/KeyguardManagerTest.java
Change-Id: I321ad3b798e6618fef8846c915fba044ac31c92b
This commit is contained in:
Brian Lee
2023-05-08 14:18:03 -07:00
parent 36f3373f7d
commit 0a4c86aa4a

View File

@@ -19,6 +19,7 @@ package android.app;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
@@ -26,6 +27,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -209,6 +211,42 @@ public class KeyguardManagerTest {
verifyDeviceLockedAndRemoveLock();
}
@Test
public void createConfirmDeviceCredentialForRemoteValidationIntent() {
RemoteLockscreenValidationSession remoteLockscreenValidationSession =
new RemoteLockscreenValidationSession.Builder()
.setSourcePublicKey("sourcePublicKey".getBytes())
.build();
ComponentName componentName = new ComponentName("pkg", "cls");
String title = "title";
String description = "description";
String checkboxLabel = "checkboxLabel";
String alternateButtonLabel = "alternateButtonLabel";
Intent intent = mKeyguardManager.createConfirmDeviceCredentialForRemoteValidationIntent(
remoteLockscreenValidationSession,
componentName,
title,
description,
checkboxLabel,
alternateButtonLabel
);
assertNotNull(intent);
assertEquals(KeyguardManager.ACTION_CONFIRM_REMOTE_DEVICE_CREDENTIAL, intent.getAction());
assertEquals(remoteLockscreenValidationSession,
intent.getParcelableExtra(
KeyguardManager.EXTRA_REMOTE_LOCKSCREEN_VALIDATION_SESSION,
RemoteLockscreenValidationSession.class));
assertEquals(componentName,
intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME, ComponentName.class));
assertEquals(title, intent.getStringExtra(KeyguardManager.EXTRA_TITLE));
assertEquals(description, intent.getStringExtra(KeyguardManager.EXTRA_DESCRIPTION));
assertEquals(checkboxLabel, intent.getStringExtra(KeyguardManager.EXTRA_CHECKBOX_LABEL));
assertEquals(alternateButtonLabel,
intent.getStringExtra(KeyguardManager.EXTRA_ALTERNATE_BUTTON_LABEL));
}
private void verifyDeviceLockedAndRemoveLock() {
assertTrue(mKeyguardManager.isDeviceSecure());
assertTrue("Failed to remove new password that was set in the test case.",