blob: 05b23956fa5186087290af870925f2bc63c7b3a2 [file] [log] [blame]
Hall Liu34d9e242018-11-21 17:05:58 -08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Hall Liu066612a2018-11-20 15:32:33 -080017package android.telecom;
18
19import android.annotation.IntDef;
20import android.annotation.SystemApi;
Hall Liu34d9e242018-11-21 17:05:58 -080021import android.annotation.TestApi;
Hall Liu066612a2018-11-20 15:32:33 -080022import android.os.Parcel;
23import android.os.Parcelable;
24
25import java.lang.annotation.Retention;
26import java.lang.annotation.RetentionPolicy;
Hall Liu7ddcfd62018-12-10 18:38:11 -080027import java.util.Objects;
Hall Liu066612a2018-11-20 15:32:33 -080028
29public final class PhoneAccountSuggestion implements Parcelable {
30
31 /** @hide */
32 @Retention(RetentionPolicy.SOURCE)
33 @IntDef(value = {REASON_NONE, REASON_INTRA_CARRIER, REASON_FREQUENT,
34 REASON_USER_SET, REASON_OTHER}, prefix = { "REASON_" })
35 public @interface SuggestionReason {}
36
Hall Liu34d9e242018-11-21 17:05:58 -080037 /**
38 * Indicates that this account is not suggested for use, but is still available.
39 */
Hall Liu066612a2018-11-20 15:32:33 -080040 public static final int REASON_NONE = 0;
Hall Liu34d9e242018-11-21 17:05:58 -080041
42 /**
43 * Indicates that the {@link PhoneAccountHandle} is suggested because the number we're calling
44 * is on the same carrier, and therefore may have lower rates.
45 */
Hall Liu066612a2018-11-20 15:32:33 -080046 public static final int REASON_INTRA_CARRIER = 1;
Hall Liu34d9e242018-11-21 17:05:58 -080047
48 /**
49 * Indicates that the {@link PhoneAccountHandle} is suggested because the user uses it
50 * frequently for the number that we are calling.
51 */
Hall Liu066612a2018-11-20 15:32:33 -080052 public static final int REASON_FREQUENT = 2;
Hall Liu34d9e242018-11-21 17:05:58 -080053
54 /**
55 * Indicates that the {@link PhoneAccountHandle} is suggested because the user explicitly
56 * specified that it be used for the number we are calling.
57 */
Hall Liu066612a2018-11-20 15:32:33 -080058 public static final int REASON_USER_SET = 3;
Hall Liu34d9e242018-11-21 17:05:58 -080059
60 /**
61 * Indicates that the {@link PhoneAccountHandle} is suggested for a reason not otherwise
62 * enumerated here.
63 */
Hall Liu066612a2018-11-20 15:32:33 -080064 public static final int REASON_OTHER = 4;
65
66 private PhoneAccountHandle mHandle;
67 private int mReason;
68 private boolean mShouldAutoSelect;
69
70 /**
71 * @hide
72 */
73 @SystemApi
Hall Liu34d9e242018-11-21 17:05:58 -080074 @TestApi
Hall Liu066612a2018-11-20 15:32:33 -080075 public PhoneAccountSuggestion(PhoneAccountHandle handle, @SuggestionReason int reason,
76 boolean shouldAutoSelect) {
77 this.mHandle = handle;
78 this.mReason = reason;
79 this.mShouldAutoSelect = shouldAutoSelect;
80 }
81
82 private PhoneAccountSuggestion(Parcel in) {
83 mHandle = in.readParcelable(PhoneAccountHandle.class.getClassLoader());
84 mReason = in.readInt();
85 mShouldAutoSelect = in.readByte() != 0;
86 }
87
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070088 public static final @android.annotation.NonNull Creator<PhoneAccountSuggestion> CREATOR =
Hall Liu066612a2018-11-20 15:32:33 -080089 new Creator<PhoneAccountSuggestion>() {
90 @Override
91 public PhoneAccountSuggestion createFromParcel(Parcel in) {
92 return new PhoneAccountSuggestion(in);
93 }
94
95 @Override
96 public PhoneAccountSuggestion[] newArray(int size) {
97 return new PhoneAccountSuggestion[size];
98 }
99 };
100
Hall Liu34d9e242018-11-21 17:05:58 -0800101 /**
102 * @return The {@link PhoneAccountHandle} for this suggestion.
103 */
104 public PhoneAccountHandle getPhoneAccountHandle() {
Hall Liu066612a2018-11-20 15:32:33 -0800105 return mHandle;
106 }
107
Hall Liu34d9e242018-11-21 17:05:58 -0800108 /**
109 * @return The reason for this suggestion
110 */
Hall Liu066612a2018-11-20 15:32:33 -0800111 public @SuggestionReason int getReason() {
112 return mReason;
113 }
114
Hall Liu34d9e242018-11-21 17:05:58 -0800115 /**
116 * Suggests whether the dialer should automatically place the call using this account without
117 * user interaction. This may be set on multiple {@link PhoneAccountSuggestion}s, and the dialer
118 * is free to choose which one to use.
119 * @return {@code true} if the hint is to auto-select, {@code false} otherwise.
120 */
Hall Liu066612a2018-11-20 15:32:33 -0800121 public boolean shouldAutoSelect() {
122 return mShouldAutoSelect;
123 }
124
125 @Override
126 public int describeContents() {
127 return 0;
128 }
129
130 @Override
131 public void writeToParcel(Parcel dest, int flags) {
132 dest.writeParcelable(mHandle, flags);
133 dest.writeInt(mReason);
134 dest.writeByte((byte) (mShouldAutoSelect ? 1 : 0));
135 }
Hall Liu7ddcfd62018-12-10 18:38:11 -0800136
137 @Override
138 public boolean equals(Object o) {
139 if (this == o) return true;
140 if (o == null || getClass() != o.getClass()) return false;
141 PhoneAccountSuggestion that = (PhoneAccountSuggestion) o;
142 return mReason == that.mReason
143 && mShouldAutoSelect == that.mShouldAutoSelect
144 && Objects.equals(mHandle, that.mHandle);
145 }
146
147 @Override
148 public int hashCode() {
149 return Objects.hash(mHandle, mReason, mShouldAutoSelect);
150 }
Hall Liu066612a2018-11-20 15:32:33 -0800151}