Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [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 | |
| 17 | package com.android.server.telecom; |
| 18 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.CALL_PHONE; |
| 20 | import static android.Manifest.permission.MODIFY_PHONE_STATE; |
| 21 | import static android.Manifest.permission.READ_PHONE_STATE; |
| 22 | import static android.Manifest.permission.REGISTER_CALL_PROVIDER; |
| 23 | import static android.Manifest.permission.REGISTER_CONNECTION_MANAGER; |
| 24 | import static android.Manifest.permission.REGISTER_SIM_SUBSCRIPTION; |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 25 | import static android.Manifest.permission.WRITE_SECURE_SETTINGS; |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 26 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 28 | import android.content.ComponentName; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
| 31 | import android.content.pm.ApplicationInfo; |
| 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.res.Resources; |
| 34 | import android.net.Uri; |
| 35 | import android.os.Binder; |
| 36 | import android.os.Bundle; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 37 | import android.os.IBinder; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 38 | import android.os.UserHandle; |
| 39 | import android.os.UserManager; |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 40 | import android.telecom.DefaultDialerManager; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 41 | import android.telecom.PhoneAccount; |
| 42 | import android.telecom.PhoneAccountHandle; |
| 43 | import android.telecom.TelecomManager; |
| 44 | import android.telephony.SubscriptionManager; |
| 45 | import android.telephony.TelephonyManager; |
| 46 | import android.text.TextUtils; |
| 47 | |
| 48 | // TODO: Needed for move to system service: import com.android.internal.R; |
| 49 | import com.android.internal.telecom.ITelecomService; |
| 50 | import com.android.internal.util.IndentingPrintWriter; |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 51 | import com.android.server.telecom.components.UserCallIntentProcessor; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 52 | |
| 53 | import java.io.FileDescriptor; |
| 54 | import java.io.PrintWriter; |
| 55 | import java.util.ArrayList; |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 56 | import java.util.Collections; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 57 | import java.util.List; |
| 58 | |
| 59 | /** |
| 60 | * Implementation of the ITelecom interface. |
| 61 | */ |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 62 | public class TelecomServiceImpl { |
Santos Cordon | 7385396 | 2015-02-27 15:13:35 -0800 | [diff] [blame] | 63 | private static final String PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION = |
| 64 | "android.permission.PROCESS_PHONE_ACCOUNT_REGISTRATION"; |
| 65 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 66 | private final ITelecomService.Stub mBinderImpl = new ITelecomService.Stub() { |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 67 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 68 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme, |
| 69 | String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 70 | synchronized (mLock) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 71 | if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 72 | return null; |
| 73 | } |
| 74 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 75 | long token = Binder.clearCallingIdentity(); |
| 76 | try { |
| 77 | PhoneAccountHandle defaultOutgoingPhoneAccount = |
Santos Cordon | 6a21264 | 2015-05-08 16:35:23 -0700 | [diff] [blame] | 78 | mPhoneAccountRegistrar.getOutgoingPhoneAccountForScheme(uriScheme); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 79 | // Make sure that the calling user can see this phone account. |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 80 | // TODO: Does this isVisible check actually work considering we are clearing |
| 81 | // the calling identity? |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 82 | if (defaultOutgoingPhoneAccount != null |
| 83 | && !isVisibleToCaller(defaultOutgoingPhoneAccount)) { |
| 84 | Log.w(this, "No account found for the calling user"); |
| 85 | return null; |
| 86 | } |
| 87 | return defaultOutgoingPhoneAccount; |
| 88 | } catch (Exception e) { |
| 89 | Log.e(this, e, "getDefaultOutgoingPhoneAccount"); |
| 90 | throw e; |
| 91 | } finally { |
| 92 | Binder.restoreCallingIdentity(token); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 93 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 99 | synchronized (mLock) { |
| 100 | try { |
| 101 | PhoneAccountHandle userSelectedOutgoingPhoneAccount = |
| 102 | mPhoneAccountRegistrar.getUserSelectedOutgoingPhoneAccount(); |
| 103 | // Make sure that the calling user can see this phone account. |
| 104 | if (!isVisibleToCaller(userSelectedOutgoingPhoneAccount)) { |
| 105 | Log.w(this, "No account found for the calling user"); |
| 106 | return null; |
| 107 | } |
| 108 | return userSelectedOutgoingPhoneAccount; |
| 109 | } catch (Exception e) { |
| 110 | Log.e(this, e, "getUserSelectedOutgoingPhoneAccount"); |
| 111 | throw e; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 112 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 118 | synchronized (mLock) { |
| 119 | enforceModifyPermission(); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 120 | |
| 121 | long token = Binder.clearCallingIdentity(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 122 | try { |
| 123 | mPhoneAccountRegistrar.setUserSelectedOutgoingPhoneAccount(accountHandle); |
| 124 | } catch (Exception e) { |
| 125 | Log.e(this, e, "setUserSelectedOutgoingPhoneAccount"); |
| 126 | throw e; |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 127 | } finally { |
| 128 | Binder.restoreCallingIdentity(token); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 129 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
| 133 | @Override |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 134 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts( |
| 135 | boolean includeDisabledAccounts, String callingPackage) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 136 | if (!canReadPhoneState(callingPackage, "getDefaultOutgoingPhoneAccount")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 137 | return Collections.emptyList(); |
| 138 | } |
| 139 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 140 | synchronized (mLock) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 141 | long token = Binder.clearCallingIdentity(); |
| 142 | try { |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 143 | // TODO: Does this isVisible check actually work considering we are clearing |
| 144 | // the calling identity? |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 145 | return filterForAccountsVisibleToCaller( |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 146 | mPhoneAccountRegistrar.getCallCapablePhoneAccounts( |
| 147 | null, includeDisabledAccounts)); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 148 | } catch (Exception e) { |
| 149 | Log.e(this, e, "getCallCapablePhoneAccounts"); |
| 150 | throw e; |
| 151 | } finally { |
| 152 | Binder.restoreCallingIdentity(token); |
| 153 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
| 157 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 158 | public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme, |
| 159 | String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 160 | synchronized (mLock) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 161 | if (!canReadPhoneState(callingPackage, "getPhoneAccountsSupportingScheme")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 162 | return Collections.emptyList(); |
| 163 | } |
| 164 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 165 | long token = Binder.clearCallingIdentity(); |
| 166 | try { |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 167 | // TODO: Does this isVisible check actually work considering we are clearing |
| 168 | // the calling identity? |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 169 | return filterForAccountsVisibleToCaller( |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 170 | mPhoneAccountRegistrar.getCallCapablePhoneAccounts(uriScheme, false)); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 171 | } catch (Exception e) { |
| 172 | Log.e(this, e, "getPhoneAccountsSupportingScheme %s", uriScheme); |
| 173 | throw e; |
| 174 | } finally { |
| 175 | Binder.restoreCallingIdentity(token); |
| 176 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public List<PhoneAccountHandle> getPhoneAccountsForPackage(String packageName) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 182 | synchronized (mLock) { |
| 183 | try { |
| 184 | return filterForAccountsVisibleToCaller( |
| 185 | mPhoneAccountRegistrar.getPhoneAccountsForPackage(packageName)); |
| 186 | } catch (Exception e) { |
| 187 | Log.e(this, e, "getPhoneAccountsForPackage %s", packageName); |
| 188 | throw e; |
| 189 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public PhoneAccount getPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 195 | synchronized (mLock) { |
| 196 | try { |
| 197 | if (!isVisibleToCaller(accountHandle)) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 198 | Log.w(this, "%s is not visible for the calling user [gPA]", accountHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 199 | return null; |
| 200 | } |
Santos Cordon | 6a21264 | 2015-05-08 16:35:23 -0700 | [diff] [blame] | 201 | // TODO: Do we really want to return for *any* user? |
| 202 | return mPhoneAccountRegistrar.getPhoneAccount(accountHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 203 | } catch (Exception e) { |
| 204 | Log.e(this, e, "getPhoneAccount %s", accountHandle); |
| 205 | throw e; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 206 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public int getAllPhoneAccountsCount() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 212 | synchronized (mLock) { |
| 213 | try { |
| 214 | // This list is pre-filtered for the calling user. |
| 215 | return getAllPhoneAccounts().size(); |
| 216 | } catch (Exception e) { |
| 217 | Log.e(this, e, "getAllPhoneAccountsCount"); |
| 218 | throw e; |
| 219 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public List<PhoneAccount> getAllPhoneAccounts() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 225 | synchronized (mLock) { |
| 226 | try { |
| 227 | List<PhoneAccount> allPhoneAccounts = mPhoneAccountRegistrar |
| 228 | .getAllPhoneAccounts(); |
| 229 | List<PhoneAccount> profilePhoneAccounts = new ArrayList<>( |
| 230 | allPhoneAccounts.size()); |
| 231 | for (PhoneAccount phoneAccount : profilePhoneAccounts) { |
| 232 | if (isVisibleToCaller(phoneAccount)) { |
| 233 | profilePhoneAccounts.add(phoneAccount); |
| 234 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 235 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 236 | return profilePhoneAccounts; |
| 237 | } catch (Exception e) { |
| 238 | Log.e(this, e, "getAllPhoneAccounts"); |
| 239 | throw e; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 240 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 246 | synchronized (mLock) { |
| 247 | try { |
| 248 | return filterForAccountsVisibleToCaller( |
| 249 | mPhoneAccountRegistrar.getAllPhoneAccountHandles()); |
| 250 | } catch (Exception e) { |
| 251 | Log.e(this, e, "getAllPhoneAccounts"); |
| 252 | throw e; |
| 253 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public PhoneAccountHandle getSimCallManager() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 259 | synchronized (mLock) { |
| 260 | try { |
| 261 | PhoneAccountHandle accountHandle = mPhoneAccountRegistrar.getSimCallManager(); |
| 262 | if (!isVisibleToCaller(accountHandle)) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 263 | Log.w(this, "%s is not visible for the calling user [gsCM]", accountHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 264 | return null; |
| 265 | } |
| 266 | return accountHandle; |
| 267 | } catch (Exception e) { |
| 268 | Log.e(this, e, "getSimCallManager"); |
| 269 | throw e; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 270 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public void setSimCallManager(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 276 | synchronized (mLock) { |
| 277 | enforceModifyPermission(); |
| 278 | try { |
| 279 | mPhoneAccountRegistrar.setSimCallManager(accountHandle); |
| 280 | } catch (Exception e) { |
| 281 | Log.e(this, e, "setSimCallManager"); |
| 282 | throw e; |
| 283 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 288 | public List<PhoneAccountHandle> getSimCallManagers(String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 289 | synchronized (mLock) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 290 | if (!canReadPhoneState(callingPackage, "getSimCallManagers")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 291 | return Collections.emptyList(); |
| 292 | } |
| 293 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 294 | long token = Binder.clearCallingIdentity(); |
| 295 | try { |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 296 | // TODO: Does this isVisible check actually work considering we are clearing |
| 297 | // the calling identity? |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 298 | return filterForAccountsVisibleToCaller( |
| 299 | mPhoneAccountRegistrar.getConnectionManagerPhoneAccounts()); |
| 300 | } catch (Exception e) { |
| 301 | Log.e(this, e, "getSimCallManagers"); |
| 302 | throw e; |
| 303 | } finally { |
| 304 | Binder.restoreCallingIdentity(token); |
| 305 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void registerPhoneAccount(PhoneAccount account) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 311 | synchronized (mLock) { |
| 312 | try { |
| 313 | enforcePhoneAccountModificationForPackage( |
| 314 | account.getAccountHandle().getComponentName().getPackageName()); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 315 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { |
| 316 | enforceRegisterSimSubscriptionPermission(); |
| 317 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 318 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_MULTI_USER)) { |
| 319 | enforceRegisterMultiUser(); |
| 320 | } |
| 321 | enforceUserHandleMatchesCaller(account.getAccountHandle()); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 322 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 323 | mPhoneAccountRegistrar.registerPhoneAccount(account); |
Santos Cordon | 7385396 | 2015-02-27 15:13:35 -0800 | [diff] [blame] | 324 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 325 | // Broadcast an intent indicating the phone account which was registered. |
| 326 | long token = Binder.clearCallingIdentity(); |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 327 | try { |
| 328 | Intent intent = new Intent(TelecomManager.ACTION_PHONE_ACCOUNT_REGISTERED); |
| 329 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 330 | account.getAccountHandle()); |
| 331 | Log.i(this, "Sending phone-account intent as user"); |
| 332 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL, |
| 333 | PERMISSION_PROCESS_PHONE_ACCOUNT_REGISTRATION); |
| 334 | } finally { |
| 335 | Binder.restoreCallingIdentity(token); |
| 336 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 337 | } catch (Exception e) { |
| 338 | Log.e(this, e, "registerPhoneAccount %s", account); |
| 339 | throw e; |
| 340 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 346 | synchronized (mLock) { |
| 347 | try { |
| 348 | enforcePhoneAccountModificationForPackage( |
| 349 | accountHandle.getComponentName().getPackageName()); |
| 350 | enforceUserHandleMatchesCaller(accountHandle); |
| 351 | mPhoneAccountRegistrar.unregisterPhoneAccount(accountHandle); |
| 352 | } catch (Exception e) { |
| 353 | Log.e(this, e, "unregisterPhoneAccount %s", accountHandle); |
| 354 | throw e; |
| 355 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | @Override |
| 360 | public void clearAccounts(String packageName) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 361 | synchronized (mLock) { |
| 362 | try { |
| 363 | enforcePhoneAccountModificationForPackage(packageName); |
| 364 | mPhoneAccountRegistrar |
| 365 | .clearAccounts(packageName, Binder.getCallingUserHandle()); |
| 366 | } catch (Exception e) { |
| 367 | Log.e(this, e, "clearAccounts %s", packageName); |
| 368 | throw e; |
| 369 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * @see android.telecom.TelecomManager#isVoiceMailNumber |
| 375 | */ |
| 376 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 377 | public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number, |
| 378 | String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 379 | synchronized (mLock) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 380 | if (!canReadPhoneState(callingPackage, "isVoiceMailNumber")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 381 | return false; |
| 382 | } |
| 383 | |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 384 | if (!isVisibleToCaller(accountHandle)) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 385 | Log.w(this, "%s is not visible for the calling user [iVMN]", accountHandle); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 386 | return false; |
| 387 | } |
| 388 | |
| 389 | long token = Binder.clearCallingIdentity(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 390 | try { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 391 | return mPhoneAccountRegistrar.isVoiceMailNumber(accountHandle, number); |
| 392 | } catch (Exception e) { |
| 393 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 394 | throw e; |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 395 | } finally { |
| 396 | Binder.restoreCallingIdentity(token); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 397 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
| 401 | /** |
Yorke Lee | fb5ec30 | 2015-04-15 16:15:55 -0700 | [diff] [blame] | 402 | * @see android.telecom.TelecomManager#getVoiceMailNumber |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 403 | */ |
| 404 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 405 | public String getVoiceMailNumber(PhoneAccountHandle accountHandle, String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 406 | synchronized (mLock) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 407 | if (!canReadPhoneState(callingPackage, "getVoiceMailNumber")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 408 | return null; |
| 409 | } |
| 410 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 411 | try { |
| 412 | if (!isVisibleToCaller(accountHandle)) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 413 | Log.w(this, "%s is not visible for the calling user [gVMN]", accountHandle); |
Yorke Lee | fb5ec30 | 2015-04-15 16:15:55 -0700 | [diff] [blame] | 414 | return null; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 415 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 416 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 417 | int subId = SubscriptionManager.getDefaultVoiceSubId(); |
| 418 | if (accountHandle != null) { |
| 419 | subId = mPhoneAccountRegistrar |
| 420 | .getSubscriptionIdForPhoneAccount(accountHandle); |
| 421 | } |
Yorke Lee | fb5ec30 | 2015-04-15 16:15:55 -0700 | [diff] [blame] | 422 | return getTelephonyManager().getVoiceMailNumber(subId); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 423 | } catch (Exception e) { |
| 424 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 425 | throw e; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 426 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | /** |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 431 | * @see android.telecom.TelecomManager#getLine1Number |
| 432 | */ |
| 433 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 434 | public String getLine1Number(PhoneAccountHandle accountHandle, String callingPackage) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 435 | if (!canReadPhoneState(callingPackage, "getLine1Number")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 436 | return null; |
| 437 | } |
| 438 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 439 | synchronized (mLock) { |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 440 | if (!isVisibleToCaller(accountHandle)) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 441 | Log.w(this, "%s is not visible for the calling user [gL1N]", accountHandle); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 442 | return null; |
| 443 | } |
| 444 | |
| 445 | long token = Binder.clearCallingIdentity(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 446 | try { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 447 | int subId = |
| 448 | mPhoneAccountRegistrar.getSubscriptionIdForPhoneAccount(accountHandle); |
| 449 | return getTelephonyManager().getLine1NumberForSubscriber(subId); |
| 450 | } catch (Exception e) { |
| 451 | Log.e(this, e, "getSubscriptionIdForPhoneAccount"); |
| 452 | throw e; |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 453 | } finally { |
| 454 | Binder.restoreCallingIdentity(token); |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 455 | } |
Nancy Chen | ba30475 | 2015-01-24 23:29:22 -0800 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
| 459 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 460 | * @see android.telecom.TelecomManager#silenceRinger |
| 461 | */ |
| 462 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 463 | public void silenceRinger(String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 464 | synchronized (mLock) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 465 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 466 | |
| 467 | long token = Binder.clearCallingIdentity(); |
| 468 | try { |
Santos Cordon | a83f8a7 | 2015-06-02 17:12:39 -0700 | [diff] [blame] | 469 | Log.i(this, "Silence Ringer requested by %s", callingPackage); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 470 | mCallsManager.getRinger().silence(); |
| 471 | } finally { |
| 472 | Binder.restoreCallingIdentity(token); |
| 473 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 474 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * @see android.telecom.TelecomManager#getDefaultPhoneApp |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 479 | * @deprecated - Use {@link android.telecom.TelecomManager#getDefaultDialerPackage()} |
| 480 | * instead. |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 481 | */ |
| 482 | @Override |
| 483 | public ComponentName getDefaultPhoneApp() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 484 | // No need to synchronize |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 485 | Resources resources = mContext.getResources(); |
| 486 | return new ComponentName( |
| 487 | resources.getString(R.string.ui_default_package), |
| 488 | resources.getString(R.string.dialer_default_class)); |
| 489 | } |
| 490 | |
| 491 | /** |
Yorke Lee | 5291d4a | 2015-04-24 16:42:36 -0700 | [diff] [blame] | 492 | * @return the package name of the current user-selected default dialer. If no default |
| 493 | * has been selected, the package name of the system dialer is returned. If |
| 494 | * neither exists, then {@code null} is returned. |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 495 | * @see android.telecom.TelecomManager#getDefaultDialerPackage |
| 496 | */ |
| 497 | @Override |
| 498 | public String getDefaultDialerPackage() { |
Yorke Lee | 29c003e | 2015-05-04 17:09:27 -0700 | [diff] [blame] | 499 | final long token = Binder.clearCallingIdentity(); |
| 500 | try { |
| 501 | return DefaultDialerManager.getDefaultDialerApplication(mContext); |
| 502 | } finally { |
| 503 | Binder.restoreCallingIdentity(token); |
| 504 | } |
Yorke Lee | 5b3fc0a | 2015-04-23 17:42:57 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /** |
| 508 | * @see android.telecom.TelecomManager#getSystemDialerPackage |
| 509 | */ |
| 510 | @Override |
| 511 | public String getSystemDialerPackage() { |
| 512 | return mContext.getResources().getString(R.string.ui_default_package); |
| 513 | } |
| 514 | |
| 515 | /** |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 516 | * @see android.telecom.TelecomManager#isInCall |
| 517 | */ |
| 518 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 519 | public boolean isInCall(String callingPackage) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 520 | if (!canReadPhoneState(callingPackage, "isInCall")) { |
| 521 | return false; |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 524 | synchronized (mLock) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 525 | final int callState = mCallsManager.getCallState(); |
| 526 | return callState == TelephonyManager.CALL_STATE_OFFHOOK |
| 527 | || callState == TelephonyManager.CALL_STATE_RINGING; |
| 528 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
| 532 | * @see android.telecom.TelecomManager#isRinging |
| 533 | */ |
| 534 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 535 | public boolean isRinging(String callingPackage) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 536 | if (!canReadPhoneState(callingPackage, "isRinging")) { |
| 537 | return false; |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 540 | synchronized (mLock) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 541 | return mCallsManager.getCallState() == TelephonyManager.CALL_STATE_RINGING; |
| 542 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /** |
| 546 | * @see TelecomManager#getCallState |
| 547 | */ |
| 548 | @Override |
| 549 | public int getCallState() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 550 | synchronized (mLock) { |
| 551 | return mCallsManager.getCallState(); |
| 552 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /** |
| 556 | * @see android.telecom.TelecomManager#endCall |
| 557 | */ |
| 558 | @Override |
| 559 | public boolean endCall() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 560 | synchronized (mLock) { |
| 561 | enforceModifyPermission(); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 562 | |
| 563 | long token = Binder.clearCallingIdentity(); |
| 564 | try { |
| 565 | return endCallInternal(); |
| 566 | } finally { |
| 567 | Binder.restoreCallingIdentity(token); |
| 568 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 569 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /** |
| 573 | * @see android.telecom.TelecomManager#acceptRingingCall |
| 574 | */ |
| 575 | @Override |
| 576 | public void acceptRingingCall() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 577 | synchronized (mLock) { |
| 578 | enforceModifyPermission(); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 579 | |
| 580 | long token = Binder.clearCallingIdentity(); |
| 581 | try { |
| 582 | acceptRingingCallInternal(); |
| 583 | } finally { |
| 584 | Binder.restoreCallingIdentity(token); |
| 585 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 586 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | /** |
| 590 | * @see android.telecom.TelecomManager#showInCallScreen |
| 591 | */ |
| 592 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 593 | public void showInCallScreen(boolean showDialpad, String callingPackage) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 594 | if (!canReadPhoneState(callingPackage, "showInCallScreen")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 595 | return; |
| 596 | } |
| 597 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 598 | synchronized (mLock) { |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 599 | |
| 600 | long token = Binder.clearCallingIdentity(); |
| 601 | try { |
| 602 | mCallsManager.getInCallController().bringToForeground(showDialpad); |
| 603 | } finally { |
| 604 | Binder.restoreCallingIdentity(token); |
| 605 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 606 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | /** |
| 610 | * @see android.telecom.TelecomManager#cancelMissedCallsNotification |
| 611 | */ |
| 612 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 613 | public void cancelMissedCallsNotification(String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 614 | synchronized (mLock) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 615 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | ebf2d0f | 2015-05-15 10:28:29 -0700 | [diff] [blame] | 616 | long token = Binder.clearCallingIdentity(); |
| 617 | try { |
| 618 | mCallsManager.getMissedCallNotifier().clearMissedCalls(); |
| 619 | } finally { |
| 620 | Binder.restoreCallingIdentity(token); |
| 621 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 622 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /** |
| 626 | * @see android.telecom.TelecomManager#handleMmi |
| 627 | */ |
| 628 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 629 | public boolean handlePinMmi(String dialString, String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 630 | synchronized (mLock) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 631 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 632 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 633 | // Switch identity so that TelephonyManager checks Telecom's permissions instead. |
| 634 | long token = Binder.clearCallingIdentity(); |
| 635 | boolean retval = false; |
| 636 | try { |
| 637 | retval = getTelephonyManager().handlePinMmi(dialString); |
| 638 | } finally { |
| 639 | Binder.restoreCallingIdentity(token); |
| 640 | } |
| 641 | |
| 642 | return retval; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 643 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /** |
| 647 | * @see android.telecom.TelecomManager#handleMmi |
| 648 | */ |
| 649 | @Override |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 650 | public boolean handlePinMmiForPhoneAccount( |
| 651 | PhoneAccountHandle accountHandle, |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 652 | String dialString, |
| 653 | String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 654 | synchronized (mLock) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 655 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 656 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 657 | if (!isVisibleToCaller(accountHandle)) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 658 | Log.w(this, "%s is not visible for the calling user [hMMI]", accountHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 659 | return false; |
| 660 | } |
| 661 | |
| 662 | // Switch identity so that TelephonyManager checks Telecom's permissions instead. |
| 663 | long token = Binder.clearCallingIdentity(); |
| 664 | boolean retval = false; |
| 665 | try { |
| 666 | int subId = mPhoneAccountRegistrar |
| 667 | .getSubscriptionIdForPhoneAccount(accountHandle); |
| 668 | retval = getTelephonyManager().handlePinMmiForSubscriber(subId, dialString); |
| 669 | } finally { |
| 670 | Binder.restoreCallingIdentity(token); |
| 671 | } |
| 672 | |
| 673 | return retval; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 674 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /** |
| 678 | * @see android.telecom.TelecomManager#getAdnUriForPhoneAccount |
| 679 | */ |
| 680 | @Override |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 681 | public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle, |
| 682 | String callingPackage) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 683 | synchronized (mLock) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 684 | enforcePermissionOrPrivilegedDialer(MODIFY_PHONE_STATE, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 685 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 686 | if (!isVisibleToCaller(accountHandle)) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 687 | Log.w(this, "%s is not visible for the calling user [gA4PA]", accountHandle); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 688 | return null; |
| 689 | } |
| 690 | |
| 691 | // Switch identity so that TelephonyManager checks Telecom's permissions instead. |
| 692 | long token = Binder.clearCallingIdentity(); |
| 693 | String retval = "content://icc/adn/"; |
| 694 | try { |
| 695 | long subId = mPhoneAccountRegistrar |
| 696 | .getSubscriptionIdForPhoneAccount(accountHandle); |
| 697 | retval = retval + "subId/" + subId; |
| 698 | } finally { |
| 699 | Binder.restoreCallingIdentity(token); |
| 700 | } |
| 701 | |
| 702 | return Uri.parse(retval); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 703 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /** |
| 707 | * @see android.telecom.TelecomManager#isTtySupported |
| 708 | */ |
| 709 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 710 | public boolean isTtySupported(String callingPackage) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 711 | if (!canReadPhoneState(callingPackage, "hasVoiceMailNumber")) { |
| 712 | return false; |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 715 | synchronized (mLock) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 716 | return mCallsManager.isTtySupported(); |
| 717 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /** |
| 721 | * @see android.telecom.TelecomManager#getCurrentTtyMode |
| 722 | */ |
| 723 | @Override |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 724 | public int getCurrentTtyMode(String callingPackage) { |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 725 | if (!canReadPhoneState(callingPackage, "getCurrentTtyMode")) { |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 726 | return TelecomManager.TTY_MODE_OFF; |
| 727 | } |
| 728 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 729 | synchronized (mLock) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 730 | return mCallsManager.getCurrentTtyMode(); |
| 731 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /** |
| 735 | * @see android.telecom.TelecomManager#addNewIncomingCall |
| 736 | */ |
| 737 | @Override |
| 738 | public void addNewIncomingCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 739 | synchronized (mLock) { |
| 740 | Log.i(this, "Adding new incoming call with phoneAccountHandle %s", |
| 741 | phoneAccountHandle); |
| 742 | if (phoneAccountHandle != null && phoneAccountHandle.getComponentName() != null) { |
| 743 | mAppOpsManager.checkPackage( |
| 744 | Binder.getCallingUid(), |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 745 | phoneAccountHandle.getComponentName().getPackageName()); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 746 | |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 747 | // Make sure it doesn't cross the UserHandle boundary |
| 748 | enforceUserHandleMatchesCaller(phoneAccountHandle); |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 749 | long token = Binder.clearCallingIdentity(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 750 | |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 751 | try { |
| 752 | Intent intent = new Intent(TelecomManager.ACTION_INCOMING_CALL); |
| 753 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 754 | phoneAccountHandle); |
| 755 | intent.putExtra(CallIntentProcessor.KEY_IS_INCOMING_CALL, true); |
| 756 | if (extras != null) { |
| 757 | intent.putExtra(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS, extras); |
| 758 | } |
| 759 | CallIntentProcessor.processIncomingCallIntent(mCallsManager, intent); |
| 760 | } finally { |
| 761 | Binder.restoreCallingIdentity(token); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 762 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 763 | } else { |
| 764 | Log.w(this, |
| 765 | "Null phoneAccountHandle. Ignoring request to add new incoming call"); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 766 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
| 770 | /** |
| 771 | * @see android.telecom.TelecomManager#addNewUnknownCall |
| 772 | */ |
| 773 | @Override |
| 774 | public void addNewUnknownCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 775 | synchronized (mLock) { |
David Stevens | 0785274 | 2015-04-10 18:22:47 -0700 | [diff] [blame] | 776 | if (phoneAccountHandle != null && phoneAccountHandle.getComponentName() != null) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 777 | mAppOpsManager.checkPackage( |
| 778 | Binder.getCallingUid(), |
| 779 | phoneAccountHandle.getComponentName().getPackageName()); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 780 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 781 | // Make sure it doesn't cross the UserHandle boundary |
| 782 | enforceUserHandleMatchesCaller(phoneAccountHandle); |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 783 | long token = Binder.clearCallingIdentity(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 784 | |
Sharvil Nanavati | 6d3efb4 | 2015-05-14 11:36:40 -0700 | [diff] [blame] | 785 | try { |
| 786 | Intent intent = new Intent(TelecomManager.ACTION_NEW_UNKNOWN_CALL); |
| 787 | intent.putExtras(extras); |
| 788 | intent.putExtra(CallIntentProcessor.KEY_IS_UNKNOWN_CALL, true); |
| 789 | intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, |
| 790 | phoneAccountHandle); |
| 791 | CallIntentProcessor.processUnknownCallIntent(mCallsManager, intent); |
| 792 | } finally { |
| 793 | Binder.restoreCallingIdentity(token); |
| 794 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 795 | } else { |
| 796 | Log.i(this, |
| 797 | "Null phoneAccountHandle or not initiated by Telephony. " + |
| 798 | "Ignoring request to add new unknown call."); |
| 799 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 800 | } |
| 801 | } |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 802 | |
| 803 | /** |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 804 | * @see android.telecom.TelecomManager#placeCall |
| 805 | */ |
| 806 | @Override |
| 807 | public void placeCall(Uri handle, Bundle extras, String callingPackage) { |
| 808 | enforceCallingPackage(callingPackage); |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 809 | if (!canCallPhone(callingPackage, "placeCall")) { |
| 810 | throw new SecurityException("Package " + callingPackage |
| 811 | + " is not allowed to place phone calls"); |
| 812 | } |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 813 | |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 814 | synchronized (mLock) { |
Yorke Lee | b3feab5 | 2015-04-30 12:35:16 -0700 | [diff] [blame] | 815 | final UserHandle userHandle = Binder.getCallingUserHandle(); |
Yorke Lee | b791066 | 2015-04-24 12:00:19 -0700 | [diff] [blame] | 816 | long token = Binder.clearCallingIdentity(); |
Yorke Lee | 5806175 | 2015-05-04 11:06:26 -0700 | [diff] [blame] | 817 | try { |
| 818 | final Intent intent = new Intent(Intent.ACTION_CALL, handle); |
| 819 | intent.putExtras(extras); |
| 820 | new UserCallIntentProcessor(mContext, userHandle).processIntent(intent, |
| 821 | callingPackage); |
| 822 | } finally { |
| 823 | Binder.restoreCallingIdentity(token); |
| 824 | } |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
| 828 | /** |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 829 | * @see android.telecom.TelecomManager#enablePhoneAccount |
| 830 | */ |
| 831 | @Override |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 832 | public boolean enablePhoneAccount(PhoneAccountHandle accountHandle, boolean isEnabled) { |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 833 | enforceModifyPermission(); |
| 834 | synchronized (mLock) { |
| 835 | long token = Binder.clearCallingIdentity(); |
| 836 | try { |
| 837 | // enable/disable phone account |
Yorke Lee | 71734c2 | 2015-06-02 14:22:56 -0700 | [diff] [blame] | 838 | return mPhoneAccountRegistrar.enablePhoneAccount(accountHandle, isEnabled); |
| 839 | } finally { |
| 840 | Binder.restoreCallingIdentity(token); |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | @Override |
| 846 | public boolean setDefaultDialer(String packageName) { |
| 847 | enforcePermission(MODIFY_PHONE_STATE); |
| 848 | enforcePermission(WRITE_SECURE_SETTINGS); |
| 849 | synchronized (mLock) { |
| 850 | long token = Binder.clearCallingIdentity(); |
| 851 | try { |
| 852 | return DefaultDialerManager.setDefaultDialerApplication(mContext, packageName); |
Santos Cordon | ea5cb93 | 2015-05-07 16:28:38 -0700 | [diff] [blame] | 853 | } finally { |
| 854 | Binder.restoreCallingIdentity(token); |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /** |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 860 | * Dumps the current state of the TelecomService. Used when generating problem reports. |
| 861 | * |
| 862 | * @param fd The file descriptor. |
| 863 | * @param writer The print writer to dump the state to. |
| 864 | * @param args Optional dump arguments. |
| 865 | */ |
| 866 | @Override |
| 867 | protected void dump(FileDescriptor fd, final PrintWriter writer, String[] args) { |
| 868 | if (mContext.checkCallingOrSelfPermission( |
| 869 | android.Manifest.permission.DUMP) |
| 870 | != PackageManager.PERMISSION_GRANTED) { |
| 871 | writer.println("Permission Denial: can't dump TelecomService " + |
| 872 | "from from pid=" + Binder.getCallingPid() + ", uid=" + |
| 873 | Binder.getCallingUid()); |
| 874 | return; |
| 875 | } |
| 876 | |
| 877 | final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 878 | if (mCallsManager != null) { |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 879 | pw.println("CallsManager: "); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 880 | pw.increaseIndent(); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 881 | mCallsManager.dump(pw); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 882 | pw.decreaseIndent(); |
| 883 | |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 884 | pw.println("PhoneAccountRegistrar: "); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 885 | pw.increaseIndent(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 886 | mPhoneAccountRegistrar.dump(pw); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 887 | pw.decreaseIndent(); |
| 888 | } |
Santos Cordon | 2685dab | 2015-04-17 17:12:09 -0700 | [diff] [blame] | 889 | |
| 890 | Log.dumpCallEvents(pw); |
Tyler Gunn | 4768986 | 2014-12-17 17:10:28 -0800 | [diff] [blame] | 891 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 892 | }; |
| 893 | |
| 894 | private Context mContext; |
| 895 | private AppOpsManager mAppOpsManager; |
| 896 | private UserManager mUserManager; |
| 897 | private PackageManager mPackageManager; |
| 898 | private CallsManager mCallsManager; |
| 899 | private final PhoneAccountRegistrar mPhoneAccountRegistrar; |
| 900 | private final TelecomSystem.SyncRoot mLock; |
| 901 | |
| 902 | public TelecomServiceImpl( |
| 903 | Context context, |
| 904 | CallsManager callsManager, |
| 905 | PhoneAccountRegistrar phoneAccountRegistrar, |
| 906 | TelecomSystem.SyncRoot lock) { |
| 907 | mContext = context; |
| 908 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
| 909 | |
| 910 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
| 911 | mPackageManager = mContext.getPackageManager(); |
| 912 | |
| 913 | mCallsManager = callsManager; |
| 914 | mLock = lock; |
| 915 | mPhoneAccountRegistrar = phoneAccountRegistrar; |
| 916 | } |
| 917 | |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 918 | public ITelecomService.Stub getBinder() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 919 | return mBinderImpl; |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | // |
| 923 | // Supporting methods for the ITelecomService interface implementation. |
| 924 | // |
| 925 | |
| 926 | private boolean isVisibleToCaller(PhoneAccountHandle accountHandle) { |
| 927 | if (accountHandle == null) { |
| 928 | return false; |
| 929 | } |
Santos Cordon | 6a21264 | 2015-05-08 16:35:23 -0700 | [diff] [blame] | 930 | return isVisibleToCaller(mPhoneAccountRegistrar.getPhoneAccount(accountHandle)); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | private boolean isVisibleToCaller(PhoneAccount account) { |
| 934 | if (account == null) { |
| 935 | return false; |
| 936 | } |
| 937 | |
| 938 | // If this PhoneAccount has CAPABILITY_MULTI_USER, it should be visible to all users and |
| 939 | // all profiles. Only Telephony and SIP accounts should have this capability. |
| 940 | if (account.hasCapabilities(PhoneAccount.CAPABILITY_MULTI_USER)) { |
| 941 | return true; |
| 942 | } |
| 943 | |
| 944 | UserHandle phoneAccountUserHandle = account.getAccountHandle().getUserHandle(); |
| 945 | if (phoneAccountUserHandle == null) { |
| 946 | return false; |
| 947 | } |
| 948 | |
Sailesh Nepal | 91fc809 | 2015-02-14 15:44:55 -0800 | [diff] [blame] | 949 | if (phoneAccountUserHandle.equals(Binder.getCallingUserHandle())) { |
| 950 | return true; |
| 951 | } |
| 952 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 953 | List<UserHandle> profileUserHandles; |
Sailesh Nepal | 91fc809 | 2015-02-14 15:44:55 -0800 | [diff] [blame] | 954 | if (UserHandle.getCallingUserId() == UserHandle.USER_OWNER) { |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 955 | profileUserHandles = mUserManager.getUserProfiles(); |
| 956 | } else { |
| 957 | // Otherwise, it has to be owned by the current caller's profile. |
| 958 | profileUserHandles = new ArrayList<>(1); |
| 959 | profileUserHandles.add(Binder.getCallingUserHandle()); |
| 960 | } |
| 961 | |
| 962 | return profileUserHandles.contains(phoneAccountUserHandle); |
| 963 | } |
| 964 | |
| 965 | /** |
| 966 | * Given a list of {@link PhoneAccountHandle}s, filter them to the ones that the calling |
| 967 | * user can see. |
| 968 | * |
| 969 | * @param phoneAccountHandles Unfiltered list of account handles. |
| 970 | * |
| 971 | * @return {@link PhoneAccountHandle}s visible to the calling user and its profiles. |
| 972 | */ |
| 973 | private List<PhoneAccountHandle> filterForAccountsVisibleToCaller( |
| 974 | List<PhoneAccountHandle> phoneAccountHandles) { |
| 975 | List<PhoneAccountHandle> profilePhoneAccountHandles = |
| 976 | new ArrayList<>(phoneAccountHandles.size()); |
| 977 | for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) { |
| 978 | if (isVisibleToCaller(phoneAccountHandle)) { |
| 979 | profilePhoneAccountHandles.add(phoneAccountHandle); |
| 980 | } |
| 981 | } |
| 982 | return profilePhoneAccountHandles; |
| 983 | } |
| 984 | |
| 985 | private boolean isCallerSystemApp() { |
| 986 | int uid = Binder.getCallingUid(); |
| 987 | String[] packages = mPackageManager.getPackagesForUid(uid); |
| 988 | for (String packageName : packages) { |
| 989 | if (isPackageSystemApp(packageName)) { |
| 990 | return true; |
| 991 | } |
| 992 | } |
| 993 | return false; |
| 994 | } |
| 995 | |
| 996 | private boolean isPackageSystemApp(String packageName) { |
| 997 | try { |
| 998 | ApplicationInfo applicationInfo = mPackageManager.getApplicationInfo(packageName, |
| 999 | PackageManager.GET_META_DATA); |
| 1000 | if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1001 | return true; |
| 1002 | } |
| 1003 | } catch (PackageManager.NameNotFoundException e) { |
| 1004 | } |
| 1005 | return false; |
| 1006 | } |
| 1007 | |
| 1008 | private void acceptRingingCallInternal() { |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1009 | Call call = mCallsManager.getFirstCallWithState(CallState.RINGING); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1010 | if (call != null) { |
| 1011 | call.answer(call.getVideoState()); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | private boolean endCallInternal() { |
| 1016 | // Always operate on the foreground call if one exists, otherwise get the first call in |
| 1017 | // priority order by call-state. |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1018 | Call call = mCallsManager.getForegroundCall(); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1019 | if (call == null) { |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1020 | call = mCallsManager.getFirstCallWithState( |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1021 | CallState.ACTIVE, |
| 1022 | CallState.DIALING, |
| 1023 | CallState.RINGING, |
| 1024 | CallState.ON_HOLD); |
| 1025 | } |
| 1026 | |
| 1027 | if (call != null) { |
| 1028 | if (call.getState() == CallState.RINGING) { |
| 1029 | call.reject(false /* rejectWithMessage */, null); |
| 1030 | } else { |
| 1031 | call.disconnect(); |
| 1032 | } |
| 1033 | return true; |
| 1034 | } |
| 1035 | |
| 1036 | return false; |
| 1037 | } |
| 1038 | |
| 1039 | private void enforcePhoneAccountModificationForPackage(String packageName) { |
| 1040 | // TODO: Use a new telecomm permission for this instead of reusing modify. |
| 1041 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1042 | int result = mContext.checkCallingOrSelfPermission(MODIFY_PHONE_STATE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1043 | |
| 1044 | // Callers with MODIFY_PHONE_STATE can use the PhoneAccount mechanism to implement |
| 1045 | // built-in behavior even when PhoneAccounts are not exposed as a third-part API. They |
| 1046 | // may also modify PhoneAccounts on behalf of any 'packageName'. |
| 1047 | |
| 1048 | if (result != PackageManager.PERMISSION_GRANTED) { |
| 1049 | // Other callers are only allowed to modify PhoneAccounts if the relevant system |
| 1050 | // feature is enabled ... |
| 1051 | enforceConnectionServiceFeature(); |
| 1052 | // ... and the PhoneAccounts they refer to are for their own package. |
| 1053 | enforceCallingPackage(packageName); |
| 1054 | } |
| 1055 | } |
| 1056 | |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1057 | private void enforcePermissionOrPrivilegedDialer(String permission, String packageName) { |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1058 | if (!isPrivilegedDialerCalling(packageName)) { |
| 1059 | try { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1060 | enforcePermission(permission); |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1061 | } catch (SecurityException e) { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1062 | Log.e(this, e, "Caller must be the default or system dialer, or have the permission" |
| 1063 | + " %s to perform this operation.", permission); |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1064 | throw e; |
| 1065 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | private void enforceCallingPackage(String packageName) { |
| 1070 | mAppOpsManager.checkPackage(Binder.getCallingUid(), packageName); |
| 1071 | } |
| 1072 | |
| 1073 | private void enforceConnectionServiceFeature() { |
| 1074 | enforceFeature(PackageManager.FEATURE_CONNECTION_SERVICE); |
| 1075 | } |
| 1076 | |
| 1077 | private void enforceRegisterCallProviderPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1078 | enforcePermission(REGISTER_CALL_PROVIDER); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | private void enforceRegisterSimSubscriptionPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1082 | enforcePermission(REGISTER_SIM_SUBSCRIPTION); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | private void enforceRegisterConnectionManagerPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1086 | enforcePermission(REGISTER_CONNECTION_MANAGER); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1087 | } |
| 1088 | |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1089 | private void enforceModifyPermission() { |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1090 | enforcePermission(MODIFY_PHONE_STATE); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | private void enforcePermission(String permission) { |
| 1094 | mContext.enforceCallingOrSelfPermission(permission, null); |
| 1095 | } |
| 1096 | |
| 1097 | private void enforceRegisterMultiUser() { |
| 1098 | if (!isCallerSystemApp()) { |
| 1099 | throw new SecurityException("CAPABILITY_MULTI_USER is only available to system apps."); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | private void enforceUserHandleMatchesCaller(PhoneAccountHandle accountHandle) { |
| 1104 | if (!Binder.getCallingUserHandle().equals(accountHandle.getUserHandle())) { |
| 1105 | throw new SecurityException("Calling UserHandle does not match PhoneAccountHandle's"); |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | private void enforceFeature(String feature) { |
| 1110 | PackageManager pm = mContext.getPackageManager(); |
| 1111 | if (!pm.hasSystemFeature(feature)) { |
| 1112 | throw new UnsupportedOperationException( |
| 1113 | "System does not support feature " + feature); |
| 1114 | } |
| 1115 | } |
| 1116 | |
Svet Ganov | 38f1a4d | 2015-04-17 15:28:03 -0700 | [diff] [blame] | 1117 | private boolean canReadPhoneState(String callingPackage, String message) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 1118 | // The system/default dialer can always read phone state - so that emergency calls will |
| 1119 | // still work. |
| 1120 | if (isPrivilegedDialerCalling(callingPackage)) { |
| 1121 | return true; |
| 1122 | } |
| 1123 | |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1124 | // Accessing phone state is gated by a special permission. |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1125 | mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, message); |
Svet Ganov | 0961118 | 2015-04-16 12:29:01 -0700 | [diff] [blame] | 1126 | |
| 1127 | // Some apps that have the permission can be restricted via app ops. |
| 1128 | return mAppOpsManager.noteOp(AppOpsManager.OP_READ_PHONE_STATE, |
| 1129 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1130 | } |
| 1131 | |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1132 | private boolean canCallPhone(String callingPackage, String message) { |
Yorke Lee | 57138a6 | 2015-05-18 18:18:08 -0700 | [diff] [blame] | 1133 | // The system/default dialer can always read phone state - so that emergency calls will |
| 1134 | // still work. |
| 1135 | if (isPrivilegedDialerCalling(callingPackage)) { |
| 1136 | return true; |
| 1137 | } |
| 1138 | |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1139 | // Accessing phone state is gated by a special permission. |
Yorke Lee | cb0bd8a | 2015-05-18 11:57:14 -0700 | [diff] [blame] | 1140 | mContext.enforceCallingOrSelfPermission(CALL_PHONE, message); |
Yorke Lee | a3a3adc | 2015-04-23 12:49:01 -0700 | [diff] [blame] | 1141 | |
| 1142 | // Some apps that have the permission can be restricted via app ops. |
| 1143 | return mAppOpsManager.noteOp(AppOpsManager.OP_CALL_PHONE, |
| 1144 | Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1145 | } |
| 1146 | |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 1147 | private boolean isCallerSimCallManager() { |
Etan Cohen | b600a5f | 2015-03-06 17:37:30 -0800 | [diff] [blame] | 1148 | PhoneAccountHandle accountHandle = TelecomSystem.getInstance().getPhoneAccountRegistrar() |
| 1149 | .getSimCallManager(); |
Sailesh Nepal | 2a98c97 | 2015-03-04 15:43:15 -0800 | [diff] [blame] | 1150 | if (accountHandle != null) { |
| 1151 | try { |
| 1152 | mAppOpsManager.checkPackage( |
| 1153 | Binder.getCallingUid(), accountHandle.getComponentName().getPackageName()); |
| 1154 | return true; |
| 1155 | } catch (SecurityException e) { |
| 1156 | } |
| 1157 | } |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
Yorke Lee | 5310196 | 2015-04-29 16:25:29 -0700 | [diff] [blame] | 1161 | private boolean isPrivilegedDialerCalling(String callingPackage) { |
| 1162 | mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage); |
| 1163 | return DefaultDialerManager.isDefaultOrSystemDialer(mContext, callingPackage); |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | private TelephonyManager getTelephonyManager() { |
| 1167 | return (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE); |
| 1168 | } |
Santos Cordon | f987d1a | 2014-12-02 03:37:03 -0800 | [diff] [blame] | 1169 | } |