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

Commit 7a23baed authored by Liefu Liu's avatar Liefu Liu Committed by Christopher Werner
Browse files

Changes in ContactsContract to support SIM in getDefaultAccountForNewContacts and

setDefaultAccountForNewContacts.

Bug: 368127857
Test: cts test (atest
CtsContactsProviderTestCases:ContactsContract_DefaultAccountTest)
Flag:android.provider.new_default_account_api_enabled

	modified:   core/java/android/provider/ContactsContract.java

Change-Id: If90fb3cb03be3899489a71838952ca7444140db4
parent e0dbf7e2
Loading
Loading
Loading
Loading
+16 −16
Original line number Original line Diff line number Diff line
@@ -3209,7 +3209,11 @@ public final class ContactsContract {
                    return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_NOT_SET, null);
                    return new DefaultAccountAndState(DEFAULT_ACCOUNT_STATE_NOT_SET, null);
                }
                }


                private static boolean isCloudOrSimAccount(@DefaultAccountState int state) {
                /**
                 *
                 * @hide
                 */
                public static boolean isCloudOrSimAccount(@DefaultAccountState int state) {
                    return state == DEFAULT_ACCOUNT_STATE_CLOUD
                    return state == DEFAULT_ACCOUNT_STATE_CLOUD
                            || state == DEFAULT_ACCOUNT_STATE_SIM;
                            || state == DEFAULT_ACCOUNT_STATE_SIM;
                }
                }
@@ -3287,23 +3291,20 @@ public final class ContactsContract {
                Bundle response = nullSafeCall(resolver, ContactsContract.AUTHORITY_URI,
                Bundle response = nullSafeCall(resolver, ContactsContract.AUTHORITY_URI,
                        QUERY_DEFAULT_ACCOUNT_FOR_NEW_CONTACTS_METHOD, null, null);
                        QUERY_DEFAULT_ACCOUNT_FOR_NEW_CONTACTS_METHOD, null, null);


                int defaultContactsAccountState = response.getInt(KEY_DEFAULT_ACCOUNT_STATE, -1);
                int defaultAccountState = response.getInt(KEY_DEFAULT_ACCOUNT_STATE, -1);
                if (defaultContactsAccountState
                if (DefaultAccountAndState.isCloudOrSimAccount(defaultAccountState)) {
                        == DefaultAccountAndState.DEFAULT_ACCOUNT_STATE_CLOUD) {
                    String accountName = response.getString(Settings.ACCOUNT_NAME);
                    String accountName = response.getString(Settings.ACCOUNT_NAME);
                    String accountType = response.getString(Settings.ACCOUNT_TYPE);
                    String accountType = response.getString(Settings.ACCOUNT_TYPE);
                    if (TextUtils.isEmpty(accountName) || TextUtils.isEmpty(accountType)) {
                    if (TextUtils.isEmpty(accountName) || TextUtils.isEmpty(accountType)) {
                        throw new IllegalStateException(
                        throw new IllegalStateException(
                                "account name and type cannot be null or empty");
                                "account name and type cannot be null or empty");
                    }
                    }
                    return new DefaultAccountAndState(
                    return new DefaultAccountAndState(defaultAccountState,
                            DefaultAccountAndState.DEFAULT_ACCOUNT_STATE_CLOUD,
                            new Account(accountName, accountType));
                            new Account(accountName, accountType));
                } else if (defaultContactsAccountState
                } else if (defaultAccountState == DefaultAccountAndState.DEFAULT_ACCOUNT_STATE_LOCAL
                        == DefaultAccountAndState.DEFAULT_ACCOUNT_STATE_LOCAL
                        || defaultAccountState
                        || defaultContactsAccountState
                        == DefaultAccountAndState.DEFAULT_ACCOUNT_STATE_NOT_SET) {
                        == DefaultAccountAndState.DEFAULT_ACCOUNT_STATE_NOT_SET) {
                    return new DefaultAccountAndState(defaultContactsAccountState, /*cloudAccount=*/
                    return new DefaultAccountAndState(defaultAccountState, /*account=*/
                            null);
                            null);
                } else {
                } else {
                    throw new IllegalStateException("Invalid default account state");
                    throw new IllegalStateException("Invalid default account state");
@@ -3348,12 +3349,11 @@ public final class ContactsContract {
                Bundle extras = new Bundle();
                Bundle extras = new Bundle();


                extras.putInt(KEY_DEFAULT_ACCOUNT_STATE, defaultAccountAndState.getState());
                extras.putInt(KEY_DEFAULT_ACCOUNT_STATE, defaultAccountAndState.getState());
                if (defaultAccountAndState.getState()
                if (DefaultAccountAndState.isCloudOrSimAccount(defaultAccountAndState.getState())) {
                        == DefaultAccountAndState.DEFAULT_ACCOUNT_STATE_CLOUD) {
                    Account account = defaultAccountAndState.getAccount();
                    Account cloudAccount = defaultAccountAndState.getAccount();
                    assert account != null;
                    assert cloudAccount != null;
                    extras.putString(Settings.ACCOUNT_NAME, account.name);
                    extras.putString(Settings.ACCOUNT_NAME, cloudAccount.name);
                    extras.putString(Settings.ACCOUNT_TYPE, account.type);
                    extras.putString(Settings.ACCOUNT_TYPE, cloudAccount.type);
                }
                }
                nullSafeCall(resolver, ContactsContract.AUTHORITY_URI,
                nullSafeCall(resolver, ContactsContract.AUTHORITY_URI,
                        SET_DEFAULT_ACCOUNT_FOR_NEW_CONTACTS_METHOD, null, extras);
                        SET_DEFAULT_ACCOUNT_FOR_NEW_CONTACTS_METHOD, null, extras);