Return USER_CANCELED exception type for credMan get & create flows

Test: Built & deployed locally

Change-Id: I9a615a6d7c032a203bf2e2864a754b033dd0694e
This commit is contained in:
Reema Bajwa
2023-01-12 01:42:41 +00:00
parent 843cd7b139
commit ef7e8d04bc
5 changed files with 21 additions and 18 deletions

View File

@@ -81,8 +81,9 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
mClientAppInfo.getPackageName()),
providerDataList));
} catch (RemoteException e) {
Log.i(TAG, "Issue with invoking pending intent: " + e.getMessage());
// TODO: Propagate failure
respondToClientWithErrorAndFinish(
CreateCredentialException.TYPE_UNKNOWN,
"Unable to invoke selector");
}
}
@@ -112,8 +113,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
@Override
public void onUiCancellation() {
// TODO("Replace with properly defined error type")
respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREDENTIAL,
respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_USER_CANCELED,
"User cancelled the selector");
}

View File

@@ -76,8 +76,8 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
mRequestId, mClientRequest, mClientAppInfo.getPackageName()),
providerDataList));
} catch (RemoteException e) {
Log.i(TAG, "Issue with invoking pending intent: " + e.getMessage());
// TODO: Propagate failure
respondToClientWithErrorAndFinish(
GetCredentialException.TYPE_UNKNOWN, "Unable to instantiate selector");
}
}
@@ -128,8 +128,7 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
@Override
public void onUiCancellation() {
// TODO("Replace with user cancelled error type when ready")
respondToClientWithErrorAndFinish(GetCredentialException.TYPE_NO_CREDENTIAL,
respondToClientWithErrorAndFinish(GetCredentialException.TYPE_USER_CANCELED,
"User cancelled the selector");
}
}

View File

@@ -39,6 +39,12 @@ public class PendingIntentResultHandler {
return pendingIntentResponse.getResultCode() == Activity.RESULT_OK;
}
/** Returns true if the pending intent was cancelled by the user. */
public static boolean isCancelledResponse(
ProviderPendingIntentResponse pendingIntentResponse) {
return pendingIntentResponse.getResultCode() == Activity.RESULT_CANCELED;
}
/** Extracts the {@link CredentialsResponseContent} object added to the result data. */
public static CredentialsResponseContent extractResponseContent(Intent resultData) {
if (resultData == null) {

View File

@@ -263,9 +263,9 @@ public final class ProviderCreateSession extends ProviderSession<
Log.i(TAG, "Pending intent contains provider exception");
return exception;
}
} else if (PendingIntentResultHandler.isCancelledResponse(pendingIntentResponse)) {
return new CreateCredentialException(CreateCredentialException.TYPE_USER_CANCELED);
} else {
Log.i(TAG, "Pending intent result code not Activity.RESULT_OK");
// TODO("Update with unknown exception when ready")
return new CreateCredentialException(CreateCredentialException.TYPE_NO_CREDENTIAL);
}
return null;
@@ -273,12 +273,11 @@ public final class ProviderCreateSession extends ProviderSession<
/**
* When an invalid state occurs, e.g. entry mismatch or no response from provider,
* we send back a TYPE_NO_CREDENTIAL error as to the developer, it is the same as not
* getting any credentials back.
* we send back a TYPE_UNKNOWN error as to the developer.
*/
private void invokeCallbackOnInternalInvalidState() {
mCallbacks.onFinalErrorReceived(mComponentName,
CreateCredentialException.TYPE_NO_CREDENTIAL,
CreateCredentialException.TYPE_UNKNOWN,
null);
}
}

View File

@@ -420,8 +420,9 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
Log.i(TAG, "Pending intent contains provider exception");
return exception;
}
} else if (PendingIntentResultHandler.isCancelledResponse(pendingIntentResponse)) {
return new GetCredentialException(GetCredentialException.TYPE_USER_CANCELED);
} else {
Log.i(TAG, "Pending intent result code not Activity.RESULT_OK");
return new GetCredentialException(GetCredentialException.TYPE_NO_CREDENTIAL);
}
return null;
@@ -429,12 +430,10 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
/**
* When an invalid state occurs, e.g. entry mismatch or no response from provider,
* we send back a TYPE_NO_CREDENTIAL error as to the developer, it is the same as not
* getting any credentials back.
* we send back a TYPE_UNKNOWN error as to the developer.
*/
private void invokeCallbackOnInternalInvalidState() {
mCallbacks.onFinalErrorReceived(mComponentName,
GetCredentialException.TYPE_NO_CREDENTIAL,
null);
GetCredentialException.TYPE_UNKNOWN, null);
}
}