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

Commit ee512d28 authored by Reema Bajwa's avatar Reema Bajwa Committed by Android (Google) Code Review
Browse files

Merge "Propagate ancellation signal to cred man service"

parents b81b5637 53dacd6f
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.credentials.ClearCredentialStateRequest;
import android.credentials.IClearCredentialStateCallback;
import android.credentials.ui.ProviderData;
import android.credentials.ui.RequestInfo;
import android.os.CancellationSignal;
import android.os.RemoteException;
import android.service.credentials.CallingAppInfo;
import android.service.credentials.CredentialProviderInfo;
@@ -41,9 +42,9 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta

    public ClearRequestSession(Context context, int userId, int callingUid,
            IClearCredentialStateCallback callback, ClearCredentialStateRequest request,
            CallingAppInfo callingAppInfo) {
            CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal) {
        super(context, userId, callingUid, request, callback, RequestInfo.TYPE_UNDEFINED,
                callingAppInfo);
                callingAppInfo, cancellationSignal);
    }

    /**
@@ -111,6 +112,12 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta

    private void respondToClientWithResponseAndFinish() {
        Log.i(TAG, "respondToClientWithResponseAndFinish");
        if (isSessionCancelled()) {
            // TODO: Differentiate btw cancelled and false
            logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ true);
            finishSession(/*propagateCancellation=*/true);
            return;
        }
        try {
            mClientCallback.onSuccess();
            logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ true);
@@ -118,18 +125,24 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
            Log.i(TAG, "Issue while propagating the response to the client");
            logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ false);
        }
        finishSession();
        finishSession(/*propagateCancellation=*/false);
    }

    private void respondToClientWithErrorAndFinish(String errorType, String errorMsg) {
        Log.i(TAG, "respondToClientWithErrorAndFinish");
        if (isSessionCancelled()) {
            // TODO: Differentiate btw cancelled and false
            logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ true);
            finishSession(/*propagateCancellation=*/true);
            return;
        }
        try {
            mClientCallback.onError(errorType, errorMsg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        logApiCalled(RequestType.CLEAR_CREDENTIALS, /* isSuccessful */ false);
        finishSession();
        finishSession(/*propagateCancellation=*/false);
    }

    private void processResponses() {
+18 −4
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.credentials.CredentialManager;
import android.credentials.ICreateCredentialCallback;
import android.credentials.ui.ProviderData;
import android.credentials.ui.RequestInfo;
import android.os.CancellationSignal;
import android.os.RemoteException;
import android.service.credentials.CallingAppInfo;
import android.service.credentials.CredentialProviderInfo;
@@ -47,9 +48,10 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
    CreateRequestSession(@NonNull Context context, int userId, int callingUid,
            CreateCredentialRequest request,
            ICreateCredentialCallback callback,
            CallingAppInfo callingAppInfo) {
            CallingAppInfo callingAppInfo,
            CancellationSignal cancellationSignal) {
        super(context, userId, callingUid, request, callback, RequestInfo.TYPE_CREATE,
                callingAppInfo);
                callingAppInfo, cancellationSignal);
    }

    /**
@@ -119,6 +121,12 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR

    private void respondToClientWithResponseAndFinish(CreateCredentialResponse response) {
        Log.i(TAG, "respondToClientWithResponseAndFinish");
        if (isSessionCancelled()) {
            // TODO: Differentiate btw cancelled and false
            logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ true);
            finishSession(/*propagateCancellation=*/true);
            return;
        }
        try {
            mClientCallback.onResponse(response);
            logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ true);
@@ -126,18 +134,24 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
            Log.i(TAG, "Issue while responding to client: " + e.getMessage());
            logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ false);
        }
        finishSession();
        finishSession(/*propagateCancellation=*/false);
    }

    private void respondToClientWithErrorAndFinish(String errorType, String errorMsg) {
        Log.i(TAG, "respondToClientWithErrorAndFinish");
        if (isSessionCancelled()) {
            // TODO: Differentiate btw cancelled and false
            logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ true);
            finishSession(/*propagateCancellation=*/true);
            return;
        }
        try {
            mClientCallback.onError(errorType, errorMsg);
        } catch (RemoteException e) {
            Log.i(TAG, "Issue while responding to client: " + e.getMessage());
        }
        logApiCalled(RequestType.CREATE_CREDENTIALS, /* isSuccessful */ false);
        finishSession();
        finishSession(/*propagateCancellation=*/false);
    }

    @Override
+8 −10
Original line number Diff line number Diff line
@@ -194,7 +194,6 @@ public final class CredentialManagerService
    }



    @GuardedBy("mLock")
    private List<CredentialManagerServiceImpl> getOrConstructSystemServiceListLock(
            int resolvedUserId) {
@@ -338,7 +337,8 @@ public final class CredentialManagerService
                            callingUid,
                            callback,
                            request,
                            constructCallingAppInfo(callingPackage, userId));
                            constructCallingAppInfo(callingPackage, userId),
                            CancellationSignal.fromTransport(cancelTransport));

            List<ProviderSession> providerSessions;

@@ -404,8 +404,6 @@ public final class CredentialManagerService
                                    + e.getMessage());
                }
            }

            // Iterate over all provider sessions and invoke the request
            providerSessions.forEach(ProviderSession::invokeSession);

            return cancelTransport;
@@ -430,7 +428,8 @@ public final class CredentialManagerService
                            callingUid,
                            request,
                            callback,
                            constructCallingAppInfo(callingPackage, userId));
                            constructCallingAppInfo(callingPackage, userId),
                            CancellationSignal.fromTransport(cancelTransport));

            // Initiate all provider sessions
            List<ProviderSession> providerSessions =
@@ -450,8 +449,7 @@ public final class CredentialManagerService
            }

            // Iterate over all provider sessions and invoke the request
            providerSessions.forEach(
                    ProviderSession::invokeSession);
            providerSessions.forEach(ProviderSession::invokeSession);
            return cancelTransport;
        }

@@ -542,7 +540,8 @@ public final class CredentialManagerService
                            callingUid,
                            callback,
                            request,
                            constructCallingAppInfo(callingPackage, userId));
                            constructCallingAppInfo(callingPackage, userId),
                            CancellationSignal.fromTransport(cancelTransport));

            // Initiate all provider sessions
            // TODO: Determine if provider needs to have clear capability in their manifest
@@ -563,8 +562,7 @@ public final class CredentialManagerService
            }

            // Iterate over all provider sessions and invoke the request
            providerSessions.forEach(
                    ProviderSession::invokeSession);
            providerSessions.forEach(ProviderSession::invokeSession);
            return cancelTransport;
        }

+17 −5
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.credentials.GetCredentialResponse;
import android.credentials.IGetCredentialCallback;
import android.credentials.ui.ProviderData;
import android.credentials.ui.RequestInfo;
import android.os.CancellationSignal;
import android.os.RemoteException;
import android.service.credentials.CallingAppInfo;
import android.service.credentials.CredentialProviderInfo;
@@ -43,8 +44,9 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest

    public GetRequestSession(Context context, int userId, int callingUid,
            IGetCredentialCallback callback, GetCredentialRequest request,
            CallingAppInfo callingAppInfo) {
        super(context, userId, callingUid, request, callback, RequestInfo.TYPE_GET, callingAppInfo);
            CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal) {
        super(context, userId, callingUid, request, callback, RequestInfo.TYPE_GET,
                callingAppInfo, cancellationSignal);
    }

    /**
@@ -102,6 +104,12 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
    }

    private void respondToClientWithResponseAndFinish(GetCredentialResponse response) {
        if (isSessionCancelled()) {
            // TODO: Differentiate btw cancelled and false
            logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ false);
            finishSession(/*propagateCancellation=*/true);
            return;
        }
        try {
            mClientCallback.onResponse(response);
            logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ true);
@@ -109,18 +117,22 @@ public final class GetRequestSession extends RequestSession<GetCredentialRequest
            Log.i(TAG, "Issue while responding to client with a response : " + e.getMessage());
            logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ false);
        }
        finishSession();
        finishSession(/*propagateCancellation=*/false);
    }

    private void respondToClientWithErrorAndFinish(String errorType, String errorMsg) {
        if (isSessionCancelled()) {
            logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ false);
            finishSession(/*propagateCancellation=*/true);
            return;
        }
        try {
            mClientCallback.onError(errorType, errorMsg);
        } catch (RemoteException e) {
            Log.i(TAG, "Issue while responding to client with error : " + e.getMessage());

        }
        logApiCalled(RequestType.GET_CREDENTIALS, /* isSuccessful */ false);
        finishSession();
        finishSession(/*propagateCancellation=*/false);
    }

    @Override
+16 −0
Original line number Diff line number Diff line
@@ -23,8 +23,11 @@ import android.content.Context;
import android.credentials.Credential;
import android.credentials.ui.ProviderData;
import android.credentials.ui.ProviderPendingIntentResponse;
import android.os.ICancellationSignal;
import android.os.RemoteException;
import android.service.credentials.CredentialEntry;
import android.service.credentials.CredentialProviderInfo;
import android.util.Log;
import android.util.Pair;

import java.util.UUID;
@@ -47,6 +50,7 @@ public abstract class ProviderSession<T, R>
    @NonNull protected Status mStatus = Status.NOT_STARTED;
    @Nullable protected final ProviderInternalCallback mCallbacks;
    @Nullable protected Credential mFinalCredentialResponse;
    @Nullable protected ICancellationSignal mProviderCancellationSignal;
    @NonNull protected final T mProviderRequest;
    @Nullable protected R mProviderResponse;
    @NonNull protected Boolean mProviderResponseSet = false;
@@ -149,6 +153,18 @@ public abstract class ProviderSession<T, R>
        return  mFinalCredentialResponse;
    }

    /** Propagates cancellation signal to the remote provider service. */
    public void cancelProviderRemoteSession() {
        try {
            if (mProviderCancellationSignal != null) {
                mProviderCancellationSignal.cancel();
            }
            setStatus(Status.CANCELED);
        } catch (RemoteException e) {
            Log.i(TAG, "Issue while cancelling provider session: " + e.getMessage());
        }
    }

    protected void setStatus(@NonNull Status status) {
        mStatus = status;
    }
Loading