Add "enabled" to SelectPhoneAccountDialogFragment.

This is used to inform the user an account cannot be used right now. On most dual SIM devices, only a single SIM can make calls at the same time. The UI will be implemented in a followup CL.

This CL also packs the parameters of SelectPhoneAccountDialogFragment into a proto. There are too many arguments and it needs structured representation.

TEST=TAP
Bug: 69675796,72618783
Test: TAP
PiperOrigin-RevId: 194139636
Change-Id: I7d9f92c73b650654fff28ba625a2c8e3dfa0b96c
diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
index 295aa96..e1fdd91 100644
--- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
+++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
@@ -47,10 +47,9 @@
 import com.android.contacts.common.compat.PhoneAccountCompat;
 import com.android.dialer.location.GeoUtil;
 import com.android.dialer.phonenumberutil.PhoneNumberHelper;
+import com.android.dialer.protos.ProtoParsers;
 import com.android.dialer.telecom.TelecomUtil;
 import com.google.common.base.Optional;
-import java.util.ArrayList;
-import java.util.List;
 
 /**
  * Dialog that allows the user to select a phone accounts for a given action. Optionally provides
@@ -58,128 +57,73 @@
  */
 public class SelectPhoneAccountDialogFragment extends DialogFragment {
 
-  private static final String ARG_TITLE_RES_ID = "title_res_id";
-  private static final String ARG_CAN_SET_DEFAULT = "can_set_default";
-  private static final String ARG_SET_DEFAULT_RES_ID = "set_default_res_id";
-  private static final String ARG_ACCOUNT_HANDLES = "account_handles";
+  private static final String ARG_OPTIONS = "options";
   private static final String ARG_IS_DEFAULT_CHECKED = "is_default_checked";
-  private static final String ARG_LISTENER = "listener";
-  private static final String ARG_CALL_ID = "call_id";
-  private static final String ARG_HINTS = "hints";
 
-  private List<PhoneAccountHandle> mAccountHandles;
-  private List<String> mHints;
-  private boolean mIsSelected;
-  private boolean mIsDefaultChecked;
-  private SelectPhoneAccountListener mListener;
+  private SelectPhoneAccountDialogOptions options =
+      SelectPhoneAccountDialogOptions.getDefaultInstance();
+  private SelectPhoneAccountListener listener;
 
-  public SelectPhoneAccountDialogFragment() {}
+  private boolean isDefaultChecked;
+  private boolean isSelected;
 
-  /**
-   * Create new fragment instance with default title and no option to set as default.
-   *
-   * @param accountHandles The {@code PhoneAccountHandle}s available to select from.
-   * @param listener The listener for the results of the account selection.
-   */
+  /** Create new fragment instance. */
   public static SelectPhoneAccountDialogFragment newInstance(
-      List<PhoneAccountHandle> accountHandles,
-      SelectPhoneAccountListener listener,
-      @Nullable String callId) {
-    return newInstance(
-        R.string.select_account_dialog_title, false, 0, accountHandles, listener, callId, null);
-  }
-
-  /**
-   * Create new fragment instance. This method also allows specifying a custom title and "set
-   * default" checkbox.
-   *
-   * @param titleResId The resource ID for the string to use in the title of the dialog.
-   * @param canSetDefault {@code true} if the dialog should include an option to set the selection
-   *     as the default. False otherwise.
-   * @param setDefaultResId The resource ID for the string to use in the "set as default" checkbox
-   * @param accountHandles The {@code PhoneAccountHandle}s available to select from.
-   * @param listener The listener for the results of the account selection.
-   * @param callId The callId to be passed back to the listener in {@link
-   *     SelectPhoneAccountListener#EXTRA_CALL_ID}
-   * @param hints Additional information to be shown underneath the phone account to help user
-   *     choose. Index must match {@code accountHandles}
-   */
-  public static SelectPhoneAccountDialogFragment newInstance(
-      int titleResId,
-      boolean canSetDefault,
-      int setDefaultResId,
-      List<PhoneAccountHandle> accountHandles,
-      SelectPhoneAccountListener listener,
-      @Nullable String callId,
-      @Nullable List<String> hints) {
-    ArrayList<PhoneAccountHandle> accountHandlesCopy = new ArrayList<>();
-    if (accountHandles != null) {
-      accountHandlesCopy.addAll(accountHandles);
-    }
+      SelectPhoneAccountDialogOptions options, SelectPhoneAccountListener listener) {
     SelectPhoneAccountDialogFragment fragment = new SelectPhoneAccountDialogFragment();
-    final Bundle args = new Bundle();
-    args.putInt(ARG_TITLE_RES_ID, titleResId);
-    args.putBoolean(ARG_CAN_SET_DEFAULT, canSetDefault);
-    if (setDefaultResId != 0) {
-      args.putInt(ARG_SET_DEFAULT_RES_ID, setDefaultResId);
-    }
-    args.putParcelableArrayList(ARG_ACCOUNT_HANDLES, accountHandlesCopy);
-    args.putParcelable(ARG_LISTENER, listener);
-    args.putString(ARG_CALL_ID, callId);
-    if (hints != null) {
-      args.putStringArrayList(ARG_HINTS, new ArrayList<>(hints));
-    }
-    fragment.setArguments(args);
     fragment.setListener(listener);
+    Bundle arguments = new Bundle();
+    ProtoParsers.put(arguments, ARG_OPTIONS, options);
+    fragment.setArguments(arguments);
     return fragment;
   }
 
   public void setListener(SelectPhoneAccountListener listener) {
-    mListener = listener;
+    this.listener = listener;
   }
 
   @Nullable
   @VisibleForTesting
   public SelectPhoneAccountListener getListener() {
-    return mListener;
+    return listener;
   }
 
   @VisibleForTesting
   public boolean canSetDefault() {
-    return getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
+    return options.getCanSetDefault();
   }
 
   @Override
   public void onSaveInstanceState(Bundle outState) {
     super.onSaveInstanceState(outState);
-    outState.putBoolean(ARG_IS_DEFAULT_CHECKED, mIsDefaultChecked);
+    outState.putBoolean(ARG_IS_DEFAULT_CHECKED, isDefaultChecked);
   }
 
   @Override
   public Dialog onCreateDialog(Bundle savedInstanceState) {
-    int titleResId = getArguments().getInt(ARG_TITLE_RES_ID);
-    boolean canSetDefault = getArguments().getBoolean(ARG_CAN_SET_DEFAULT);
-    mAccountHandles = getArguments().getParcelableArrayList(ARG_ACCOUNT_HANDLES);
-    mListener = getArguments().getParcelable(ARG_LISTENER);
-    mHints = getArguments().getStringArrayList(ARG_HINTS);
+    options =
+        ProtoParsers.getTrusted(
+            getArguments(), ARG_OPTIONS, SelectPhoneAccountDialogOptions.getDefaultInstance());
     if (savedInstanceState != null) {
-      mIsDefaultChecked = savedInstanceState.getBoolean(ARG_IS_DEFAULT_CHECKED);
+      isDefaultChecked = savedInstanceState.getBoolean(ARG_IS_DEFAULT_CHECKED);
     }
-    mIsSelected = false;
+    isSelected = false;
 
     final DialogInterface.OnClickListener selectionListener =
         new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
-            mIsSelected = true;
-            PhoneAccountHandle selectedAccountHandle = mAccountHandles.get(which);
+            isSelected = true;
+            PhoneAccountHandle selectedAccountHandle =
+                SelectPhoneAccountDialogOptionsUtil.getPhoneAccountHandle(
+                    options.getEntriesList().get(which));
             Bundle result = new Bundle();
             result.putParcelable(
                 SelectPhoneAccountListener.EXTRA_SELECTED_ACCOUNT_HANDLE, selectedAccountHandle);
-            result.putBoolean(SelectPhoneAccountListener.EXTRA_SET_DEFAULT, mIsDefaultChecked);
+            result.putBoolean(SelectPhoneAccountListener.EXTRA_SET_DEFAULT, isDefaultChecked);
             result.putString(SelectPhoneAccountListener.EXTRA_CALL_ID, getCallId());
-            if (mListener != null) {
-              mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_SELECTED, result);
+            if (listener != null) {
+              listener.onReceiveResult(SelectPhoneAccountListener.RESULT_SELECTED, result);
             }
           }
         };
@@ -188,22 +132,23 @@
         new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton check, boolean isChecked) {
-            mIsDefaultChecked = isChecked;
+            isDefaultChecked = isChecked;
           }
         };
 
     AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
     ListAdapter selectAccountListAdapter =
         new SelectAccountListAdapter(
-            builder.getContext(), R.layout.select_account_list_item, mAccountHandles, mHints);
+            builder.getContext(), R.layout.select_account_list_item, options);
 
     AlertDialog dialog =
         builder
-            .setTitle(titleResId)
+            .setTitle(
+                options.hasTitle() ? options.getTitle() : R.string.select_account_dialog_title)
             .setAdapter(selectAccountListAdapter, selectionListener)
             .create();
 
-    if (canSetDefault) {
+    if (options.getCanSetDefault()) {
       // Generate custom checkbox view, lint suppressed since no appropriate parent (is dialog)
       @SuppressLint("InflateParams")
       LinearLayout checkboxLayout =
@@ -213,11 +158,13 @@
 
       CheckBox checkBox = checkboxLayout.findViewById(R.id.default_account_checkbox_view);
       checkBox.setOnCheckedChangeListener(checkListener);
-      checkBox.setChecked(mIsDefaultChecked);
+      checkBox.setChecked(isDefaultChecked);
 
       TextView textView = checkboxLayout.findViewById(R.id.default_account_checkbox_text);
       int setDefaultResId =
-          getArguments().getInt(ARG_SET_DEFAULT_RES_ID, R.string.set_default_account);
+          options.hasSetDefaultLabel()
+              ? options.getSetDefaultLabel()
+              : R.string.set_default_account;
       textView.setText(setDefaultResId);
       textView.setOnClickListener((view) -> checkBox.performClick());
       checkboxLayout.setOnClickListener((view) -> checkBox.performClick());
@@ -230,17 +177,17 @@
 
   @Override
   public void onCancel(DialogInterface dialog) {
-    if (!mIsSelected && mListener != null) {
+    if (!isSelected && listener != null) {
       Bundle result = new Bundle();
       result.putString(SelectPhoneAccountListener.EXTRA_CALL_ID, getCallId());
-      mListener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, result);
+      listener.onReceiveResult(SelectPhoneAccountListener.RESULT_DISMISSED, result);
     }
     super.onCancel(dialog);
   }
 
   @Nullable
   private String getCallId() {
-    return getArguments().getString(ARG_CALL_ID);
+    return options.getCallId();
   }
 
   public static class SelectPhoneAccountListener extends ResultReceiver {
@@ -274,18 +221,14 @@
     public void onDialogDismissed(@Nullable String callId) {}
   }
 
-  private static class SelectAccountListAdapter extends ArrayAdapter<PhoneAccountHandle> {
+  private static class SelectAccountListAdapter
+      extends ArrayAdapter<SelectPhoneAccountDialogOptions.Entry> {
 
     private int mResId;
-    private final List<String> mHints;
 
     SelectAccountListAdapter(
-        Context context,
-        int resource,
-        List<PhoneAccountHandle> accountHandles,
-        @Nullable List<String> hints) {
-      super(context, resource, accountHandles);
-      mHints = hints;
+        Context context, int resource, SelectPhoneAccountDialogOptions options) {
+      super(context, resource, options.getEntriesList());
       mResId = resource;
     }
 
@@ -311,7 +254,9 @@
         holder = (ViewHolder) rowView.getTag();
       }
 
-      PhoneAccountHandle accountHandle = getItem(position);
+      SelectPhoneAccountDialogOptions.Entry entry = getItem(position);
+      PhoneAccountHandle accountHandle =
+          SelectPhoneAccountDialogOptionsUtil.getPhoneAccountHandle(entry);
       PhoneAccount account =
           getContext().getSystemService(TelecomManager.class).getPhoneAccount(accountHandle);
       if (account == null) {
@@ -331,16 +276,12 @@
       }
       holder.imageView.setImageDrawable(
           PhoneAccountCompat.createIconDrawable(account, getContext()));
-      if (mHints != null && position < mHints.size()) {
-        String hint = mHints.get(position);
-        if (TextUtils.isEmpty(hint)) {
-          holder.hintTextView.setVisibility(View.GONE);
-        } else {
-          holder.hintTextView.setVisibility(View.VISIBLE);
-          holder.hintTextView.setText(hint);
-        }
-      } else {
+
+      if (TextUtils.isEmpty(entry.getHint())) {
         holder.hintTextView.setVisibility(View.GONE);
+      } else {
+        holder.hintTextView.setVisibility(View.VISIBLE);
+        holder.hintTextView.setText(entry.getHint());
       }
 
       return rowView;
diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java
new file mode 100644
index 0000000..5a44ae7
--- /dev/null
+++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogOptionsUtil.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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 com.android.contacts.common.widget;
+
+import android.telecom.PhoneAccountHandle;
+import com.android.dialer.common.Assert;
+import com.android.dialer.telecom.TelecomUtil;
+import java.util.Collection;
+
+/** Provides common operation on a {@link SelectPhoneAccountDialogOptions} */
+public final class SelectPhoneAccountDialogOptionsUtil {
+  private SelectPhoneAccountDialogOptionsUtil() {}
+
+  public static PhoneAccountHandle getPhoneAccountHandle(
+      SelectPhoneAccountDialogOptions.Entry entry) {
+    return Assert.isNotNull(
+        TelecomUtil.composePhoneAccountHandle(
+            entry.getPhoneAccountHandleComponentName(), entry.getPhoneAccountHandleId()));
+  }
+
+  public static SelectPhoneAccountDialogOptions.Entry.Builder setPhoneAccountHandle(
+      SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder,
+      PhoneAccountHandle phoneAccountHandle) {
+    entryBuilder.setPhoneAccountHandleComponentName(
+        phoneAccountHandle.getComponentName().flattenToString());
+    entryBuilder.setPhoneAccountHandleId(phoneAccountHandle.getId());
+    return entryBuilder;
+  }
+
+  public static SelectPhoneAccountDialogOptions.Builder builderWithAccounts(
+      Collection<PhoneAccountHandle> phoneAccountHandles) {
+    SelectPhoneAccountDialogOptions.Builder optionsBuilder =
+        SelectPhoneAccountDialogOptions.newBuilder();
+    for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
+      optionsBuilder.addEntries(
+          SelectPhoneAccountDialogOptionsUtil.setPhoneAccountHandle(
+              SelectPhoneAccountDialogOptions.Entry.newBuilder(), phoneAccountHandle));
+    }
+    return optionsBuilder;
+  }
+}
diff --git a/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto b/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto
new file mode 100644
index 0000000..9938f57
--- /dev/null
+++ b/java/com/android/contacts/common/widget/select_phone_account_dialog_options.proto
@@ -0,0 +1,54 @@
+// Copyright (C) 2018 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
+
+syntax = "proto2";
+
+option java_package = "com.android.contacts.common.widget";
+option java_multiple_files = true;
+option optimize_for = LITE_RUNTIME;
+
+
+package com.android.contacts.common.widget;
+
+// Parameters for SelectPhoneAccountDialogFragment
+message SelectPhoneAccountDialogOptions {
+  // The resource ID for the title. Defaults to
+  // R.string.select_account_dialog_title
+  optional int32 title = 1;
+  // Whether the dialog should include a "set as default" checkbox. Defaults to
+  // false
+  optional bool can_set_default = 2;
+  // The label on the "set as default" checkbox. Defaults
+  // R.string.set_default_account
+  optional int32 set_default_label = 3;
+  // The call ID to pass back to the callback
+  optional string call_id = 4;
+  // Phone accounts to show in the dialog
+  repeated Entry entries = 5;
+
+  message Entry {
+    // PhoneAccountHandle.getComponentName().flattenToString()
+    optional string phone_account_handle_component_name = 1;
+    // PhoneAccountHandle.getId()
+    optional string phone_account_handle_id = 2;
+    // The hint to show under the phone account, for example showing the user
+    // the account was selected frequently before.
+    optional string hint = 3;
+    // Whether the account is actually selectable. Defaults to true Sometimes an
+    // account will be temporarily unusable, for example the user is already in
+    // a call so the other SIM cannot be used. Hint should also be set to inform
+    // the user why the account is unavailable.
+    optional bool enabled = 4;
+  }
+}
\ No newline at end of file
diff --git a/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java b/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java
index 9929ddd..d2652ee 100644
--- a/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java
+++ b/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java
@@ -56,6 +56,7 @@
 import com.android.contacts.common.util.ContactDisplayUtils;
 import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
 import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener;
+import com.android.contacts.common.widget.SelectPhoneAccountDialogOptionsUtil;
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
 import com.android.dialer.compat.telephony.TelephonyManagerCompat;
@@ -234,10 +235,12 @@
         } else {
           SelectPhoneAccountListener callback =
               new HandleAdnEntryAccountSelectedCallback(applicationContext, handler, sc);
-
           DialogFragment dialogFragment =
               SelectPhoneAccountDialogFragment.newInstance(
-                  subscriptionAccountHandles, callback, null);
+                  SelectPhoneAccountDialogOptionsUtil.builderWithAccounts(
+                          subscriptionAccountHandles)
+                      .build(),
+                  callback);
           dialogFragment.show(((Activity) context).getFragmentManager(), TAG_SELECT_ACCT_FRAGMENT);
         }
 
@@ -292,7 +295,9 @@
 
         DialogFragment dialogFragment =
             SelectPhoneAccountDialogFragment.newInstance(
-                subscriptionAccountHandles, listener, null);
+                SelectPhoneAccountDialogOptionsUtil.builderWithAccounts(subscriptionAccountHandles)
+                    .build(),
+                listener);
         dialogFragment.show(((Activity) context).getFragmentManager(), TAG_SELECT_ACCT_FRAGMENT);
       }
       return true;
diff --git a/java/com/android/dialer/precall/impl/CallingAccountSelector.java b/java/com/android/dialer/precall/impl/CallingAccountSelector.java
index 16e7641..6514a49 100644
--- a/java/com/android/dialer/precall/impl/CallingAccountSelector.java
+++ b/java/com/android/dialer/precall/impl/CallingAccountSelector.java
@@ -28,6 +28,8 @@
 import android.telephony.PhoneNumberUtils;
 import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
 import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener;
+import com.android.contacts.common.widget.SelectPhoneAccountDialogOptions;
+import com.android.contacts.common.widget.SelectPhoneAccountDialogOptionsUtil;
 import com.android.dialer.callintent.CallIntentBuilder;
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
@@ -44,6 +46,7 @@
 import com.android.dialer.preferredsim.suggestion.SuggestionProvider;
 import com.android.dialer.preferredsim.suggestion.SuggestionProvider.Suggestion;
 import com.android.dialer.telecom.TelecomUtil;
+import com.google.common.base.Optional;
 import java.util.List;
 
 /** PreCallAction to select which phone account to call with. Ignored if there's only one account */
@@ -211,24 +214,34 @@
         default:
       }
     }
-    List<PhoneAccountHandle> phoneAccountHandles =
+    SelectPhoneAccountDialogOptions.Builder optionsBuilder =
+        SelectPhoneAccountDialogOptions.newBuilder()
+            .setTitle(R.string.pre_call_select_phone_account)
+            .setCanSetDefault(dataId != null)
+            .setSetDefaultLabel(R.string.pre_call_select_phone_account_remember);
+
+    for (PhoneAccountHandle phoneAccountHandle :
         coordinator
             .getActivity()
             .getSystemService(TelecomManager.class)
-            .getCallCapablePhoneAccounts();
+            .getCallCapablePhoneAccounts()) {
+      SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder =
+          SelectPhoneAccountDialogOptions.Entry.newBuilder();
+      SelectPhoneAccountDialogOptionsUtil.setPhoneAccountHandle(entryBuilder, phoneAccountHandle);
+      Optional<String> hint =
+          SuggestionProvider.getHint(coordinator.getActivity(), phoneAccountHandle, suggestion);
+      if (hint.isPresent()) {
+        entryBuilder.setHint(hint.get());
+      }
+      optionsBuilder.addEntries(entryBuilder);
+    }
     selectPhoneAccountDialogFragment =
         SelectPhoneAccountDialogFragment.newInstance(
-            R.string.pre_call_select_phone_account,
-            dataId != null /* canSetDefault */,
-            R.string.pre_call_select_phone_account_remember,
-            phoneAccountHandles,
+            optionsBuilder.build(),
             new SelectedListener(
                 coordinator,
                 pendingAction,
-                new PreferredAccountRecorder(number, suggestion, dataId)),
-            null /* call ID */,
-            SuggestionProvider.buildHint(
-                coordinator.getActivity(), phoneAccountHandles, suggestion));
+                new PreferredAccountRecorder(number, suggestion, dataId)));
     selectPhoneAccountDialogFragment.show(
         coordinator.getActivity().getFragmentManager(), TAG_CALLING_ACCOUNT_SELECTOR);
   }
diff --git a/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java b/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java
index f710f73..50ae01f 100644
--- a/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java
+++ b/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java
@@ -24,10 +24,9 @@
 import com.android.dialer.common.Assert;
 import com.android.dialer.common.LogUtil;
 import com.google.common.base.Optional;
-import java.util.ArrayList;
-import java.util.List;
 
 /** Provides hints to the user when selecting a SIM to make a call. */
+@SuppressWarnings("Guava")
 public interface SuggestionProvider {
 
   String EXTRA_SIM_SUGGESTION_REASON = "sim_suggestion_reason";
@@ -80,35 +79,25 @@
       @NonNull Context context, @NonNull String number, @NonNull PhoneAccountHandle newAccount);
 
   /**
-   * Return a list of suggestion strings matching the list position of the {@code
-   * phoneAccountHandles}. The list will contain {@code null} if the PhoneAccountHandle does not
-   * have suggestions.
+   * Return the hint for {@code phoneAccountHandle}. Absent if no hint is available for the account.
    */
-  @Nullable
-  static List<String> buildHint(
-      Context context,
-      List<PhoneAccountHandle> phoneAccountHandles,
-      @Nullable Suggestion suggestion) {
+  static Optional<String> getHint(
+      Context context, PhoneAccountHandle phoneAccountHandle, @Nullable Suggestion suggestion) {
     if (suggestion == null) {
-      return null;
+      return Optional.absent();
     }
-    List<String> hints = new ArrayList<>();
-    for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
-      if (!phoneAccountHandle.equals(suggestion.phoneAccountHandle)) {
-        hints.add(null);
-        continue;
-      }
-      switch (suggestion.reason) {
-        case INTRA_CARRIER:
-          hints.add(context.getString(R.string.pre_call_select_phone_account_hint_intra_carrier));
-          break;
-        case FREQUENT:
-          hints.add(context.getString(R.string.pre_call_select_phone_account_hint_frequent));
-          break;
-        default:
-          LogUtil.w("CallingAccountSelector.buildHint", "unhandled reason " + suggestion.reason);
-      }
+    if (!phoneAccountHandle.equals(suggestion.phoneAccountHandle)) {
+      return Optional.absent();
     }
-    return hints;
+    switch (suggestion.reason) {
+      case INTRA_CARRIER:
+        return Optional.of(
+            context.getString(R.string.pre_call_select_phone_account_hint_intra_carrier));
+      case FREQUENT:
+        return Optional.of(context.getString(R.string.pre_call_select_phone_account_hint_frequent));
+      default:
+        LogUtil.w("CallingAccountSelector.getHint", "unhandled reason " + suggestion.reason);
+        return Optional.absent();
+    }
   }
 }
diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java
index 86799bf..68de8dc 100644
--- a/java/com/android/incallui/InCallActivity.java
+++ b/java/com/android/incallui/InCallActivity.java
@@ -55,6 +55,8 @@
 import android.widget.CheckBox;
 import android.widget.Toast;
 import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
+import com.android.contacts.common.widget.SelectPhoneAccountDialogOptions;
+import com.android.contacts.common.widget.SelectPhoneAccountDialogOptionsUtil;
 import com.android.dialer.animation.AnimUtils;
 import com.android.dialer.animation.AnimationListenerAdapter;
 import com.android.dialer.common.Assert;
@@ -395,16 +397,30 @@
                       waitingForAccountCall.getNumber(),
                       result.getSuggestion().orNull(),
                       result.getDataId().orNull()));
+              SelectPhoneAccountDialogOptions.Builder optionsBuilder =
+                  SelectPhoneAccountDialogOptions.newBuilder()
+                      .setTitle(R.string.select_phone_account_for_calls)
+                      .setCanSetDefault(result.getDataId().isPresent())
+                      .setSetDefaultLabel(R.string.select_phone_account_for_calls_remember)
+                      .setCallId(waitingForAccountCall.getId());
+
+              for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
+                SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder =
+                    SelectPhoneAccountDialogOptions.Entry.newBuilder();
+                SelectPhoneAccountDialogOptionsUtil.setPhoneAccountHandle(
+                    entryBuilder, phoneAccountHandle);
+                Optional<String> hint =
+                    SuggestionProvider.getHint(
+                        this, phoneAccountHandle, result.getSuggestion().orNull());
+                if (hint.isPresent()) {
+                  entryBuilder.setHint(hint.get());
+                }
+                optionsBuilder.addEntries(entryBuilder);
+              }
+
               selectPhoneAccountDialogFragment =
                   SelectPhoneAccountDialogFragment.newInstance(
-                      R.string.select_phone_account_for_calls,
-                      result.getDataId().isPresent() /* canSetDefault */,
-                      R.string.select_phone_account_for_calls_remember /* setDefaultResId */,
-                      phoneAccountHandles,
-                      selectPhoneAccountListener,
-                      waitingForAccountCall.getId(),
-                      SuggestionProvider.buildHint(
-                          this, phoneAccountHandles, result.getSuggestion().orNull() /* hints */));
+                      optionsBuilder.build(), selectPhoneAccountListener);
               selectPhoneAccountDialogFragment.show(
                   getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT);
             }))