blob: 2589d9504f6ded0f938c29ffee1f3b4c801b59a5 [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.os.Parcel;
22import android.os.Parcelable;
23
24import java.lang.annotation.Retention;
25import java.lang.annotation.RetentionPolicy;
Hall Liu7ddcfd62018-12-10 18:38:11 -080026import java.util.Objects;
Hall Liu066612a2018-11-20 15:32:33 -080027
28public final class PhoneAccountSuggestion implements Parcelable {
29
30 /** @hide */
31 @Retention(RetentionPolicy.SOURCE)
32 @IntDef(value = {REASON_NONE, REASON_INTRA_CARRIER, REASON_FREQUENT,
33 REASON_USER_SET, REASON_OTHER}, prefix = { "REASON_" })
34 public @interface SuggestionReason {}
35
Hall Liu34d9e242018-11-21 17:05:58 -080036 /**
37 * Indicates that this account is not suggested for use, but is still available.
38 */
Hall Liu066612a2018-11-20 15:32:33 -080039 public static final int REASON_NONE = 0;
Hall Liu34d9e242018-11-21 17:05:58 -080040
41 /**
42 * Indicates that the {@link PhoneAccountHandle} is suggested because the number we're calling
43 * is on the same carrier, and therefore may have lower rates.
44 */
Hall Liu066612a2018-11-20 15:32:33 -080045 public static final int REASON_INTRA_CARRIER = 1;
Hall Liu34d9e242018-11-21 17:05:58 -080046
47 /**
48 * Indicates that the {@link PhoneAccountHandle} is suggested because the user uses it
49 * frequently for the number that we are calling.
50 */
Hall Liu066612a2018-11-20 15:32:33 -080051 public static final int REASON_FREQUENT = 2;
Hall Liu34d9e242018-11-21 17:05:58 -080052
53 /**
54 * Indicates that the {@link PhoneAccountHandle} is suggested because the user explicitly
55 * specified that it be used for the number we are calling.
56 */
Hall Liu066612a2018-11-20 15:32:33 -080057 public static final int REASON_USER_SET = 3;
Hall Liu34d9e242018-11-21 17:05:58 -080058
59 /**
60 * Indicates that the {@link PhoneAccountHandle} is suggested for a reason not otherwise
61 * enumerated here.
62 */
Hall Liu066612a2018-11-20 15:32:33 -080063 public static final int REASON_OTHER = 4;
64
65 private PhoneAccountHandle mHandle;
66 private int mReason;
67 private boolean mShouldAutoSelect;
68
69 /**
Hall Liuee609ff2019-02-26 17:58:53 -080070 * Creates a new instance of {@link PhoneAccountSuggestion}. This constructor is intended for
71 * use by apps implementing a {@link PhoneAccountSuggestionService}, and generally should not be
72 * used by dialer apps other than for testing purposes.
73 *
74 * @param handle The {@link PhoneAccountHandle} for this suggestion.
75 * @param reason The reason for this suggestion
76 * @param shouldAutoSelect Whether the dialer should automatically place the call using this
77 * account. See {@link #shouldAutoSelect()}.
Hall Liu066612a2018-11-20 15:32:33 -080078 */
Hall Liu1059cd52019-02-28 18:54:15 -080079 public PhoneAccountSuggestion(@NonNull PhoneAccountHandle handle, @SuggestionReason int reason,
Hall Liu066612a2018-11-20 15:32:33 -080080 boolean shouldAutoSelect) {
81 this.mHandle = handle;
82 this.mReason = reason;
83 this.mShouldAutoSelect = shouldAutoSelect;
84 }
85
86 private PhoneAccountSuggestion(Parcel in) {
87 mHandle = in.readParcelable(PhoneAccountHandle.class.getClassLoader());
88 mReason = in.readInt();
89 mShouldAutoSelect = in.readByte() != 0;
90 }
91
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070092 public static final @android.annotation.NonNull Creator<PhoneAccountSuggestion> CREATOR =
Hall Liu066612a2018-11-20 15:32:33 -080093 new Creator<PhoneAccountSuggestion>() {
94 @Override
95 public PhoneAccountSuggestion createFromParcel(Parcel in) {
96 return new PhoneAccountSuggestion(in);
97 }
98
99 @Override
100 public PhoneAccountSuggestion[] newArray(int size) {
101 return new PhoneAccountSuggestion[size];
102 }
103 };
104
Hall Liu34d9e242018-11-21 17:05:58 -0800105 /**
106 * @return The {@link PhoneAccountHandle} for this suggestion.
107 */
Hall Liu1059cd52019-02-28 18:54:15 -0800108 @NonNull public PhoneAccountHandle getPhoneAccountHandle() {
Hall Liu066612a2018-11-20 15:32:33 -0800109 return mHandle;
110 }
111
Hall Liu34d9e242018-11-21 17:05:58 -0800112 /**
113 * @return The reason for this suggestion
114 */
Hall Liu066612a2018-11-20 15:32:33 -0800115 public @SuggestionReason int getReason() {
116 return mReason;
117 }
118
Hall Liu34d9e242018-11-21 17:05:58 -0800119 /**
120 * Suggests whether the dialer should automatically place the call using this account without
121 * user interaction. This may be set on multiple {@link PhoneAccountSuggestion}s, and the dialer
122 * is free to choose which one to use.
123 * @return {@code true} if the hint is to auto-select, {@code false} otherwise.
124 */
Hall Liu066612a2018-11-20 15:32:33 -0800125 public boolean shouldAutoSelect() {
126 return mShouldAutoSelect;
127 }
128
129 @Override
130 public int describeContents() {
131 return 0;
132 }
133
134 @Override
135 public void writeToParcel(Parcel dest, int flags) {
136 dest.writeParcelable(mHandle, flags);
137 dest.writeInt(mReason);
138 dest.writeByte((byte) (mShouldAutoSelect ? 1 : 0));
139 }
Hall Liu7ddcfd62018-12-10 18:38:11 -0800140
141 @Override
142 public boolean equals(Object o) {
143 if (this == o) return true;
144 if (o == null || getClass() != o.getClass()) return false;
145 PhoneAccountSuggestion that = (PhoneAccountSuggestion) o;
146 return mReason == that.mReason
147 && mShouldAutoSelect == that.mShouldAutoSelect
148 && Objects.equals(mHandle, that.mHandle);
149 }
150
151 @Override
152 public int hashCode() {
153 return Objects.hash(mHandle, mReason, mShouldAutoSelect);
154 }
Hall Liu066612a2018-11-20 15:32:33 -0800155}