Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef7e8d04 authored by Reema Bajwa's avatar Reema Bajwa
Browse files

Return USER_CANCELED exception type for credMan get & create flows

Test: Built & deployed locally

Change-Id: I9a615a6d7c032a203bf2e2864a754b033dd0694e
parent 843cd7b1
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -81,8 +81,9 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
                            mClientAppInfo.getPackageName()),
                            mClientAppInfo.getPackageName()),
                    providerDataList));
                    providerDataList));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.i(TAG, "Issue with invoking pending intent: " + e.getMessage());
            respondToClientWithErrorAndFinish(
            // TODO: Propagate failure
                    CreateCredentialException.TYPE_UNKNOWN,
                    "Unable to invoke selector");
        }
        }
    }
    }


@@ -112,8 +113,7 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR


    @Override
    @Override
    public void onUiCancellation() {
    public void onUiCancellation() {
        // TODO("Replace with properly defined error type")
        respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_USER_CANCELED,
        respondToClientWithErrorAndFinish(CreateCredentialException.TYPE_NO_CREDENTIAL,
                "User cancelled the selector");
                "User cancelled the selector");
    }
    }


+3 −4
Original line number Original line Diff line number Diff line
@@ -76,8 +76,8 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
                    mRequestId, mClientRequest, mClientAppInfo.getPackageName()),
                    mRequestId, mClientRequest, mClientAppInfo.getPackageName()),
                    providerDataList));
                    providerDataList));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.i(TAG, "Issue with invoking pending intent: " + e.getMessage());
            respondToClientWithErrorAndFinish(
            // TODO: Propagate failure
                    GetCredentialException.TYPE_UNKNOWN, "Unable to instantiate selector");
        }
        }
    }
    }


@@ -128,8 +128,7 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest


    @Override
    @Override
    public void onUiCancellation() {
    public void onUiCancellation() {
        // TODO("Replace with user cancelled error type when ready")
        respondToClientWithErrorAndFinish(GetCredentialException.TYPE_USER_CANCELED,
        respondToClientWithErrorAndFinish(GetCredentialException.TYPE_NO_CREDENTIAL,
                "User cancelled the selector");
                "User cancelled the selector");
    }
    }
}
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,12 @@ public class PendingIntentResultHandler {
        return pendingIntentResponse.getResultCode() == Activity.RESULT_OK;
        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. */
    /** Extracts the {@link CredentialsResponseContent} object added to the result data. */
    public static CredentialsResponseContent extractResponseContent(Intent resultData) {
    public static CredentialsResponseContent extractResponseContent(Intent resultData) {
        if (resultData == null) {
        if (resultData == null) {
+4 −5
Original line number Original line Diff line number Diff line
@@ -263,9 +263,9 @@ public final class ProviderCreateSession extends ProviderSession<
                Log.i(TAG, "Pending intent contains provider exception");
                Log.i(TAG, "Pending intent contains provider exception");
                return exception;
                return exception;
            }
            }
        } else if (PendingIntentResultHandler.isCancelledResponse(pendingIntentResponse)) {
            return new CreateCredentialException(CreateCredentialException.TYPE_USER_CANCELED);
        } else {
        } 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 new CreateCredentialException(CreateCredentialException.TYPE_NO_CREDENTIAL);
        }
        }
        return null;
        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,
     * 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
     * we send back a TYPE_UNKNOWN error as to the developer.
     * getting any credentials back.
     */
     */
    private void invokeCallbackOnInternalInvalidState() {
    private void invokeCallbackOnInternalInvalidState() {
        mCallbacks.onFinalErrorReceived(mComponentName,
        mCallbacks.onFinalErrorReceived(mComponentName,
                CreateCredentialException.TYPE_NO_CREDENTIAL,
                CreateCredentialException.TYPE_UNKNOWN,
                null);
                null);
    }
    }
}
}
+4 −5
Original line number Original line Diff line number Diff line
@@ -420,8 +420,9 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
                Log.i(TAG, "Pending intent contains provider exception");
                Log.i(TAG, "Pending intent contains provider exception");
                return exception;
                return exception;
            }
            }
        } else if (PendingIntentResultHandler.isCancelledResponse(pendingIntentResponse)) {
            return new GetCredentialException(GetCredentialException.TYPE_USER_CANCELED);
        } else {
        } else {
            Log.i(TAG, "Pending intent result code not Activity.RESULT_OK");
            return new GetCredentialException(GetCredentialException.TYPE_NO_CREDENTIAL);
            return new GetCredentialException(GetCredentialException.TYPE_NO_CREDENTIAL);
        }
        }
        return null;
        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,
     * 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
     * we send back a TYPE_UNKNOWN error as to the developer.
     * getting any credentials back.
     */
     */
    private void invokeCallbackOnInternalInvalidState() {
    private void invokeCallbackOnInternalInvalidState() {
        mCallbacks.onFinalErrorReceived(mComponentName,
        mCallbacks.onFinalErrorReceived(mComponentName,
                GetCredentialException.TYPE_NO_CREDENTIAL,
                GetCredentialException.TYPE_UNKNOWN, null);
                null);
    }
    }
}
}