Loading services/credentials/java/com/android/server/credentials/ClearRequestSession.java +4 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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); } /** Loading services/credentials/java/com/android/server/credentials/CreateRequestSession.java +3 −1 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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); } /** Loading services/credentials/java/com/android/server/credentials/CredentialManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -458,6 +458,7 @@ public final class CredentialManagerService callback, request, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); Loading Loading @@ -512,6 +513,7 @@ public final class CredentialManagerService getCredentialCallback, request, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan, prepareGetCredentialCallback); Loading Loading @@ -629,6 +631,7 @@ public final class CredentialManagerService request, callback, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); Loading Loading @@ -846,6 +849,7 @@ public final class CredentialManagerService callback, request, constructCallingAppInfo(callingPackage, userId, null), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); Loading services/credentials/java/com/android/server/credentials/CredentialManagerUi.java +30 −33 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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; } Loading @@ -139,6 +145,7 @@ 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 providerDataList the list of provider data from remote providers */ Loading @@ -146,30 +153,20 @@ public class CredentialManagerUi { 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()); for (String provider: allProviders) { if (!enabledProviders.contains(provider)) { disabledProviderDataList.add(new DisabledProviderData(provider)); } } mEnabledProviders); 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 Loading services/credentials/java/com/android/server/credentials/GetRequestSession.java +9 −4 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -45,13 +46,16 @@ 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 Loading @@ -61,6 +65,7 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest, /** * 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. */ Loading Loading
services/credentials/java/com/android/server/credentials/ClearRequestSession.java +4 −2 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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); } /** Loading
services/credentials/java/com/android/server/credentials/CreateRequestSession.java +3 −1 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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); } /** Loading
services/credentials/java/com/android/server/credentials/CredentialManagerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -458,6 +458,7 @@ public final class CredentialManagerService callback, request, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); Loading Loading @@ -512,6 +513,7 @@ public final class CredentialManagerService getCredentialCallback, request, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan, prepareGetCredentialCallback); Loading Loading @@ -629,6 +631,7 @@ public final class CredentialManagerService request, callback, constructCallingAppInfo(callingPackage, userId, request.getOrigin()), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); Loading Loading @@ -846,6 +849,7 @@ public final class CredentialManagerService callback, request, constructCallingAppInfo(callingPackage, userId, null), getEnabledProviders(), CancellationSignal.fromTransport(cancelTransport), timestampBegan); addSessionLocked(userId, session); Loading
services/credentials/java/com/android/server/credentials/CredentialManagerUi.java +30 −33 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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; } Loading @@ -139,6 +145,7 @@ 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 providerDataList the list of provider data from remote providers */ Loading @@ -146,30 +153,20 @@ public class CredentialManagerUi { 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()); for (String provider: allProviders) { if (!enabledProviders.contains(provider)) { disabledProviderDataList.add(new DisabledProviderData(provider)); } } mEnabledProviders); 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 Loading
services/credentials/java/com/android/server/credentials/GetRequestSession.java +9 −4 Original line number Diff line number Diff line Loading @@ -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; /** Loading @@ -45,13 +46,16 @@ 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 Loading @@ -61,6 +65,7 @@ public class GetRequestSession extends RequestSession<GetCredentialRequest, /** * 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. */ Loading