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