AppUriAuthenticationPolicy and UrisToAliases equals and hashcode
Bug: 177979648
Test: atest android.devicepolicy.cts.CredentialManagementAppTest
atest android.devicepolicy.cts.AppUriAuthenticationPolicyTest
atest android.security.CredentialManagementAppTest
Change-Id: I66d715ba6b47749e2e89c037caecc29f02d3a017
This commit is contained in:
@@ -37,8 +37,6 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@@ -149,37 +147,6 @@ public final class CredentialManagementAppTest {
|
||||
private void assertCredentialManagementAppsEqual(CredentialManagementApp actual,
|
||||
CredentialManagementApp expected) {
|
||||
assertThat(actual.getPackageName(), is(expected.getPackageName()));
|
||||
assertAuthenticationPoliciesEqual(actual.getAuthenticationPolicy(),
|
||||
expected.getAuthenticationPolicy());
|
||||
}
|
||||
|
||||
private void assertAuthenticationPoliciesEqual(AppUriAuthenticationPolicy actual,
|
||||
AppUriAuthenticationPolicy expected) {
|
||||
Iterator<Map.Entry<String, Map<Uri, String>>> actualIter =
|
||||
actual.getAppAndUriMappings().entrySet().iterator();
|
||||
Iterator<Map.Entry<String, Map<Uri, String>>> expectedIter =
|
||||
expected.getAppAndUriMappings().entrySet().iterator();
|
||||
|
||||
assertThat(actual.getAppAndUriMappings().size(),
|
||||
is(expected.getAppAndUriMappings().size()));
|
||||
while (actualIter.hasNext()) {
|
||||
Map.Entry<String, Map<Uri, String>> actualAppToUri = actualIter.next();
|
||||
Map.Entry<String, Map<Uri, String>> expectedAppToUri = expectedIter.next();
|
||||
assertThat(actualAppToUri.getKey(), is(expectedAppToUri.getKey()));
|
||||
assertUrisToAliasesEqual(actualAppToUri.getValue(), expectedAppToUri.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertUrisToAliasesEqual(Map<Uri, String> actual, Map<Uri, String> expected) {
|
||||
Iterator<Map.Entry<Uri, String>> actualIter = actual.entrySet().iterator();
|
||||
Iterator<Map.Entry<Uri, String>> expectedIter = expected.entrySet().iterator();
|
||||
|
||||
assertThat(actual.size(), is(expected.size()));
|
||||
while (actualIter.hasNext()) {
|
||||
Map.Entry<Uri, String> actualUriToAlias = actualIter.next();
|
||||
Map.Entry<Uri, String> expectedUriToAlias = expectedIter.next();
|
||||
assertThat(actualUriToAlias.getKey(), is(expectedUriToAlias.getKey()));
|
||||
assertThat(actualUriToAlias.getValue(), is(expectedUriToAlias.getValue()));
|
||||
}
|
||||
assertThat(actual.getAuthenticationPolicy(), is(expected.getAuthenticationPolicy()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,4 +238,21 @@ public final class AppUriAuthenticationPolicy implements Parcelable {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof AppUriAuthenticationPolicy)) {
|
||||
return false;
|
||||
}
|
||||
AppUriAuthenticationPolicy other = (AppUriAuthenticationPolicy) obj;
|
||||
return Objects.equals(mAppToUris, other.mAppToUris);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return mAppToUris.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The mapping from URI to alias, which determines the alias to use when the user visits a URI.
|
||||
@@ -135,4 +136,21 @@ public final class UrisToAliases implements Parcelable {
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeMap(mUrisToAliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof UrisToAliases)) {
|
||||
return false;
|
||||
}
|
||||
UrisToAliases other = (UrisToAliases) obj;
|
||||
return Objects.equals(mUrisToAliases, other.mUrisToAliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return mUrisToAliases.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user