Merge changes from topic "acct-suggestion-1" am: f3935f0268
am: 5da9fe3d79

Change-Id: I2d342eef80a5bcfed1e538add6c5807f5faf3dd1
diff --git a/api/current.txt b/api/current.txt
index cce9c85..c299973 100755
--- a/api/current.txt
+++ b/api/current.txt
@@ -41114,8 +41114,9 @@
     method public void swapConference();
     method public void unhold();
     method public void unregisterCallback(android.telecom.Call.Callback);
-    field public static final java.lang.String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
+    field public static final deprecated java.lang.String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
     field public static final java.lang.String EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS = "android.telecom.extra.LAST_EMERGENCY_CALLBACK_TIME_MILLIS";
+    field public static final java.lang.String EXTRA_SUGGESTED_PHONE_ACCOUNTS = "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
     field public static final int STATE_ACTIVE = 4; // 0x4
     field public static final int STATE_CONNECTING = 9; // 0x9
     field public static final int STATE_DIALING = 1; // 0x1
@@ -41686,6 +41687,20 @@
     field public static final android.os.Parcelable.Creator<android.telecom.PhoneAccountHandle> CREATOR;
   }
 
+  public final class PhoneAccountSuggestion implements android.os.Parcelable {
+    method public int describeContents();
+    method public android.telecom.PhoneAccountHandle getPhoneAccountHandle();
+    method public int getReason();
+    method public boolean shouldAutoSelect();
+    method public void writeToParcel(android.os.Parcel, int);
+    field public static final android.os.Parcelable.Creator<android.telecom.PhoneAccountSuggestion> CREATOR;
+    field public static final int REASON_FREQUENT = 2; // 0x2
+    field public static final int REASON_INTRA_CARRIER = 1; // 0x1
+    field public static final int REASON_NONE = 0; // 0x0
+    field public static final int REASON_OTHER = 4; // 0x4
+    field public static final int REASON_USER_SET = 3; // 0x3
+  }
+
   public final class RemoteConference {
     method public void disconnect();
     method public java.util.List<android.telecom.RemoteConnection> getConferenceableConnections();
diff --git a/api/system-current.txt b/api/system-current.txt
index 96eb0e3..c85582f 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -5022,6 +5022,10 @@
     field public static final int CAPABILITY_MULTI_USER = 32; // 0x20
   }
 
+  public final class PhoneAccountSuggestion implements android.os.Parcelable {
+    ctor public PhoneAccountSuggestion(android.telecom.PhoneAccountHandle, int, boolean);
+  }
+
   public final class RemoteConference {
     method public deprecated void setAudioState(android.telecom.AudioState);
   }
diff --git a/api/test-current.txt b/api/test-current.txt
index 8466ef0..b5b128a 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -963,6 +963,10 @@
     ctor public CallAudioState(boolean, int, int, android.bluetooth.BluetoothDevice, java.util.Collection<android.bluetooth.BluetoothDevice>);
   }
 
+  public final class PhoneAccountSuggestion implements android.os.Parcelable {
+    ctor public PhoneAccountSuggestion(android.telecom.PhoneAccountHandle, int, boolean);
+  }
+
 }
 
 package android.telephony {
diff --git a/telecomm/java/android/telecom/Call.java b/telecomm/java/android/telecom/Call.java
index cef99865..bf0ffb9 100644
--- a/telecomm/java/android/telecom/Call.java
+++ b/telecomm/java/android/telecom/Call.java
@@ -123,10 +123,21 @@
      * The key to retrieve the optional {@code PhoneAccount}s Telecom can bundle with its Call
      * extras. Used to pass the phone accounts to display on the front end to the user in order to
      * select phone accounts to (for example) place a call.
+     * @deprecated Use the list from {@link #EXTRA_SUGGESTED_PHONE_ACCOUNTS} instead.
      */
+    @Deprecated
     public static final String AVAILABLE_PHONE_ACCOUNTS = "selectPhoneAccountAccounts";
 
     /**
+     * Key for extra used to pass along a list of {@link PhoneAccountSuggestion}s to the in-call
+     * UI when a call enters the {@link #STATE_SELECT_PHONE_ACCOUNT} state. The list included here
+     * will have the same length and be in the same order as the list passed with
+     * {@link #AVAILABLE_PHONE_ACCOUNTS}.
+     */
+    public static final String EXTRA_SUGGESTED_PHONE_ACCOUNTS =
+            "android.telecom.extra.SUGGESTED_PHONE_ACCOUNTS";
+
+    /**
      * Extra key used to indicate the time (in milliseconds since midnight, January 1, 1970 UTC)
      * when the last outgoing emergency call was made.  This is used to identify potential emergency
      * callbacks.
diff --git a/telecomm/java/android/telecom/PhoneAccountSuggestion.java b/telecomm/java/android/telecom/PhoneAccountSuggestion.java
new file mode 100644
index 0000000..4e6a178
--- /dev/null
+++ b/telecomm/java/android/telecom/PhoneAccountSuggestion.java
@@ -0,0 +1,135 @@
+/*
+ * 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 android.telecom;
+
+import android.annotation.IntDef;
+import android.annotation.SystemApi;
+import android.annotation.TestApi;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+public final class PhoneAccountSuggestion implements Parcelable {
+
+    /** @hide */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(value = {REASON_NONE, REASON_INTRA_CARRIER, REASON_FREQUENT,
+            REASON_USER_SET, REASON_OTHER}, prefix = { "REASON_" })
+    public @interface SuggestionReason {}
+
+    /**
+     * Indicates that this account is not suggested for use, but is still available.
+     */
+    public static final int REASON_NONE = 0;
+
+    /**
+     * Indicates that the {@link PhoneAccountHandle} is suggested because the number we're calling
+     * is on the same carrier, and therefore may have lower rates.
+     */
+    public static final int REASON_INTRA_CARRIER = 1;
+
+    /**
+     * Indicates that the {@link PhoneAccountHandle} is suggested because the user uses it
+     * frequently for the number that we are calling.
+     */
+    public static final int REASON_FREQUENT = 2;
+
+    /**
+     * Indicates that the {@link PhoneAccountHandle} is suggested because the user explicitly
+     * specified that it be used for the number we are calling.
+     */
+    public static final int REASON_USER_SET = 3;
+
+    /**
+     * Indicates that the {@link PhoneAccountHandle} is suggested for a reason not otherwise
+     * enumerated here.
+     */
+    public static final int REASON_OTHER = 4;
+
+    private PhoneAccountHandle mHandle;
+    private int mReason;
+    private boolean mShouldAutoSelect;
+
+    /**
+     * @hide
+     */
+    @SystemApi
+    @TestApi
+    public PhoneAccountSuggestion(PhoneAccountHandle handle, @SuggestionReason int reason,
+            boolean shouldAutoSelect) {
+        this.mHandle = handle;
+        this.mReason = reason;
+        this.mShouldAutoSelect = shouldAutoSelect;
+    }
+
+    private PhoneAccountSuggestion(Parcel in) {
+        mHandle = in.readParcelable(PhoneAccountHandle.class.getClassLoader());
+        mReason = in.readInt();
+        mShouldAutoSelect = in.readByte() != 0;
+    }
+
+    public static final Creator<PhoneAccountSuggestion> CREATOR =
+            new Creator<PhoneAccountSuggestion>() {
+                @Override
+                public PhoneAccountSuggestion createFromParcel(Parcel in) {
+                    return new PhoneAccountSuggestion(in);
+                }
+
+                @Override
+                public PhoneAccountSuggestion[] newArray(int size) {
+                    return new PhoneAccountSuggestion[size];
+                }
+            };
+
+    /**
+     * @return The {@link PhoneAccountHandle} for this suggestion.
+     */
+    public PhoneAccountHandle getPhoneAccountHandle() {
+        return mHandle;
+    }
+
+    /**
+     * @return The reason for this suggestion
+     */
+    public @SuggestionReason int getReason() {
+        return mReason;
+    }
+
+    /**
+     * Suggests whether the dialer should automatically place the call using this account without
+     * user interaction. This may be set on multiple {@link PhoneAccountSuggestion}s, and the dialer
+     * is free to choose which one to use.
+     * @return {@code true} if the hint is to auto-select, {@code false} otherwise.
+     */
+    public boolean shouldAutoSelect() {
+        return mShouldAutoSelect;
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeParcelable(mHandle, flags);
+        dest.writeInt(mReason);
+        dest.writeByte((byte) (mShouldAutoSelect ? 1 : 0));
+    }
+}