Require an app activity for launching UIs.

Apis (get/create credentials) that involves UIs now requires an app
activity as an input paramter that's used to launch UIs throughout the
flows. This way the UIs will be launched within the app activity task
stack.

Bug: 246564035
Bug: 253156924
Bug: 253156958
CTS-Coverage-Bug: 246637346
Test: Local Build & Deployment
Change-Id: Ia099c387adce516ebc52deb9ae00a6b046e9d296
This commit is contained in:
Helen Qin
2022-11-23 05:48:02 +00:00
parent 1db4fabbeb
commit d4984fab25
2 changed files with 19 additions and 14 deletions

View File

@@ -13018,8 +13018,8 @@ 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.CredentialManagerException>);
method public void executeCreateCredential(@NonNull android.credentials.CreateCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CredentialManagerException>);
method public void executeGetCredential(@NonNull android.credentials.GetCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.CredentialManagerException>);
method public void executeCreateCredential(@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.CredentialManagerException>);
method public void executeGetCredential(@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.CredentialManagerException>);
}
public class CredentialManagerException extends java.lang.Exception {

View File

@@ -22,6 +22,7 @@ import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemService;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.IntentSender;
@@ -65,17 +66,20 @@ public final class CredentialManager {
* credential, display a picker when multiple credentials exist, etc.
*
* @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 executeGetCredential(
@NonNull GetCredentialRequest request,
@NonNull Activity activity,
@Nullable CancellationSignal cancellationSignal,
@CallbackExecutor @NonNull Executor executor,
@NonNull OutcomeReceiver<
GetCredentialResponse, CredentialManagerException> callback) {
requireNonNull(request, "request must not be null");
requireNonNull(activity, "activity must not be null");
requireNonNull(executor, "executor must not be null");
requireNonNull(callback, "callback must not be null");
@@ -88,8 +92,7 @@ public final class CredentialManager {
try {
cancelRemote = mService.executeGetCredential(
request,
// TODO: use a real activity instead of context.
new GetCredentialTransport(mContext, executor, callback),
new GetCredentialTransport(activity, executor, callback),
mContext.getOpPackageName());
} catch (RemoteException e) {
e.rethrowFromSystemServer();
@@ -107,17 +110,20 @@ public final class CredentialManager {
* or storing the new credential, etc.
*
* @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 executeCreateCredential(
@NonNull CreateCredentialRequest request,
@NonNull Activity activity,
@Nullable CancellationSignal cancellationSignal,
@CallbackExecutor @NonNull Executor executor,
@NonNull OutcomeReceiver<
CreateCredentialResponse, CredentialManagerException> callback) {
requireNonNull(request, "request must not be null");
requireNonNull(activity, "activity must not be null");
requireNonNull(executor, "executor must not be null");
requireNonNull(callback, "callback must not be null");
@@ -129,8 +135,7 @@ public final class CredentialManager {
ICancellationSignal cancelRemote = null;
try {
cancelRemote = mService.executeCreateCredential(request,
// TODO: use a real activity instead of context.
new CreateCredentialTransport(mContext, executor, callback),
new CreateCredentialTransport(activity, executor, callback),
mContext.getOpPackageName());
} catch (RemoteException e) {
e.rethrowFromSystemServer();
@@ -188,14 +193,14 @@ public final class CredentialManager {
private static class GetCredentialTransport extends IGetCredentialCallback.Stub {
// TODO: listen for cancellation to release callback.
private final Context mActivityContext;
private final Activity mActivity;
private final Executor mExecutor;
private final OutcomeReceiver<
GetCredentialResponse, CredentialManagerException> mCallback;
private GetCredentialTransport(Context activityContext, Executor executor,
private GetCredentialTransport(Activity activity, Executor executor,
OutcomeReceiver<GetCredentialResponse, CredentialManagerException> callback) {
mActivityContext = activityContext;
mActivity = activity;
mExecutor = executor;
mCallback = callback;
}
@@ -203,7 +208,7 @@ public final class CredentialManager {
@Override
public void onPendingIntent(PendingIntent pendingIntent) {
try {
mActivityContext.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
mActivity.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "startIntentSender() failed for intent:"
+ pendingIntent.getIntentSender(), e);
@@ -226,14 +231,14 @@ public final class CredentialManager {
private static class CreateCredentialTransport extends ICreateCredentialCallback.Stub {
// TODO: listen for cancellation to release callback.
private final Context mActivityContext;
private final Activity mActivity;
private final Executor mExecutor;
private final OutcomeReceiver<
CreateCredentialResponse, CredentialManagerException> mCallback;
private CreateCredentialTransport(Context activityContext, Executor executor,
private CreateCredentialTransport(Activity activity, Executor executor,
OutcomeReceiver<CreateCredentialResponse, CredentialManagerException> callback) {
mActivityContext = activityContext;
mActivity = activity;
mExecutor = executor;
mCallback = callback;
}
@@ -241,7 +246,7 @@ public final class CredentialManager {
@Override
public void onPendingIntent(PendingIntent pendingIntent) {
try {
mActivityContext.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
mActivity.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "startIntentSender() failed for intent:"
+ pendingIntent.getIntentSender(), e);