| 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 | /** |
| 94 | * Flag indicating that this {@code PhoneAccount} is always enabled and cannot be disabled by |
| 95 | * the user. |
| 96 | * This capability is reserved for important {@code PhoneAccount}s such as the emergency calling |
| 97 | * only {@code PhoneAccount}. |
| 98 | * <p> |
| 99 | * See {@link #getCapabilities} |
| 100 | * @hide |
| 101 | */ |
| 102 | public static final int CAPABILITY_ALWAYS_ENABLED = 0x20; |
| 103 | |
| 104 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 105 | * URI scheme for telephone number URIs. |
| 106 | */ |
| 107 | public static final String SCHEME_TEL = "tel"; |
| 108 | |
| 109 | /** |
| 110 | * URI scheme for voicemail URIs. |
| 111 | */ |
| 112 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 113 | |
| 114 | /** |
| 115 | * URI scheme for SIP URIs. |
| 116 | */ |
| 117 | public static final String SCHEME_SIP = "sip"; |
| 118 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 119 | private final PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 120 | private final Uri mAddress; |
| 121 | private final Uri mSubscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 122 | private final int mCapabilities; |
| 123 | private final int mIconResId; |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 124 | private final CharSequence mLabel; |
| 125 | private final CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 126 | private final List<String> mSupportedUriSchemes; |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 127 | private final boolean mIsEnabled; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 128 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 129 | public static class Builder { |
| 130 | private PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 131 | private Uri mAddress; |
| 132 | private Uri mSubscriptionAddress; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 133 | private int mCapabilities; |
| 134 | private int mIconResId; |
| 135 | private CharSequence mLabel; |
| 136 | private CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 137 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 138 | private boolean mIsEnabled = false; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 139 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 140 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 141 | this.mAccountHandle = accountHandle; |
| 142 | this.mLabel = label; |
| 143 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 144 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 145 | /** |
| 146 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 147 | * {@link PhoneAccount}. |
| 148 | * |
| 149 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 150 | */ |
| 151 | public Builder(PhoneAccount phoneAccount) { |
| 152 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 153 | mAddress = phoneAccount.getAddress(); |
| 154 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 155 | mCapabilities = phoneAccount.getCapabilities(); |
| 156 | mIconResId = phoneAccount.getIconResId(); |
| 157 | mLabel = phoneAccount.getLabel(); |
| 158 | mShortDescription = phoneAccount.getShortDescription(); |
| 159 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
| 160 | mIsEnabled = phoneAccount.isEnabled(); |
| 161 | } |
| 162 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 163 | public Builder setAddress(Uri value) { |
| 164 | this.mAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 165 | return this; |
| 166 | } |
| 167 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 168 | public Builder setSubscriptionAddress(Uri value) { |
| 169 | this.mSubscriptionAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 170 | return this; |
| 171 | } |
| 172 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 173 | public Builder setCapabilities(int value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 174 | this.mCapabilities = value; |
| 175 | return this; |
| 176 | } |
| 177 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 178 | public Builder setIconResId(int value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 179 | this.mIconResId = value; |
| 180 | return this; |
| 181 | } |
| 182 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 183 | public Builder setShortDescription(CharSequence value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 184 | this.mShortDescription = value; |
| 185 | return this; |
| 186 | } |
| 187 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 188 | /** |
| 189 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 190 | * |
| 191 | * @param uriScheme The URI scheme. |
| 192 | * @return The Builder. |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 193 | * @hide |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 194 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 195 | public Builder addSupportedUriScheme(String uriScheme) { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 196 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 197 | this.mSupportedUriSchemes.add(uriScheme); |
| 198 | } |
| 199 | return this; |
| 200 | } |
| 201 | |
| 202 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 203 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 204 | * |
| 205 | * @param uriSchemes The URI schemes. |
| 206 | * @return The Builder. |
| 207 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 208 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 209 | mSupportedUriSchemes.clear(); |
| 210 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 211 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 212 | for (String uriScheme : uriSchemes) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 213 | addSupportedUriScheme(uriScheme); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | return this; |
| 217 | } |
| 218 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 219 | /** |
| 220 | * Specifies whether the {@link PhoneAccount} is enabled or not. {@link PhoneAccount}s are |
| 221 | * by default not enabled. |
| 222 | * |
| 223 | * @param value {@code True} if the {@link PhoneAccount} is enabled. |
| 224 | * @return The Builder. |
| 225 | * @hide |
| 226 | */ |
| 227 | public Builder setEnabled(boolean value) { |
| 228 | this.mIsEnabled = value; |
| 229 | return this; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 234 | * |
| 235 | * @return The {@link PhoneAccount}. |
| 236 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 237 | public PhoneAccount build() { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 238 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 239 | if (mSupportedUriSchemes.isEmpty()) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 240 | addSupportedUriScheme(SCHEME_TEL); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 243 | return new PhoneAccount( |
| 244 | mAccountHandle, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 245 | mAddress, |
| 246 | mSubscriptionAddress, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 247 | mCapabilities, |
| 248 | mIconResId, |
| 249 | mLabel, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 250 | mShortDescription, |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 251 | mSupportedUriSchemes, |
| 252 | mIsEnabled); |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | private PhoneAccount( |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 257 | PhoneAccountHandle account, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 258 | Uri address, |
| 259 | Uri subscriptionAddress, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 260 | int capabilities, |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 261 | int iconResId, |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 262 | CharSequence label, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 263 | CharSequence shortDescription, |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 264 | List<String> supportedUriSchemes, |
| 265 | boolean enabled) { |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 266 | mAccountHandle = account; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 267 | mAddress = address; |
| 268 | mSubscriptionAddress = subscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 269 | mCapabilities = capabilities; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 270 | mIconResId = iconResId; |
| 271 | mLabel = label; |
| 272 | mShortDescription = shortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 273 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 274 | mIsEnabled = enabled; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 277 | public static Builder builder( |
| 278 | PhoneAccountHandle accountHandle, |
| 279 | CharSequence label) { |
| 280 | return new Builder(accountHandle, label); |
| 281 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 282 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 283 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 284 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 285 | * |
| 286 | * @return The builder. |
| 287 | * @hide |
| 288 | */ |
| 289 | public Builder toBuilder() { return new Builder(this); } |
| 290 | |
| 291 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 292 | * The unique identifier of this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 293 | * |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 294 | * @return A {@code PhoneAccountHandle}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 295 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 296 | public PhoneAccountHandle getAccountHandle() { |
| 297 | return mAccountHandle; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 301 | * 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] | 302 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 303 | * 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] | 304 | * {@code PhoneAccount} may be addressed. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 305 | * |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 306 | * @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] | 307 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 308 | public Uri getAddress() { |
| 309 | return mAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 313 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 314 | * {@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] | 315 | * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration |
| 316 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 317 | * has been used to alter the callback number. |
| 318 | * <p> |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 319 | * |
| 320 | * @return The subscription number, suitable for display to the user. |
| 321 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 322 | public Uri getSubscriptionAddress() { |
| 323 | return mSubscriptionAddress; |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 327 | * The capabilities of this {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 328 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 329 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 330 | */ |
| 331 | public int getCapabilities() { |
| 332 | return mCapabilities; |
| 333 | } |
| 334 | |
| 335 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 336 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 337 | * bit mask. |
| 338 | * |
| 339 | * @param capability The capabilities to check. |
| 340 | * @return {@code True} if the phone account has the capability. |
| 341 | */ |
| 342 | public boolean hasCapabilities(int capability) { |
| 343 | return (mCapabilities & capability) == capability; |
| 344 | } |
| 345 | |
| 346 | /** |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 347 | * A short label describing a {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 348 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 349 | * @return A label for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 350 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 351 | public CharSequence getLabel() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 352 | return mLabel; |
| 353 | } |
| 354 | |
| 355 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 356 | * A short paragraph describing this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 357 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 358 | * @return A description for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 359 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 360 | public CharSequence getShortDescription() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 361 | return mShortDescription; |
| 362 | } |
| 363 | |
| 364 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 365 | * The URI schemes supported by this {@code PhoneAccount}. |
| 366 | * |
| 367 | * @return The URI schemes. |
| 368 | */ |
| 369 | public List<String> getSupportedUriSchemes() { |
| 370 | return mSupportedUriSchemes; |
| 371 | } |
| 372 | |
| 373 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 374 | * 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] | 375 | * scheme. |
| 376 | * |
| 377 | * @param uriScheme The URI scheme to check. |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 378 | * @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] | 379 | * specified URI scheme. |
| 380 | */ |
| 381 | public boolean supportsUriScheme(String uriScheme) { |
| 382 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | for (String scheme : mSupportedUriSchemes) { |
| 387 | if (scheme != null && scheme.equals(uriScheme)) { |
| 388 | return true; |
| 389 | } |
| 390 | } |
| 391 | return false; |
| 392 | } |
| 393 | |
| 394 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 395 | * Determines whether this {@code PhoneAccount} is enabled. |
| 396 | * |
| 397 | * @return {@code True} if this {@code PhoneAccount} is enabled.. |
| 398 | */ |
| 399 | public boolean isEnabled() { |
| 400 | return mIsEnabled; |
| 401 | } |
| 402 | |
| 403 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 404 | * The icon resource ID for the icon of this {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 405 | * |
| 406 | * @return A resource ID. |
| 407 | */ |
| 408 | public int getIconResId() { |
| 409 | return mIconResId; |
| 410 | } |
| 411 | |
| 412 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 413 | * An icon to represent this {@code PhoneAccount} in a user interface. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 414 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 415 | * @return An icon for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 416 | */ |
| 417 | public Drawable getIcon(Context context) { |
| 418 | return getIcon(context, mIconResId); |
| 419 | } |
| 420 | |
| 421 | private Drawable getIcon(Context context, int resId) { |
| 422 | Context packageContext; |
| 423 | try { |
| 424 | packageContext = context.createPackageContext( |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 425 | mAccountHandle.getComponentName().getPackageName(), 0); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 426 | } catch (PackageManager.NameNotFoundException e) { |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 427 | Log.w(this, "Cannot find package %s", mAccountHandle.getComponentName().getPackageName()); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 428 | return null; |
| 429 | } |
| 430 | try { |
| Alan Viverette | 03d30a5 | 2014-08-14 12:59:10 -0700 | [diff] [blame] | 431 | return packageContext.getDrawable(resId); |
| Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 432 | } catch (NotFoundException|MissingResourceException e) { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 433 | Log.e(this, e, "Cannot find icon %d in package %s", |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 434 | resId, mAccountHandle.getComponentName().getPackageName()); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 435 | return null; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | // |
| 440 | // Parcelable implementation |
| 441 | // |
| 442 | |
| 443 | @Override |
| 444 | public int describeContents() { |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public void writeToParcel(Parcel out, int flags) { |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 450 | out.writeParcelable(mAccountHandle, 0); |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 451 | out.writeParcelable(mAddress, 0); |
| 452 | out.writeParcelable(mSubscriptionAddress, 0); |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 453 | out.writeInt(mCapabilities); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 454 | out.writeInt(mIconResId); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 455 | out.writeCharSequence(mLabel); |
| 456 | out.writeCharSequence(mShortDescription); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 457 | out.writeList(mSupportedUriSchemes); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 458 | out.writeInt(mIsEnabled ? 1 : 0); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 461 | public static final Creator<PhoneAccount> CREATOR |
| 462 | = new Creator<PhoneAccount>() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 463 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 464 | public PhoneAccount createFromParcel(Parcel in) { |
| 465 | return new PhoneAccount(in); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 469 | public PhoneAccount[] newArray(int size) { |
| 470 | return new PhoneAccount[size]; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 471 | } |
| 472 | }; |
| 473 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 474 | private PhoneAccount(Parcel in) { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 475 | ClassLoader classLoader = PhoneAccount.class.getClassLoader(); |
| 476 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 477 | mAccountHandle = in.readParcelable(getClass().getClassLoader()); |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 478 | mAddress = in.readParcelable(getClass().getClassLoader()); |
| 479 | mSubscriptionAddress = in.readParcelable(getClass().getClassLoader()); |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 480 | mCapabilities = in.readInt(); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 481 | mIconResId = in.readInt(); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 482 | mLabel = in.readCharSequence(); |
| 483 | mShortDescription = in.readCharSequence(); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 484 | |
| 485 | List<String> supportedUriSchemes = new ArrayList<>(); |
| 486 | in.readList(supportedUriSchemes, classLoader); |
| 487 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 488 | mIsEnabled = in.readInt() == 1; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 489 | } |
| 490 | } |