Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20ff3551 authored by Helen Qin's avatar Helen Qin
Browse files

Framework credential manager developer APIs definitions.

The CredentialManager module provides solution for developers to create
or get credential from a user that can be used to authenticate to the app.
It can potentially launch system level UI flows to collect user consent,
render a unified selector when more than one credential exists, and
perform anything else needed.

Check bug id for detailed design.

Note that this is still very early stage of productionizing the module
and proper test cases will be added subsequently when the service
gets more concrete business logic.

Bug: 246564035
CTS-Coverage-Bug: 246637346
Test: Local Build & Deployment
Change-Id: Ia5884a7f6a3908de3b8b4b29f154f98e25730bd7
parent 09ebd974
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
@@ -9820,6 +9820,7 @@ package android.content {
    field public static final int CONTEXT_IGNORE_SECURITY = 2; // 0x2
    field public static final int CONTEXT_INCLUDE_CODE = 1; // 0x1
    field public static final int CONTEXT_RESTRICTED = 4; // 0x4
    field public static final String CREDENTIAL_SERVICE = "credential";
    field public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
    field public static final String DEVICE_POLICY_SERVICE = "device_policy";
    field public static final String DISPLAY_HASH_SERVICE = "display_hash";
@@ -12879,6 +12880,82 @@ package android.content.res.loader {
}
package android.credentials {
  public final class CreateCredentialRequest implements android.os.Parcelable {
    ctor public CreateCredentialRequest(@NonNull String, @NonNull android.os.Bundle);
    method public int describeContents();
    method @NonNull public android.os.Bundle getData();
    method @NonNull public String getType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.CreateCredentialRequest> CREATOR;
  }
  public final class CreateCredentialResponse implements android.os.Parcelable {
    ctor public CreateCredentialResponse(@NonNull android.os.Bundle);
    method public int describeContents();
    method @NonNull public android.os.Bundle getData();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.CreateCredentialResponse> CREATOR;
  }
  public final class Credential implements android.os.Parcelable {
    ctor public Credential(@NonNull String, @NonNull android.os.Bundle);
    method public int describeContents();
    method @NonNull public android.os.Bundle getData();
    method @NonNull public String getType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.Credential> CREATOR;
  }
  public final class CredentialManager {
    method public void executeCreateCredential(@NonNull android.credentials.CreateCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.CreateCredentialResponse,android.credentials.CredentialManagerException>);
    method public void executeGetCredential(@NonNull android.credentials.GetCredentialRequest, @Nullable android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.os.OutcomeReceiver<android.credentials.GetCredentialResponse,android.credentials.CredentialManagerException>);
  }
  public class CredentialManagerException extends java.lang.Exception {
    ctor public CredentialManagerException(int, @Nullable String);
    ctor public CredentialManagerException(int, @Nullable String, @Nullable Throwable);
    ctor public CredentialManagerException(int, @Nullable Throwable);
    ctor public CredentialManagerException(int);
    field public static final int ERROR_UNKNOWN = 0; // 0x0
    field public final int errorCode;
  }
  public final class GetCredentialOption implements android.os.Parcelable {
    ctor public GetCredentialOption(@NonNull String, @NonNull android.os.Bundle);
    method public int describeContents();
    method @NonNull public android.os.Bundle getData();
    method @NonNull public String getType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.GetCredentialOption> CREATOR;
  }
  public final class GetCredentialRequest implements android.os.Parcelable {
    method public int describeContents();
    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.credentials.GetCredentialRequest> CREATOR;
  }
  public static final class GetCredentialRequest.Builder {
    ctor public GetCredentialRequest.Builder();
    method @NonNull public android.credentials.GetCredentialRequest.Builder addGetCredentialOption(@NonNull android.credentials.GetCredentialOption);
    method @NonNull public android.credentials.GetCredentialRequest build();
    method @NonNull public android.credentials.GetCredentialRequest.Builder setGetCredentialOptions(@NonNull java.util.List<android.credentials.GetCredentialOption>);
  }
  public final class GetCredentialResponse implements android.os.Parcelable {
    ctor public GetCredentialResponse(@NonNull android.credentials.Credential);
    ctor public GetCredentialResponse();
    method public int describeContents();
    method @Nullable public android.credentials.Credential getCredential();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.credentials.GetCredentialResponse> CREATOR;
  }
}
package android.database {
  public abstract class AbstractCursor implements android.database.CrossProcessCursor {
+11 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.credentials.CredentialManager;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
@@ -3933,6 +3934,7 @@ public abstract class Context {
            //@hide: ATTESTATION_VERIFICATION_SERVICE,
            //@hide: SAFETY_CENTER_SERVICE,
            DISPLAY_HASH_SERVICE,
            CREDENTIAL_SERVICE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ServiceName {}
@@ -6058,6 +6060,15 @@ public abstract class Context {
     */
    public static final String HEALTHCONNECT_SERVICE = "healthconnect";

    /**
     * Use with {@link #getSystemService(String)} to retrieve a
     * {@link android.credentials.CredentialManager} to authenticate a user to your app.
     *
     * @see #getSystemService(String)
     * @see CredentialManager
     */
    public static final String CREDENTIAL_SERVICE = "credential";

    /**
     * Determine whether the given permission is allowed for a particular
     * process and user ID running in the system.
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.credentials;

parcelable CreateCredentialRequest;
 No newline at end of file
+114 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.credentials;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.AnnotationValidations;
import com.android.internal.util.Preconditions;

/**
 * A request to register a specific type of user credential, potentially launching UI flows to
 * collect user consent and any other operation needed.
 */
public final class CreateCredentialRequest implements Parcelable {

    /**
     * The requested credential type.
     */
    @NonNull
    private final String mType;

    /**
     * The request data.
     */
    @NonNull
    private final Bundle mData;

    /**
     * Returns the requested credential type.
     */
    @NonNull
    public String getType() {
        return mType;
    }

    /**
     * Returns the request data.
     */
    @NonNull
    public Bundle getData() {
        return mData;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString8(mType);
        dest.writeBundle(mData);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public String toString() {
        return "CreateCredentialRequest {" + "type=" + mType + ", data=" + mData + "}";
    }

    /**
     * Constructs a {@link CreateCredentialRequest}.
     *
     * @param type the requested credential type.
     * @param data the request data.
     *
     * @throws IllegalArgumentException If type is empty.
     */
    public CreateCredentialRequest(@NonNull String type, @NonNull Bundle data) {
        mType = Preconditions.checkStringNotEmpty(type, "type must not be empty");
        mData = requireNonNull(data, "data must not be null");
    }

    private CreateCredentialRequest(@NonNull Parcel in) {
        String type = in.readString8();
        Bundle data = in.readBundle();

        mType = type;
        AnnotationValidations.validate(NonNull.class, null, mType);
        mData = data;
        AnnotationValidations.validate(NonNull.class, null, mData);
    }

    public static final @NonNull Parcelable.Creator<CreateCredentialRequest> CREATOR =
            new Parcelable.Creator<CreateCredentialRequest>() {
        @Override
        public CreateCredentialRequest[] newArray(int size) {
            return new CreateCredentialRequest[size];
        }

        @Override
        public CreateCredentialRequest createFromParcel(@NonNull Parcel in) {
            return new CreateCredentialRequest(in);
        }
    };
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.credentials;

parcelable CreateCredentialResponse;
 No newline at end of file
Loading