Merge "Update creddesc flag method." into udc-dev
This commit is contained in:
@@ -505,7 +505,19 @@ public final class CredentialManager {
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static boolean isCredentialDescriptionApiEnabled() {
|
||||
public static boolean isCredentialDescriptionApiEnabled(Context context) {
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
CredentialManager credentialManager =
|
||||
(CredentialManager) context.getSystemService(Context.CREDENTIAL_SERVICE);
|
||||
if (credentialManager != null) {
|
||||
return credentialManager.isCredentialDescriptionApiEnabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isCredentialDescriptionApiEnabled() {
|
||||
return DeviceConfig.getBoolean(
|
||||
DeviceConfig.NAMESPACE_CREDENTIAL, DEVICE_CONFIG_ENABLE_CREDENTIAL_DESC_API, false);
|
||||
}
|
||||
@@ -527,11 +539,6 @@ public final class CredentialManager {
|
||||
*/
|
||||
public void registerCredentialDescription(
|
||||
@NonNull RegisterCredentialDescriptionRequest request) {
|
||||
|
||||
if (!isCredentialDescriptionApiEnabled()) {
|
||||
throw new UnsupportedOperationException("This API is not currently supported.");
|
||||
}
|
||||
|
||||
requireNonNull(request, "request must not be null");
|
||||
|
||||
try {
|
||||
@@ -550,11 +557,6 @@ public final class CredentialManager {
|
||||
*/
|
||||
public void unregisterCredentialDescription(
|
||||
@NonNull UnregisterCredentialDescriptionRequest request) {
|
||||
|
||||
if (!isCredentialDescriptionApiEnabled()) {
|
||||
throw new UnsupportedOperationException("This API is not currently supported.");
|
||||
}
|
||||
|
||||
requireNonNull(request, "request must not be null");
|
||||
|
||||
try {
|
||||
|
||||
@@ -19,7 +19,6 @@ package android.credentials;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
@@ -593,15 +592,12 @@ public class CredentialManagerTest {
|
||||
|
||||
@Test
|
||||
public void testRegisterCredentialDescription_nullRequest() {
|
||||
assumeTrue(CredentialManager.isCredentialDescriptionApiEnabled());
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> mCredentialManager.registerCredentialDescription(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterCredentialDescription_success() throws RemoteException {
|
||||
assumeTrue(CredentialManager.isCredentialDescriptionApiEnabled());
|
||||
|
||||
mCredentialManager.registerCredentialDescription(mRegisterRequest);
|
||||
verify(mMockCredentialManagerService).registerCredentialDescription(same(mRegisterRequest),
|
||||
eq(mPackageName));
|
||||
@@ -609,16 +605,12 @@ public class CredentialManagerTest {
|
||||
|
||||
@Test
|
||||
public void testUnregisterCredentialDescription_nullRequest() {
|
||||
assumeTrue(CredentialManager.isCredentialDescriptionApiEnabled());
|
||||
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> mCredentialManager.unregisterCredentialDescription(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnregisterCredentialDescription_success() throws RemoteException {
|
||||
assumeTrue(CredentialManager.isCredentialDescriptionApiEnabled());
|
||||
|
||||
mCredentialManager.unregisterCredentialDescription(mUnregisterRequest);
|
||||
verify(mMockCredentialManagerService).unregisterCredentialDescription(
|
||||
same(mUnregisterRequest), eq(mPackageName));
|
||||
|
||||
@@ -422,8 +422,7 @@ public final class CredentialManagerService
|
||||
GetRequestSession session) {
|
||||
List<ProviderSession> providerSessions;
|
||||
|
||||
// TODO(b/268143699): temporarily disable the flag due to bug.
|
||||
if (false) {
|
||||
if (isCredentialDescriptionApiEnabled()) {
|
||||
List<CredentialOption> optionsThatRequireActiveCredentials =
|
||||
request.getCredentialOptions().stream()
|
||||
.filter(
|
||||
@@ -776,6 +775,10 @@ public final class CredentialManagerService
|
||||
throws IllegalArgumentException, NonCredentialProviderCallerException {
|
||||
Log.i(TAG, "registerCredentialDescription");
|
||||
|
||||
if (!isCredentialDescriptionApiEnabled()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
enforceCallingPackage(callingPackage, Binder.getCallingUid());
|
||||
|
||||
List<CredentialProviderInfo> services =
|
||||
@@ -828,6 +831,10 @@ public final class CredentialManagerService
|
||||
throws IllegalArgumentException {
|
||||
Log.i(TAG, "registerCredentialDescription");
|
||||
|
||||
if (!isCredentialDescriptionApiEnabled()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
enforceCallingPackage(callingPackage, Binder.getCallingUid());
|
||||
|
||||
List<CredentialProviderInfo> services =
|
||||
|
||||
Reference in New Issue
Block a user