Merge "Change includes: Use CallingAppInfo instead of callingPackage in get/create requests Change exceptions for providers Test: make"
This commit is contained in:
@@ -39530,9 +39530,9 @@ package android.service.credentials {
|
||||
}
|
||||
|
||||
public final class BeginCreateCredentialRequest implements android.os.Parcelable {
|
||||
ctor public BeginCreateCredentialRequest(@NonNull String, @NonNull String, @NonNull android.os.Bundle);
|
||||
ctor public BeginCreateCredentialRequest(@NonNull android.service.credentials.CallingAppInfo, @NonNull String, @NonNull android.os.Bundle);
|
||||
method public int describeContents();
|
||||
method @NonNull public String getCallingPackage();
|
||||
method @NonNull public android.service.credentials.CallingAppInfo getCallingAppInfo();
|
||||
method @NonNull public android.os.Bundle getData();
|
||||
method @NonNull public String getType();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
@@ -39564,29 +39564,29 @@ package android.service.credentials {
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialOption> CREATOR;
|
||||
}
|
||||
|
||||
public final class BeginGetCredentialsRequest implements android.os.Parcelable {
|
||||
public final class BeginGetCredentialRequest implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public java.util.List<android.service.credentials.BeginGetCredentialOption> getBeginGetCredentialOptions();
|
||||
method @NonNull public String getCallingPackage();
|
||||
method @NonNull public android.service.credentials.CallingAppInfo getCallingAppInfo();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialsRequest> CREATOR;
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialRequest> CREATOR;
|
||||
}
|
||||
|
||||
public static final class BeginGetCredentialsRequest.Builder {
|
||||
ctor public BeginGetCredentialsRequest.Builder(@NonNull String);
|
||||
method @NonNull public android.service.credentials.BeginGetCredentialsRequest.Builder addBeginGetCredentialOption(@NonNull android.service.credentials.BeginGetCredentialOption);
|
||||
method @NonNull public android.service.credentials.BeginGetCredentialsRequest build();
|
||||
method @NonNull public android.service.credentials.BeginGetCredentialsRequest.Builder setBeginGetCredentialOptions(@NonNull java.util.List<android.service.credentials.BeginGetCredentialOption>);
|
||||
public static final class BeginGetCredentialRequest.Builder {
|
||||
ctor public BeginGetCredentialRequest.Builder(@NonNull android.service.credentials.CallingAppInfo);
|
||||
method @NonNull public android.service.credentials.BeginGetCredentialRequest.Builder addBeginGetCredentialOption(@NonNull android.service.credentials.BeginGetCredentialOption);
|
||||
method @NonNull public android.service.credentials.BeginGetCredentialRequest build();
|
||||
method @NonNull public android.service.credentials.BeginGetCredentialRequest.Builder setBeginGetCredentialOptions(@NonNull java.util.List<android.service.credentials.BeginGetCredentialOption>);
|
||||
}
|
||||
|
||||
public final class BeginGetCredentialsResponse implements android.os.Parcelable {
|
||||
method @NonNull public static android.service.credentials.BeginGetCredentialsResponse createWithAuthentication(@NonNull android.service.credentials.Action);
|
||||
method @NonNull public static android.service.credentials.BeginGetCredentialsResponse createWithResponseContent(@NonNull android.service.credentials.CredentialsResponseContent);
|
||||
public final class BeginGetCredentialResponse implements android.os.Parcelable {
|
||||
method @NonNull public static android.service.credentials.BeginGetCredentialResponse createWithAuthentication(@NonNull android.service.credentials.Action);
|
||||
method @NonNull public static android.service.credentials.BeginGetCredentialResponse createWithResponseContent(@NonNull android.service.credentials.CredentialsResponseContent);
|
||||
method public int describeContents();
|
||||
method @Nullable public android.service.credentials.Action getAuthenticationAction();
|
||||
method @Nullable public android.service.credentials.CredentialsResponseContent getCredentialsResponseContent();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialsResponse> CREATOR;
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.BeginGetCredentialResponse> CREATOR;
|
||||
}
|
||||
|
||||
public final class CallingAppInfo implements android.os.Parcelable {
|
||||
@@ -39599,9 +39599,9 @@ package android.service.credentials {
|
||||
}
|
||||
|
||||
public final class CreateCredentialRequest implements android.os.Parcelable {
|
||||
ctor public CreateCredentialRequest(@NonNull String, @NonNull String, @NonNull android.os.Bundle);
|
||||
ctor public CreateCredentialRequest(@NonNull android.service.credentials.CallingAppInfo, @NonNull String, @NonNull android.os.Bundle);
|
||||
method public int describeContents();
|
||||
method @NonNull public String getCallingPackage();
|
||||
method @NonNull public android.service.credentials.CallingAppInfo getCallingAppInfo();
|
||||
method @NonNull public android.os.Bundle getData();
|
||||
method @NonNull public String getType();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
@@ -39633,19 +39633,10 @@ package android.service.credentials {
|
||||
method @NonNull public android.service.credentials.CredentialEntry.Builder setAutoSelectAllowed(@NonNull boolean);
|
||||
}
|
||||
|
||||
public class CredentialProviderException extends java.lang.Exception {
|
||||
ctor public CredentialProviderException(int, @NonNull String, @NonNull Throwable);
|
||||
ctor public CredentialProviderException(int, @NonNull String);
|
||||
ctor public CredentialProviderException(int, @NonNull Throwable);
|
||||
ctor public CredentialProviderException(int);
|
||||
method public int getErrorCode();
|
||||
field public static final int ERROR_UNKNOWN = 0; // 0x0
|
||||
}
|
||||
|
||||
public abstract class CredentialProviderService extends android.app.Service {
|
||||
ctor public CredentialProviderService();
|
||||
method public abstract void onBeginCreateCredential(@NonNull android.service.credentials.BeginCreateCredentialRequest, @NonNull android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.service.credentials.BeginCreateCredentialResponse,android.service.credentials.CredentialProviderException>);
|
||||
method public abstract void onBeginGetCredentials(@NonNull android.service.credentials.BeginGetCredentialsRequest, @NonNull android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.service.credentials.BeginGetCredentialsResponse,android.service.credentials.CredentialProviderException>);
|
||||
method public abstract void onBeginCreateCredential(@NonNull android.service.credentials.BeginCreateCredentialRequest, @NonNull android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.service.credentials.BeginCreateCredentialResponse,android.credentials.CreateCredentialException>);
|
||||
method public abstract void onBeginGetCredential(@NonNull android.service.credentials.BeginGetCredentialRequest, @NonNull android.os.CancellationSignal, @NonNull android.os.OutcomeReceiver<android.service.credentials.BeginGetCredentialResponse,android.credentials.GetCredentialException>);
|
||||
method @NonNull public final android.os.IBinder onBind(@NonNull android.content.Intent);
|
||||
field public static final String CAPABILITY_META_DATA_KEY = "android.credentials.capabilities";
|
||||
field public static final String EXTRA_CREATE_CREDENTIAL_EXCEPTION = "android.service.credentials.extra.CREATE_CREDENTIAL_EXCEPTION";
|
||||
@@ -39679,14 +39670,14 @@ package android.service.credentials {
|
||||
|
||||
public final class GetCredentialRequest implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method @NonNull public String getCallingPackage();
|
||||
method @NonNull public android.service.credentials.CallingAppInfo getCallingAppInfo();
|
||||
method @NonNull public java.util.List<android.credentials.GetCredentialOption> getGetCredentialOptions();
|
||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.GetCredentialRequest> CREATOR;
|
||||
}
|
||||
|
||||
public static final class GetCredentialRequest.Builder {
|
||||
ctor public GetCredentialRequest.Builder(@NonNull String);
|
||||
ctor public GetCredentialRequest.Builder(@NonNull android.service.credentials.CallingAppInfo);
|
||||
method @NonNull public android.service.credentials.GetCredentialRequest.Builder addGetCredentialOption(@NonNull android.credentials.GetCredentialOption);
|
||||
method @NonNull public android.service.credentials.GetCredentialRequest build();
|
||||
method @NonNull public android.service.credentials.GetCredentialRequest.Builder setGetCredentialOptions(@NonNull java.util.List<android.credentials.GetCredentialOption>);
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class Action implements Parcelable {
|
||||
* level authentication before displaying any content etc.
|
||||
*
|
||||
* <p> See details on usage of {@code Action} for various actionable entries in
|
||||
* {@link BeginCreateCredentialResponse} and {@link BeginGetCredentialsResponse}.
|
||||
* {@link BeginCreateCredentialResponse} and {@link BeginGetCredentialResponse}.
|
||||
*
|
||||
* @param slice the display content to be displayed on the UI, along with this action
|
||||
* @param pendingIntent the intent to be invoked when the user selects this action
|
||||
|
||||
@@ -31,28 +31,28 @@ import java.util.Objects;
|
||||
* See {@link BeginCreateCredentialResponse} for the counterpart response
|
||||
*/
|
||||
public final class BeginCreateCredentialRequest implements Parcelable {
|
||||
private final @NonNull String mCallingPackage;
|
||||
private final @NonNull CallingAppInfo mCallingAppInfo;
|
||||
private final @NonNull String mType;
|
||||
private final @NonNull Bundle mData;
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @throws IllegalArgumentException If {@code callingPackage}, or {@code type} string is
|
||||
* @throws IllegalArgumentException If {@code callingAppInfo}, or {@code type} string is
|
||||
* null or empty.
|
||||
* @throws NullPointerException If {@code data} is null.
|
||||
*/
|
||||
public BeginCreateCredentialRequest(@NonNull String callingPackage,
|
||||
public BeginCreateCredentialRequest(@NonNull CallingAppInfo callingAppInfo,
|
||||
@NonNull String type, @NonNull Bundle data) {
|
||||
mCallingPackage = Preconditions.checkStringNotEmpty(callingPackage,
|
||||
"callingPackage must not be null or empty");
|
||||
mCallingAppInfo = Objects.requireNonNull(callingAppInfo,
|
||||
"callingAppInfo must not be null");
|
||||
mType = Preconditions.checkStringNotEmpty(type,
|
||||
"type must not be null or empty");
|
||||
mData = Objects.requireNonNull(data, "data must not be null");
|
||||
}
|
||||
|
||||
private BeginCreateCredentialRequest(@NonNull Parcel in) {
|
||||
mCallingPackage = in.readString8();
|
||||
mCallingAppInfo = in.readTypedObject(CallingAppInfo.CREATOR);
|
||||
mType = in.readString8();
|
||||
mData = in.readBundle(Bundle.class.getClassLoader());
|
||||
}
|
||||
@@ -77,15 +77,15 @@ public final class BeginCreateCredentialRequest implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeString8(mCallingPackage);
|
||||
dest.writeTypedObject(mCallingAppInfo, flags);
|
||||
dest.writeString8(mType);
|
||||
dest.writeBundle(mData);
|
||||
}
|
||||
|
||||
/** Returns the calling package of the calling app. */
|
||||
/** Returns the info pertaining to the calling app. */
|
||||
@NonNull
|
||||
public String getCallingPackage() {
|
||||
return mCallingPackage;
|
||||
public CallingAppInfo getCallingAppInfo() {
|
||||
return mCallingAppInfo;
|
||||
}
|
||||
|
||||
/** Returns the type of the credential to be created. */
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.android.internal.util.Preconditions;
|
||||
/**
|
||||
* A specific type of credential request to be sent to the provider during the query phase of
|
||||
* a get flow. This request contains limited parameters needed to populate a list of
|
||||
* {@link CredentialEntry} on the {@link BeginGetCredentialsResponse}.
|
||||
* {@link CredentialEntry} on the {@link BeginGetCredentialResponse}.
|
||||
*/
|
||||
public final class BeginGetCredentialOption implements Parcelable {
|
||||
|
||||
@@ -56,7 +56,7 @@ public final class BeginGetCredentialOption implements Parcelable {
|
||||
/**
|
||||
* Returns the request candidate query data, denoting a set of parameters
|
||||
* that can be used to populate a candidate list of credentials, as
|
||||
* {@link CredentialEntry} on {@link BeginGetCredentialsResponse}. This list
|
||||
* {@link CredentialEntry} on {@link BeginGetCredentialResponse}. This list
|
||||
* of entries is then presented to the user on a selector.
|
||||
*
|
||||
* <p>This data does not contain any sensitive parameters, and will be sent
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package android.service.credentials;
|
||||
|
||||
parcelable BeginGetCredentialsRequest;
|
||||
parcelable BeginGetCredentialRequest;
|
||||
@@ -35,16 +35,16 @@ import java.util.Objects;
|
||||
*
|
||||
* <p>This request contains a list of {@link GetCredentialOption} that have parameters
|
||||
* to be used to query credentials, and return a list of {@link CredentialEntry} to be set
|
||||
* on the {@link BeginGetCredentialsResponse}. This list is then shown to the user on a selector.
|
||||
* on the {@link BeginGetCredentialResponse}. This list is then shown to the user on a selector.
|
||||
*
|
||||
* If a {@link PendingIntent} is set on a {@link CredentialEntry}, and the user selects that
|
||||
* entry, a {@link GetCredentialRequest} with all parameters needed to get the actual
|
||||
* {@link android.credentials.Credential} will be sent as part of the {@link Intent} fired
|
||||
* through the {@link PendingIntent}.
|
||||
*/
|
||||
public final class BeginGetCredentialsRequest implements Parcelable {
|
||||
/** Calling package of the app requesting for credentials. */
|
||||
@NonNull private final String mCallingPackage;
|
||||
public final class BeginGetCredentialRequest implements Parcelable {
|
||||
/** Info pertaining to the app requesting for credentials. */
|
||||
@NonNull private final CallingAppInfo mCallingAppInfo;
|
||||
|
||||
/**
|
||||
* List of credential options. Each {@link BeginGetCredentialOption} object holds parameters to
|
||||
@@ -52,35 +52,36 @@ public final class BeginGetCredentialsRequest implements Parcelable {
|
||||
*
|
||||
* This request does not reveal sensitive parameters. Complete list of parameters
|
||||
* is retrieved through the {@link PendingIntent} set on each {@link CredentialEntry}
|
||||
* on {@link CredentialsResponseContent} set on {@link BeginGetCredentialsResponse},
|
||||
* on {@link CredentialsResponseContent} set on {@link BeginGetCredentialResponse},
|
||||
* when the user selects one of these entries.
|
||||
*/
|
||||
@NonNull private final List<BeginGetCredentialOption> mBeginGetCredentialOptions;
|
||||
|
||||
private BeginGetCredentialsRequest(@NonNull String callingPackage,
|
||||
private BeginGetCredentialRequest(@NonNull CallingAppInfo callingAppInfo,
|
||||
@NonNull List<BeginGetCredentialOption> getBeginCredentialOptions) {
|
||||
this.mCallingPackage = callingPackage;
|
||||
this.mCallingAppInfo = callingAppInfo;
|
||||
this.mBeginGetCredentialOptions = getBeginCredentialOptions;
|
||||
}
|
||||
|
||||
private BeginGetCredentialsRequest(@NonNull Parcel in) {
|
||||
mCallingPackage = in.readString8();
|
||||
private BeginGetCredentialRequest(@NonNull Parcel in) {
|
||||
mCallingAppInfo = in.readTypedObject(CallingAppInfo.CREATOR);
|
||||
List<BeginGetCredentialOption> getBeginCredentialOptions = new ArrayList<>();
|
||||
in.readTypedList(getBeginCredentialOptions, BeginGetCredentialOption.CREATOR);
|
||||
mBeginGetCredentialOptions = getBeginCredentialOptions;
|
||||
AnnotationValidations.validate(NonNull.class, null, mBeginGetCredentialOptions);
|
||||
}
|
||||
|
||||
public static final @NonNull Creator<BeginGetCredentialsRequest> CREATOR =
|
||||
new Creator<BeginGetCredentialsRequest>() {
|
||||
@NonNull
|
||||
public static final Creator<BeginGetCredentialRequest> CREATOR =
|
||||
new Creator<BeginGetCredentialRequest>() {
|
||||
@Override
|
||||
public BeginGetCredentialsRequest createFromParcel(Parcel in) {
|
||||
return new BeginGetCredentialsRequest(in);
|
||||
public BeginGetCredentialRequest createFromParcel(Parcel in) {
|
||||
return new BeginGetCredentialRequest(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeginGetCredentialsRequest[] newArray(int size) {
|
||||
return new BeginGetCredentialsRequest[size];
|
||||
public BeginGetCredentialRequest[] newArray(int size) {
|
||||
return new BeginGetCredentialRequest[size];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -91,40 +92,40 @@ public final class BeginGetCredentialsRequest implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeString8(mCallingPackage);
|
||||
dest.writeTypedObject(mCallingAppInfo, flags);
|
||||
dest.writeTypedList(mBeginGetCredentialOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the calling package of the app requesting credentials.
|
||||
* Returns info pertaining to the app requesting credentials.
|
||||
*/
|
||||
public @NonNull String getCallingPackage() {
|
||||
return mCallingPackage;
|
||||
public @NonNull CallingAppInfo getCallingAppInfo() {
|
||||
return mCallingAppInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of type specific credential options to list credentials for in
|
||||
* {@link BeginGetCredentialsResponse}.
|
||||
* {@link BeginGetCredentialResponse}.
|
||||
*/
|
||||
public @NonNull List<BeginGetCredentialOption> getBeginGetCredentialOptions() {
|
||||
return mBeginGetCredentialOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for {@link BeginGetCredentialsRequest}.
|
||||
* Builder for {@link BeginGetCredentialRequest}.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String mCallingPackage;
|
||||
private CallingAppInfo mCallingAppInfo;
|
||||
private List<BeginGetCredentialOption> mBeginGetCredentialOptions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates a new builder.
|
||||
* @param callingPackage the calling package of the app requesting credentials
|
||||
* @param callingAppInfo info pertaining to the app requesting credentials
|
||||
*
|
||||
* @throws IllegalArgumentException If {@code callingPackage} is null or empty.
|
||||
* @throws IllegalArgumentException If {@code callingAppInfo} is null or empty.
|
||||
*/
|
||||
public Builder(@NonNull String callingPackage) {
|
||||
mCallingPackage = Preconditions.checkStringNotEmpty(callingPackage);
|
||||
public Builder(@NonNull CallingAppInfo callingAppInfo) {
|
||||
mCallingAppInfo = Objects.requireNonNull(callingAppInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,18 +159,17 @@ public final class BeginGetCredentialsRequest implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a new {@link BeginGetCredentialsRequest} instance.
|
||||
* Builds a new {@link BeginGetCredentialRequest} instance.
|
||||
*
|
||||
* @throws NullPointerException If {@code beginGetCredentialOptions} is null.
|
||||
* @throws IllegalArgumentException If {@code beginGetCredentialOptions} is empty, or if
|
||||
* {@code callingPackage} is null or empty.
|
||||
* {@code callingAppInfo} is null or empty.
|
||||
*/
|
||||
public @NonNull BeginGetCredentialsRequest build() {
|
||||
Preconditions.checkStringNotEmpty(mCallingPackage,
|
||||
"Must set the calling package");
|
||||
public @NonNull BeginGetCredentialRequest build() {
|
||||
Objects.requireNonNull(mCallingAppInfo, "callingAppInfo");
|
||||
Preconditions.checkCollectionNotEmpty(mBeginGetCredentialOptions,
|
||||
"beginGetCredentialOptions");
|
||||
return new BeginGetCredentialsRequest(mCallingPackage, mBeginGetCredentialOptions);
|
||||
return new BeginGetCredentialRequest(mCallingAppInfo, mBeginGetCredentialOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package android.service.credentials;
|
||||
|
||||
parcelable BeginGetCredentialResponse;
|
||||
@@ -27,7 +27,7 @@ import java.util.Objects;
|
||||
* Response from a credential provider, containing credential entries and other associated
|
||||
* data to be shown on the account selector UI.
|
||||
*/
|
||||
public final class BeginGetCredentialsResponse implements Parcelable {
|
||||
public final class BeginGetCredentialResponse implements Parcelable {
|
||||
/** Content to be used for the UI. */
|
||||
private final @Nullable CredentialsResponseContent mCredentialsResponseContent;
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class BeginGetCredentialsResponse implements Parcelable {
|
||||
private final @Nullable Action mAuthenticationAction;
|
||||
|
||||
/**
|
||||
* Creates a {@link BeginGetCredentialsResponse} instance with an authentication
|
||||
* Creates a {@link BeginGetCredentialResponse} instance with an authentication
|
||||
* {@link Action} set. Providers must use this method when no content can be shown
|
||||
* before authentication.
|
||||
*
|
||||
@@ -55,49 +55,49 @@ public final class BeginGetCredentialsResponse implements Parcelable {
|
||||
*
|
||||
* @throws NullPointerException If {@code authenticationAction} is null.
|
||||
*/
|
||||
public static @NonNull BeginGetCredentialsResponse createWithAuthentication(
|
||||
public static @NonNull BeginGetCredentialResponse createWithAuthentication(
|
||||
@NonNull Action authenticationAction) {
|
||||
Objects.requireNonNull(authenticationAction,
|
||||
"authenticationAction must not be null");
|
||||
return new BeginGetCredentialsResponse(null, authenticationAction);
|
||||
return new BeginGetCredentialResponse(null, authenticationAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link BeginGetCredentialsRequest} instance with content to be shown on the UI.
|
||||
* Creates a {@link BeginGetCredentialRequest} instance with content to be shown on the UI.
|
||||
* Providers must use this method when there is content to be shown without top level
|
||||
* authentication required, including credential entries, action entries or a remote entry,
|
||||
*
|
||||
* @throws NullPointerException If {@code credentialsResponseContent} is null.
|
||||
*/
|
||||
public static @NonNull BeginGetCredentialsResponse createWithResponseContent(
|
||||
public static @NonNull BeginGetCredentialResponse createWithResponseContent(
|
||||
@NonNull CredentialsResponseContent credentialsResponseContent) {
|
||||
Objects.requireNonNull(credentialsResponseContent,
|
||||
"credentialsResponseContent must not be null");
|
||||
return new BeginGetCredentialsResponse(credentialsResponseContent, null);
|
||||
return new BeginGetCredentialResponse(credentialsResponseContent, null);
|
||||
}
|
||||
|
||||
private BeginGetCredentialsResponse(@Nullable CredentialsResponseContent
|
||||
private BeginGetCredentialResponse(@Nullable CredentialsResponseContent
|
||||
credentialsResponseContent,
|
||||
@Nullable Action authenticationAction) {
|
||||
mCredentialsResponseContent = credentialsResponseContent;
|
||||
mAuthenticationAction = authenticationAction;
|
||||
}
|
||||
|
||||
private BeginGetCredentialsResponse(@NonNull Parcel in) {
|
||||
private BeginGetCredentialResponse(@NonNull Parcel in) {
|
||||
mCredentialsResponseContent = in.readTypedObject(CredentialsResponseContent.CREATOR);
|
||||
mAuthenticationAction = in.readTypedObject(Action.CREATOR);
|
||||
}
|
||||
|
||||
public static final @NonNull Creator<BeginGetCredentialsResponse> CREATOR =
|
||||
new Creator<BeginGetCredentialsResponse>() {
|
||||
public static final @NonNull Creator<BeginGetCredentialResponse> CREATOR =
|
||||
new Creator<BeginGetCredentialResponse>() {
|
||||
@Override
|
||||
public BeginGetCredentialsResponse createFromParcel(Parcel in) {
|
||||
return new BeginGetCredentialsResponse(in);
|
||||
public BeginGetCredentialResponse createFromParcel(Parcel in) {
|
||||
return new BeginGetCredentialResponse(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeginGetCredentialsResponse[] newArray(int size) {
|
||||
return new BeginGetCredentialsResponse[size];
|
||||
public BeginGetCredentialResponse[] newArray(int size) {
|
||||
return new BeginGetCredentialResponse[size];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
package android.service.credentials;
|
||||
|
||||
parcelable BeginGetCredentialsResponse;
|
||||
@@ -22,7 +22,6 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.internal.util.AnnotationValidations;
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -29,28 +29,28 @@ import java.util.Objects;
|
||||
* Request for creating a credential.
|
||||
*/
|
||||
public final class CreateCredentialRequest implements Parcelable {
|
||||
private final @NonNull String mCallingPackage;
|
||||
private final @NonNull CallingAppInfo mCallingAppInfo;
|
||||
private final @NonNull String mType;
|
||||
private final @NonNull Bundle mData;
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @throws IllegalArgumentException If {@code callingPackage}, or {@code type} string is
|
||||
* @throws IllegalArgumentException If {@code callingAppInfo}, or {@code type} string is
|
||||
* null or empty.
|
||||
* @throws NullPointerException If {@code data} is null.
|
||||
*/
|
||||
public CreateCredentialRequest(@NonNull String callingPackage,
|
||||
public CreateCredentialRequest(@NonNull CallingAppInfo callingAppInfo,
|
||||
@NonNull String type, @NonNull Bundle data) {
|
||||
mCallingPackage = Preconditions.checkStringNotEmpty(callingPackage,
|
||||
"callingPackage must not be null or empty");
|
||||
mCallingAppInfo = Objects.requireNonNull(callingAppInfo,
|
||||
"callingAppInfo must not be null");
|
||||
mType = Preconditions.checkStringNotEmpty(type,
|
||||
"type must not be null or empty");
|
||||
mData = Objects.requireNonNull(data, "data must not be null");
|
||||
}
|
||||
|
||||
private CreateCredentialRequest(@NonNull Parcel in) {
|
||||
mCallingPackage = in.readString8();
|
||||
mCallingAppInfo = in.readTypedObject(CallingAppInfo.CREATOR);
|
||||
mType = in.readString8();
|
||||
mData = in.readTypedObject(Bundle.CREATOR);
|
||||
}
|
||||
@@ -75,15 +75,15 @@ public final class CreateCredentialRequest implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeString8(mCallingPackage);
|
||||
dest.writeTypedObject(mCallingAppInfo, flags);
|
||||
dest.writeString8(mType);
|
||||
dest.writeTypedObject(mData, flags);
|
||||
}
|
||||
|
||||
/** Returns the calling package of the calling app. */
|
||||
/** Returns info pertaining to the calling app. */
|
||||
@NonNull
|
||||
public String getCallingPackage() {
|
||||
return mCallingPackage;
|
||||
public CallingAppInfo getCallingAppInfo() {
|
||||
return mCallingAppInfo;
|
||||
}
|
||||
|
||||
/** Returns the type of the credential to be created. */
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Contains custom exceptions to be used by credential providers on failure.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class CredentialProviderException extends Exception {
|
||||
public static final int ERROR_UNKNOWN = 0;
|
||||
@@ -44,6 +46,14 @@ public class CredentialProviderException extends Exception {
|
||||
*/
|
||||
public static final int ERROR_TASK_CANCELED = 2;
|
||||
|
||||
/**
|
||||
* For internal use only.
|
||||
* Error code to be used when the provider encounters a failure while processing the request.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int ERROR_PROVIDER_FAILURE = 3;
|
||||
|
||||
private final int mErrorCode;
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,8 @@ import android.annotation.SdkConstant;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.credentials.CreateCredentialException;
|
||||
import android.credentials.GetCredentialException;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -54,7 +56,7 @@ public abstract class CredentialProviderService extends Service {
|
||||
/**
|
||||
* Intent extra: The {@link GetCredentialRequest} attached with
|
||||
* the {@code pendingIntent} that is invoked when the user selects a {@link CredentialEntry}
|
||||
* returned as part of the {@link BeginGetCredentialsResponse}
|
||||
* returned as part of the {@link BeginGetCredentialResponse}
|
||||
*
|
||||
* <p>
|
||||
* Type: {@link GetCredentialRequest}
|
||||
@@ -87,7 +89,7 @@ public abstract class CredentialProviderService extends Service {
|
||||
/**
|
||||
* Intent extra: The result of an authentication flow, to be set on finish of the
|
||||
* {@link android.app.Activity} invoked through the {@link android.app.PendingIntent} set on
|
||||
* a {@link BeginGetCredentialsResponse}. This result should contain the actual content,
|
||||
* a {@link BeginGetCredentialResponse}. This result should contain the actual content,
|
||||
* including credential entries and action entries, to be shown on the selector.
|
||||
*
|
||||
* <p>
|
||||
@@ -154,22 +156,21 @@ public abstract class CredentialProviderService extends Service {
|
||||
}
|
||||
|
||||
private final ICredentialProviderService mInterface = new ICredentialProviderService.Stub() {
|
||||
@Override
|
||||
public ICancellationSignal onBeginGetCredentials(BeginGetCredentialsRequest request,
|
||||
IBeginGetCredentialsCallback callback) {
|
||||
public ICancellationSignal onBeginGetCredential(BeginGetCredentialRequest request,
|
||||
IBeginGetCredentialCallback callback) {
|
||||
Objects.requireNonNull(request);
|
||||
Objects.requireNonNull(callback);
|
||||
|
||||
ICancellationSignal transport = CancellationSignal.createTransport();
|
||||
|
||||
mHandler.sendMessage(obtainMessage(
|
||||
CredentialProviderService::onBeginGetCredentials,
|
||||
CredentialProviderService::onBeginGetCredential,
|
||||
CredentialProviderService.this, request,
|
||||
CancellationSignal.fromTransport(transport),
|
||||
new OutcomeReceiver<BeginGetCredentialsResponse,
|
||||
CredentialProviderException>() {
|
||||
new OutcomeReceiver<BeginGetCredentialResponse,
|
||||
GetCredentialException>() {
|
||||
@Override
|
||||
public void onResult(BeginGetCredentialsResponse result) {
|
||||
public void onResult(BeginGetCredentialResponse result) {
|
||||
try {
|
||||
callback.onSuccess(result);
|
||||
} catch (RemoteException e) {
|
||||
@@ -177,9 +178,9 @@ public abstract class CredentialProviderService extends Service {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onError(CredentialProviderException e) {
|
||||
public void onError(GetCredentialException e) {
|
||||
try {
|
||||
callback.onFailure(e.getErrorCode(), e.getMessage());
|
||||
callback.onFailure(e.errorType, e.getMessage());
|
||||
} catch (RemoteException ex) {
|
||||
ex.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -202,7 +203,7 @@ public abstract class CredentialProviderService extends Service {
|
||||
CredentialProviderService.this, request,
|
||||
CancellationSignal.fromTransport(transport),
|
||||
new OutcomeReceiver<
|
||||
BeginCreateCredentialResponse, CredentialProviderException>() {
|
||||
BeginCreateCredentialResponse, CreateCredentialException>() {
|
||||
@Override
|
||||
public void onResult(BeginCreateCredentialResponse result) {
|
||||
try {
|
||||
@@ -212,9 +213,9 @@ public abstract class CredentialProviderService extends Service {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onError(CredentialProviderException e) {
|
||||
public void onError(CreateCredentialException e) {
|
||||
try {
|
||||
callback.onFailure(e.getErrorCode(), e.getMessage());
|
||||
callback.onFailure(e.errorType, e.getMessage());
|
||||
} catch (RemoteException ex) {
|
||||
ex.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -229,13 +230,11 @@ public abstract class CredentialProviderService extends Service {
|
||||
* Called by the android system to retrieve user credentials from the connected provider
|
||||
* service.
|
||||
*
|
||||
*
|
||||
*
|
||||
* <p>This API denotes a query stage request for getting user's credentials from a given
|
||||
* credential provider. The request contains a list of
|
||||
* {@link android.credentials.GetCredentialOption} that have parameters to be used for
|
||||
* populating candidate credentials, as a list of {@link CredentialEntry} to be set
|
||||
* on the {@link BeginGetCredentialsResponse}. This list is then shown to the user on a
|
||||
* on the {@link BeginGetCredentialResponse}. This list is then shown to the user on a
|
||||
* selector.
|
||||
*
|
||||
* <p>If a {@link PendingIntent} is set on a {@link CredentialEntry}, and the user selects that
|
||||
@@ -247,10 +246,10 @@ public abstract class CredentialProviderService extends Service {
|
||||
* the android system
|
||||
* @param callback object used to relay the response of the credentials request
|
||||
*/
|
||||
public abstract void onBeginGetCredentials(@NonNull BeginGetCredentialsRequest request,
|
||||
public abstract void onBeginGetCredential(@NonNull BeginGetCredentialRequest request,
|
||||
@NonNull CancellationSignal cancellationSignal,
|
||||
@NonNull OutcomeReceiver<
|
||||
BeginGetCredentialsResponse, CredentialProviderException> callback);
|
||||
BeginGetCredentialResponse, GetCredentialException> callback);
|
||||
|
||||
/**
|
||||
* Called by the android system to create a credential.
|
||||
@@ -262,5 +261,5 @@ public abstract class CredentialProviderService extends Service {
|
||||
public abstract void onBeginCreateCredential(@NonNull BeginCreateCredentialRequest request,
|
||||
@NonNull CancellationSignal cancellationSignal,
|
||||
@NonNull OutcomeReceiver<BeginCreateCredentialResponse,
|
||||
CredentialProviderException> callback);
|
||||
CreateCredentialException> callback);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The content to be displayed on the account selector UI, including credential entries,
|
||||
* actions etc. Returned as part of {@link BeginGetCredentialsResponse}
|
||||
* actions etc. Returned as part of {@link BeginGetCredentialResponse}
|
||||
*/
|
||||
public final class CredentialsResponseContent implements Parcelable {
|
||||
/** List of credential entries to be displayed on the UI. */
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.Objects;
|
||||
*/
|
||||
public final class GetCredentialRequest implements Parcelable {
|
||||
/** Calling package of the app requesting for credentials. */
|
||||
private final @NonNull String mCallingPackage;
|
||||
private final @NonNull CallingAppInfo mCallingAppInfo;
|
||||
|
||||
/**
|
||||
* List of credential options. Each {@link GetCredentialOption} object holds parameters to
|
||||
@@ -41,14 +41,14 @@ public final class GetCredentialRequest implements Parcelable {
|
||||
*/
|
||||
private final @NonNull List<GetCredentialOption> mGetCredentialOptions;
|
||||
|
||||
private GetCredentialRequest(@NonNull String callingPackage,
|
||||
private GetCredentialRequest(@NonNull CallingAppInfo callingAppInfo,
|
||||
@NonNull List<GetCredentialOption> getCredentialOptions) {
|
||||
this.mCallingPackage = callingPackage;
|
||||
this.mCallingAppInfo = callingAppInfo;
|
||||
this.mGetCredentialOptions = getCredentialOptions;
|
||||
}
|
||||
|
||||
private GetCredentialRequest(@NonNull Parcel in) {
|
||||
mCallingPackage = in.readString8();
|
||||
mCallingAppInfo = in.readTypedObject(CallingAppInfo.CREATOR);
|
||||
List<GetCredentialOption> getCredentialOptions = new ArrayList<>();
|
||||
in.readTypedList(getCredentialOptions, GetCredentialOption.CREATOR);
|
||||
mGetCredentialOptions = getCredentialOptions;
|
||||
@@ -75,15 +75,15 @@ public final class GetCredentialRequest implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||
dest.writeString8(mCallingPackage);
|
||||
dest.writeTypedObject(mCallingAppInfo, flags);
|
||||
dest.writeTypedList(mGetCredentialOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the calling package of the app requesting credentials.
|
||||
* Returns info pertaining to the app requesting credentials.
|
||||
*/
|
||||
public @NonNull String getCallingPackage() {
|
||||
return mCallingPackage;
|
||||
public @NonNull CallingAppInfo getCallingAppInfo() {
|
||||
return mCallingAppInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,17 +97,17 @@ public final class GetCredentialRequest implements Parcelable {
|
||||
* Builder for {@link GetCredentialRequest}.
|
||||
*/
|
||||
public static final class Builder {
|
||||
private String mCallingPackage;
|
||||
private CallingAppInfo mCallingAppInfo;
|
||||
private List<GetCredentialOption> mGetCredentialOptions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates a new builder.
|
||||
* @param callingPackage the calling package of the app requesting credentials
|
||||
* @param callingAppInfo info pertaining to the app requesting credentials
|
||||
*
|
||||
* @throws IllegalArgumentException If {@code callingPackag}e is null or empty.
|
||||
*/
|
||||
public Builder(@NonNull String callingPackage) {
|
||||
mCallingPackage = Preconditions.checkStringNotEmpty(callingPackage);
|
||||
public Builder(@NonNull CallingAppInfo callingAppInfo) {
|
||||
mCallingAppInfo = Objects.requireNonNull(callingAppInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,14 +145,14 @@ public final class GetCredentialRequest implements Parcelable {
|
||||
*
|
||||
* @throws NullPointerException If {@code getCredentialOptions} is null.
|
||||
* @throws IllegalArgumentException If {@code getCredentialOptions} is empty, or if
|
||||
* {@code callingPackage} is null or empty.
|
||||
* {@code callingAppInfo} is null or empty.
|
||||
*/
|
||||
public @NonNull GetCredentialRequest build() {
|
||||
Preconditions.checkStringNotEmpty(mCallingPackage,
|
||||
"Must set the calling package");
|
||||
Objects.requireNonNull(mCallingAppInfo,
|
||||
"mCallingAppInfo");
|
||||
Preconditions.checkCollectionNotEmpty(mGetCredentialOptions,
|
||||
"getCredentialOptions");
|
||||
return new GetCredentialRequest(mCallingPackage, mGetCredentialOptions);
|
||||
return new GetCredentialRequest(mCallingAppInfo, mGetCredentialOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ import android.service.credentials.BeginCreateCredentialResponse;
|
||||
*/
|
||||
oneway interface IBeginCreateCredentialCallback {
|
||||
void onSuccess(in BeginCreateCredentialResponse request);
|
||||
void onFailure(int errorCode, in CharSequence message);
|
||||
void onFailure(String errorType, in CharSequence message);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package android.service.credentials;
|
||||
|
||||
import android.service.credentials.BeginGetCredentialResponse;
|
||||
|
||||
/**
|
||||
* Interface from the system to a credential provider service.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
oneway interface IBeginGetCredentialCallback {
|
||||
void onSuccess(in BeginGetCredentialResponse response);
|
||||
void onFailure(String errorType, in CharSequence message);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package android.service.credentials;
|
||||
|
||||
import android.service.credentials.BeginGetCredentialsResponse;
|
||||
|
||||
/**
|
||||
* Interface from the system to a credential provider service.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
oneway interface IBeginGetCredentialsCallback {
|
||||
void onSuccess(in BeginGetCredentialsResponse response);
|
||||
void onFailure(int errorCode, in CharSequence message);
|
||||
}
|
||||
@@ -17,9 +17,9 @@
|
||||
package android.service.credentials;
|
||||
|
||||
import android.os.ICancellationSignal;
|
||||
import android.service.credentials.BeginGetCredentialsRequest;
|
||||
import android.service.credentials.BeginGetCredentialRequest;
|
||||
import android.service.credentials.BeginCreateCredentialRequest;
|
||||
import android.service.credentials.IBeginGetCredentialsCallback;
|
||||
import android.service.credentials.IBeginGetCredentialCallback;
|
||||
import android.service.credentials.IBeginCreateCredentialCallback;
|
||||
import android.os.ICancellationSignal;
|
||||
|
||||
@@ -29,6 +29,6 @@ import android.os.ICancellationSignal;
|
||||
* @hide
|
||||
*/
|
||||
interface ICredentialProviderService {
|
||||
ICancellationSignal onBeginGetCredentials(in BeginGetCredentialsRequest request, in IBeginGetCredentialsCallback callback);
|
||||
ICancellationSignal onBeginGetCredential(in BeginGetCredentialRequest request, in IBeginGetCredentialCallback callback);
|
||||
ICancellationSignal onBeginCreateCredential(in BeginCreateCredentialRequest request, in IBeginCreateCredentialCallback callback);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.app.slice.Slice
|
||||
import android.app.slice.SliceSpec
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.Signature
|
||||
import android.credentials.CreateCredentialRequest
|
||||
import android.credentials.GetCredentialOption
|
||||
import android.credentials.GetCredentialRequest
|
||||
@@ -40,6 +41,7 @@ import android.os.Binder
|
||||
import android.os.Bundle
|
||||
import android.os.ResultReceiver
|
||||
import android.service.credentials.CredentialProviderService
|
||||
import android.util.ArraySet
|
||||
import com.android.credentialmanager.createflow.CreateCredentialUiState
|
||||
import com.android.credentialmanager.getflow.GetCredentialUiState
|
||||
import com.android.credentialmanager.jetpack.developer.CreatePasswordRequest.Companion.toBundle
|
||||
@@ -351,7 +353,8 @@ class CredentialManagerRepo(
|
||||
intent, (PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||
or PendingIntent.FLAG_ONE_SHOT))
|
||||
val createPasswordRequest = android.service.credentials.CreateCredentialRequest(
|
||||
context.applicationInfo.packageName,
|
||||
android.service.credentials.CallingAppInfo(
|
||||
context.applicationInfo.packageName, ArraySet<Signature>()),
|
||||
TYPE_PASSWORD_CREDENTIAL,
|
||||
toBundle("beckett-bakert@gmail.com", "password123")
|
||||
)
|
||||
|
||||
@@ -32,8 +32,8 @@ import android.credentials.ICreateCredentialCallback;
|
||||
import android.credentials.ICredentialManager;
|
||||
import android.credentials.IGetCredentialCallback;
|
||||
import android.credentials.IListEnabledProvidersCallback;
|
||||
import android.credentials.ListEnabledProvidersResponse;
|
||||
import android.credentials.ISetEnabledProvidersCallback;
|
||||
import android.credentials.ListEnabledProvidersResponse;
|
||||
import android.os.Binder;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ICancellationSignal;
|
||||
@@ -41,7 +41,7 @@ import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.service.credentials.BeginCreateCredentialRequest;
|
||||
import android.service.credentials.BeginGetCredentialsRequest;
|
||||
import android.service.credentials.BeginGetCredentialRequest;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
@@ -183,15 +183,11 @@ public final class CredentialManagerService
|
||||
// TODO : Return error when no providers available
|
||||
|
||||
// Iterate over all provider sessions and invoke the request
|
||||
providerSessions.forEach(
|
||||
providerGetSession -> {
|
||||
providerGetSession
|
||||
.getRemoteCredentialService()
|
||||
.onBeginGetCredentials(
|
||||
(BeginGetCredentialsRequest)
|
||||
providerGetSession.getProviderRequest(),
|
||||
/* callback= */ providerGetSession);
|
||||
});
|
||||
providerSessions.forEach(providerGetSession -> {
|
||||
providerGetSession.getRemoteCredentialService().onBeginGetCredential(
|
||||
(BeginGetCredentialRequest) providerGetSession.getProviderRequest(),
|
||||
/*callback=*/providerGetSession);
|
||||
});
|
||||
return cancelTransport;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,15 +22,18 @@ import android.annotation.UserIdInt;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.Signature;
|
||||
import android.credentials.ui.CreateCredentialProviderData;
|
||||
import android.credentials.ui.Entry;
|
||||
import android.credentials.ui.ProviderPendingIntentResponse;
|
||||
import android.service.credentials.BeginCreateCredentialRequest;
|
||||
import android.service.credentials.BeginCreateCredentialResponse;
|
||||
import android.service.credentials.CallingAppInfo;
|
||||
import android.service.credentials.CreateCredentialRequest;
|
||||
import android.service.credentials.CreateEntry;
|
||||
import android.service.credentials.CredentialProviderInfo;
|
||||
import android.service.credentials.CredentialProviderService;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
|
||||
@@ -65,11 +68,12 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
CreateCredentialRequest providerCreateRequest =
|
||||
createProviderRequest(providerInfo.getCapabilities(),
|
||||
createRequestSession.mClientRequest,
|
||||
createRequestSession.mClientCallingPackage);
|
||||
new CallingAppInfo(createRequestSession.mClientCallingPackage,
|
||||
new ArraySet<Signature>()));
|
||||
if (providerCreateRequest != null) {
|
||||
BeginCreateCredentialRequest providerBeginCreateRequest =
|
||||
new BeginCreateCredentialRequest(
|
||||
providerCreateRequest.getCallingPackage(),
|
||||
providerCreateRequest.getCallingAppInfo(),
|
||||
providerCreateRequest.getType(),
|
||||
createRequestSession.mClientRequest.getCandidateQueryData());
|
||||
return new ProviderCreateSession(context, providerInfo, createRequestSession, userId,
|
||||
@@ -82,10 +86,10 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
@Nullable
|
||||
private static CreateCredentialRequest createProviderRequest(List<String> providerCapabilities,
|
||||
android.credentials.CreateCredentialRequest clientRequest,
|
||||
String clientCallingPackage) {
|
||||
CallingAppInfo callingAppInfo) {
|
||||
String capability = clientRequest.getType();
|
||||
if (providerCapabilities.contains(capability)) {
|
||||
return new CreateCredentialRequest(clientCallingPackage, capability,
|
||||
return new CreateCredentialRequest(callingAppInfo, capability,
|
||||
clientRequest.getCredentialData());
|
||||
}
|
||||
Log.i(TAG, "Unable to create provider request - capabilities do not match");
|
||||
@@ -120,7 +124,8 @@ public final class ProviderCreateSession extends ProviderSession<
|
||||
|
||||
/** Called when the provider response resulted in a failure. */
|
||||
@Override
|
||||
public void onProviderResponseFailure(int errorCode, @Nullable CharSequence message) {
|
||||
public void onProviderResponseFailure(int errorCode, @Nullable String errorType,
|
||||
@Nullable CharSequence message) {
|
||||
updateStatusAndInvokeCallback(toStatus(errorCode));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.annotation.UserIdInt;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.Signature;
|
||||
import android.credentials.GetCredentialOption;
|
||||
import android.credentials.GetCredentialResponse;
|
||||
import android.credentials.ui.Entry;
|
||||
@@ -29,13 +30,15 @@ import android.credentials.ui.GetCredentialProviderData;
|
||||
import android.credentials.ui.ProviderPendingIntentResponse;
|
||||
import android.service.credentials.Action;
|
||||
import android.service.credentials.BeginGetCredentialOption;
|
||||
import android.service.credentials.BeginGetCredentialsRequest;
|
||||
import android.service.credentials.BeginGetCredentialsResponse;
|
||||
import android.service.credentials.BeginGetCredentialRequest;
|
||||
import android.service.credentials.BeginGetCredentialResponse;
|
||||
import android.service.credentials.CallingAppInfo;
|
||||
import android.service.credentials.CredentialEntry;
|
||||
import android.service.credentials.CredentialProviderInfo;
|
||||
import android.service.credentials.CredentialProviderService;
|
||||
import android.service.credentials.CredentialsResponseContent;
|
||||
import android.service.credentials.GetCredentialRequest;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.Slog;
|
||||
@@ -53,10 +56,10 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class ProviderGetSession extends ProviderSession<BeginGetCredentialsRequest,
|
||||
BeginGetCredentialsResponse>
|
||||
public final class ProviderGetSession extends ProviderSession<BeginGetCredentialRequest,
|
||||
BeginGetCredentialResponse>
|
||||
implements
|
||||
RemoteCredentialService.ProviderCallbacks<BeginGetCredentialsResponse> {
|
||||
RemoteCredentialService.ProviderCallbacks<BeginGetCredentialResponse> {
|
||||
private static final String TAG = "ProviderGetSession";
|
||||
|
||||
// Key to be used as an entry key for a credential entry
|
||||
@@ -90,9 +93,9 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
getRequestSession.mClientCallingPackage);
|
||||
if (completeRequest != null) {
|
||||
// TODO: Update to using query data when ready
|
||||
BeginGetCredentialsRequest beginGetCredentialsRequest =
|
||||
new BeginGetCredentialsRequest.Builder(
|
||||
completeRequest.getCallingPackage())
|
||||
BeginGetCredentialRequest beginGetCredentialRequest =
|
||||
new BeginGetCredentialRequest.Builder(
|
||||
completeRequest.getCallingAppInfo())
|
||||
.setBeginGetCredentialOptions(
|
||||
completeRequest.getGetCredentialOptions().stream().map(
|
||||
option -> {
|
||||
@@ -104,7 +107,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
}).collect(Collectors.toList()))
|
||||
.build();
|
||||
return new ProviderGetSession(context, providerInfo, getRequestSession, userId,
|
||||
remoteCredentialService, beginGetCredentialsRequest, completeRequest);
|
||||
remoteCredentialService, beginGetCredentialRequest, completeRequest);
|
||||
}
|
||||
Log.i(TAG, "Unable to create provider session");
|
||||
return null;
|
||||
@@ -126,7 +129,9 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
}
|
||||
}
|
||||
if (!filteredOptions.isEmpty()) {
|
||||
return new GetCredentialRequest.Builder(clientCallingPackage).setGetCredentialOptions(
|
||||
return new GetCredentialRequest.Builder(
|
||||
new CallingAppInfo(clientCallingPackage,
|
||||
new ArraySet<Signature>())).setGetCredentialOptions(
|
||||
filteredOptions).build();
|
||||
}
|
||||
Log.i(TAG, "In createProviderRequest - returning null");
|
||||
@@ -137,7 +142,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
CredentialProviderInfo info,
|
||||
ProviderInternalCallback callbacks,
|
||||
int userId, RemoteCredentialService remoteCredentialService,
|
||||
BeginGetCredentialsRequest beginGetRequest,
|
||||
BeginGetCredentialRequest beginGetRequest,
|
||||
GetCredentialRequest completeGetRequest) {
|
||||
super(context, info, beginGetRequest, callbacks, userId, remoteCredentialService);
|
||||
mCompleteRequest = completeGetRequest;
|
||||
@@ -152,14 +157,15 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
|
||||
/** Called when the provider response has been updated by an external source. */
|
||||
@Override // Callback from the remote provider
|
||||
public void onProviderResponseSuccess(@Nullable BeginGetCredentialsResponse response) {
|
||||
public void onProviderResponseSuccess(@Nullable BeginGetCredentialResponse response) {
|
||||
Log.i(TAG, "in onProviderResponseSuccess");
|
||||
onUpdateResponse(response);
|
||||
}
|
||||
|
||||
/** Called when the provider response resulted in a failure. */
|
||||
@Override // Callback from the remote provider
|
||||
public void onProviderResponseFailure(int errorCode, @Nullable CharSequence message) {
|
||||
public void onProviderResponseFailure(int errorCode, @Nullable String errorType,
|
||||
@Nullable CharSequence message) {
|
||||
updateStatusAndInvokeCallback(toStatus(errorCode));
|
||||
}
|
||||
|
||||
@@ -349,7 +355,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
.getResultData());
|
||||
if (content != null) {
|
||||
onUpdateResponse(
|
||||
BeginGetCredentialsResponse.createWithResponseContent(content));
|
||||
BeginGetCredentialResponse.createWithResponseContent(content));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -366,7 +372,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
|
||||
|
||||
|
||||
/** Updates the response being maintained in state by this provider session. */
|
||||
private void onUpdateResponse(BeginGetCredentialsResponse response) {
|
||||
private void onUpdateResponse(BeginGetCredentialResponse response) {
|
||||
mProviderResponse = response;
|
||||
if (response.getAuthenticationAction() != null) {
|
||||
Log.i(TAG , "updateResponse with authentication entry");
|
||||
|
||||
@@ -21,18 +21,19 @@ import android.annotation.Nullable;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.credentials.CreateCredentialException;
|
||||
import android.credentials.GetCredentialException;
|
||||
import android.os.Handler;
|
||||
import android.os.ICancellationSignal;
|
||||
import android.os.RemoteException;
|
||||
import android.service.credentials.BeginCreateCredentialRequest;
|
||||
import android.service.credentials.BeginCreateCredentialResponse;
|
||||
import android.service.credentials.BeginGetCredentialsRequest;
|
||||
import android.service.credentials.BeginGetCredentialsResponse;
|
||||
import android.service.credentials.BeginGetCredentialRequest;
|
||||
import android.service.credentials.BeginGetCredentialResponse;
|
||||
import android.service.credentials.CredentialProviderException;
|
||||
import android.service.credentials.CredentialProviderException.CredentialProviderError;
|
||||
import android.service.credentials.CredentialProviderService;
|
||||
import android.service.credentials.IBeginCreateCredentialCallback;
|
||||
import android.service.credentials.IBeginGetCredentialsCallback;
|
||||
import android.service.credentials.IBeginGetCredentialCallback;
|
||||
import android.service.credentials.ICredentialProviderService;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
@@ -71,7 +72,8 @@ public class RemoteCredentialService extends ServiceConnector.Impl<ICredentialPr
|
||||
/** Called when a successful response is received from the remote provider. */
|
||||
void onProviderResponseSuccess(@Nullable T response);
|
||||
/** Called when a failure response is received from the remote provider. */
|
||||
void onProviderResponseFailure(int errorCode, @Nullable CharSequence message);
|
||||
void onProviderResponseFailure(int errorCode, @Nullable String errorType,
|
||||
@Nullable CharSequence message);
|
||||
/** Called when the remote provider service dies. */
|
||||
void onProviderServiceDied(RemoteCredentialService service);
|
||||
}
|
||||
@@ -106,35 +108,34 @@ public class RemoteCredentialService extends ServiceConnector.Impl<ICredentialPr
|
||||
* @param callback the callback to be used to send back the provider response to the
|
||||
* {@link ProviderGetSession} class that maintains provider state
|
||||
*/
|
||||
public void onBeginGetCredentials(@NonNull BeginGetCredentialsRequest request,
|
||||
ProviderCallbacks<BeginGetCredentialsResponse> callback) {
|
||||
public void onBeginGetCredential(@NonNull BeginGetCredentialRequest request,
|
||||
ProviderCallbacks<BeginGetCredentialResponse> callback) {
|
||||
Log.i(TAG, "In onGetCredentials in RemoteCredentialService");
|
||||
AtomicReference<ICancellationSignal> cancellationSink = new AtomicReference<>();
|
||||
AtomicReference<CompletableFuture<BeginGetCredentialsResponse>> futureRef =
|
||||
AtomicReference<CompletableFuture<BeginGetCredentialResponse>> futureRef =
|
||||
new AtomicReference<>();
|
||||
|
||||
CompletableFuture<BeginGetCredentialsResponse> connectThenExecute = postAsync(service -> {
|
||||
CompletableFuture<BeginGetCredentialsResponse> getCredentials =
|
||||
CompletableFuture<BeginGetCredentialResponse> connectThenExecute = postAsync(service -> {
|
||||
CompletableFuture<BeginGetCredentialResponse> getCredentials =
|
||||
new CompletableFuture<>();
|
||||
ICancellationSignal cancellationSignal =
|
||||
service.onBeginGetCredentials(request,
|
||||
new IBeginGetCredentialsCallback.Stub() {
|
||||
service.onBeginGetCredential(request,
|
||||
new IBeginGetCredentialCallback.Stub() {
|
||||
@Override
|
||||
public void onSuccess(BeginGetCredentialsResponse response) {
|
||||
public void onSuccess(BeginGetCredentialResponse response) {
|
||||
Log.i(TAG, "In onSuccess in RemoteCredentialService");
|
||||
getCredentials.complete(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@CredentialProviderError int errorCode,
|
||||
CharSequence message) {
|
||||
public void onFailure(String errorType, CharSequence message) {
|
||||
Log.i(TAG, "In onFailure in RemoteCredentialService");
|
||||
String errorMsg = message == null ? "" : String.valueOf(message);
|
||||
getCredentials.completeExceptionally(new CredentialProviderException(
|
||||
errorCode, errorMsg));
|
||||
getCredentials.completeExceptionally(
|
||||
new GetCredentialException(errorType, errorMsg));
|
||||
}
|
||||
});
|
||||
CompletableFuture<BeginGetCredentialsResponse> future = futureRef.get();
|
||||
CompletableFuture<BeginGetCredentialResponse> future = futureRef.get();
|
||||
if (future != null && future.isCancelled()) {
|
||||
dispatchCancellationSignal(cancellationSignal);
|
||||
} else {
|
||||
@@ -175,12 +176,11 @@ public class RemoteCredentialService extends ServiceConnector.Impl<ICredentialPr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@CredentialProviderError int errorCode,
|
||||
CharSequence message) {
|
||||
public void onFailure(String errorType, CharSequence message) {
|
||||
Log.i(TAG, "In onFailure in RemoteCredentialService");
|
||||
String errorMsg = message == null ? "" : String.valueOf(message);
|
||||
createCredentialFuture.completeExceptionally(
|
||||
new CredentialProviderException(errorCode, errorMsg));
|
||||
new CreateCredentialException(errorType, errorMsg));
|
||||
}});
|
||||
CompletableFuture<BeginCreateCredentialResponse> future = futureRef.get();
|
||||
if (future != null && future.isCancelled()) {
|
||||
@@ -209,22 +209,34 @@ public class RemoteCredentialService extends ServiceConnector.Impl<ICredentialPr
|
||||
dispatchCancellationSignal(cancellationSink.get());
|
||||
callback.onProviderResponseFailure(
|
||||
CredentialProviderException.ERROR_TIMEOUT,
|
||||
null,
|
||||
error.getMessage());
|
||||
} else if (error instanceof CancellationException) {
|
||||
Log.i(TAG, "In RemoteCredentialService execute error is cancellation");
|
||||
dispatchCancellationSignal(cancellationSink.get());
|
||||
callback.onProviderResponseFailure(
|
||||
CredentialProviderException.ERROR_TASK_CANCELED,
|
||||
null,
|
||||
error.getMessage());
|
||||
} else if (error instanceof CredentialProviderException) {
|
||||
Log.i(TAG, "In RemoteCredentialService execute error is provider error");
|
||||
callback.onProviderResponseFailure(((CredentialProviderException) error)
|
||||
.getErrorCode(),
|
||||
} else if (error instanceof GetCredentialException) {
|
||||
Log.i(TAG, "In RemoteCredentialService execute error is provider get"
|
||||
+ "error");
|
||||
callback.onProviderResponseFailure(
|
||||
CredentialProviderException.ERROR_PROVIDER_FAILURE,
|
||||
((GetCredentialException) error).errorType,
|
||||
error.getMessage());
|
||||
} else if (error instanceof CreateCredentialException) {
|
||||
Log.i(TAG, "In RemoteCredentialService execute error is provider create "
|
||||
+ "error");
|
||||
callback.onProviderResponseFailure(
|
||||
CredentialProviderException.ERROR_PROVIDER_FAILURE,
|
||||
((CreateCredentialException) error).errorType,
|
||||
error.getMessage());
|
||||
} else {
|
||||
Log.i(TAG, "In RemoteCredentialService execute error is unknown");
|
||||
callback.onProviderResponseFailure(
|
||||
CredentialProviderException.ERROR_UNKNOWN,
|
||||
null,
|
||||
error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user