Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 18 | |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.pm.PackageManager; |
Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 22 | import android.content.res.Resources.NotFoundException; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 24 | import android.net.Uri; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 27 | import android.text.TextUtils; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 28 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 29 | import java.lang.String; |
| 30 | import java.util.ArrayList; |
| 31 | import java.util.Collections; |
| 32 | import java.util.List; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 33 | import java.util.MissingResourceException; |
| 34 | |
| 35 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 36 | * Describes a distinct account, line of service or call placement method that the system |
| 37 | * can use to place phone calls. |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 38 | * @hide |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 39 | */ |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 40 | @SystemApi |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 41 | public class PhoneAccount implements Parcelable { |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 44 | * Flag indicating that this {@code PhoneAccount} can act as a connection manager for |
| 45 | * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount} |
| 46 | * will be allowed to manage phone calls including using its own proprietary phone-call |
| 47 | * implementation (like VoIP calling) to make calls instead of the telephony stack. |
| 48 | * <p> |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 49 | * When a user opts to place a call using the SIM-based telephony stack, the |
| 50 | * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first |
| 51 | * if the user has explicitly selected it to be used as the default connection manager. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 52 | * <p> |
| 53 | * See {@link #getCapabilities} |
| 54 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 55 | public static final int CAPABILITY_CONNECTION_MANAGER = 0x1; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 58 | * Flag indicating that this {@code PhoneAccount} can make phone calls in place of |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 59 | * traditional SIM-based telephony calls. This account will be treated as a distinct method |
| 60 | * for placing calls alongside the traditional SIM-based telephony stack. This flag is |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 61 | * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 62 | * calls from or use the built-in telephony stack to place its calls. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 63 | * <p> |
| 64 | * See {@link #getCapabilities} |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 65 | * <p> |
Evan Charlton | 7800fb7 | 2014-07-20 18:09:38 -0700 | [diff] [blame] | 66 | * {@hide} |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 67 | */ |
| 68 | public static final int CAPABILITY_CALL_PROVIDER = 0x2; |
| 69 | |
Ihab Awad | 7522bbd | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 70 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 71 | * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 72 | * subscription. |
Ihab Awad | 7522bbd | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 73 | * <p> |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 74 | * Only the Android framework can register a {@code PhoneAccount} having this capability. |
| 75 | * <p> |
| 76 | * See {@link #getCapabilities} |
Ihab Awad | 7522bbd | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 77 | */ |
| 78 | public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; |
| 79 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 80 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 81 | * Flag indicating that this {@code PhoneAccount} is capable of placing video calls. |
| 82 | * <p> |
| 83 | * See {@link #getCapabilities} |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 84 | * @hide |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 85 | */ |
| 86 | public static final int CAPABILITY_VIDEO_CALLING = 0x8; |
| 87 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 88 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 89 | * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. |
| 90 | * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. |
| 91 | * <p> |
| 92 | * See {@link #getCapabilities} |
| 93 | */ |
| 94 | public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; |
| 95 | |
| 96 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 97 | * URI scheme for telephone number URIs. |
| 98 | */ |
| 99 | public static final String SCHEME_TEL = "tel"; |
| 100 | |
| 101 | /** |
| 102 | * URI scheme for voicemail URIs. |
| 103 | */ |
| 104 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 105 | |
| 106 | /** |
| 107 | * URI scheme for SIP URIs. |
| 108 | */ |
| 109 | public static final String SCHEME_SIP = "sip"; |
| 110 | |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Indicating no color is set. |
| 113 | */ |
| 114 | public static final int NO_COLOR = -1; |
| 115 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 116 | private final PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 117 | private final Uri mAddress; |
| 118 | private final Uri mSubscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 119 | private final int mCapabilities; |
| 120 | private final int mIconResId; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 121 | private final int mColor; |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 122 | private final CharSequence mLabel; |
| 123 | private final CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 124 | private final List<String> mSupportedUriSchemes; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 125 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 126 | public static class Builder { |
| 127 | private PhoneAccountHandle mAccountHandle; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 128 | private Uri mAddress; |
| 129 | private Uri mSubscriptionAddress; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 130 | private int mCapabilities; |
| 131 | private int mIconResId; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 132 | private int mColor = NO_COLOR; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 133 | private CharSequence mLabel; |
| 134 | private CharSequence mShortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 135 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 136 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 137 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 138 | this.mAccountHandle = accountHandle; |
| 139 | this.mLabel = label; |
| 140 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 141 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 142 | /** |
| 143 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 144 | * {@link PhoneAccount}. |
| 145 | * |
| 146 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 147 | */ |
| 148 | public Builder(PhoneAccount phoneAccount) { |
| 149 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 150 | mAddress = phoneAccount.getAddress(); |
| 151 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 152 | mCapabilities = phoneAccount.getCapabilities(); |
| 153 | mIconResId = phoneAccount.getIconResId(); |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 154 | mColor = phoneAccount.getColor(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 155 | mLabel = phoneAccount.getLabel(); |
| 156 | mShortDescription = phoneAccount.getShortDescription(); |
| 157 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 160 | public Builder setAddress(Uri value) { |
| 161 | this.mAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 162 | return this; |
| 163 | } |
| 164 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 165 | public Builder setSubscriptionAddress(Uri value) { |
| 166 | this.mSubscriptionAddress = value; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 167 | return this; |
| 168 | } |
| 169 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 170 | public Builder setCapabilities(int value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 171 | this.mCapabilities = value; |
| 172 | return this; |
| 173 | } |
| 174 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 175 | public Builder setIconResId(int value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 176 | this.mIconResId = value; |
| 177 | return this; |
| 178 | } |
| 179 | |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 180 | public Builder setColor(int value) { |
| 181 | this.mColor = value; |
| 182 | return this; |
| 183 | } |
| 184 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 185 | public Builder setShortDescription(CharSequence value) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 186 | this.mShortDescription = value; |
| 187 | return this; |
| 188 | } |
| 189 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 190 | /** |
| 191 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 192 | * |
| 193 | * @param uriScheme The URI scheme. |
| 194 | * @return The Builder. |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 195 | * @hide |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 196 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 197 | public Builder addSupportedUriScheme(String uriScheme) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 198 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 199 | this.mSupportedUriSchemes.add(uriScheme); |
| 200 | } |
| 201 | return this; |
| 202 | } |
| 203 | |
| 204 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 205 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 206 | * |
| 207 | * @param uriSchemes The URI schemes. |
| 208 | * @return The Builder. |
| 209 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 210 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 211 | mSupportedUriSchemes.clear(); |
| 212 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 213 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 214 | for (String uriScheme : uriSchemes) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 215 | addSupportedUriScheme(uriScheme); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | return this; |
| 219 | } |
| 220 | |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 221 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 222 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 223 | * |
| 224 | * @return The {@link PhoneAccount}. |
| 225 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 226 | public PhoneAccount build() { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 227 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 228 | if (mSupportedUriSchemes.isEmpty()) { |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 229 | addSupportedUriScheme(SCHEME_TEL); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 232 | return new PhoneAccount( |
| 233 | mAccountHandle, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 234 | mAddress, |
| 235 | mSubscriptionAddress, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 236 | mCapabilities, |
| 237 | mIconResId, |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 238 | mColor, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 239 | mLabel, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 240 | mShortDescription, |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 241 | mSupportedUriSchemes); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | private PhoneAccount( |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 246 | PhoneAccountHandle account, |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 247 | Uri address, |
| 248 | Uri subscriptionAddress, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 249 | int capabilities, |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 250 | int iconResId, |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 251 | int color, |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 252 | CharSequence label, |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 253 | CharSequence shortDescription, |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 254 | List<String> supportedUriSchemes) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 255 | mAccountHandle = account; |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 256 | mAddress = address; |
| 257 | mSubscriptionAddress = subscriptionAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 258 | mCapabilities = capabilities; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 259 | mIconResId = iconResId; |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 260 | mColor = color; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 261 | mLabel = label; |
| 262 | mShortDescription = shortDescription; |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 263 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 266 | public static Builder builder( |
| 267 | PhoneAccountHandle accountHandle, |
| 268 | CharSequence label) { |
| 269 | return new Builder(accountHandle, label); |
| 270 | } |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 271 | |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 272 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 273 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 274 | * |
| 275 | * @return The builder. |
| 276 | * @hide |
| 277 | */ |
| 278 | public Builder toBuilder() { return new Builder(this); } |
| 279 | |
| 280 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 281 | * The unique identifier of this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 282 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 283 | * @return A {@code PhoneAccountHandle}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 284 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 285 | public PhoneAccountHandle getAccountHandle() { |
| 286 | return mAccountHandle; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 290 | * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 291 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 292 | * will appear to come, if applicable, and the destination to which incoming calls using this |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 293 | * {@code PhoneAccount} may be addressed. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 294 | * |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 295 | * @return A address expressed as a {@code Uri}, for example, a phone number. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 296 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 297 | public Uri getAddress() { |
| 298 | return mAddress; |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 302 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 303 | * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 304 | * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration |
Evan Charlton | 222db52 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 305 | * |
| 306 | * @return The subscription number, suitable for display to the user. |
| 307 | */ |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 308 | public Uri getSubscriptionAddress() { |
| 309 | return mSubscriptionAddress; |
Evan Charlton | 222db52 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 313 | * The capabilities of this {@code PhoneAccount}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 314 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 315 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 316 | */ |
| 317 | public int getCapabilities() { |
| 318 | return mCapabilities; |
| 319 | } |
| 320 | |
| 321 | /** |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 322 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 323 | * bit mask. |
| 324 | * |
| 325 | * @param capability The capabilities to check. |
| 326 | * @return {@code True} if the phone account has the capability. |
| 327 | */ |
| 328 | public boolean hasCapabilities(int capability) { |
| 329 | return (mCapabilities & capability) == capability; |
| 330 | } |
| 331 | |
| 332 | /** |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 333 | * A short label describing a {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 334 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 335 | * @return A label for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 336 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 337 | public CharSequence getLabel() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 338 | return mLabel; |
| 339 | } |
| 340 | |
| 341 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 342 | * A short paragraph describing this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 343 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 344 | * @return A description for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 345 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 346 | public CharSequence getShortDescription() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 347 | return mShortDescription; |
| 348 | } |
| 349 | |
| 350 | /** |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 351 | * The URI schemes supported by this {@code PhoneAccount}. |
| 352 | * |
| 353 | * @return The URI schemes. |
| 354 | */ |
| 355 | public List<String> getSupportedUriSchemes() { |
| 356 | return mSupportedUriSchemes; |
| 357 | } |
| 358 | |
| 359 | /** |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 360 | * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 361 | * scheme. |
| 362 | * |
| 363 | * @param uriScheme The URI scheme to check. |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 364 | * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 365 | * specified URI scheme. |
| 366 | */ |
| 367 | public boolean supportsUriScheme(String uriScheme) { |
| 368 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 369 | return false; |
| 370 | } |
| 371 | |
| 372 | for (String scheme : mSupportedUriSchemes) { |
| 373 | if (scheme != null && scheme.equals(uriScheme)) { |
| 374 | return true; |
| 375 | } |
| 376 | } |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 381 | * The icon resource ID for the icon of this {@code PhoneAccount}. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 382 | * |
| 383 | * @return A resource ID. |
| 384 | */ |
| 385 | public int getIconResId() { |
| 386 | return mIconResId; |
| 387 | } |
| 388 | |
| 389 | /** |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 390 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 391 | * |
| 392 | * @return A hexadecimal color value. |
| 393 | */ |
| 394 | public int getColor() { |
| 395 | return mColor; |
| 396 | } |
| 397 | |
| 398 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 399 | * An icon to represent this {@code PhoneAccount} in a user interface. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 400 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 401 | * @return An icon for this {@code PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 402 | */ |
| 403 | public Drawable getIcon(Context context) { |
| 404 | return getIcon(context, mIconResId); |
| 405 | } |
| 406 | |
| 407 | private Drawable getIcon(Context context, int resId) { |
| 408 | Context packageContext; |
| 409 | try { |
| 410 | packageContext = context.createPackageContext( |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 411 | mAccountHandle.getComponentName().getPackageName(), 0); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 412 | } catch (PackageManager.NameNotFoundException e) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 413 | Log.w(this, "Cannot find package %s", mAccountHandle.getComponentName().getPackageName()); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 414 | return null; |
| 415 | } |
| 416 | try { |
Alan Viverette | 03d30a5 | 2014-08-14 12:59:10 -0700 | [diff] [blame] | 417 | return packageContext.getDrawable(resId); |
Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 418 | } catch (NotFoundException|MissingResourceException e) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 419 | Log.e(this, e, "Cannot find icon %d in package %s", |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 420 | resId, mAccountHandle.getComponentName().getPackageName()); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 421 | return null; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // |
| 426 | // Parcelable implementation |
| 427 | // |
| 428 | |
| 429 | @Override |
| 430 | public int describeContents() { |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | @Override |
| 435 | public void writeToParcel(Parcel out, int flags) { |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 436 | out.writeParcelable(mAccountHandle, 0); |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 437 | out.writeParcelable(mAddress, 0); |
| 438 | out.writeParcelable(mSubscriptionAddress, 0); |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 439 | out.writeInt(mCapabilities); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 440 | out.writeInt(mIconResId); |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 441 | out.writeInt(mColor); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 442 | out.writeCharSequence(mLabel); |
| 443 | out.writeCharSequence(mShortDescription); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 444 | out.writeList(mSupportedUriSchemes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 447 | public static final Creator<PhoneAccount> CREATOR |
| 448 | = new Creator<PhoneAccount>() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 449 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 450 | public PhoneAccount createFromParcel(Parcel in) { |
| 451 | return new PhoneAccount(in); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | @Override |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 455 | public PhoneAccount[] newArray(int size) { |
| 456 | return new PhoneAccount[size]; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 457 | } |
| 458 | }; |
| 459 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 460 | private PhoneAccount(Parcel in) { |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 461 | ClassLoader classLoader = PhoneAccount.class.getClassLoader(); |
| 462 | |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 463 | mAccountHandle = in.readParcelable(getClass().getClassLoader()); |
Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 464 | mAddress = in.readParcelable(getClass().getClassLoader()); |
| 465 | mSubscriptionAddress = in.readParcelable(getClass().getClassLoader()); |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 466 | mCapabilities = in.readInt(); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 467 | mIconResId = in.readInt(); |
Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 468 | mColor = in.readInt(); |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 469 | mLabel = in.readCharSequence(); |
| 470 | mShortDescription = in.readCharSequence(); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 471 | |
| 472 | List<String> supportedUriSchemes = new ArrayList<>(); |
| 473 | in.readList(supportedUriSchemes, classLoader); |
| 474 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 475 | } |
| 476 | } |