Loading core/api/current.txt +3 −3 Original line number Diff line number Diff line Loading @@ -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); core/java/android/credentials/CredentialManager.java +127 −47 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"); Loading @@ -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(); Loading @@ -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"); Loading @@ -198,7 +200,7 @@ public final class CredentialManager { return; } pendingGetCredentialHandle.show(activity, cancellationSignal, executor, callback); pendingGetCredentialHandle.show(context, cancellationSignal, executor, callback); } /** Loading @@ -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 Loading Loading @@ -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"); Loading @@ -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(); Loading Loading @@ -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); } } } Loading Loading @@ -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"); } Loading @@ -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"); } Loading @@ -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; } Loading @@ -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; } Loading @@ -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); } } } Loading @@ -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); } } } Loading @@ -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); } } } } core/java/android/credentials/PrepareGetCredentialResponse.java +4 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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( Loading @@ -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( Loading core/tests/coretests/src/android/credentials/CredentialManagerTest.java +16 −16 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/api/current.txt +3 −3 Original line number Diff line number Diff line Loading @@ -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);
core/java/android/credentials/CredentialManager.java +127 −47 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"); Loading @@ -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(); Loading @@ -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"); Loading @@ -198,7 +200,7 @@ public final class CredentialManager { return; } pendingGetCredentialHandle.show(activity, cancellationSignal, executor, callback); pendingGetCredentialHandle.show(context, cancellationSignal, executor, callback); } /** Loading @@ -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 Loading Loading @@ -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"); Loading @@ -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(); Loading Loading @@ -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); } } } Loading Loading @@ -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"); } Loading @@ -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"); } Loading @@ -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; } Loading @@ -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; } Loading @@ -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); } } } Loading @@ -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); } } } Loading @@ -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); } } } }
core/java/android/credentials/PrepareGetCredentialResponse.java +4 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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( Loading @@ -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( Loading
core/tests/coretests/src/android/credentials/CredentialManagerTest.java +16 −16 File changed.Preview size limit exceeded, changes collapsed. Show changes