Merge "Make framework classes non final"
diff --git a/core/api/current.txt b/core/api/current.txt
index 6393973..7113150 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -39711,7 +39711,7 @@
 
 package android.service.credentials {
 
-  public final class Action implements android.os.Parcelable {
+  public class Action implements android.os.Parcelable {
     ctor public Action(@NonNull android.app.slice.Slice, @NonNull android.app.PendingIntent);
     method public int describeContents();
     method @NonNull public android.app.PendingIntent getPendingIntent();
@@ -39720,7 +39720,7 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.Action> CREATOR;
   }
 
-  public final class BeginCreateCredentialRequest implements android.os.Parcelable {
+  public class BeginCreateCredentialRequest implements android.os.Parcelable {
     ctor public BeginCreateCredentialRequest(@NonNull android.service.credentials.CallingAppInfo, @NonNull String, @NonNull android.os.Bundle);
     method public int describeContents();
     method @NonNull public android.service.credentials.CallingAppInfo getCallingAppInfo();
@@ -39746,7 +39746,7 @@
     method @NonNull public android.service.credentials.BeginCreateCredentialResponse.Builder setRemoteCreateEntry(@Nullable android.service.credentials.CreateEntry);
   }
 
-  public final class BeginGetCredentialOption implements android.os.Parcelable {
+  public class BeginGetCredentialOption implements android.os.Parcelable {
     ctor public BeginGetCredentialOption(@NonNull String, @NonNull android.os.Bundle);
     method public int describeContents();
     method @NonNull public android.os.Bundle getCandidateQueryData();
@@ -39808,7 +39808,7 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.CreateCredentialRequest> CREATOR;
   }
 
-  public final class CreateEntry implements android.os.Parcelable {
+  public class CreateEntry implements android.os.Parcelable {
     ctor public CreateEntry(@NonNull android.app.slice.Slice, @NonNull android.app.PendingIntent);
     method public int describeContents();
     method @NonNull public android.app.PendingIntent getPendingIntent();
@@ -39817,7 +39817,8 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.CreateEntry> CREATOR;
   }
 
-  public final class CredentialEntry implements android.os.Parcelable {
+  public class CredentialEntry implements android.os.Parcelable {
+    ctor public CredentialEntry(@NonNull String, @NonNull android.app.slice.Slice, @NonNull android.app.PendingIntent, boolean);
     method public int describeContents();
     method @NonNull public android.app.PendingIntent getPendingIntent();
     method @NonNull public android.app.slice.Slice getSlice();
@@ -39827,12 +39828,6 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.service.credentials.CredentialEntry> CREATOR;
   }
 
-  public static final class CredentialEntry.Builder {
-    ctor public CredentialEntry.Builder(@NonNull String, @NonNull android.app.slice.Slice, @NonNull android.app.PendingIntent);
-    method @NonNull public android.service.credentials.CredentialEntry build();
-    method @NonNull public android.service.credentials.CredentialEntry.Builder setAutoSelectAllowed(@NonNull boolean);
-  }
-
   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.credentials.CreateCredentialException>);
diff --git a/core/java/android/service/credentials/Action.java b/core/java/android/service/credentials/Action.java
index 878df4b..e187505 100644
--- a/core/java/android/service/credentials/Action.java
+++ b/core/java/android/service/credentials/Action.java
@@ -17,6 +17,7 @@
 package android.service.credentials;
 
 import android.annotation.NonNull;
+import android.annotation.SuppressLint;
 import android.app.PendingIntent;
 import android.app.slice.Slice;
 import android.os.Parcel;
@@ -27,8 +28,14 @@
 /**
  * An action defined by the provider that intents into the provider's app for specific
  * user actions.
+ *
+ * <p>Any class that derives this class must only add extra field values to the {@code slice}
+ * object passed into the constructor. Any other field will not be parceled through. If the
+ * derived class has custom parceling implementation, this class will not be able to unpack
+ * the parcel without having access to that implementation.
  */
-public final class Action implements Parcelable {
+@SuppressLint("ParcelNotFinal")
+public class Action implements Parcelable {
     /** Slice object containing display content to be displayed with this action on the UI. */
     private final @NonNull Slice mSlice;
     /** The pending intent to be invoked when the user selects this action. */
diff --git a/core/java/android/service/credentials/BeginCreateCredentialRequest.java b/core/java/android/service/credentials/BeginCreateCredentialRequest.java
index d976813..348bb2b 100644
--- a/core/java/android/service/credentials/BeginCreateCredentialRequest.java
+++ b/core/java/android/service/credentials/BeginCreateCredentialRequest.java
@@ -17,6 +17,7 @@
 package android.service.credentials;
 
 import android.annotation.NonNull;
+import android.annotation.SuppressLint;
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -29,8 +30,14 @@
  * Request for beginning a create credential request.
  *
  * See {@link BeginCreateCredentialResponse} for the counterpart response
+ *
+ * <p>Any class that derives this class must only add extra field values to the {@code slice}
+ * object passed into the constructor. Any other field will not be parceled through. If the
+ * derived class has custom parceling implementation, this class will not be able to unpack
+ * the parcel without having access to that implementation.
  */
-public final class BeginCreateCredentialRequest implements Parcelable {
+@SuppressLint("ParcelNotFinal")
+public class BeginCreateCredentialRequest implements Parcelable {
     private final @NonNull CallingAppInfo mCallingAppInfo;
     private final @NonNull String mType;
     private final @NonNull Bundle mData;
diff --git a/core/java/android/service/credentials/BeginGetCredentialOption.java b/core/java/android/service/credentials/BeginGetCredentialOption.java
index 74ac6c4..65d63c3 100644
--- a/core/java/android/service/credentials/BeginGetCredentialOption.java
+++ b/core/java/android/service/credentials/BeginGetCredentialOption.java
@@ -19,6 +19,7 @@
 import static java.util.Objects.requireNonNull;
 
 import android.annotation.NonNull;
+import android.annotation.SuppressLint;
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -30,8 +31,14 @@
  * 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 BeginGetCredentialResponse}.
+ *
+ * <p>Any class that derives this class must only add extra field values to the {@code slice}
+ * object passed into the constructor. Any other field will not be parceled through. If the
+ * derived class has custom parceling implementation, this class will not be able to unpack
+ * the parcel without having access to that implementation.
  */
-public final class BeginGetCredentialOption implements Parcelable {
+@SuppressLint("ParcelNotFinal")
+public class BeginGetCredentialOption implements Parcelable {
 
     /**
      * The requested credential type.
diff --git a/core/java/android/service/credentials/CreateEntry.java b/core/java/android/service/credentials/CreateEntry.java
index eb25e25..84a5f1c 100644
--- a/core/java/android/service/credentials/CreateEntry.java
+++ b/core/java/android/service/credentials/CreateEntry.java
@@ -17,6 +17,7 @@
 package android.service.credentials;
 
 import android.annotation.NonNull;
+import android.annotation.SuppressLint;
 import android.app.PendingIntent;
 import android.app.slice.Slice;
 import android.os.Parcel;
@@ -25,8 +26,14 @@
 /**
  * An entry to be shown on the UI. This entry represents where the credential to be created will
  * be stored. Examples include user's account, family group etc.
+ *
+ * <p>Any class that derives this class must only add extra field values to the {@code slice}
+ * object passed into the constructor. Any other field will not be parceled through. If the
+ * derived class has custom parceling implementation, this class will not be able to unpack
+ * the parcel without having access to that implementation.
  */
-public final class CreateEntry implements Parcelable {
+@SuppressLint("ParcelNotFinal")
+public class CreateEntry implements Parcelable {
     private final @NonNull Slice mSlice;
     private final @NonNull PendingIntent mPendingIntent;
 
diff --git a/core/java/android/service/credentials/CredentialEntry.java b/core/java/android/service/credentials/CredentialEntry.java
index 3c399d2..21e7b80 100644
--- a/core/java/android/service/credentials/CredentialEntry.java
+++ b/core/java/android/service/credentials/CredentialEntry.java
@@ -17,6 +17,7 @@
 package android.service.credentials;
 
 import android.annotation.NonNull;
+import android.annotation.SuppressLint;
 import android.app.PendingIntent;
 import android.app.slice.Slice;
 import android.credentials.GetCredentialResponse;
@@ -28,10 +29,25 @@
 import java.util.Objects;
 
 /**
- * A credential entry that is displayed on the account selector UI. Each entry corresponds to
- * something that the user can select.
+ * A credential entry that is to be displayed on the account selector that is presented to the
+ * user.
+ *
+ * <p>If user selects this entry, the corresponding {@code pendingIntent} will be invoked to
+ * launch activities that require some user engagement before getting the credential
+ * corresponding to this entry, e.g. authentication, confirmation etc.
+ *
+ * Once the activity fulfills the required user engagement, the {@link android.app.Activity}
+ * result should be set to {@link android.app.Activity#RESULT_OK}, and the
+ * {@link CredentialProviderService#EXTRA_GET_CREDENTIAL_RESPONSE} must be set with a
+ * {@link GetCredentialResponse} object.
+ *
+ * <p>Any class that derives this class must only add extra field values to the {@code slice}
+ * object passed into the constructor. Any other field will not be parceled through. If the
+ * derived class has custom parceling implementation, this class will not be able to unpack
+ * the parcel without having access to that implementation.
  */
-public final class CredentialEntry implements Parcelable {
+@SuppressLint("ParcelNotFinal")
+public class CredentialEntry implements Parcelable {
     /** The type of the credential entry to be shown on the UI. */
     private final @NonNull String mType;
 
@@ -43,13 +59,25 @@
     private final @NonNull PendingIntent mPendingIntent;
 
     /** A flag denoting whether auto-select is enabled for this entry. */
-    private final @NonNull boolean mAutoSelectAllowed;
+    private final boolean mAutoSelectAllowed;
 
-    private CredentialEntry(@NonNull String type, @NonNull Slice slice,
-            @NonNull PendingIntent pendingIntent, @NonNull boolean autoSelectAllowed) {
-        mType = type;
-        mSlice = slice;
-        mPendingIntent = pendingIntent;
+    /**
+     * Constructs an instance of the credential entry to be displayed on the UI
+     * @param type the type of credential underlying this credential entry
+     * @param slice the content to be displayed with this entry on the UI
+     * @param pendingIntent the pendingIntent to be invoked when this entry is selected by the user
+     * @param autoSelectAllowed whether this entry should be auto selected if it is the only one
+     *                          on the selector
+     *
+     * @throws NullPointerException If {@code slice}, or {@code pendingIntent} is null.
+     * @throws IllegalArgumentException If {@code type} is null or empty, or if
+     * {@code pendingIntent} is null.
+     */
+    public CredentialEntry(@NonNull String type, @NonNull Slice slice,
+            @NonNull PendingIntent pendingIntent, boolean autoSelectAllowed) {
+        mType = Preconditions.checkStringNotEmpty(type, "type must not be null");
+        mSlice = Objects.requireNonNull(slice, "slice must not be null");
+        mPendingIntent = Objects.requireNonNull(pendingIntent, "pendingintent must not be null");
         mAutoSelectAllowed = autoSelectAllowed;
     }
 
@@ -113,76 +141,4 @@
     public boolean isAutoSelectAllowed() {
         return mAutoSelectAllowed;
     }
-
-    /**
-     * Builder for {@link CredentialEntry}.
-     */
-    public static final class Builder {
-        private String mType;
-        private Slice mSlice;
-        private PendingIntent mPendingIntent;
-        private boolean mAutoSelectAllowed = false;
-
-        /**
-         * Creates a builder for a {@link CredentialEntry} that should invoke a
-         * {@link PendingIntent} when selected by the user.
-         *
-         * <p>The {@code pendingIntent} can be used to launch activities that require some user
-         * engagement before getting the credential corresponding to this entry,
-         * e.g. authentication, confirmation etc.
-         * Once the activity fulfills the required user engagement, the
-         * {@link android.app.Activity} result should be set to
-         * {@link android.app.Activity#RESULT_OK}, and the
-         * {@link CredentialProviderService#EXTRA_GET_CREDENTIAL_RESPONSE} must be set with a
-         * {@link GetCredentialResponse} object.
-         *
-         * @param type the type of credential underlying this credential entry
-         * @param slice the content to be displayed with this entry on the UI
-         * @param pendingIntent the pendingIntent to be invoked when this entry is selected by the
-         *                      user
-         *
-         * @throws NullPointerException If {@code slice}, or {@code pendingIntent} is null.
-         * @throws IllegalArgumentException If {@code type} is null or empty, or if
-         * {@code pendingIntent} was not created with {@link PendingIntent#getActivity}
-         * or {@link PendingIntent#getActivities}.
-         */
-        public Builder(@NonNull String type, @NonNull Slice slice,
-                @NonNull PendingIntent pendingIntent) {
-            mType = Preconditions.checkStringNotEmpty(type, "type must not be "
-                    + "null, or empty");
-            mSlice = Objects.requireNonNull(slice,
-                    "slice must not be null");
-            mPendingIntent = Objects.requireNonNull(pendingIntent,
-                    "pendingIntent must not be null");
-            if (!mPendingIntent.isActivity()) {
-                throw new IllegalStateException("Pending intent must start an activity");
-            }
-        }
-
-        /**
-         * Sets whether the entry is allowed to be auto selected by the framework.
-         * The default value is set to false.
-         *
-         * <p> The entry is only auto selected if it is the only entry on the user selector,
-         * AND the developer has also enabled auto select, while building the request.
-         */
-        public @NonNull Builder setAutoSelectAllowed(@NonNull boolean autoSelectAllowed) {
-            mAutoSelectAllowed = autoSelectAllowed;
-            return this;
-        }
-
-        /**
-         * Creates a new {@link CredentialEntry} instance.
-         *
-         * @throws NullPointerException If {@code slice} is null.
-         * @throws IllegalArgumentException If {@code type} is null, or empty.
-         * @throws IllegalStateException If neither {@code pendingIntent} nor {@code credential}
-         * is set, or if both are set.
-         */
-        public @NonNull CredentialEntry build() {
-            Preconditions.checkState(mPendingIntent != null,
-                    "pendingIntent must not be null");
-            return new CredentialEntry(mType, mSlice, mPendingIntent, mAutoSelectAllowed);
-        }
-    }
 }