blob: f23f4c9b9e9e3a891ae558839e3704f5ca9620a6 [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;
Hall Liu1059cd52019-02-28 18:54:15 -080020import android.annotation.NonNull;
Hall Liu066612a2018-11-20 15:32:33 -080021import android.annotation.SystemApi;
Hall Liu34d9e242018-11-21 17:05:58 -080022import android.annotation.TestApi;
Hall Liu066612a2018-11-20 15:32:33 -080023import android.os.Parcel;
24import android.os.Parcelable;
25
26import java.lang.annotation.Retention;
27import java.lang.annotation.RetentionPolicy;
Hall Liu7ddcfd62018-12-10 18:38:11 -080028import java.util.Objects;
Hall Liu066612a2018-11-20 15:32:33 -080029
30public final class PhoneAccountSuggestion implements Parcelable {
31
32 /** @hide */
33 @Retention(RetentionPolicy.SOURCE)
34 @IntDef(value = {REASON_NONE, REASON_INTRA_CARRIER, REASON_FREQUENT,
35 REASON_USER_SET, REASON_OTHER}, prefix = { "REASON_" })
36 public @interface SuggestionReason {}
37
Hall Liu34d9e242018-11-21 17:05:58 -080038 /**
39 * Indicates that this account is not suggested for use, but is still available.
40 */
Hall Liu066612a2018-11-20 15:32:33 -080041 public static final int REASON_NONE = 0;
Hall Liu34d9e242018-11-21 17:05:58 -080042
43 /**
44 * Indicates that the {@link PhoneAccountHandle} is suggested because the number we're calling
45 * is on the same carrier, and therefore may have lower rates.
46 */
Hall Liu066612a2018-11-20 15:32:33 -080047 public static final int REASON_INTRA_CARRIER = 1;
Hall Liu34d9e242018-11-21 17:05:58 -080048
49 /**
50 * Indicates that the {@link PhoneAccountHandle} is suggested because the user uses it
51 * frequently for the number that we are calling.
52 */
Hall Liu066612a2018-11-20 15:32:33 -080053 public static final int REASON_FREQUENT = 2;
Hall Liu34d9e242018-11-21 17:05:58 -080054
55 /**
56 * Indicates that the {@link PhoneAccountHandle} is suggested because the user explicitly
57 * specified that it be used for the number we are calling.
58 */
Hall Liu066612a2018-11-20 15:32:33 -080059 public static final int REASON_USER_SET = 3;
Hall Liu34d9e242018-11-21 17:05:58 -080060
61 /**
62 * Indicates that the {@link PhoneAccountHandle} is suggested for a reason not otherwise
63 * enumerated here.
64 */
Hall Liu066612a2018-11-20 15:32:33 -080065 public static final int REASON_OTHER = 4;
66
67 private PhoneAccountHandle mHandle;
68 private int mReason;
69 private boolean mShouldAutoSelect;
70
71 /**
72 * @hide
73 */
74 @SystemApi
Hall Liu34d9e242018-11-21 17:05:58 -080075 @TestApi
Hall Liu1059cd52019-02-28 18:54:15 -080076 public PhoneAccountSuggestion(@NonNull PhoneAccountHandle handle, @SuggestionReason int reason,
Hall Liu066612a2018-11-20 15:32:33 -080077 boolean shouldAutoSelect) {
78 this.mHandle = handle;
79 this.mReason = reason;
80 this.mShouldAutoSelect = shouldAutoSelect;
81 }
82
83 private PhoneAccountSuggestion(Parcel in) {
84 mHandle = in.readParcelable(PhoneAccountHandle.class.getClassLoader());
85 mReason = in.readInt();
86 mShouldAutoSelect = in.readByte() != 0;
87 }
88
89 public static final Creator<PhoneAccountSuggestion> CREATOR =
90 new Creator<PhoneAccountSuggestion>() {
91 @Override
92 public PhoneAccountSuggestion createFromParcel(Parcel in) {
93 return new PhoneAccountSuggestion(in);
94 }
95
96 @Override
97 public PhoneAccountSuggestion[] newArray(int size) {
98 return new PhoneAccountSuggestion[size];
99 }
100 };
101
Hall Liu34d9e242018-11-21 17:05:58 -0800102 /**
103 * @return The {@link PhoneAccountHandle} for this suggestion.
104 */
Hall Liu1059cd52019-02-28 18:54:15 -0800105 @NonNull public PhoneAccountHandle getPhoneAccountHandle() {
Hall Liu066612a2018-11-20 15:32:33 -0800106 return mHandle;
107 }
108
Hall Liu34d9e242018-11-21 17:05:58 -0800109 /**
110 * @return The reason for this suggestion
111 */
Hall Liu066612a2018-11-20 15:32:33 -0800112 public @SuggestionReason int getReason() {
113 return mReason;
114 }
115
Hall Liu34d9e242018-11-21 17:05:58 -0800116 /**
117 * Suggests whether the dialer should automatically place the call using this account without
118 * user interaction. This may be set on multiple {@link PhoneAccountSuggestion}s, and the dialer
119 * is free to choose which one to use.
120 * @return {@code true} if the hint is to auto-select, {@code false} otherwise.
121 */
Hall Liu066612a2018-11-20 15:32:33 -0800122 public boolean shouldAutoSelect() {
123 return mShouldAutoSelect;
124 }
125
126 @Override
127 public int describeContents() {
128 return 0;
129 }
130
131 @Override
132 public void writeToParcel(Parcel dest, int flags) {
133 dest.writeParcelable(mHandle, flags);
134 dest.writeInt(mReason);
135 dest.writeByte((byte) (mShouldAutoSelect ? 1 : 0));
136 }
Hall Liu7ddcfd62018-12-10 18:38:11 -0800137
138 @Override
139 public boolean equals(Object o) {
140 if (this == o) return true;
141 if (o == null || getClass() != o.getClass()) return false;
142 PhoneAccountSuggestion that = (PhoneAccountSuggestion) o;
143 return mReason == that.mReason
144 && mShouldAutoSelect == that.mShouldAutoSelect
145 && Objects.equals(mHandle, that.mHandle);
146 }
147
148 @Override
149 public int hashCode() {
150 return Objects.hash(mHandle, mReason, mShouldAutoSelect);
151 }
Hall Liu066612a2018-11-20 15:32:33 -0800152}