Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -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 | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 17 | package com.android.server.telecom; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 18 | |
Tyler Gunn | cb59b67 | 2014-08-20 09:02:11 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Evan Charlton | af51ceb | 2014-07-30 11:56:36 -0700 | [diff] [blame] | 20 | import android.content.Intent; |
| 21 | import android.content.pm.PackageManager; |
| 22 | import android.content.pm.ResolveInfo; |
Tyler Gunn | cb59b67 | 2014-08-20 09:02:11 -0700 | [diff] [blame] | 23 | import android.content.pm.ServiceInfo; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame^] | 24 | import android.os.Environment; |
| 25 | import android.os.UserHandle; |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 26 | import android.provider.Settings; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 27 | import android.telecom.ConnectionService; |
| 28 | import android.telecom.PhoneAccount; |
| 29 | import android.telecom.PhoneAccountHandle; |
| 30 | import android.telecom.TelecomManager; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 31 | import android.content.ComponentName; |
| 32 | import android.content.Context; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 33 | import android.net.Uri; |
Evan Charlton | af51ceb | 2014-07-30 11:56:36 -0700 | [diff] [blame] | 34 | import android.text.TextUtils; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 35 | import android.util.AtomicFile; |
| 36 | import android.util.Xml; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 37 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame^] | 38 | // TODO: Needed for move to system service: import com.android.internal.R; |
Sailesh Nepal | 0e1dc5a | 2014-07-30 11:08:54 -0700 | [diff] [blame] | 39 | import com.android.internal.annotations.VisibleForTesting; |
| 40 | import com.android.internal.util.FastXmlSerializer; |
| 41 | import com.android.internal.util.XmlUtils; |
| 42 | |
Evan Charlton | af51ceb | 2014-07-30 11:56:36 -0700 | [diff] [blame] | 43 | import org.xmlpull.v1.XmlPullParser; |
| 44 | import org.xmlpull.v1.XmlPullParserException; |
| 45 | import org.xmlpull.v1.XmlSerializer; |
| 46 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 47 | import java.io.BufferedInputStream; |
| 48 | import java.io.BufferedOutputStream; |
| 49 | import java.io.File; |
| 50 | import java.io.FileNotFoundException; |
| 51 | import java.io.FileOutputStream; |
| 52 | import java.io.IOException; |
| 53 | import java.io.InputStream; |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 54 | import java.lang.Integer; |
Tyler Gunn | cb59b67 | 2014-08-20 09:02:11 -0700 | [diff] [blame] | 55 | import java.lang.SecurityException; |
Tyler Gunn | d900ce6 | 2014-08-13 11:40:59 -0700 | [diff] [blame] | 56 | import java.lang.String; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 57 | import java.util.ArrayList; |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 58 | import java.util.Collections; |
Tyler Gunn | d900ce6 | 2014-08-13 11:40:59 -0700 | [diff] [blame] | 59 | import java.util.Iterator; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 60 | import java.util.List; |
| 61 | import java.util.Objects; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 62 | import java.util.concurrent.CopyOnWriteArrayList; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 65 | * Handles writing and reading PhoneAccountHandle registration entries. This is a simple verbatim |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 66 | * delegate for all the account handling methods on {@link android.telecom.TelecomManager} as implemented in |
| 67 | * {@link TelecomServiceImpl}, with the notable exception that {@link TelecomServiceImpl} is |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 68 | * responsible for security checking to make sure that the caller has proper authority over |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 69 | * the {@code ComponentName}s they are declaring in their {@code PhoneAccountHandle}s. |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 70 | */ |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 71 | public final class PhoneAccountRegistrar { |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 72 | |
Yorke Lee | 5e8836a | 2014-08-22 15:25:18 -0700 | [diff] [blame] | 73 | public static final PhoneAccountHandle NO_ACCOUNT_SELECTED = |
| 74 | new PhoneAccountHandle(new ComponentName("null", "null"), "NO_ACCOUNT_SELECTED"); |
| 75 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 76 | public abstract static class Listener { |
| 77 | public void onAccountsChanged(PhoneAccountRegistrar registrar) {} |
| 78 | public void onDefaultOutgoingChanged(PhoneAccountRegistrar registrar) {} |
| 79 | public void onSimCallManagerChanged(PhoneAccountRegistrar registrar) {} |
| 80 | } |
| 81 | |
| 82 | private static final String FILE_NAME = "phone-account-registrar-state.xml"; |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 83 | @VisibleForTesting |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 84 | public static final int EXPECTED_STATE_VERSION = 3; |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 85 | |
| 86 | /** Keep in sync with the same in SipSettings.java */ |
| 87 | private static final String SIP_SHARED_PREFERENCES = "SIP_PREFERENCES"; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 88 | |
| 89 | private final List<Listener> mListeners = new CopyOnWriteArrayList<>(); |
| 90 | private final AtomicFile mAtomicFile; |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 91 | private final Context mContext; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 92 | private State mState; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 93 | |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 94 | public PhoneAccountRegistrar(Context context) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 95 | this(context, FILE_NAME); |
| 96 | } |
| 97 | |
| 98 | @VisibleForTesting |
| 99 | public PhoneAccountRegistrar(Context context, String fileName) { |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame^] | 100 | // TODO: This file path is subject to change -- it is storing the phone account registry |
| 101 | // state file in the path /data/system/users/0/, which is likely not correct in a |
| 102 | // multi-user setting. |
| 103 | /** UNCOMMENT_FOR_MOVE_TO_SYSTEM_SERVICE |
| 104 | String filePath = Environment.getUserSystemDirectory(UserHandle.myUserId()). |
| 105 | getAbsolutePath(); |
| 106 | mAtomicFile = new AtomicFile(new File(filePath, fileName)); |
| 107 | UNCOMMENT_FOR_MOVE_TO_SYSTEM_SERVICE */ |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 108 | mAtomicFile = new AtomicFile(new File(context.getFilesDir(), fileName)); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame^] | 109 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 110 | mState = new State(); |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 111 | mContext = context; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 112 | read(); |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 115 | /** |
| 116 | * Retrieves the default outgoing phone account supporting the specified uriScheme. |
| 117 | * @param uriScheme The URI scheme for the outgoing call. |
| 118 | * @return The {@link PhoneAccountHandle} to use. |
| 119 | */ |
| 120 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { |
Yorke Lee | 5e8836a | 2014-08-22 15:25:18 -0700 | [diff] [blame] | 121 | final PhoneAccountHandle userSelected = getUserSelectedOutgoingPhoneAccount(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 122 | |
Yorke Lee | 5e8836a | 2014-08-22 15:25:18 -0700 | [diff] [blame] | 123 | if (userSelected != null) { |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 124 | // If there is a default PhoneAccount, ensure it supports calls to handles with the |
| 125 | // specified uriScheme. |
| 126 | final PhoneAccount userSelectedAccount = getPhoneAccount(userSelected); |
| 127 | if (userSelectedAccount.supportsUriScheme(uriScheme)) { |
| 128 | return userSelected; |
| 129 | } |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 132 | List<PhoneAccountHandle> outgoing = getCallCapablePhoneAccounts(uriScheme); |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 133 | switch (outgoing.size()) { |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 134 | case 0: |
| 135 | // There are no accounts, so there can be no default |
| 136 | return null; |
| 137 | case 1: |
| 138 | // There is only one account, which is by definition the default |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 139 | return outgoing.get(0); |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 140 | default: |
| 141 | // There are multiple accounts with no selected default |
| 142 | return null; |
Ihab Awad | f2a8491 | 2014-07-22 21:09:25 -0700 | [diff] [blame] | 143 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 144 | } |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 145 | |
Yorke Lee | 5e8836a | 2014-08-22 15:25:18 -0700 | [diff] [blame] | 146 | PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
| 147 | if (mState.defaultOutgoing != null) { |
| 148 | // Return the registered outgoing default iff it still exists (we keep a sticky |
| 149 | // default to survive account deletion and re-addition) |
| 150 | for (int i = 0; i < mState.accounts.size(); i++) { |
| 151 | if (mState.accounts.get(i).getAccountHandle().equals(mState.defaultOutgoing)) { |
| 152 | return mState.defaultOutgoing; |
| 153 | } |
| 154 | } |
| 155 | // At this point, there was a registered default but it has been deleted; proceed |
| 156 | // as though there were no default |
| 157 | } |
| 158 | return null; |
| 159 | } |
| 160 | |
Andrew Lee | a51a386 | 2014-09-03 14:58:45 -0700 | [diff] [blame] | 161 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 162 | if (accountHandle == null) { |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 163 | // Asking to clear the default outgoing is a valid request |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 164 | mState.defaultOutgoing = null; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 165 | } else { |
| 166 | boolean found = false; |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 167 | for (PhoneAccount m : mState.accounts) { |
Evan Charlton | 94d0162 | 2014-07-20 12:32:05 -0700 | [diff] [blame] | 168 | if (Objects.equals(accountHandle, m.getAccountHandle())) { |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 169 | found = true; |
| 170 | break; |
| 171 | } |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 172 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 173 | |
| 174 | if (!found) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 175 | Log.w(this, "Trying to set nonexistent default outgoing %s", |
| 176 | accountHandle); |
| 177 | return; |
| 178 | } |
| 179 | |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 180 | if (!getPhoneAccount(accountHandle).hasCapabilities( |
| 181 | PhoneAccount.CAPABILITY_CALL_PROVIDER)) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 182 | Log.w(this, "Trying to set non-call-provider default outgoing %s", |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 183 | accountHandle); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 184 | return; |
| 185 | } |
| 186 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 187 | mState.defaultOutgoing = accountHandle; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 190 | write(); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 191 | fireDefaultOutgoingChanged(); |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 194 | public void setSimCallManager(PhoneAccountHandle callManager) { |
| 195 | if (callManager != null) { |
| 196 | PhoneAccount callManagerAccount = getPhoneAccount(callManager); |
| 197 | if (callManagerAccount == null) { |
| 198 | Log.d(this, "setSimCallManager: Nonexistent call manager: %s", callManager); |
| 199 | return; |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 200 | } else if (!callManagerAccount.hasCapabilities( |
| 201 | PhoneAccount.CAPABILITY_CONNECTION_MANAGER)) { |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 202 | Log.d(this, "setSimCallManager: Not a call manager: %s", callManagerAccount); |
| 203 | return; |
| 204 | } |
Yorke Lee | 5e8836a | 2014-08-22 15:25:18 -0700 | [diff] [blame] | 205 | } else { |
| 206 | callManager = NO_ACCOUNT_SELECTED; |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 207 | } |
| 208 | mState.simCallManager = callManager; |
Yorke Lee | 5e8836a | 2014-08-22 15:25:18 -0700 | [diff] [blame] | 209 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 210 | write(); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 211 | fireSimCallManagerChanged(); |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | public PhoneAccountHandle getSimCallManager() { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 215 | if (mState.simCallManager != null) { |
Yorke Lee | 5e8836a | 2014-08-22 15:25:18 -0700 | [diff] [blame] | 216 | if (NO_ACCOUNT_SELECTED.equals(mState.simCallManager)) { |
| 217 | return null; |
| 218 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 219 | // Return the registered sim call manager iff it still exists (we keep a sticky |
| 220 | // setting to survive account deletion and re-addition) |
| 221 | for (int i = 0; i < mState.accounts.size(); i++) { |
| 222 | if (mState.accounts.get(i).getAccountHandle().equals(mState.simCallManager)) { |
| 223 | return mState.simCallManager; |
| 224 | } |
| 225 | } |
| 226 | } |
Evan Charlton | af51ceb | 2014-07-30 11:56:36 -0700 | [diff] [blame] | 227 | |
| 228 | // See if the OEM has specified a default one. |
Evan Charlton | af51ceb | 2014-07-30 11:56:36 -0700 | [diff] [blame] | 229 | String defaultConnectionMgr = |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 230 | mContext.getResources().getString(R.string.default_connection_manager_component); |
Evan Charlton | af51ceb | 2014-07-30 11:56:36 -0700 | [diff] [blame] | 231 | if (!TextUtils.isEmpty(defaultConnectionMgr)) { |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 232 | PackageManager pm = mContext.getPackageManager(); |
Evan Charlton | af51ceb | 2014-07-30 11:56:36 -0700 | [diff] [blame] | 233 | |
| 234 | ComponentName componentName = ComponentName.unflattenFromString(defaultConnectionMgr); |
| 235 | Intent intent = new Intent(ConnectionService.SERVICE_INTERFACE); |
| 236 | intent.setComponent(componentName); |
| 237 | |
| 238 | // Make sure that the component can be resolved. |
| 239 | List<ResolveInfo> resolveInfos = pm.queryIntentServices(intent, 0); |
| 240 | if (!resolveInfos.isEmpty()) { |
| 241 | // See if there is registered PhoneAccount by this component. |
| 242 | List<PhoneAccountHandle> handles = getAllPhoneAccountHandles(); |
| 243 | for (PhoneAccountHandle handle : handles) { |
| 244 | if (componentName.equals(handle.getComponentName())) { |
| 245 | return handle; |
| 246 | } |
| 247 | } |
| 248 | Log.d(this, "%s does not have a PhoneAccount; not using as default", componentName); |
| 249 | } else { |
| 250 | Log.d(this, "%s could not be resolved; not using as default", componentName); |
| 251 | } |
| 252 | } else { |
| 253 | Log.v(this, "No default connection manager specified"); |
| 254 | } |
| 255 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 256 | return null; |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 259 | /** |
| 260 | * Retrieves a list of all {@link PhoneAccountHandle}s registered. |
| 261 | * |
| 262 | * @return The list of {@link PhoneAccountHandle}s. |
| 263 | */ |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 264 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
| 265 | List<PhoneAccountHandle> accountHandles = new ArrayList<>(); |
| 266 | for (PhoneAccount m : mState.accounts) { |
| 267 | accountHandles.add(m.getAccountHandle()); |
| 268 | } |
| 269 | return accountHandles; |
| 270 | } |
| 271 | |
| 272 | public List<PhoneAccount> getAllPhoneAccounts() { |
| 273 | return new ArrayList<>(mState.accounts); |
| 274 | } |
| 275 | |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 276 | /** |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 277 | * Determines the number of all {@link PhoneAccount}s. |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 278 | * |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 279 | * @return The total number {@link PhoneAccount}s. |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 280 | */ |
| 281 | public int getAllPhoneAccountsCount() { |
| 282 | return mState.accounts.size(); |
| 283 | } |
| 284 | |
| 285 | /** |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 286 | * Retrieves a list of all call provider phone accounts. |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 287 | * |
| 288 | * @return The phone account handles. |
| 289 | */ |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 290 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts() { |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 291 | return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER); |
| 292 | } |
| 293 | |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 294 | /** |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 295 | * Retrieves a list of all phone account call provider phone accounts supporting the |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 296 | * specified URI scheme. |
| 297 | * |
| 298 | * @param uriScheme The URI scheme. |
| 299 | * @return The phone account handles. |
| 300 | */ |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 301 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts(String uriScheme) { |
| 302 | return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CALL_PROVIDER, uriScheme); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 305 | /** |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 306 | * Retrieves a list of all phone account handles with the connection manager capability. |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 307 | * |
| 308 | * @return The phone account handles. |
| 309 | */ |
| 310 | public List<PhoneAccountHandle> getConnectionManagerPhoneAccounts() { |
Santos Cordon | e3d8245 | 2014-09-15 13:44:29 -0700 | [diff] [blame] | 311 | return getPhoneAccountHandles(PhoneAccount.CAPABILITY_CONNECTION_MANAGER, |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 312 | null /* supportedUriScheme */); |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 315 | public PhoneAccount getPhoneAccount(PhoneAccountHandle handle) { |
| 316 | for (PhoneAccount m : mState.accounts) { |
| 317 | if (Objects.equals(handle, m.getAccountHandle())) { |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 318 | return m; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | return null; |
| 322 | } |
| 323 | |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 324 | // TODO: Should we implement an artificial limit for # of accounts associated with a single |
| 325 | // ComponentName? |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 326 | public void registerPhoneAccount(PhoneAccount account) { |
Tyler Gunn | cb59b67 | 2014-08-20 09:02:11 -0700 | [diff] [blame] | 327 | // Enforce the requirement that a connection service for a phone account has the correct |
| 328 | // permission. |
| 329 | if (!phoneAccountHasPermission(account.getAccountHandle())) { |
| 330 | Log.w(this, "Phone account %s does not have BIND_CONNECTION_SERVICE permission.", |
| 331 | account.getAccountHandle()); |
| 332 | throw new SecurityException( |
| 333 | "PhoneAccount connection service requires BIND_CONNECTION_SERVICE permission."); |
| 334 | } |
| 335 | |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 336 | addOrReplacePhoneAccount(account); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Adds a {@code PhoneAccount}, replacing an existing one if found. |
| 341 | * |
| 342 | * @param account The {@code PhoneAccount} to add or replace. |
| 343 | */ |
| 344 | private void addOrReplacePhoneAccount(PhoneAccount account) { |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 345 | mState.accounts.add(account); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 346 | // Search for duplicates and remove any that are found. |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 347 | for (int i = 0; i < mState.accounts.size() - 1; i++) { |
| 348 | if (Objects.equals( |
| 349 | account.getAccountHandle(), mState.accounts.get(i).getAccountHandle())) { |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 350 | // replace existing entry. |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 351 | mState.accounts.remove(i); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 352 | break; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 356 | write(); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 357 | fireAccountsChanged(); |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 360 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 361 | for (int i = 0; i < mState.accounts.size(); i++) { |
| 362 | if (Objects.equals(accountHandle, mState.accounts.get(i).getAccountHandle())) { |
| 363 | mState.accounts.remove(i); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 364 | break; |
| 365 | } |
| 366 | } |
| 367 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 368 | write(); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 369 | fireAccountsChanged(); |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Tyler Gunn | d900ce6 | 2014-08-13 11:40:59 -0700 | [diff] [blame] | 372 | /** |
| 373 | * Un-registers all phone accounts associated with a specified package. |
| 374 | * |
| 375 | * @param packageName The package for which phone accounts will be removed. |
| 376 | */ |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 377 | public void clearAccounts(String packageName) { |
Tyler Gunn | d900ce6 | 2014-08-13 11:40:59 -0700 | [diff] [blame] | 378 | boolean accountsRemoved = false; |
| 379 | Iterator<PhoneAccount> it = mState.accounts.iterator(); |
| 380 | while (it.hasNext()) { |
| 381 | PhoneAccount phoneAccount = it.next(); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 382 | if (Objects.equals( |
| 383 | packageName, |
Tyler Gunn | d900ce6 | 2014-08-13 11:40:59 -0700 | [diff] [blame] | 384 | phoneAccount.getAccountHandle().getComponentName().getPackageName())) { |
| 385 | Log.i(this, "Removing phone account " + phoneAccount.getLabel()); |
| 386 | it.remove(); |
| 387 | accountsRemoved = true; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
Tyler Gunn | d900ce6 | 2014-08-13 11:40:59 -0700 | [diff] [blame] | 391 | if (accountsRemoved) { |
| 392 | write(); |
| 393 | fireAccountsChanged(); |
| 394 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | public void addListener(Listener l) { |
| 398 | mListeners.add(l); |
| 399 | } |
| 400 | |
| 401 | public void removeListener(Listener l) { |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 402 | if (l != null) { |
| 403 | mListeners.remove(l); |
| 404 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | private void fireAccountsChanged() { |
| 408 | for (Listener l : mListeners) { |
| 409 | l.onAccountsChanged(this); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | private void fireDefaultOutgoingChanged() { |
| 414 | for (Listener l : mListeners) { |
| 415 | l.onDefaultOutgoingChanged(this); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | private void fireSimCallManagerChanged() { |
| 420 | for (Listener l : mListeners) { |
| 421 | l.onSimCallManagerChanged(this); |
| 422 | } |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Tyler Gunn | cb59b67 | 2014-08-20 09:02:11 -0700 | [diff] [blame] | 425 | /** |
| 426 | * Determines if the connection service specified by a {@link PhoneAccountHandle} has the |
| 427 | * {@link Manifest.permission#BIND_CONNECTION_SERVICE} permission. |
| 428 | * |
| 429 | * @param phoneAccountHandle The phone account to check. |
| 430 | * @return {@code True} if the phone account has permission. |
| 431 | */ |
| 432 | public boolean phoneAccountHasPermission(PhoneAccountHandle phoneAccountHandle) { |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame^] | 433 | PackageManager packageManager = mContext.getPackageManager(); |
Tyler Gunn | cb59b67 | 2014-08-20 09:02:11 -0700 | [diff] [blame] | 434 | try { |
| 435 | ServiceInfo serviceInfo = packageManager.getServiceInfo( |
| 436 | phoneAccountHandle.getComponentName(), 0); |
| 437 | |
| 438 | return serviceInfo.permission != null && |
| 439 | serviceInfo.permission.equals(Manifest.permission.BIND_CONNECTION_SERVICE); |
| 440 | } catch (PackageManager.NameNotFoundException e) { |
| 441 | Log.w(this, "Name not found %s", e); |
| 442 | return false; |
| 443 | } |
| 444 | } |
| 445 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 446 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| 447 | |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 448 | /** |
| 449 | * Returns a list of phone account handles with the specified flag. |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 450 | * |
| 451 | * @param flags Flags which the {@code PhoneAccount} must have. |
Santos Cordon | afe59e5 | 2014-08-22 16:48:43 -0700 | [diff] [blame] | 452 | */ |
| 453 | private List<PhoneAccountHandle> getPhoneAccountHandles(int flags) { |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 454 | return getPhoneAccountHandles(flags, null); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Returns a list of phone account handles with the specified flag, supporting the specified |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 459 | * URI scheme. |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 460 | * |
| 461 | * @param flags Flags which the {@code PhoneAccount} must have. |
| 462 | * @param uriScheme URI schemes the PhoneAccount must handle. {@code Null} bypasses the |
| 463 | * URI scheme check. |
| 464 | */ |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 465 | private List<PhoneAccountHandle> getPhoneAccountHandles(int flags, String uriScheme) { |
Evan Charlton | 94d0162 | 2014-07-20 12:32:05 -0700 | [diff] [blame] | 466 | List<PhoneAccountHandle> accountHandles = new ArrayList<>(); |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 467 | for (PhoneAccount m : mState.accounts) { |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 468 | if (m.hasCapabilities(flags) && (uriScheme == null || m.supportsUriScheme(uriScheme))) { |
Ihab Awad | f2a8491 | 2014-07-22 21:09:25 -0700 | [diff] [blame] | 469 | accountHandles.add(m.getAccountHandle()); |
| 470 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 471 | } |
Evan Charlton | 94d0162 | 2014-07-20 12:32:05 -0700 | [diff] [blame] | 472 | return accountHandles; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 475 | /** |
| 476 | * The state of this {@code PhoneAccountRegistrar}. |
| 477 | */ |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 478 | @VisibleForTesting |
| 479 | public static class State { |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 480 | /** |
| 481 | * The account selected by the user to be employed by default for making outgoing calls. |
| 482 | * If the user has not made such a selection, then this is null. |
| 483 | */ |
| 484 | public PhoneAccountHandle defaultOutgoing = null; |
| 485 | |
| 486 | /** |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 487 | * A {@code PhoneAccount} having {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} which |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 488 | * manages and optimizes a user's PSTN SIM connections. |
| 489 | */ |
| 490 | public PhoneAccountHandle simCallManager; |
| 491 | |
| 492 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 493 | * The complete list of {@code PhoneAccount}s known to the Telecom subsystem. |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 494 | */ |
| 495 | public final List<PhoneAccount> accounts = new ArrayList<>(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 496 | |
| 497 | /** |
| 498 | * The version number of the State data. |
| 499 | */ |
| 500 | public int versionNumber; |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| 504 | // |
| 505 | // State management |
| 506 | // |
| 507 | |
| 508 | private void write() { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 509 | final FileOutputStream os; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 510 | try { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 511 | os = mAtomicFile.startWrite(); |
| 512 | boolean success = false; |
| 513 | try { |
| 514 | XmlSerializer serializer = new FastXmlSerializer(); |
| 515 | serializer.setOutput(new BufferedOutputStream(os), "utf-8"); |
| 516 | writeToXml(mState, serializer); |
| 517 | serializer.flush(); |
| 518 | success = true; |
| 519 | } finally { |
| 520 | if (success) { |
| 521 | mAtomicFile.finishWrite(os); |
| 522 | } else { |
| 523 | mAtomicFile.failWrite(os); |
| 524 | } |
| 525 | } |
| 526 | } catch (IOException e) { |
| 527 | Log.e(this, e, "Writing state to XML file"); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 531 | private void read() { |
| 532 | final InputStream is; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 533 | try { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 534 | is = mAtomicFile.openRead(); |
| 535 | } catch (FileNotFoundException ex) { |
| 536 | return; |
| 537 | } |
| 538 | |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 539 | boolean versionChanged = false; |
| 540 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 541 | XmlPullParser parser; |
| 542 | try { |
| 543 | parser = Xml.newPullParser(); |
| 544 | parser.setInput(new BufferedInputStream(is), null); |
| 545 | parser.nextTag(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 546 | mState = readFromXml(parser, mContext); |
| 547 | versionChanged = mState.versionNumber < EXPECTED_STATE_VERSION; |
| 548 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 549 | } catch (IOException | XmlPullParserException e) { |
| 550 | Log.e(this, e, "Reading state from XML file"); |
| 551 | mState = new State(); |
| 552 | } finally { |
| 553 | try { |
| 554 | is.close(); |
| 555 | } catch (IOException e) { |
| 556 | Log.e(this, e, "Closing InputStream"); |
| 557 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 558 | } |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 559 | |
| 560 | // If an upgrade occurred, write out the changed data. |
| 561 | if (versionChanged) { |
| 562 | write(); |
| 563 | } |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 566 | private static void writeToXml(State state, XmlSerializer serializer) |
| 567 | throws IOException { |
| 568 | sStateXml.writeToXml(state, serializer); |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 569 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 570 | |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 571 | private static State readFromXml(XmlPullParser parser, Context context) |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 572 | throws IOException, XmlPullParserException { |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 573 | State s = sStateXml.readFromXml(parser, 0, context); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 574 | return s != null ? s : new State(); |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 577 | //////////////////////////////////////////////////////////////////////////////////////////////// |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 578 | // |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 579 | // XML serialization |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 580 | // |
| 581 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 582 | @VisibleForTesting |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 583 | public abstract static class XmlSerialization<T> { |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 584 | private static final String LENGTH_ATTRIBUTE = "length"; |
| 585 | private static final String VALUE_TAG = "value"; |
| 586 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 587 | /** |
| 588 | * Write the supplied object to XML |
| 589 | */ |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 590 | public abstract void writeToXml(T o, XmlSerializer serializer) |
| 591 | throws IOException; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * Read from the supplied XML into a new object, returning null in case of an |
| 595 | * unrecoverable schema mismatch or other data error. 'parser' must be already |
| 596 | * positioned at the first tag that is expected to have been emitted by this |
| 597 | * object's writeToXml(). This object tries to fail early without modifying |
| 598 | * 'parser' if it does not recognize the data it sees. |
| 599 | */ |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 600 | public abstract T readFromXml(XmlPullParser parser, int version, Context context) |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 601 | throws IOException, XmlPullParserException; |
| 602 | |
| 603 | protected void writeTextSafely(String tagName, Object value, XmlSerializer serializer) |
| 604 | throws IOException { |
| 605 | if (value != null) { |
| 606 | serializer.startTag(null, tagName); |
| 607 | serializer.text(Objects.toString(value)); |
| 608 | serializer.endTag(null, tagName); |
| 609 | } |
| 610 | } |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 611 | |
| 612 | /** |
| 613 | * Serializes a string array. |
| 614 | * |
| 615 | * @param tagName The tag name for the string array. |
| 616 | * @param values The string values to serialize. |
| 617 | * @param serializer The serializer. |
| 618 | * @throws IOException |
| 619 | */ |
| 620 | protected void writeStringList(String tagName, List<String> values, |
| 621 | XmlSerializer serializer) |
| 622 | throws IOException { |
| 623 | |
| 624 | serializer.startTag(null, tagName); |
| 625 | if (values != null) { |
| 626 | serializer.attribute(null, LENGTH_ATTRIBUTE, Objects.toString(values.size())); |
| 627 | for (String toSerialize : values) { |
| 628 | serializer.startTag(null, VALUE_TAG); |
| 629 | if (toSerialize != null ){ |
| 630 | serializer.text(toSerialize); |
| 631 | } |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 632 | serializer.endTag(null, VALUE_TAG); |
| 633 | } |
| 634 | } else { |
| 635 | serializer.attribute(null, LENGTH_ATTRIBUTE, "0"); |
| 636 | } |
| 637 | serializer.endTag(null, tagName); |
| 638 | |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Reads a string array from the XML parser. |
| 643 | * |
| 644 | * @param parser The XML parser. |
| 645 | * @return String array containing the parsed values. |
| 646 | * @throws IOException Exception related to IO. |
| 647 | * @throws XmlPullParserException Exception related to parsing. |
| 648 | */ |
| 649 | protected List<String> readStringList(XmlPullParser parser) |
| 650 | throws IOException, XmlPullParserException { |
| 651 | |
| 652 | int length = Integer.parseInt(parser.getAttributeValue(null, LENGTH_ATTRIBUTE)); |
| 653 | List<String> arrayEntries = new ArrayList<String>(length); |
| 654 | String value = null; |
| 655 | |
| 656 | if (length == 0) { |
| 657 | return arrayEntries; |
| 658 | } |
| 659 | |
| 660 | int outerDepth = parser.getDepth(); |
| 661 | while (XmlUtils.nextElementWithin(parser, outerDepth)) { |
| 662 | if (parser.getName().equals(VALUE_TAG)) { |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 663 | parser.next(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 664 | value = parser.getText(); |
| 665 | arrayEntries.add(value); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | return arrayEntries; |
| 670 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 673 | @VisibleForTesting |
| 674 | public static final XmlSerialization<State> sStateXml = |
| 675 | new XmlSerialization<State>() { |
| 676 | private static final String CLASS_STATE = "phone_account_registrar_state"; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 677 | private static final String DEFAULT_OUTGOING = "default_outgoing"; |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 678 | private static final String SIM_CALL_MANAGER = "sim_call_manager"; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 679 | private static final String ACCOUNTS = "accounts"; |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 680 | private static final String VERSION = "version"; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 681 | |
| 682 | @Override |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 683 | public void writeToXml(State o, XmlSerializer serializer) |
| 684 | throws IOException { |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 685 | if (o != null) { |
| 686 | serializer.startTag(null, CLASS_STATE); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 687 | serializer.attribute(null, VERSION, Objects.toString(EXPECTED_STATE_VERSION)); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 688 | |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 689 | if (o.defaultOutgoing != null) { |
| 690 | serializer.startTag(null, DEFAULT_OUTGOING); |
| 691 | sPhoneAccountHandleXml.writeToXml(o.defaultOutgoing, serializer); |
| 692 | serializer.endTag(null, DEFAULT_OUTGOING); |
| 693 | } |
| 694 | |
| 695 | if (o.simCallManager != null) { |
| 696 | serializer.startTag(null, SIM_CALL_MANAGER); |
| 697 | sPhoneAccountHandleXml.writeToXml(o.simCallManager, serializer); |
| 698 | serializer.endTag(null, SIM_CALL_MANAGER); |
| 699 | } |
| 700 | |
| 701 | serializer.startTag(null, ACCOUNTS); |
| 702 | for (PhoneAccount m : o.accounts) { |
| 703 | sPhoneAccountXml.writeToXml(m, serializer); |
| 704 | } |
| 705 | serializer.endTag(null, ACCOUNTS); |
| 706 | |
| 707 | serializer.endTag(null, CLASS_STATE); |
Ihab Awad | 293edf2 | 2014-07-24 17:52:29 -0700 | [diff] [blame] | 708 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | @Override |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 712 | public State readFromXml(XmlPullParser parser, int version, Context context) |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 713 | throws IOException, XmlPullParserException { |
| 714 | if (parser.getName().equals(CLASS_STATE)) { |
| 715 | State s = new State(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 716 | |
| 717 | String rawVersion = parser.getAttributeValue(null, VERSION); |
| 718 | s.versionNumber = TextUtils.isEmpty(rawVersion) ? 1 : |
| 719 | Integer.parseInt(rawVersion); |
| 720 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 721 | int outerDepth = parser.getDepth(); |
| 722 | while (XmlUtils.nextElementWithin(parser, outerDepth)) { |
| 723 | if (parser.getName().equals(DEFAULT_OUTGOING)) { |
| 724 | parser.nextTag(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 725 | s.defaultOutgoing = sPhoneAccountHandleXml.readFromXml(parser, |
| 726 | s.versionNumber, context); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 727 | } else if (parser.getName().equals(SIM_CALL_MANAGER)) { |
| 728 | parser.nextTag(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 729 | s.simCallManager = sPhoneAccountHandleXml.readFromXml(parser, |
| 730 | s.versionNumber, context); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 731 | } else if (parser.getName().equals(ACCOUNTS)) { |
| 732 | int accountsDepth = parser.getDepth(); |
| 733 | while (XmlUtils.nextElementWithin(parser, accountsDepth)) { |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 734 | PhoneAccount account = sPhoneAccountXml.readFromXml(parser, |
| 735 | s.versionNumber, context); |
| 736 | |
| 737 | if (account != null && s.accounts != null) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 738 | s.accounts.add(account); |
| 739 | } |
| 740 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 741 | } |
| 742 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 743 | return s; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 744 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 745 | return null; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 746 | } |
| 747 | }; |
| 748 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 749 | @VisibleForTesting |
| 750 | public static final XmlSerialization<PhoneAccount> sPhoneAccountXml = |
| 751 | new XmlSerialization<PhoneAccount>() { |
| 752 | private static final String CLASS_PHONE_ACCOUNT = "phone_account"; |
| 753 | private static final String ACCOUNT_HANDLE = "account_handle"; |
Andrew Lee | 7129f1c | 2014-09-04 11:55:07 -0700 | [diff] [blame] | 754 | private static final String ADDRESS = "handle"; |
| 755 | private static final String SUBSCRIPTION_ADDRESS = "subscription_number"; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 756 | private static final String CAPABILITIES = "capabilities"; |
| 757 | private static final String ICON_RES_ID = "icon_res_id"; |
| 758 | private static final String LABEL = "label"; |
| 759 | private static final String SHORT_DESCRIPTION = "short_description"; |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 760 | private static final String SUPPORTED_URI_SCHEMES = "supported_uri_schemes"; |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 761 | private static final String TRUE = "true"; |
| 762 | private static final String FALSE = "false"; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 763 | |
| 764 | @Override |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 765 | public void writeToXml(PhoneAccount o, XmlSerializer serializer) |
| 766 | throws IOException { |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 767 | if (o != null) { |
| 768 | serializer.startTag(null, CLASS_PHONE_ACCOUNT); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 769 | |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 770 | if (o.getAccountHandle() != null) { |
| 771 | serializer.startTag(null, ACCOUNT_HANDLE); |
| 772 | sPhoneAccountHandleXml.writeToXml(o.getAccountHandle(), serializer); |
| 773 | serializer.endTag(null, ACCOUNT_HANDLE); |
| 774 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 775 | |
Andrew Lee | 7129f1c | 2014-09-04 11:55:07 -0700 | [diff] [blame] | 776 | writeTextSafely(ADDRESS, o.getAddress(), serializer); |
| 777 | writeTextSafely(SUBSCRIPTION_ADDRESS, o.getSubscriptionAddress(), serializer); |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 778 | writeTextSafely(CAPABILITIES, Integer.toString(o.getCapabilities()), serializer); |
| 779 | writeTextSafely(ICON_RES_ID, Integer.toString(o.getIconResId()), serializer); |
| 780 | writeTextSafely(LABEL, o.getLabel(), serializer); |
| 781 | writeTextSafely(SHORT_DESCRIPTION, o.getShortDescription(), serializer); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 782 | writeStringList(SUPPORTED_URI_SCHEMES, o.getSupportedUriSchemes(), serializer); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 783 | |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 784 | serializer.endTag(null, CLASS_PHONE_ACCOUNT); |
| 785 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 788 | public PhoneAccount readFromXml(XmlPullParser parser, int version, Context context) |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 789 | throws IOException, XmlPullParserException { |
| 790 | if (parser.getName().equals(CLASS_PHONE_ACCOUNT)) { |
| 791 | int outerDepth = parser.getDepth(); |
| 792 | PhoneAccountHandle accountHandle = null; |
Andrew Lee | 7129f1c | 2014-09-04 11:55:07 -0700 | [diff] [blame] | 793 | Uri address = null; |
| 794 | Uri subscriptionAddress = null; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 795 | int capabilities = 0; |
| 796 | int iconResId = 0; |
| 797 | String label = null; |
| 798 | String shortDescription = null; |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 799 | List<String> supportedUriSchemes = null; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 800 | |
| 801 | while (XmlUtils.nextElementWithin(parser, outerDepth)) { |
| 802 | if (parser.getName().equals(ACCOUNT_HANDLE)) { |
| 803 | parser.nextTag(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 804 | accountHandle = sPhoneAccountHandleXml.readFromXml(parser, version, |
| 805 | context); |
Andrew Lee | 7129f1c | 2014-09-04 11:55:07 -0700 | [diff] [blame] | 806 | } else if (parser.getName().equals(ADDRESS)) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 807 | parser.next(); |
Andrew Lee | 7129f1c | 2014-09-04 11:55:07 -0700 | [diff] [blame] | 808 | address = Uri.parse(parser.getText()); |
| 809 | } else if (parser.getName().equals(SUBSCRIPTION_ADDRESS)) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 810 | parser.next(); |
Andrew Lee | 7129f1c | 2014-09-04 11:55:07 -0700 | [diff] [blame] | 811 | String nextText = parser.getText(); |
| 812 | subscriptionAddress = nextText == null ? null : Uri.parse(nextText); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 813 | } else if (parser.getName().equals(CAPABILITIES)) { |
| 814 | parser.next(); |
| 815 | capabilities = Integer.parseInt(parser.getText()); |
| 816 | } else if (parser.getName().equals(ICON_RES_ID)) { |
| 817 | parser.next(); |
| 818 | iconResId = Integer.parseInt(parser.getText()); |
| 819 | } else if (parser.getName().equals(LABEL)) { |
| 820 | parser.next(); |
| 821 | label = parser.getText(); |
| 822 | } else if (parser.getName().equals(SHORT_DESCRIPTION)) { |
| 823 | parser.next(); |
| 824 | shortDescription = parser.getText(); |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 825 | } else if (parser.getName().equals(SUPPORTED_URI_SCHEMES)) { |
| 826 | supportedUriSchemes = readStringList(parser); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 829 | |
| 830 | // Upgrade older phone accounts to specify the supported URI schemes. |
| 831 | if (version < 2) { |
| 832 | ComponentName sipComponentName = new ComponentName("com.android.phone", |
| 833 | "com.android.services.telephony.sip.SipConnectionService"); |
| 834 | |
| 835 | supportedUriSchemes = new ArrayList<>(); |
| 836 | |
| 837 | // Handle the SIP connection service. |
| 838 | // Check the system settings to see if it also should handle "tel" calls. |
| 839 | if (accountHandle.getComponentName().equals(sipComponentName)) { |
| 840 | boolean useSipForPstn = useSipForPstnCalls(context); |
| 841 | supportedUriSchemes.add(PhoneAccount.SCHEME_SIP); |
| 842 | if (useSipForPstn) { |
| 843 | supportedUriSchemes.add(PhoneAccount.SCHEME_TEL); |
| 844 | } |
| 845 | } else { |
| 846 | supportedUriSchemes.add(PhoneAccount.SCHEME_TEL); |
| 847 | supportedUriSchemes.add(PhoneAccount.SCHEME_VOICEMAIL); |
| 848 | } |
| 849 | } |
| 850 | |
Andrew Lee | 7129f1c | 2014-09-04 11:55:07 -0700 | [diff] [blame] | 851 | return PhoneAccount.builder(accountHandle, label) |
| 852 | .setAddress(address) |
| 853 | .setSubscriptionAddress(subscriptionAddress) |
| 854 | .setCapabilities(capabilities) |
| 855 | .setIconResId(iconResId) |
| 856 | .setShortDescription(shortDescription) |
| 857 | .setSupportedUriSchemes(supportedUriSchemes) |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 858 | .build(); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 859 | } |
| 860 | return null; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 861 | } |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 862 | |
| 863 | /** |
| 864 | * Determines if the SIP call settings specify to use SIP for all calls, including PSTN calls. |
| 865 | * |
| 866 | * @param context The context. |
| 867 | * @return {@code True} if SIP should be used for all calls. |
| 868 | */ |
| 869 | private boolean useSipForPstnCalls(Context context) { |
| 870 | String option = Settings.System.getString(context.getContentResolver(), |
| 871 | Settings.System.SIP_CALL_OPTIONS); |
| 872 | option = (option != null) ? option : Settings.System.SIP_ADDRESS_ONLY; |
| 873 | return option.equals(Settings.System.SIP_ALWAYS); |
| 874 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 875 | }; |
| 876 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 877 | @VisibleForTesting |
| 878 | public static final XmlSerialization<PhoneAccountHandle> sPhoneAccountHandleXml = |
| 879 | new XmlSerialization<PhoneAccountHandle>() { |
| 880 | private static final String CLASS_PHONE_ACCOUNT_HANDLE = "phone_account_handle"; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 881 | private static final String COMPONENT_NAME = "component_name"; |
| 882 | private static final String ID = "id"; |
| 883 | |
| 884 | @Override |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 885 | public void writeToXml(PhoneAccountHandle o, XmlSerializer serializer) |
| 886 | throws IOException { |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 887 | if (o != null) { |
| 888 | serializer.startTag(null, CLASS_PHONE_ACCOUNT_HANDLE); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 889 | |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 890 | if (o.getComponentName() != null) { |
| 891 | writeTextSafely( |
| 892 | COMPONENT_NAME, o.getComponentName().flattenToString(), serializer); |
| 893 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 894 | |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 895 | writeTextSafely(ID, o.getId(), serializer); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 896 | |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 897 | serializer.endTag(null, CLASS_PHONE_ACCOUNT_HANDLE); |
| 898 | } |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | @Override |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 902 | public PhoneAccountHandle readFromXml(XmlPullParser parser, int version, Context context) |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 903 | throws IOException, XmlPullParserException { |
| 904 | if (parser.getName().equals(CLASS_PHONE_ACCOUNT_HANDLE)) { |
| 905 | String componentNameString = null; |
| 906 | String idString = null; |
| 907 | int outerDepth = parser.getDepth(); |
| 908 | while (XmlUtils.nextElementWithin(parser, outerDepth)) { |
| 909 | if (parser.getName().equals(COMPONENT_NAME)) { |
| 910 | parser.next(); |
| 911 | componentNameString = parser.getText(); |
| 912 | } else if (parser.getName().equals(ID)) { |
| 913 | parser.next(); |
| 914 | idString = parser.getText(); |
| 915 | } |
| 916 | } |
Ihab Awad | 2692322 | 2014-07-30 10:54:35 -0700 | [diff] [blame] | 917 | if (componentNameString != null) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 918 | return new PhoneAccountHandle( |
| 919 | ComponentName.unflattenFromString(componentNameString), |
| 920 | idString); |
| 921 | } |
| 922 | } |
| 923 | return null; |
Ihab Awad | 104f806 | 2014-07-17 11:29:35 -0700 | [diff] [blame] | 924 | } |
| 925 | }; |
Santos Cordon | 176ae28 | 2014-07-14 02:02:14 -0700 | [diff] [blame] | 926 | } |