Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 1 | /* |
| 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 Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 17 | package android.telecom; |
| 18 | |
| 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.SystemApi; |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 21 | import android.annotation.TestApi; |
Hall Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | |
| 25 | import java.lang.annotation.Retention; |
| 26 | import java.lang.annotation.RetentionPolicy; |
| 27 | |
| 28 | public 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 Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 36 | /** |
| 37 | * Indicates that this account is not suggested for use, but is still available. |
| 38 | */ |
Hall Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 39 | public static final int REASON_NONE = 0; |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 40 | |
| 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 Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 45 | public static final int REASON_INTRA_CARRIER = 1; |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 46 | |
| 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 Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 51 | public static final int REASON_FREQUENT = 2; |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 52 | |
| 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 Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 57 | public static final int REASON_USER_SET = 3; |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 58 | |
| 59 | /** |
| 60 | * Indicates that the {@link PhoneAccountHandle} is suggested for a reason not otherwise |
| 61 | * enumerated here. |
| 62 | */ |
Hall Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 63 | public static final int REASON_OTHER = 4; |
| 64 | |
| 65 | private PhoneAccountHandle mHandle; |
| 66 | private int mReason; |
| 67 | private boolean mShouldAutoSelect; |
| 68 | |
| 69 | /** |
| 70 | * @hide |
| 71 | */ |
| 72 | @SystemApi |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 73 | @TestApi |
Hall Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 74 | public PhoneAccountSuggestion(PhoneAccountHandle handle, @SuggestionReason int reason, |
| 75 | boolean shouldAutoSelect) { |
| 76 | this.mHandle = handle; |
| 77 | this.mReason = reason; |
| 78 | this.mShouldAutoSelect = shouldAutoSelect; |
| 79 | } |
| 80 | |
| 81 | private PhoneAccountSuggestion(Parcel in) { |
| 82 | mHandle = in.readParcelable(PhoneAccountHandle.class.getClassLoader()); |
| 83 | mReason = in.readInt(); |
| 84 | mShouldAutoSelect = in.readByte() != 0; |
| 85 | } |
| 86 | |
| 87 | public static final Creator<PhoneAccountSuggestion> CREATOR = |
| 88 | new Creator<PhoneAccountSuggestion>() { |
| 89 | @Override |
| 90 | public PhoneAccountSuggestion createFromParcel(Parcel in) { |
| 91 | return new PhoneAccountSuggestion(in); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public PhoneAccountSuggestion[] newArray(int size) { |
| 96 | return new PhoneAccountSuggestion[size]; |
| 97 | } |
| 98 | }; |
| 99 | |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 100 | /** |
| 101 | * @return The {@link PhoneAccountHandle} for this suggestion. |
| 102 | */ |
| 103 | public PhoneAccountHandle getPhoneAccountHandle() { |
Hall Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 104 | return mHandle; |
| 105 | } |
| 106 | |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 107 | /** |
| 108 | * @return The reason for this suggestion |
| 109 | */ |
Hall Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 110 | public @SuggestionReason int getReason() { |
| 111 | return mReason; |
| 112 | } |
| 113 | |
Hall Liu | 34d9e24 | 2018-11-21 17:05:58 -0800 | [diff] [blame^] | 114 | /** |
| 115 | * Suggests whether the dialer should automatically place the call using this account without |
| 116 | * user interaction. This may be set on multiple {@link PhoneAccountSuggestion}s, and the dialer |
| 117 | * is free to choose which one to use. |
| 118 | * @return {@code true} if the hint is to auto-select, {@code false} otherwise. |
| 119 | */ |
Hall Liu | 066612a | 2018-11-20 15:32:33 -0800 | [diff] [blame] | 120 | public boolean shouldAutoSelect() { |
| 121 | return mShouldAutoSelect; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public int describeContents() { |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void writeToParcel(Parcel dest, int flags) { |
| 131 | dest.writeParcelable(mHandle, flags); |
| 132 | dest.writeInt(mReason); |
| 133 | dest.writeByte((byte) (mShouldAutoSelect ? 1 : 0)); |
| 134 | } |
| 135 | } |