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

Commit 4b3d41dc authored by Helen Qin's avatar Helen Qin Committed by Android (Google) Code Review
Browse files

Merge "Switch the activity parameter to context." into udc-dev

parents b3ede6a3 e31d0c0e
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -13655,9 +13655,9 @@ package android.credentials {
  public final class CredentialManager {
    method public void clearCredentialState(@NonNull android.credentials.ClearCredentialStateRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<java.lang.Void,android.credentials.ClearCredentialStateException>);
    method public void createCredential(@NonNull android.credentials.CreateCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CreateCredentialException>);
    method public void getCredential(@NonNull android.credentials.GetCredentialRequest, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.GetCredentialException>);
    method public void getCredential(@NonNull android.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle, @NonNull android.app.Activity, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.GetCredentialException>);
    method public void createCredential(@NonNull android.content.Context, @NonNull android.credentials.CreateCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CreateCredentialException>);
    method public void getCredential(@NonNull android.content.Context, @NonNull android.credentials.GetCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.GetCredentialException>);
    method public void getCredential(@NonNull android.content.Context, @NonNull android.credentials.PrepareGetCredentialResponse.PendingGetCredentialHandle, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.GetCredentialException>);
    method public boolean isEnabledCredentialProviderService(@NonNull android.content.ComponentName);
    method public void prepareGetCredential(@NonNull android.credentials.GetCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.PrepareGetCredentialResponse,android.credentials.GetCredentialException>);
    method public void registerCredentialDescription(@NonNull android.credentials.RegisterCredentialDescriptionRequest);
+127 −47
Original line number Diff line number Diff line
@@ -25,11 +25,11 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.IntentSender;
import android.os.Binder;
import android.os.CancellationSignal;
import android.os.ICancellationSignal;
import android.os.OutcomeReceiver;
@@ -126,20 +126,21 @@ public final class CredentialManager {
     * need additional permission {@link CREDENTIAL_MANAGER_SET_ORIGIN}
     * to use this functionality
     *
     * @param context the context used to launch any UI needed; use an activity context to make sure
     *                the UI will be launched within the same task stack
     * @param request the request specifying type(s) of credentials to get from the user
     * @param activity the activity used to launch any UI needed
     * @param cancellationSignal an optional signal that allows for cancelling this call
     * @param executor the callback will take place on this {@link Executor}
     * @param callback the callback invoked when the request succeeds or fails
     */
    public void getCredential(
            @NonNull Context context,
            @NonNull GetCredentialRequest request,
            @NonNull Activity activity,
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull OutcomeReceiver<GetCredentialResponse, GetCredentialException> callback) {
        requireNonNull(request, "request must not be null");
        requireNonNull(activity, "activity must not be null");
        requireNonNull(context, "context must not be null");
        requireNonNull(executor, "executor must not be null");
        requireNonNull(callback, "callback must not be null");

@@ -153,7 +154,7 @@ public final class CredentialManager {
            cancelRemote =
                    mService.executeGetCredential(
                            request,
                            new GetCredentialTransport(activity, executor, callback),
                            new GetCredentialTransport(context, executor, callback),
                            mContext.getOpPackageName());
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
@@ -175,21 +176,22 @@ public final class CredentialManager {
     * request through the {@link #prepareGetCredential(
     * GetCredentialRequest, CancellationSignal, Executor, OutcomeReceiver)} API.
     *
     * @param context the context used to launch any UI needed; use an activity context to make sure
     *                the UI will be launched within the same task stack
     * @param pendingGetCredentialHandle the handle representing the pending operation to resume
     * @param activity the activity used to launch any UI needed
     * @param cancellationSignal an optional signal that allows for cancelling this call
     * @param executor the callback will take place on this {@link Executor}
     * @param callback the callback invoked when the request succeeds or fails
     */
    public void getCredential(
            @NonNull Context context,
            @NonNull PrepareGetCredentialResponse.PendingGetCredentialHandle
            pendingGetCredentialHandle,
            @NonNull Activity activity,
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull OutcomeReceiver<GetCredentialResponse, GetCredentialException> callback) {
        requireNonNull(pendingGetCredentialHandle, "pendingGetCredentialHandle must not be null");
        requireNonNull(activity, "activity must not be null");
        requireNonNull(context, "context must not be null");
        requireNonNull(executor, "executor must not be null");
        requireNonNull(callback, "callback must not be null");

@@ -198,7 +200,7 @@ public final class CredentialManager {
            return;
        }

        pendingGetCredentialHandle.show(activity, cancellationSignal, executor, callback);
        pendingGetCredentialHandle.show(context, cancellationSignal, executor, callback);
    }

    /**
@@ -207,9 +209,9 @@ public final class CredentialManager {
     *
     * <p>This API doesn't invoke any UI. It only performs the preparation work so that you can
     * later launch the remaining get-credential operation (involves UIs) through the {@link
     * #getCredential(PrepareGetCredentialResponse.PendingGetCredentialHandle, Activity,
     * #getCredential(PrepareGetCredentialResponse.PendingGetCredentialHandle, Context,
     * CancellationSignal, Executor, OutcomeReceiver)} API which incurs less latency compared to
     * the {@link #getCredential(GetCredentialRequest, Activity, CancellationSignal, Executor,
     * the {@link #getCredential(GetCredentialRequest, Context, CancellationSignal, Executor,
     * OutcomeReceiver)} API that executes the whole operation in one call.
     *
     * @param request            the request specifying type(s) of credentials to get from the user
@@ -262,21 +264,22 @@ public final class CredentialManager {
     * need additional permission {@link CREDENTIAL_MANAGER_SET_ORIGIN}
     * to use this functionality
     *
     * @param context the context used to launch any UI needed; use an activity context to make sure
     *                the UI will be launched within the same task stack
     * @param request the request specifying type(s) of credentials to get from the user
     * @param activity the activity used to launch any UI needed
     * @param cancellationSignal an optional signal that allows for cancelling this call
     * @param executor the callback will take place on this {@link Executor}
     * @param callback the callback invoked when the request succeeds or fails
     */
    public void createCredential(
            @NonNull Context context,
            @NonNull CreateCredentialRequest request,
            @NonNull Activity activity,
            @Nullable CancellationSignal cancellationSignal,
            @CallbackExecutor @NonNull Executor executor,
            @NonNull
                    OutcomeReceiver<CreateCredentialResponse, CreateCredentialException> callback) {
        requireNonNull(request, "request must not be null");
        requireNonNull(activity, "activity must not be null");
        requireNonNull(context, "context must not be null");
        requireNonNull(executor, "executor must not be null");
        requireNonNull(callback, "callback must not be null");

@@ -290,7 +293,7 @@ public final class CredentialManager {
            cancelRemote =
                    mService.executeCreateCredential(
                            request,
                            new CreateCredentialTransport(activity, executor, callback),
                            new CreateCredentialTransport(context, executor, callback),
                            mContext.getOpPackageName());
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
@@ -547,14 +550,24 @@ public final class CredentialManager {

        @Override
        public void onResponse(PrepareGetCredentialResponseInternal response) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(() -> mCallback.onResult(
                        new PrepareGetCredentialResponse(response, mGetCredentialTransport)));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onError(String errorType, String message) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(
                        () -> mCallback.onError(new GetCredentialException(errorType, message)));
            }  finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }

@@ -587,7 +600,12 @@ public final class CredentialManager {
        @Override
        public void onResponse(GetCredentialResponse response) {
            if (mCallback != null) {
                final long identity = Binder.clearCallingIdentity();
                try {
                    mCallback.onResponse(response);
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            } else {
                Log.d(TAG, "Unexpected onResponse call before the show invocation");
            }
@@ -596,7 +614,12 @@ public final class CredentialManager {
        @Override
        public void onError(String errorType, String message) {
            if (mCallback != null) {
                final long identity = Binder.clearCallingIdentity();
                try {
                    mCallback.onError(errorType, message);
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            } else {
                Log.d(TAG, "Unexpected onError call before the show invocation");
            }
@@ -606,15 +629,15 @@ public final class CredentialManager {
    private static class GetCredentialTransport extends IGetCredentialCallback.Stub {
        // TODO: listen for cancellation to release callback.

        private final Activity mActivity;
        private final Context mContext;
        private final Executor mExecutor;
        private final OutcomeReceiver<GetCredentialResponse, GetCredentialException> mCallback;

        private GetCredentialTransport(
                Activity activity,
                Context context,
                Executor executor,
                OutcomeReceiver<GetCredentialResponse, GetCredentialException> callback) {
            mActivity = activity;
            mContext = context;
            mExecutor = executor;
            mCallback = callback;
        }
@@ -622,42 +645,57 @@ public final class CredentialManager {
        @Override
        public void onPendingIntent(PendingIntent pendingIntent) {
            try {
                mActivity.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
                mContext.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                Log.e(
                        TAG,
                        "startIntentSender() failed for intent:" + pendingIntent.getIntentSender(),
                        e);
                final long identity = Binder.clearCallingIdentity();
                try {
                    mExecutor.execute(() -> mCallback.onError(
                            new GetCredentialException(GetCredentialException.TYPE_UNKNOWN)));
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            }
        }

        @Override
        public void onResponse(GetCredentialResponse response) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(() -> mCallback.onResult(response));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onError(String errorType, String message) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(
                        () -> mCallback.onError(new GetCredentialException(errorType, message)));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }

    private static class CreateCredentialTransport extends ICreateCredentialCallback.Stub {
        // TODO: listen for cancellation to release callback.

        private final Activity mActivity;
        private final Context mContext;
        private final Executor mExecutor;
        private final OutcomeReceiver<CreateCredentialResponse, CreateCredentialException>
                mCallback;

        private CreateCredentialTransport(
                Activity activity,
                Context context,
                Executor executor,
                OutcomeReceiver<CreateCredentialResponse, CreateCredentialException> callback) {
            mActivity = activity;
            mContext = context;
            mExecutor = executor;
            mCallback = callback;
        }
@@ -665,26 +703,41 @@ public final class CredentialManager {
        @Override
        public void onPendingIntent(PendingIntent pendingIntent) {
            try {
                mActivity.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
                mContext.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                Log.e(
                        TAG,
                        "startIntentSender() failed for intent:" + pendingIntent.getIntentSender(),
                        e);
                final long identity = Binder.clearCallingIdentity();
                try {
                    mExecutor.execute(() -> mCallback.onError(
                            new CreateCredentialException(CreateCredentialException.TYPE_UNKNOWN)));
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            }
        }

        @Override
        public void onResponse(CreateCredentialResponse response) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(() -> mCallback.onResult(response));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onError(String errorType, String message) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(
                        () -> mCallback.onError(new CreateCredentialException(errorType, message)));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }

@@ -702,13 +755,24 @@ public final class CredentialManager {

        @Override
        public void onSuccess() {
            final long identity = Binder.clearCallingIdentity();
            try {
                mCallback.onResult(null);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onError(String errorType, String message) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(
                    () -> mCallback.onError(new ClearCredentialStateException(errorType, message)));
                        () -> mCallback.onError(
                                new ClearCredentialStateException(errorType, message)));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }

@@ -725,18 +789,34 @@ public final class CredentialManager {
        }

        public void onResponse(Void result) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(() -> mCallback.onResult(result));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onResponse() {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(() -> mCallback.onResult(null));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }

        @Override
        public void onError(String errorType, String message) {
            final long identity = Binder.clearCallingIdentity();
            try {
                mExecutor.execute(
                    () -> mCallback.onError(new SetEnabledProvidersException(errorType, message)));
                        () -> mCallback.onError(
                                new SetEnabledProvidersException(errorType, message)));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
    }
}
+4 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.IntentSender;
import android.os.CancellationSignal;
import android.os.OutcomeReceiver;
@@ -67,7 +68,7 @@ public final class PrepareGetCredentialResponse {
        }

        /** @hide */
        void show(@NonNull Activity activity, @Nullable CancellationSignal cancellationSignal,
        void show(@NonNull Context context, @Nullable CancellationSignal cancellationSignal,
                @CallbackExecutor @NonNull Executor executor,
                @NonNull OutcomeReceiver<GetCredentialResponse, GetCredentialException> callback) {
            if (mPendingIntent == null) {
@@ -80,7 +81,7 @@ public final class PrepareGetCredentialResponse {
                @Override
                public void onPendingIntent(PendingIntent pendingIntent) {
                    try {
                        activity.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
                        context.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
                    } catch (IntentSender.SendIntentException e) {
                        Log.e(TAG, "startIntentSender() failed for intent for show()", e);
                        executor.execute(() -> callback.onError(
@@ -101,7 +102,7 @@ public final class PrepareGetCredentialResponse {
            });

            try {
                activity.startIntentSender(mPendingIntent.getIntentSender(), null, 0, 0, 0);
                context.startIntentSender(mPendingIntent.getIntentSender(), null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                Log.e(TAG, "startIntentSender() failed for intent for show()", e);
                executor.execute(() -> callback.onError(
+16 −16

File changed.

Preview size limit exceeded, changes collapsed.