Launch the CredentialManager UI from the app context.

This is a temporary version that does not impact public apis. A
follow-up change will be sent out that adds the api changes and properly
launches the UI using an app activity, not just the context.

Test: deployed locally.
Bug: 246564035
Bug: 253156924
Bug: 253156958
Change-Id: I3f43fb7332d58f2baffab7a80c4550d95c67854e
This commit is contained in:
Helen Qin
2022-11-17 07:51:47 +00:00
parent f420a0d9ef
commit 3f3724a53b
4 changed files with 41 additions and 7 deletions

View File

@@ -22,7 +22,9 @@ import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.IntentSender;
import android.os.CancellationSignal;
import android.os.ICancellationSignal;
import android.os.OutcomeReceiver;
@@ -84,8 +86,11 @@ public final class CredentialManager {
ICancellationSignal cancelRemote = null;
try {
cancelRemote = mService.executeGetCredential(request,
new GetCredentialTransport(executor, callback), mContext.getOpPackageName());
cancelRemote = mService.executeGetCredential(
request,
// TODO: use a real activity instead of context.
new GetCredentialTransport(mContext, executor, callback),
mContext.getOpPackageName());
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
@@ -124,7 +129,8 @@ public final class CredentialManager {
ICancellationSignal cancelRemote = null;
try {
cancelRemote = mService.executeCreateCredential(request,
new CreateCredentialTransport(executor, callback),
// TODO: use a real activity instead of context.
new CreateCredentialTransport(mContext, executor, callback),
mContext.getOpPackageName());
} catch (RemoteException e) {
e.rethrowFromSystemServer();
@@ -176,16 +182,29 @@ public final class CredentialManager {
private static class GetCredentialTransport extends IGetCredentialCallback.Stub {
// TODO: listen for cancellation to release callback.
private final Context mActivityContext;
private final Executor mExecutor;
private final OutcomeReceiver<
GetCredentialResponse, CredentialManagerException> mCallback;
private GetCredentialTransport(Executor executor,
private GetCredentialTransport(Context activityContext, Executor executor,
OutcomeReceiver<GetCredentialResponse, CredentialManagerException> callback) {
mActivityContext = activityContext;
mExecutor = executor;
mCallback = callback;
}
@Override
public void onPendingIntent(PendingIntent pendingIntent) {
try {
mActivityContext.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "startIntentSender() failed for intent:"
+ pendingIntent.getIntentSender(), e);
// TODO: propagate the error.
}
}
@Override
public void onResponse(GetCredentialResponse response) {
mExecutor.execute(() -> mCallback.onResult(response));
@@ -201,16 +220,29 @@ public final class CredentialManager {
private static class CreateCredentialTransport extends ICreateCredentialCallback.Stub {
// TODO: listen for cancellation to release callback.
private final Context mActivityContext;
private final Executor mExecutor;
private final OutcomeReceiver<
CreateCredentialResponse, CredentialManagerException> mCallback;
private CreateCredentialTransport(Executor executor,
private CreateCredentialTransport(Context activityContext, Executor executor,
OutcomeReceiver<CreateCredentialResponse, CredentialManagerException> callback) {
mActivityContext = activityContext;
mExecutor = executor;
mCallback = callback;
}
@Override
public void onPendingIntent(PendingIntent pendingIntent) {
try {
mActivityContext.startIntentSender(pendingIntent.getIntentSender(), null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "startIntentSender() failed for intent:"
+ pendingIntent.getIntentSender(), e);
// TODO: propagate the error.
}
}
@Override
public void onResponse(CreateCredentialResponse response) {
mExecutor.execute(() -> mCallback.onResult(response));

View File

@@ -16,6 +16,7 @@
package android.credentials;
import android.app.PendingIntent;
import android.credentials.CreateCredentialResponse;
/**
@@ -24,6 +25,7 @@ import android.credentials.CreateCredentialResponse;
* @hide
*/
interface ICreateCredentialCallback {
oneway void onPendingIntent(in PendingIntent pendingIntent);
oneway void onResponse(in CreateCredentialResponse response);
oneway void onError(int errorCode, String message);
}

View File

@@ -16,6 +16,7 @@
package android.credentials;
import android.app.PendingIntent;
import android.credentials.GetCredentialResponse;
/**
@@ -24,6 +25,7 @@ import android.credentials.GetCredentialResponse;
* @hide
*/
interface IGetCredentialCallback {
oneway void onPendingIntent(in PendingIntent pendingIntent);
oneway void onResponse(in GetCredentialResponse response);
oneway void onError(int errorCode, String message);
}

View File

@@ -36,8 +36,6 @@
android:name=".CredentialSelectorActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:noHistory="true"
android:excludeFromRecents="true"
android:theme="@style/Theme.CredentialSelector">
</activity>