Use TYPE_NO_CREDENTIAL for GET & CREATE exceptions
This constant is used whenever there are no providers, no credentials or other invalid state is reached. Test: Built & deployed locally Change-Id: I8175a8a0e5f6fca49151c746e20cfec85a67a50f
This commit is contained in:
@@ -138,6 +138,6 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
|
||||
}
|
||||
}
|
||||
// TODO: Replace with properly defined error type
|
||||
respondToClientWithErrorAndFinish("unknown", "All providers failed");
|
||||
respondToClientWithErrorAndFinish("UNKNOWN", "All providers failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.credentials.CreateCredentialException;
|
||||
import android.credentials.CreateCredentialRequest;
|
||||
import android.credentials.CreateCredentialResponse;
|
||||
import android.credentials.CredentialManager;
|
||||
@@ -98,8 +99,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
|
||||
if (response != null) {
|
||||
respondToClientWithResponseAndFinish(response);
|
||||
} else {
|
||||
// TODO("Replace with properly defined error type)
|
||||
respondToClientWithErrorAndFinish("unknown_type",
|
||||
respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREDENTIAL,
|
||||
"Invalid response");
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
|
||||
@Override
|
||||
public void onUiCancellation() {
|
||||
// TODO("Replace with properly defined error type")
|
||||
respondToClientWithErrorAndFinish("user_cancelled",
|
||||
respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREDENTIAL,
|
||||
"User cancelled the selector");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,9 @@ import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.credentials.ClearCredentialStateRequest;
|
||||
import android.credentials.CreateCredentialException;
|
||||
import android.credentials.CreateCredentialRequest;
|
||||
import android.credentials.GetCredentialException;
|
||||
import android.credentials.GetCredentialOption;
|
||||
import android.credentials.GetCredentialRequest;
|
||||
import android.credentials.IClearCredentialStateCallback;
|
||||
@@ -235,8 +237,8 @@ public final class CredentialManagerService
|
||||
|
||||
if (providerSessions.isEmpty()) {
|
||||
try {
|
||||
// TODO("Replace with properly defined error type")
|
||||
callback.onError("unknown_type", "No providers available to fulfill request.");
|
||||
callback.onError(GetCredentialException.TYPE_NO_CREDENTIAL,
|
||||
"No credentials available on this device.");
|
||||
} catch (RemoteException e) {
|
||||
Log.i(
|
||||
TAG,
|
||||
@@ -284,8 +286,8 @@ public final class CredentialManagerService
|
||||
|
||||
if (providerSessions.isEmpty()) {
|
||||
try {
|
||||
// TODO("Replace with properly defined error type")
|
||||
callback.onError("unknown_type", "No providers available to fulfill request.");
|
||||
callback.onError(CreateCredentialException.TYPE_NO_CREDENTIAL,
|
||||
"No credentials available on this device.");
|
||||
} catch (RemoteException e) {
|
||||
Log.i(
|
||||
TAG,
|
||||
@@ -402,7 +404,8 @@ public final class CredentialManagerService
|
||||
if (providerSessions.isEmpty()) {
|
||||
try {
|
||||
// TODO("Replace with properly defined error type")
|
||||
callback.onError("unknown_type", "No providers available to fulfill request.");
|
||||
callback.onError("UNKNOWN", "No crdentials available on this "
|
||||
+ "device");
|
||||
} catch (RemoteException e) {
|
||||
Log.i(
|
||||
TAG,
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.server.credentials;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.credentials.GetCredentialException;
|
||||
import android.credentials.GetCredentialRequest;
|
||||
import android.credentials.GetCredentialResponse;
|
||||
import android.credentials.IGetCredentialCallback;
|
||||
@@ -93,8 +94,7 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
|
||||
if (response != null) {
|
||||
respondToClientWithResponseAndFinish(response);
|
||||
} else {
|
||||
// TODO("Replace with no credentials/unknown type when ready)
|
||||
respondToClientWithErrorAndFinish("unknown_type",
|
||||
respondToClientWithErrorAndFinish(GetCredentialException.TYPE_NO_CREDENTIAL,
|
||||
"Invalid response from provider");
|
||||
}
|
||||
}
|
||||
@@ -108,29 +108,28 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
|
||||
}
|
||||
|
||||
private void respondToClientWithResponseAndFinish(GetCredentialResponse response) {
|
||||
Log.i(TAG, "respondToClientWithResponseAndFinish");
|
||||
try {
|
||||
mClientCallback.onResponse(response);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
Log.i(TAG, "Issue while responding to client with a response : " + e.getMessage());
|
||||
}
|
||||
finishSession();
|
||||
}
|
||||
|
||||
private void respondToClientWithErrorAndFinish(String errorType, String errorMsg) {
|
||||
Log.i(TAG, "respondToClientWithErrorAndFinish");
|
||||
try {
|
||||
mClientCallback.onError(errorType, errorMsg);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
Log.i(TAG, "Issue while responding to client with error : " + e.getMessage());
|
||||
|
||||
}
|
||||
finishSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUiCancellation() {
|
||||
// TODO("Replace with properly defined error type")
|
||||
respondToClientWithErrorAndFinish("user_canceled",
|
||||
// TODO("Replace with user cancelled error type when ready")
|
||||
respondToClientWithErrorAndFinish(GetCredentialException.TYPE_NO_CREDENTIAL,
|
||||
"User cancelled the selector");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.credentials.CreateCredentialException;
|
||||
import android.credentials.CreateCredentialResponse;
|
||||
import android.credentials.ui.CreateCredentialProviderData;
|
||||
import android.credentials.ui.Entry;
|
||||
import android.credentials.ui.ProviderPendingIntentResponse;
|
||||
@@ -99,7 +100,7 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
private ProviderCreateSession(
|
||||
@NonNull Context context,
|
||||
@NonNull CredentialProviderInfo info,
|
||||
@NonNull ProviderInternalCallback callbacks,
|
||||
@NonNull ProviderInternalCallback<CreateCredentialResponse> callbacks,
|
||||
@UserIdInt int userId,
|
||||
@NonNull RemoteCredentialService remoteCredentialService,
|
||||
@NonNull BeginCreateCredentialRequest beginCreateRequest,
|
||||
@@ -181,9 +182,7 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
onSaveEntrySelected(providerPendingIntentResponse);
|
||||
} else {
|
||||
Log.i(TAG, "Unexpected save entry key");
|
||||
// TODO("Replace with no credentials error type");
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Issue while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
break;
|
||||
case REMOTE_ENTRY_KEY:
|
||||
@@ -191,9 +190,7 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
onRemoteEntrySelected(providerPendingIntentResponse);
|
||||
} else {
|
||||
Log.i(TAG, "Unexpected remote entry key");
|
||||
// TODO("Replace with unknown/no credentials exception")
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Issue while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -250,23 +247,16 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
} else {
|
||||
Log.i(TAG, "onSaveEntrySelected - no response or error found in pending "
|
||||
+ "intent response");
|
||||
invokeCallbackWithError(
|
||||
// TODO("Replace with unknown/no credentials exception")
|
||||
"unknown",
|
||||
"Issue encountered while retrieving the credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeCallbackWithError(String errorType, @Nullable String message) {
|
||||
mCallbacks.onFinalErrorReceived(mComponentName, errorType, message);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CreateCredentialException maybeGetPendingIntentException(
|
||||
ProviderPendingIntentResponse pendingIntentResponse) {
|
||||
if (pendingIntentResponse == null) {
|
||||
Log.i(TAG, "pendingIntentResponse is null");
|
||||
return null;
|
||||
return new CreateCredentialException(CreateCredentialException.TYPE_NO_CREDENTIAL);
|
||||
}
|
||||
if (PendingIntentResultHandler.isValidResponse(pendingIntentResponse)) {
|
||||
CreateCredentialException exception = PendingIntentResultHandler
|
||||
@@ -278,8 +268,19 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
} else {
|
||||
Log.i(TAG, "Pending intent result code not Activity.RESULT_OK");
|
||||
// TODO("Update with unknown exception when ready")
|
||||
return new CreateCredentialException("unknown");
|
||||
return new CreateCredentialException(CreateCredentialException.TYPE_NO_CREDENTIAL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private void invokeCallbackOnInternalInvalidState() {
|
||||
mCallbacks.onFinalErrorReceived(mComponentName,
|
||||
CreateCredentialException.TYPE_NO_CREDENTIAL,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
|
||||
public ProviderGetSession(Context context,
|
||||
CredentialProviderInfo info,
|
||||
ProviderInternalCallback callbacks,
|
||||
ProviderInternalCallback<GetCredentialResponse> callbacks,
|
||||
int userId, RemoteCredentialService remoteCredentialService,
|
||||
BeginGetCredentialRequest beginGetRequest,
|
||||
android.credentials.GetCredentialRequest completeGetRequest) {
|
||||
@@ -196,9 +196,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
CredentialEntry credentialEntry = mUiCredentialEntries.get(entryKey);
|
||||
if (credentialEntry == null) {
|
||||
Log.i(TAG, "Unexpected credential entry key");
|
||||
// TODO("Replace with no credentials/unknown exception")
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Issue while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
return;
|
||||
}
|
||||
onCredentialEntrySelected(credentialEntry, providerPendingIntentResponse);
|
||||
@@ -207,9 +205,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
Action actionEntry = mUiActionsEntries.get(entryKey);
|
||||
if (actionEntry == null) {
|
||||
Log.i(TAG, "Unexpected action entry key");
|
||||
// TODO("Replace with no credentials/unknown exception")
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Issue while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
return;
|
||||
}
|
||||
onActionEntrySelected(providerPendingIntentResponse);
|
||||
@@ -219,9 +215,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
onAuthenticationEntrySelected(providerPendingIntentResponse);
|
||||
} else {
|
||||
Log.i(TAG, "Unexpected authentication entry key");
|
||||
// TODO("Replace with no credentials/unknown exception")
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Issue while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
break;
|
||||
case REMOTE_ENTRY_KEY:
|
||||
@@ -229,9 +223,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
onRemoteEntrySelected(providerPendingIntentResponse);
|
||||
} else {
|
||||
Log.i(TAG, "Unexpected remote entry key");
|
||||
// TODO("Replace with no credentials/unknown exception")
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Issue while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -239,11 +231,6 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeCallbackWithError(String errorType, @Nullable String errorMessage) {
|
||||
// TODO: Determine what the error message should be
|
||||
mCallbacks.onFinalErrorReceived(mComponentName, errorType, errorMessage);
|
||||
}
|
||||
|
||||
@Override // Call from request session to data to be shown on the UI
|
||||
@Nullable protected GetCredentialProviderData prepareUiData() throws IllegalArgumentException {
|
||||
Log.i(TAG, "In prepareUiData");
|
||||
@@ -376,14 +363,10 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
}
|
||||
|
||||
Log.i(TAG, "Pending intent response contains no credential, or error");
|
||||
// TODO("Replace with no credentials/unknown error when ready)
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Issue while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
Log.i(TAG, "CredentialEntry does not have a credential or a pending intent result");
|
||||
// TODO("Replace with no credentials/unknown error when ready)
|
||||
invokeCallbackWithError("unknown_type",
|
||||
"Error encountered while retrieving the credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
|
||||
private void onAuthenticationEntrySelected(
|
||||
@@ -408,9 +391,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
}
|
||||
|
||||
Log.i(TAG, "No error or respond found in pending intent response");
|
||||
// TODO("Replace with no credentials/unknown error when ready)
|
||||
invokeCallbackWithError("unknown type", "Issue"
|
||||
+ " while retrieving credential");
|
||||
invokeCallbackOnInternalInvalidState();
|
||||
}
|
||||
|
||||
private void onActionEntrySelected(ProviderPendingIntentResponse
|
||||
@@ -437,7 +418,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
ProviderPendingIntentResponse pendingIntentResponse) {
|
||||
if (pendingIntentResponse == null) {
|
||||
Log.i(TAG, "pendingIntentResponse is null");
|
||||
return null;
|
||||
return new GetCredentialException(GetCredentialException.TYPE_NO_CREDENTIAL);
|
||||
}
|
||||
if (PendingIntentResultHandler.isValidResponse(pendingIntentResponse)) {
|
||||
GetCredentialException exception = PendingIntentResultHandler
|
||||
@@ -448,9 +429,19 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "Pending intent result code not Activity.RESULT_OK");
|
||||
// TODO("Update with unknown exception when ready")
|
||||
return new GetCredentialException("unknown");
|
||||
return new GetCredentialException(GetCredentialException.TYPE_NO_CREDENTIAL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private void invokeCallbackOnInternalInvalidState() {
|
||||
mCallbacks.onFinalErrorReceived(mComponentName,
|
||||
GetCredentialException.TYPE_NO_CREDENTIAL,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,11 @@ public abstract class ProviderSession<T, R>
|
||||
return mProviderResponse != null || mProviderResponseSet;
|
||||
}
|
||||
|
||||
protected void invokeCallbackWithError(String errorType, @Nullable String errorMessage) {
|
||||
// TODO: Determine what the error message should be
|
||||
mCallbacks.onFinalErrorReceived(mComponentName, errorType, errorMessage);
|
||||
}
|
||||
|
||||
/** Update the response state stored with the provider session. */
|
||||
@Nullable protected R getProviderResponse() {
|
||||
return mProviderResponse;
|
||||
|
||||
Reference in New Issue
Block a user