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

Commit 2aae8e5b authored by Jordan Hayes's avatar Jordan Hayes
Browse files

Integrate CP2 Android B Default Account APIs

Sdk 36 introduced new APIs for managing the default account for new
contacts that change the behavior of CP2 when certain default accounts
are set,
https://developer.android.com/identity/providers/contacts-provider/contacts-storage-locations?hl=en.

The app now delegates to the default account picker in CP2 whenever the
user would have been prompted to set a default account, e.g. when
inserting without a default or through app settings.

Since CP2 does not allow new contacts in local accounts when the
default account is set to a cloud, the app hides these accounts
during insert flows.

Bug: 402284112
Test: manual and ran test suite
Flag: NONE unflaggable OS requirements
Change-Id: I39d7a879b5972f78dc690006535a3a3fa13f5bac
parent a01ad58f
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -392,13 +392,6 @@

        </activity-alias>

        <!-- Accounts changed prompt that can appear when creating a new contact. -->
        <activity
            android:name=".activities.ContactEditorAccountsChangedActivity"
            android:exported="false"
            android:theme="@style/ContactEditorAccountsChangedActivityTheme"
            android:windowSoftInputMode="adjustResize"/>

        <!-- Edit or create a contact with only the most important fields displayed initially. -->
        <activity
            android:name=".activities.ContactEditorActivity"
+0 −8
Original line number Diff line number Diff line
@@ -289,14 +289,6 @@
        <item name="android:windowCloseOnTouchOutside">true</item>
    </style>

    <style name="ContactEditorAccountsChangedActivityTheme" parent="@android:style/Theme.Material.Light.Dialog.NoActionBar.MinWidth">
        <item name="android:windowCloseOnTouchOutside">true</item>
        <item name="android:textColorPrimary">@color/primary_text_color</item>
        <item name="android:textColorSecondary">@color/secondary_text_color</item>
        <item name="android:listViewStyle">@style/ListViewStyle</item>
        <item name="android:colorAccent">@color/primary_color</item>
    </style>

    <style name="SelectableItem" parent="@android:style/Theme.Material.Light">
        <item name="android:background">?android:attr/selectableItemBackground</item>
    </style>
+2 −3
Original line number Diff line number Diff line
@@ -26,11 +26,10 @@
        android:title="@string/settings_accounts">
    </Preference>

    <com.android.contacts.preference.DefaultAccountPreference
    <Preference
        android:icon="@null"
        android:key="defaultAccount"
        android:title="@string/default_editor_account"
        android:dialogTitle="@string/default_editor_account" />
        android:title="@string/default_editor_account" />

    <Preference
        android:icon="@null"
+1 −1
Original line number Diff line number Diff line
@@ -471,7 +471,7 @@ public class SimImportFragment extends Fragment
            final ListenableFuture<List<Object>> future =
                    Futures.<Object>allAsList(
                            mAccountTypeManager.filterAccountsAsync(
                                    AccountTypeManager.writableFilter()),
                                    AccountTypeManager.insertableFilter(getContext())),
                            ContactsExecutors.getSimReadExecutor()
                                    .<Object>submit(
                                            new Callable<Object>() {
+8 −18
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.contacts.activities;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -32,8 +31,8 @@ import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.DisplayPhoto;
import android.provider.ContactsContract.Intents;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.Settings;
import android.util.Log;
import android.widget.Toast;

@@ -52,6 +51,7 @@ import com.android.contacts.model.ValuesDelta;
import com.android.contacts.model.account.AccountInfo;
import com.android.contacts.model.account.AccountType;
import com.android.contacts.model.account.AccountWithDataSet;
import com.android.contacts.preference.ContactsPreferences;
import com.android.contacts.util.ContactPhotoUtils;

import com.google.common.base.Preconditions;
@@ -140,7 +140,7 @@ public class AttachPhotoActivity extends ContactsActivity {
        // Start loading accounts in case they are needed.
        mAccountsFuture =
                AccountTypeManager.getInstance(this)
                        .filterAccountsAsync(AccountTypeManager.writableFilter());
                        .filterAccountsAsync(AccountTypeManager.insertableFilter(this));
    }

    @Override
@@ -160,23 +160,14 @@ public class AttachPhotoActivity extends ContactsActivity {
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent result) {
        if (requestCode == REQUEST_PICK_DEFAULT_ACCOUNT_FOR_NEW_CONTACT) {
            AccountWithDataSet defaultAccount = new ContactsPreferences(this).getDefaultAccount();
            // Bail if the account selector was not successful.
            if (resultCode != Activity.RESULT_OK) {
            if (defaultAccount == null) {
                Log.w(TAG, "account selector was not successful");
                finish();
                return;
            }
            // If there's an account specified, use it.
            if (result != null) {
                AccountWithDataSet account =
                        result.getParcelableExtra(Intents.Insert.EXTRA_ACCOUNT);
                if (account != null) {
                    createNewRawContact(account);
                    return;
                }
            }
            // If there isn't an account specified, then the user opted to keep the contact local.
            createNewRawContact(null);
            createNewRawContact(defaultAccount);
        } else if (requestCode == REQUEST_PICK_CONTACT) {
            if (resultCode != RESULT_OK) {
                finish();
@@ -377,14 +368,13 @@ public class AttachPhotoActivity extends ContactsActivity {
        // Technically this could block but in reality this method won't be called until the user
        // presses the save button which should allow plenty of time for the accounts to
        // finish loading. Note also that this could be stale if the accounts have changed since
        // we requested them but that's OK since ContactEditorAccountsChangedActivity will reload
        // the accounts
        // we requested them but that's OK since account picker will reload the accounts
        final List<AccountInfo> accountInfos = Futures.getUnchecked(mAccountsFuture);

        final List<AccountWithDataSet> accounts = AccountInfo.extractAccounts(accountInfos);
        if (editorUtils.shouldShowAccountChangedNotification(accounts)) {
            Intent intent =
                    new Intent(this, ContactEditorAccountsChangedActivity.class)
                    new Intent(Settings.ACTION_SET_DEFAULT_ACCOUNT)
                            .addFlags(
                                    Intent.FLAG_ACTIVITY_CLEAR_TOP
                                            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Loading