Merge "Fix bug in disabled providers in create flow" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c293fb1146
@@ -30,6 +30,7 @@ import android.service.credentials.CallingAppInfo;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Central session for a single clearCredentialState request. This class listens to the
|
||||
@@ -43,11 +44,12 @@ public final class ClearRequestSession extends RequestSession<ClearCredentialSta
|
||||
public ClearRequestSession(Context context, RequestSession.SessionLifetime sessionCallback,
|
||||
Object lock, int userId, int callingUid,
|
||||
IClearCredentialStateCallback callback, ClearCredentialStateRequest request,
|
||||
CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal,
|
||||
CallingAppInfo callingAppInfo, Set<ComponentName> enabledProviders,
|
||||
CancellationSignal cancellationSignal,
|
||||
long startedTimestamp) {
|
||||
super(context, sessionCallback, lock, userId, callingUid, request, callback,
|
||||
RequestInfo.TYPE_UNDEFINED,
|
||||
callingAppInfo, cancellationSignal, startedTimestamp);
|
||||
callingAppInfo, enabledProviders, cancellationSignal, startedTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,7 @@ import android.util.Log;
|
||||
import com.android.server.credentials.metrics.ProviderStatusForMetrics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Central session for a single {@link CredentialManager#createCredential} request.
|
||||
@@ -54,11 +55,12 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
|
||||
CreateCredentialRequest request,
|
||||
ICreateCredentialCallback callback,
|
||||
CallingAppInfo callingAppInfo,
|
||||
Set<ComponentName> enabledProviders,
|
||||
CancellationSignal cancellationSignal,
|
||||
long startedTimestamp) {
|
||||
super(context, sessionCallback, lock, userId, callingUid, request, callback,
|
||||
RequestInfo.TYPE_CREATE,
|
||||
callingAppInfo, cancellationSignal, startedTimestamp);
|
||||
callingAppInfo, enabledProviders, cancellationSignal, startedTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -458,6 +458,7 @@ public final class CredentialManagerService
|
||||
callback,
|
||||
request,
|
||||
constructCallingAppInfo(callingPackage, userId, request.getOrigin()),
|
||||
getEnabledProviders(),
|
||||
CancellationSignal.fromTransport(cancelTransport),
|
||||
timestampBegan);
|
||||
addSessionLocked(userId, session);
|
||||
@@ -512,6 +513,7 @@ public final class CredentialManagerService
|
||||
getCredentialCallback,
|
||||
request,
|
||||
constructCallingAppInfo(callingPackage, userId, request.getOrigin()),
|
||||
getEnabledProviders(),
|
||||
CancellationSignal.fromTransport(cancelTransport),
|
||||
timestampBegan,
|
||||
prepareGetCredentialCallback);
|
||||
@@ -629,6 +631,7 @@ public final class CredentialManagerService
|
||||
request,
|
||||
callback,
|
||||
constructCallingAppInfo(callingPackage, userId, request.getOrigin()),
|
||||
getEnabledProviders(),
|
||||
CancellationSignal.fromTransport(cancelTransport),
|
||||
timestampBegan);
|
||||
addSessionLocked(userId, session);
|
||||
@@ -846,6 +849,7 @@ public final class CredentialManagerService
|
||||
callback,
|
||||
request,
|
||||
constructCallingAppInfo(callingPackage, userId, null),
|
||||
getEnabledProviders(),
|
||||
CancellationSignal.fromTransport(cancelTransport),
|
||||
timestampBegan);
|
||||
addSessionLocked(userId, session);
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.credentials.CredentialManager;
|
||||
import android.credentials.CredentialProviderInfo;
|
||||
import android.credentials.ui.DisabledProviderData;
|
||||
@@ -38,34 +37,32 @@ import android.util.Log;
|
||||
import android.util.Slog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** Initiates the Credential Manager UI and receives results. */
|
||||
public class CredentialManagerUi {
|
||||
private static final String TAG = "CredentialManagerUi";
|
||||
@NonNull
|
||||
private final CredentialManagerUiCallback mCallbacks;
|
||||
@NonNull private final Context mContext;
|
||||
@NonNull
|
||||
private final Context mContext;
|
||||
// TODO : Use for starting the activity for this user
|
||||
private final int mUserId;
|
||||
|
||||
private UiStatus mStatus;
|
||||
|
||||
/** Creates intent that is ot be invoked to cancel an in-progress UI session. */
|
||||
public Intent createCancelIntent(IBinder requestId, String packageName) {
|
||||
return IntentFactory.createCancelUiIntent(requestId, /*shouldShowCancellationUi=*/ true,
|
||||
packageName);
|
||||
}
|
||||
private final Set<ComponentName> mEnabledProviders;
|
||||
|
||||
enum UiStatus {
|
||||
IN_PROGRESS,
|
||||
USER_INTERACTION,
|
||||
NOT_STARTED, TERMINATED
|
||||
}
|
||||
@NonNull private final ResultReceiver mResultReceiver = new ResultReceiver(
|
||||
|
||||
@NonNull
|
||||
private final ResultReceiver mResultReceiver = new ResultReceiver(
|
||||
new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
protected void onReceiveResult(int resultCode, Bundle resultData) {
|
||||
@@ -105,24 +102,33 @@ public class CredentialManagerUi {
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates intent that is ot be invoked to cancel an in-progress UI session. */
|
||||
public Intent createCancelIntent(IBinder requestId, String packageName) {
|
||||
return IntentFactory.createCancelUiIntent(requestId, /*shouldShowCancellationUi=*/ true,
|
||||
packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to be implemented by any class that wishes to get callbacks from the UI.
|
||||
*/
|
||||
public interface CredentialManagerUiCallback {
|
||||
/** Called when the user makes a selection. */
|
||||
void onUiSelection(UserSelectionDialogResult selection);
|
||||
|
||||
/** Called when the UI is canceled without a successful provider result. */
|
||||
void onUiCancellation(boolean isUserCancellation);
|
||||
|
||||
/** Called when the selector UI fails to come up (mostly due to parsing issue today). */
|
||||
void onUiSelectorInvocationFailure();
|
||||
}
|
||||
|
||||
public CredentialManagerUi(Context context, int userId,
|
||||
CredentialManagerUiCallback callbacks) {
|
||||
CredentialManagerUiCallback callbacks, Set<ComponentName> enabledProviders) {
|
||||
Log.i(TAG, "In CredentialManagerUi constructor");
|
||||
mContext = context;
|
||||
mUserId = userId;
|
||||
mCallbacks = callbacks;
|
||||
mEnabledProviders = enabledProviders;
|
||||
mStatus = UiStatus.IN_PROGRESS;
|
||||
}
|
||||
|
||||
@@ -139,37 +145,28 @@ public class CredentialManagerUi {
|
||||
/**
|
||||
* Creates a {@link PendingIntent} to be used to invoke the credential manager selector UI,
|
||||
* by the calling app process.
|
||||
* @param requestInfo the information about the request
|
||||
*
|
||||
* @param requestInfo the information about the request
|
||||
* @param providerDataList the list of provider data from remote providers
|
||||
*/
|
||||
public PendingIntent createPendingIntent(
|
||||
RequestInfo requestInfo, ArrayList<ProviderData> providerDataList) {
|
||||
Log.i(TAG, "In createPendingIntent");
|
||||
|
||||
ArrayList<DisabledProviderData> disabledProviderDataList = new ArrayList<>();
|
||||
Set<String> enabledProviders = providerDataList.stream()
|
||||
.map(ProviderData::getProviderFlattenedComponentName)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
Set<String> allProviders =
|
||||
List<CredentialProviderInfo> allProviders =
|
||||
CredentialProviderInfoFactory.getCredentialProviderServices(
|
||||
mContext,
|
||||
mUserId,
|
||||
CredentialManager.PROVIDER_FILTER_USER_PROVIDERS_ONLY,
|
||||
new HashSet<>())
|
||||
.stream()
|
||||
.map(CredentialProviderInfo::getServiceInfo)
|
||||
.map(ServiceInfo::getComponentName)
|
||||
.map(ComponentName::flattenToString)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
mContext,
|
||||
mUserId,
|
||||
CredentialManager.PROVIDER_FILTER_USER_PROVIDERS_ONLY,
|
||||
mEnabledProviders);
|
||||
|
||||
for (String provider: allProviders) {
|
||||
if (!enabledProviders.contains(provider)) {
|
||||
disabledProviderDataList.add(new DisabledProviderData(provider));
|
||||
}
|
||||
}
|
||||
List<DisabledProviderData> disabledProviderDataList = allProviders.stream()
|
||||
.filter(provider -> !provider.isEnabled())
|
||||
.map(disabledProvider -> new DisabledProviderData(
|
||||
disabledProvider.getComponentName().flattenToString())).toList();
|
||||
|
||||
Intent intent = IntentFactory.createCredentialSelectorIntent(requestInfo, providerDataList,
|
||||
disabledProviderDataList, mResultReceiver)
|
||||
new ArrayList<>(disabledProviderDataList), mResultReceiver)
|
||||
.setAction(UUID.randomUUID().toString());
|
||||
//TODO: Create unique pending intent using request code and cancel any pre-existing pending
|
||||
// intents
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.util.Log;
|
||||
import com.android.server.credentials.metrics.ProviderStatusForMetrics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -45,22 +46,26 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,
|
||||
IGetCredentialCallback, GetCredentialResponse>
|
||||
implements ProviderSession.ProviderInternalCallback<GetCredentialResponse> {
|
||||
private static final String TAG = "GetRequestSession";
|
||||
|
||||
public GetRequestSession(Context context, RequestSession.SessionLifetime sessionCallback,
|
||||
Object lock, int userId, int callingUid,
|
||||
IGetCredentialCallback callback, GetCredentialRequest request,
|
||||
CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal,
|
||||
CallingAppInfo callingAppInfo, Set<ComponentName> enabledProviders,
|
||||
CancellationSignal cancellationSignal,
|
||||
long startedTimestamp) {
|
||||
super(context, sessionCallback, lock, userId, callingUid, request, callback,
|
||||
RequestInfo.TYPE_GET, callingAppInfo, cancellationSignal, startedTimestamp);
|
||||
RequestInfo.TYPE_GET, callingAppInfo, enabledProviders, cancellationSignal,
|
||||
startedTimestamp);
|
||||
int numTypes = (request.getCredentialOptions().stream()
|
||||
.map(CredentialOption::getType).collect(
|
||||
Collectors.toSet())).size(); // Dedupe type strings
|
||||
Collectors.toSet())).size(); // Dedupe type strings
|
||||
mRequestSessionMetric.collectGetFlowInitialMetricInfo(numTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new provider session, and adds it list of providers that are contributing to
|
||||
* this session.
|
||||
*
|
||||
* @return the provider session created within this request session, for the given provider
|
||||
* info.
|
||||
*/
|
||||
@@ -149,7 +154,7 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest,
|
||||
@Override
|
||||
public void onUiSelectorInvocationFailure() {
|
||||
respondToClientWithErrorAndFinish(GetCredentialException.TYPE_NO_CREDENTIAL,
|
||||
"No credentials available.");
|
||||
"No credentials available.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,10 +52,11 @@ public class PrepareGetRequestSession extends GetRequestSession {
|
||||
public PrepareGetRequestSession(Context context,
|
||||
RequestSession.SessionLifetime sessionCallback, Object lock, int userId,
|
||||
int callingUid, IGetCredentialCallback getCredCallback, GetCredentialRequest request,
|
||||
CallingAppInfo callingAppInfo, CancellationSignal cancellationSignal,
|
||||
long startedTimestamp, IPrepareGetCredentialCallback prepareGetCredentialCallback) {
|
||||
CallingAppInfo callingAppInfo, Set<ComponentName> enabledProviders,
|
||||
CancellationSignal cancellationSignal, long startedTimestamp,
|
||||
IPrepareGetCredentialCallback prepareGetCredentialCallback) {
|
||||
super(context, sessionCallback, lock, userId, callingUid, getCredCallback, request,
|
||||
callingAppInfo, cancellationSignal, startedTimestamp);
|
||||
callingAppInfo, enabledProviders, cancellationSignal, startedTimestamp);
|
||||
int numTypes = (request.getCredentialOptions().stream()
|
||||
.map(CredentialOption::getType).collect(
|
||||
Collectors.toSet())).size(); // Dedupe type strings
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.android.server.credentials.metrics.RequestSessionMetric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -88,6 +89,8 @@ abstract class RequestSession<T, U, V> implements CredentialManagerUi.Credential
|
||||
|
||||
protected final SessionLifetime mSessionCallback;
|
||||
|
||||
private final Set<ComponentName> mEnabledProviders;
|
||||
|
||||
@NonNull
|
||||
protected RequestSessionStatus mRequestSessionStatus =
|
||||
RequestSessionStatus.IN_PROGRESS;
|
||||
@@ -108,6 +111,7 @@ abstract class RequestSession<T, U, V> implements CredentialManagerUi.Credential
|
||||
@NonNull T clientRequest, U clientCallback,
|
||||
@NonNull String requestType,
|
||||
CallingAppInfo callingAppInfo,
|
||||
Set<ComponentName> enabledProviders,
|
||||
CancellationSignal cancellationSignal, long timestampStarted) {
|
||||
mContext = context;
|
||||
mLock = lock;
|
||||
@@ -118,11 +122,12 @@ abstract class RequestSession<T, U, V> implements CredentialManagerUi.Credential
|
||||
mClientCallback = clientCallback;
|
||||
mRequestType = requestType;
|
||||
mClientAppInfo = callingAppInfo;
|
||||
mEnabledProviders = enabledProviders;
|
||||
mCancellationSignal = cancellationSignal;
|
||||
mHandler = new Handler(Looper.getMainLooper(), null, true);
|
||||
mRequestId = new Binder();
|
||||
mCredentialManagerUi = new CredentialManagerUi(mContext,
|
||||
mUserId, this);
|
||||
mUserId, this, mEnabledProviders);
|
||||
mHybridService = context.getResources().getString(
|
||||
R.string.config_defaultCredentialManagerHybridService);
|
||||
mRequestSessionMetric.collectInitialPhaseMetricInfo(timestampStarted, mRequestId,
|
||||
@@ -306,7 +311,7 @@ abstract class RequestSession<T, U, V> implements CredentialManagerUi.Credential
|
||||
* Allows subclasses to directly finalize the call and set closing metrics on error completion.
|
||||
*
|
||||
* @param errorType the type of error given back in the flow
|
||||
* @param errorMsg the error message given back in the flow
|
||||
* @param errorMsg the error message given back in the flow
|
||||
*/
|
||||
protected void respondToClientWithErrorAndFinish(String errorType, String errorMsg) {
|
||||
mRequestSessionMetric.collectFinalPhaseProviderMetricStatus(
|
||||
|
||||
Reference in New Issue
Block a user