diff options
| -rw-r--r-- | core/api/current.txt | 14 | ||||
| -rw-r--r-- | core/java/android/provider/ContactsContract.java | 297 |
2 files changed, 163 insertions, 148 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 1f5ea1081bc3..b8d625b70675 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -36912,13 +36912,17 @@ package android.provider { field public static final String CONTENT_DIRECTORY = "data"; } - @FlaggedApi("android.provider.new_default_account_api_enabled") public static final class ContactsContract.RawContacts.DefaultAccountAndState { - ctor public ContactsContract.RawContacts.DefaultAccountAndState(int, @Nullable android.accounts.Account); + @FlaggedApi("android.provider.new_default_account_api_enabled") public static final class ContactsContract.RawContacts.DefaultAccount { + ctor public ContactsContract.RawContacts.DefaultAccount(); + } + + @FlaggedApi("android.provider.new_default_account_api_enabled") public static final class ContactsContract.RawContacts.DefaultAccount.DefaultAccountAndState { + ctor public ContactsContract.RawContacts.DefaultAccount.DefaultAccountAndState(int, @Nullable android.accounts.Account); method @Nullable public android.accounts.Account getCloudAccount(); method public int getState(); - method @NonNull public static android.provider.ContactsContract.RawContacts.DefaultAccountAndState ofCloud(@NonNull android.accounts.Account); - method @NonNull public static android.provider.ContactsContract.RawContacts.DefaultAccountAndState ofLocal(); - method @NonNull public static android.provider.ContactsContract.RawContacts.DefaultAccountAndState ofNotSet(); + method @NonNull public static android.provider.ContactsContract.RawContacts.DefaultAccount.DefaultAccountAndState ofCloud(@NonNull android.accounts.Account); + method @NonNull public static android.provider.ContactsContract.RawContacts.DefaultAccount.DefaultAccountAndState ofLocal(); + method @NonNull public static android.provider.ContactsContract.RawContacts.DefaultAccount.DefaultAccountAndState ofNotSet(); field public static final int DEFAULT_ACCOUNT_STATE_CLOUD = 3; // 0x3 field public static final int DEFAULT_ACCOUNT_STATE_LOCAL = 2; // 0x2 field public static final int DEFAULT_ACCOUNT_STATE_NOT_SET = 1; // 0x1 diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index 01c230fe8f63..a62281049678 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -3018,169 +3018,180 @@ public final class ContactsContract { com.android.internal.R.string.config_rawContactsLocalAccountType)); } + + /** - * Represents the state of the default account, and the actual {@link Account} if it's - * a cloud account. - * If the default account is set to {@link #DEFAULT_ACCOUNT_STATE_LOCAL} or - * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}, new raw contacts requested for insertion - * without a - * specified {@link Account} will be saved in the default account. - * The default account can have one of the following four states: - * <ul> - * <li> {@link #DEFAULT_ACCOUNT_STATE_NOT_SET}: The default account has not - * been set by the user. </li> - * <li> {@link #DEFAULT_ACCOUNT_STATE_LOCAL}: The default account is set to - * the local device storage. New raw contacts requested for insertion without a - * specified - * {@link Account} will be saved in a null or custom local account. </li> - * <li> {@link #DEFAULT_ACCOUNT_STATE_CLOUD}: The default account is set to a - * cloud-synced account. New raw contacts requested for insertion without a specified - * {@link Account} will be saved in the default cloud account. </li> - * </ul> + * Class containing utility methods around the default account. + * New raw contacts requested to be inserted without a specified {@link Account} will be + * saved in the default account. */ @FlaggedApi(Flags.FLAG_NEW_DEFAULT_ACCOUNT_API_ENABLED) - public static final class DefaultAccountAndState { - /** A state indicating that default account is not set. */ - public static final int DEFAULT_ACCOUNT_STATE_NOT_SET = 1; - - /** A state indicating that default account is set to local device storage. */ - public static final int DEFAULT_ACCOUNT_STATE_LOCAL = 2; + public static final class DefaultAccount { /** - * A state indicating that the default account is set as an account that is synced - * to the cloud. - */ - public static final int DEFAULT_ACCOUNT_STATE_CLOUD = 3; + * Represents the state of the default account, and the actual {@link Account} if it's + * a cloud account. + * If the default account is set to {@link #DEFAULT_ACCOUNT_STATE_LOCAL} or + * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}, new raw contacts requested for insertion + * without a + * specified {@link Account} will be saved in the default account. + * The default account can have one of the following four states: + * <ul> + * <li> {@link #DEFAULT_ACCOUNT_STATE_NOT_SET}: The default account has not + * been set by the user. </li> + * <li> {@link #DEFAULT_ACCOUNT_STATE_LOCAL}: The default account is set to + * the local device storage. New raw contacts requested for insertion without a + * specified + * {@link Account} will be saved in a null or custom local account. </li> + * <li> {@link #DEFAULT_ACCOUNT_STATE_CLOUD}: The default account is set to a + * cloud-synced account. New raw contacts requested for insertion without a specified + * {@link Account} will be saved in the default cloud account. </li> + * </ul> + */ + @FlaggedApi(Flags.FLAG_NEW_DEFAULT_ACCOUNT_API_ENABLED) + public static final class DefaultAccountAndState { + /** A state indicating that default account is not set. */ + public static final int DEFAULT_ACCOUNT_STATE_NOT_SET = 1; + + /** A state indicating that default account is set to local device storage. */ + public static final int DEFAULT_ACCOUNT_STATE_LOCAL = 2; - /** - * The state of the default account. One of - * {@link #DEFAULT_ACCOUNT_STATE_NOT_SET}, - * {@link #DEFAULT_ACCOUNT_STATE_LOCAL} or - * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. - */ - @DefaultAccountState - private final int mState; + /** + * A state indicating that the default account is set as an account that is synced + * to the cloud. + */ + public static final int DEFAULT_ACCOUNT_STATE_CLOUD = 3; - /** - * The account of the default account, when {@link mState} is { - * - * @link #STATE_SET_TO_CLOUD}, or null otherwise. - */ - private final Account mCloudAccount; + /** + * The state of the default account. One of + * {@link #DEFAULT_ACCOUNT_STATE_NOT_SET}, + * {@link #DEFAULT_ACCOUNT_STATE_LOCAL} or + * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. + */ + @DefaultAccountState + private final int mState; - /** - * Constructs a new `DefaultAccountAndState` instance with the specified state and - * cloud - * account. - * - * @param state The state of the default account. - * @param cloudAccount The cloud account associated with the default account, - * or null if the state is not - * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. - */ - public DefaultAccountAndState(@DefaultAccountState int state, - @Nullable Account cloudAccount) { - if (!isValidDefaultAccountState(state)) { - throw new IllegalArgumentException("Invalid default account state."); + /** + * The account of the default account, when {@link mState} is { + * + * @link #STATE_SET_TO_CLOUD}, or null otherwise. + */ + private final Account mCloudAccount; + + /** + * Constructs a new `DefaultAccountAndState` instance with the specified state and + * cloud + * account. + * + * @param state The state of the default account. + * @param cloudAccount The cloud account associated with the default account, + * or null if the state is not + * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. + */ + public DefaultAccountAndState(@DefaultAccountState int state, + @Nullable Account cloudAccount) { + if (!isValidDefaultAccountState(state)) { + throw new IllegalArgumentException("Invalid default account state."); + } + if ((state == DEFAULT_ACCOUNT_STATE_CLOUD) != (cloudAccount != null)) { + throw new IllegalArgumentException( + "Default account can be set to cloud if and only if the cloud " + + "account is provided."); + } + this.mState = state; + this.mCloudAccount = + (mState == DEFAULT_ACCOUNT_STATE_CLOUD) ? cloudAccount : null; } - if ((state == DEFAULT_ACCOUNT_STATE_CLOUD) != (cloudAccount != null)) { - throw new IllegalArgumentException( - "Default account can be set to cloud if and only if the cloud " - + "account is provided."); + + /** + * Creates a `DefaultAccountAndState` instance representing a default account + * that is set to the cloud and associated with the specified cloud account. + * + * @param cloudAccount The non-null cloud account associated with the default + * contacts + * account. + * @return A new `DefaultAccountAndState` instance with state + * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. + */ + public static @NonNull DefaultAccountAndState ofCloud( + @NonNull Account cloudAccount) { + return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_CLOUD, cloudAccount); } - this.mState = state; - this.mCloudAccount = - (mState == DEFAULT_ACCOUNT_STATE_CLOUD) ? cloudAccount : null; - } - /** - * Creates a `DefaultAccountAndState` instance representing a default account - * that is set to the cloud and associated with the specified cloud account. - * - * @param cloudAccount The non-null cloud account associated with the default - * contacts - * account. - * @return A new `DefaultAccountAndState` instance with state - * {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. - */ - public static @NonNull DefaultAccountAndState ofCloud( - @NonNull Account cloudAccount) { - return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_CLOUD, cloudAccount); - } + /** + * Creates a `DefaultAccountAndState` instance representing a default account + * that is set to the local device storage. + * + * @return A new `DefaultAccountAndState` instance with state + * {@link #DEFAULT_ACCOUNT_STATE_LOCAL}. + */ + public static @NonNull DefaultAccountAndState ofLocal() { + return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_LOCAL, null); + } - /** - * Creates a `DefaultAccountAndState` instance representing a default account - * that is set to the local device storage. - * - * @return A new `DefaultAccountAndState` instance with state - * {@link #DEFAULT_ACCOUNT_STATE_LOCAL}. - */ - public static @NonNull DefaultAccountAndState ofLocal() { - return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_LOCAL, null); - } + /** + * Creates a `DefaultAccountAndState` instance representing a default account + * that is not set. + * + * @return A new `DefaultAccountAndState` instance with state + * {@link #DEFAULT_ACCOUNT_STATE_NOT_SET}. + */ + public static @NonNull DefaultAccountAndState ofNotSet() { + return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_NOT_SET, null); + } - /** - * Creates a `DefaultAccountAndState` instance representing a default account - * that is not set. - * - * @return A new `DefaultAccountAndState` instance with state - * {@link #DEFAULT_ACCOUNT_STATE_NOT_SET}. - */ - public static @NonNull DefaultAccountAndState ofNotSet() { - return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_NOT_SET, null); - } + /** + * @return the state of the default account. + */ + @DefaultAccountState + public int getState() { + return mState; + } - /** - * @return the state of the default account. - */ - @DefaultAccountState - public int getState() { - return mState; - } + /** + * @return the cloud account associated with the default account, or null if the + * state is not {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. + */ + public @Nullable Account getCloudAccount() { + return mCloudAccount; + } - /** - * @return the cloud account associated with the default account, or null if the - * state is not {@link #DEFAULT_ACCOUNT_STATE_CLOUD}. - */ - public @Nullable Account getCloudAccount() { - return mCloudAccount; - } + @Override + public int hashCode() { + return Objects.hash(mState, mCloudAccount); + } - @Override - public int hashCode() { - return Objects.hash(mState, mCloudAccount); - } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof DefaultAccountAndState that)) { + return false; + } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof DefaultAccountAndState that)) { - return false; + return mState == that.mState && Objects.equals(mCloudAccount, + that.mCloudAccount); } - return mState == that.mState && Objects.equals(mCloudAccount, - that.mCloudAccount); - } - - private static boolean isValidDefaultAccountState(int state) { - return state == DEFAULT_ACCOUNT_STATE_NOT_SET - || state == DEFAULT_ACCOUNT_STATE_LOCAL - || state == DEFAULT_ACCOUNT_STATE_CLOUD; - } + private static boolean isValidDefaultAccountState(int state) { + return state == DEFAULT_ACCOUNT_STATE_NOT_SET + || state == DEFAULT_ACCOUNT_STATE_LOCAL + || state == DEFAULT_ACCOUNT_STATE_CLOUD; + } - /** - * Annotation for all default account states. - * - * @hide - */ - @Retention(RetentionPolicy.SOURCE) - @IntDef( - prefix = {"DEFAULT_ACCOUNT_STATE_"}, - value = {DEFAULT_ACCOUNT_STATE_NOT_SET, - DEFAULT_ACCOUNT_STATE_LOCAL, DEFAULT_ACCOUNT_STATE_CLOUD}) - public @interface DefaultAccountState { + /** + * Annotation for all default account states. + * + * @hide + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef( + prefix = {"DEFAULT_ACCOUNT_STATE_"}, + value = {DEFAULT_ACCOUNT_STATE_NOT_SET, + DEFAULT_ACCOUNT_STATE_LOCAL, DEFAULT_ACCOUNT_STATE_CLOUD}) + public @interface DefaultAccountState { + } } } |