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 19 import android.app.AppOpsManager; 20 21 import android.app.Activity; 22 import android.app.BroadcastOptions; 23 import android.content.BroadcastReceiver; 24 import android.content.Context; 25 import android.content.Intent; 26 import android.content.res.Resources; 27 import android.net.Uri; 28 import android.os.Bundle; 29 import android.os.Trace; 30 import android.os.UserHandle; 31 import android.telecom.GatewayInfo; 32 import android.telecom.Log; 33 import android.telecom.PhoneAccount; 34 import android.telecom.PhoneAccountHandle; 35 import android.telecom.TelecomManager; 36 import android.telecom.VideoProfile; 37 import android.telephony.DisconnectCause; 38 import android.telephony.TelephonyManager; 39 import android.text.TextUtils; 40 41 import com.android.internal.annotations.VisibleForTesting; 42 import com.android.server.telecom.callredirection.CallRedirectionProcessor; 43 44 // TODO: Needed for move to system service: import com.android.internal.R; 45 46 /** 47 * OutgoingCallIntentBroadcaster receives CALL and CALL_PRIVILEGED Intents, and broadcasts the 48 * ACTION_NEW_OUTGOING_CALL intent. ACTION_NEW_OUTGOING_CALL is an ordered broadcast intent which 49 * contains the phone number being dialed. Applications can use this intent to (1) see which numbers 50 * are being dialed, (2) redirect a call (change the number being dialed), or (3) prevent a call 51 * from being placed. 52 * 53 * After the other applications have had a chance to see the ACTION_NEW_OUTGOING_CALL intent, it 54 * finally reaches the {@link NewOutgoingCallBroadcastIntentReceiver}. 55 * 56 * Calls where no number is present (like for a CDMA "empty flash" or a nonexistent voicemail 57 * number) are exempt from being broadcast. 58 * 59 * Calls to emergency numbers are still broadcast for informative purposes. The call is placed 60 * prior to sending ACTION_NEW_OUTGOING_CALL and cannot be redirected nor prevented. 61 */ 62 @VisibleForTesting 63 public class NewOutgoingCallIntentBroadcaster { 64 /** 65 * Legacy string constants used to retrieve gateway provider extras from intents. These still 66 * need to be copied from the source call intent to the destination intent in order to 67 * support third party gateway providers that are still using old string constants in 68 * Telephony. 69 */ 70 public static final String EXTRA_GATEWAY_PROVIDER_PACKAGE = 71 "com.android.phone.extra.GATEWAY_PROVIDER_PACKAGE"; 72 public static final String EXTRA_GATEWAY_URI = "com.android.phone.extra.GATEWAY_URI"; 73 74 private final CallsManager mCallsManager; 75 private Call mCall; 76 private final Intent mIntent; 77 private final Context mContext; 78 private final PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter; 79 private final TelecomSystem.SyncRoot mLock; 80 private final DefaultDialerCache mDefaultDialerCache; 81 82 /* 83 * Whether or not the outgoing call intent originated from the default phone application. If 84 * so, it will be allowed to make emergency calls, even with the ACTION_CALL intent. 85 */ 86 private final boolean mIsDefaultOrSystemPhoneApp; 87 88 public static class CallDisposition { 89 // True for certain types of numbers that are not intended to be intercepted or modified 90 // by third parties (e.g. emergency numbers). 91 public boolean callImmediately = false; 92 // True for all managed calls, false for self-managed calls. 93 public boolean sendBroadcast = true; 94 // True for requesting call redirection, false for not requesting it. 95 public boolean requestRedirection = true; 96 public int disconnectCause = DisconnectCause.NOT_DISCONNECTED; 97 String number; 98 Uri callingAddress; 99 } 100 101 @VisibleForTesting NewOutgoingCallIntentBroadcaster(Context context, CallsManager callsManager, Intent intent, PhoneNumberUtilsAdapter phoneNumberUtilsAdapter, boolean isDefaultPhoneApp, DefaultDialerCache defaultDialerCache)102 public NewOutgoingCallIntentBroadcaster(Context context, CallsManager callsManager, 103 Intent intent, PhoneNumberUtilsAdapter phoneNumberUtilsAdapter, 104 boolean isDefaultPhoneApp, DefaultDialerCache defaultDialerCache) { 105 mContext = context; 106 mCallsManager = callsManager; 107 mIntent = intent; 108 mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter; 109 mIsDefaultOrSystemPhoneApp = isDefaultPhoneApp; 110 mLock = mCallsManager.getLock(); 111 mDefaultDialerCache = defaultDialerCache; 112 } 113 114 /** 115 * Processes the result of the outgoing call broadcast intent, and performs callbacks to 116 * the OutgoingCallIntentBroadcasterListener as necessary. 117 */ 118 public class NewOutgoingCallBroadcastIntentReceiver extends BroadcastReceiver { 119 120 @Override onReceive(Context context, Intent intent)121 public void onReceive(Context context, Intent intent) { 122 try { 123 Log.startSession("NOCBIR.oR"); 124 Trace.beginSection("onReceiveNewOutgoingCallBroadcast"); 125 synchronized (mLock) { 126 Log.v(this, "onReceive: %s", intent); 127 128 // Once the NEW_OUTGOING_CALL broadcast is finished, the resultData is 129 // used as the actual number to call. (If null, no call will be placed.) 130 String resultNumber = getResultData(); 131 Log.i(this, "Received new-outgoing-call-broadcast for %s with data %s", mCall, 132 Log.pii(resultNumber)); 133 134 boolean endEarly = false; 135 long disconnectTimeout = 136 Timeouts.getNewOutgoingCallCancelMillis(mContext.getContentResolver()); 137 if (resultNumber == null) { 138 Log.v(this, "Call cancelled (null number), returning..."); 139 disconnectTimeout = getDisconnectTimeoutFromApp( 140 getResultExtras(false), disconnectTimeout); 141 endEarly = true; 142 } else if (isPotentialEmergencyNumber(resultNumber)) { 143 Log.w(this, "Cannot modify outgoing call to emergency number %s.", 144 resultNumber); 145 disconnectTimeout = 0; 146 endEarly = true; 147 } 148 149 if (endEarly) { 150 if (mCall != null) { 151 mCall.disconnect(disconnectTimeout); 152 } 153 return; 154 } 155 156 // If this call is already disconnected then we have nothing more to do. 157 if (mCall.isDisconnected()) { 158 Log.w(this, "Call has already been disconnected," + 159 " ignore the broadcast Call %s", mCall); 160 return; 161 } 162 163 // TODO: Remove the assumption that phone numbers are either SIP or TEL. 164 // This does not impact self-managed ConnectionServices as they do not use the 165 // NewOutgoingCallIntentBroadcaster. 166 Uri resultHandleUri = Uri.fromParts( 167 mPhoneNumberUtilsAdapter.isUriNumber(resultNumber) ? 168 PhoneAccount.SCHEME_SIP : PhoneAccount.SCHEME_TEL, 169 resultNumber, null); 170 171 Uri originalUri = mIntent.getData(); 172 173 if (originalUri.getSchemeSpecificPart().equals(resultNumber)) { 174 Log.v(this, "Call number unmodified after" + 175 " new outgoing call intent broadcast."); 176 } else { 177 Log.v(this, "Retrieved modified handle after outgoing call intent" + 178 " broadcast: Original: %s, Modified: %s", 179 Log.pii(originalUri), 180 Log.pii(resultHandleUri)); 181 } 182 183 GatewayInfo gatewayInfo = getGateWayInfoFromIntent(intent, resultHandleUri); 184 placeOutgoingCallImmediately(mCall, resultHandleUri, gatewayInfo, 185 mIntent.getBooleanExtra( 186 TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false), 187 mIntent.getIntExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, 188 VideoProfile.STATE_AUDIO_ONLY)); 189 } 190 } finally { 191 Trace.endSection(); 192 Log.endSession(); 193 } 194 } 195 } 196 197 /** 198 * Processes the supplied intent and starts the outgoing call broadcast process relevant to the 199 * intent. 200 * 201 * This method will handle three kinds of actions: 202 * 203 * - CALL (intent launched by all third party dialers) 204 * - CALL_PRIVILEGED (intent launched by system apps e.g. system Dialer, voice Dialer) 205 * - CALL_EMERGENCY (intent launched by lock screen emergency dialer) 206 * 207 * @return {@link DisconnectCause#NOT_DISCONNECTED} if the call succeeded, and an appropriate 208 * {@link DisconnectCause} if the call did not, describing why it failed. 209 */ 210 @VisibleForTesting evaluateCall()211 public CallDisposition evaluateCall() { 212 CallDisposition result = new CallDisposition(); 213 214 Intent intent = mIntent; 215 String action = intent.getAction(); 216 final Uri handle = intent.getData(); 217 218 if (handle == null) { 219 Log.w(this, "Empty handle obtained from the call intent."); 220 result.disconnectCause = DisconnectCause.INVALID_NUMBER; 221 return result; 222 } 223 224 boolean isVoicemailNumber = PhoneAccount.SCHEME_VOICEMAIL.equals(handle.getScheme()); 225 if (isVoicemailNumber) { 226 if (Intent.ACTION_CALL.equals(action) 227 || Intent.ACTION_CALL_PRIVILEGED.equals(action)) { 228 // Voicemail calls will be handled directly by the telephony connection manager 229 Log.i(this, "Voicemail number dialed. Skipping redirection and broadcast", intent); 230 mIntent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, 231 VideoProfile.STATE_AUDIO_ONLY); 232 result.callImmediately = true; 233 result.requestRedirection = false; 234 result.sendBroadcast = false; 235 result.callingAddress = handle; 236 return result; 237 } else { 238 Log.i(this, "Unhandled intent %s. Ignoring and not placing call.", intent); 239 result.disconnectCause = DisconnectCause.OUTGOING_CANCELED; 240 return result; 241 } 242 } 243 244 PhoneAccountHandle targetPhoneAccount = mIntent.getParcelableExtra( 245 TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE); 246 boolean isSelfManaged = false; 247 if (targetPhoneAccount != null) { 248 PhoneAccount phoneAccount = 249 mCallsManager.getPhoneAccountRegistrar().getPhoneAccountUnchecked( 250 targetPhoneAccount); 251 if (phoneAccount != null) { 252 isSelfManaged = phoneAccount.isSelfManaged(); 253 } 254 } 255 256 result.number = ""; 257 result.callingAddress = handle; 258 259 if (isSelfManaged) { 260 // Self-managed call. 261 result.callImmediately = true; 262 result.sendBroadcast = false; 263 result.requestRedirection = false; 264 Log.i(this, "Skipping NewOutgoingCallBroadcast for self-managed call."); 265 return result; 266 } 267 268 // Placing a managed call 269 String number = getNumberFromCallIntent(intent); 270 result.number = number; 271 if (number == null) { 272 result.disconnectCause = DisconnectCause.NO_PHONE_NUMBER_SUPPLIED; 273 return result; 274 } 275 276 final boolean isPotentialEmergencyNumber = isPotentialEmergencyNumber(number); 277 Log.v(this, "isPotentialEmergencyNumber = %s", isPotentialEmergencyNumber); 278 279 action = calculateCallIntentAction(intent, isPotentialEmergencyNumber); 280 intent.setAction(action); 281 282 if (Intent.ACTION_CALL.equals(action)) { 283 if (isPotentialEmergencyNumber) { 284 if (!mIsDefaultOrSystemPhoneApp) { 285 Log.w(this, "Cannot call potential emergency number %s with CALL Intent %s " 286 + "unless caller is system or default dialer.", number, intent); 287 launchSystemDialer(intent.getData()); 288 result.disconnectCause = DisconnectCause.OUTGOING_CANCELED; 289 return result; 290 } else { 291 result.callImmediately = true; 292 result.requestRedirection = false; 293 } 294 } 295 } else if (Intent.ACTION_CALL_EMERGENCY.equals(action)) { 296 if (!isPotentialEmergencyNumber) { 297 Log.w(this, "Cannot call non-potential-emergency number %s with EMERGENCY_CALL " 298 + "Intent %s.", number, intent); 299 result.disconnectCause = DisconnectCause.OUTGOING_CANCELED; 300 return result; 301 } 302 result.callImmediately = true; 303 result.requestRedirection = false; 304 } else { 305 Log.w(this, "Unhandled Intent %s. Ignoring and not placing call.", intent); 306 result.disconnectCause = DisconnectCause.INVALID_NUMBER; 307 return result; 308 } 309 310 String scheme = mPhoneNumberUtilsAdapter.isUriNumber(number) 311 ? PhoneAccount.SCHEME_SIP : PhoneAccount.SCHEME_TEL; 312 result.callingAddress = Uri.fromParts(scheme, number, null); 313 return result; 314 } 315 getNumberFromCallIntent(Intent intent)316 private String getNumberFromCallIntent(Intent intent) { 317 String number; 318 number = mPhoneNumberUtilsAdapter.getNumberFromIntent(intent, mContext); 319 if (TextUtils.isEmpty(number)) { 320 Log.w(this, "Empty number obtained from the call intent."); 321 return null; 322 } 323 324 boolean isUriNumber = mPhoneNumberUtilsAdapter.isUriNumber(number); 325 if (!isUriNumber) { 326 number = mPhoneNumberUtilsAdapter.convertKeypadLettersToDigits(number); 327 number = mPhoneNumberUtilsAdapter.stripSeparators(number); 328 } 329 return number; 330 } 331 processCall(Call call, CallDisposition disposition)332 public void processCall(Call call, CallDisposition disposition) { 333 mCall = call; 334 if (disposition.callImmediately) { 335 boolean speakerphoneOn = mIntent.getBooleanExtra( 336 TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false); 337 int videoState = mIntent.getIntExtra( 338 TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, 339 VideoProfile.STATE_AUDIO_ONLY); 340 placeOutgoingCallImmediately(mCall, disposition.callingAddress, null, 341 speakerphoneOn, videoState); 342 343 // Don't return but instead continue and send the ACTION_NEW_OUTGOING_CALL broadcast 344 // so that third parties can still inspect (but not intercept) the outgoing call. When 345 // the broadcast finally reaches the OutgoingCallBroadcastReceiver, we'll know not to 346 // initiate the call again because of the presence of the EXTRA_ALREADY_CALLED extra. 347 } 348 349 boolean callRedirectionWithService = false; 350 if (disposition.requestRedirection) { 351 CallRedirectionProcessor callRedirectionProcessor = new CallRedirectionProcessor( 352 mContext, mCallsManager, mCall, disposition.callingAddress, 353 mCallsManager.getPhoneAccountRegistrar(), 354 getGateWayInfoFromIntent(mIntent, mIntent.getData()), 355 mIntent.getBooleanExtra(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, 356 false), 357 mIntent.getIntExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, 358 VideoProfile.STATE_AUDIO_ONLY)); 359 /** 360 * If there is an available {@link android.telecom.CallRedirectionService}, use the 361 * {@link CallRedirectionProcessor} to perform call redirection instead of using 362 * broadcasting. 363 */ 364 callRedirectionWithService = callRedirectionProcessor 365 .canMakeCallRedirectionWithService(); 366 if (callRedirectionWithService) { 367 callRedirectionProcessor.performCallRedirection(); 368 } 369 } 370 371 if (disposition.sendBroadcast) { 372 UserHandle targetUser = mCall.getInitiatingUser(); 373 Log.i(this, "Sending NewOutgoingCallBroadcast for %s to %s", mCall, targetUser); 374 broadcastIntent(mIntent, disposition.number, 375 !disposition.callImmediately && !callRedirectionWithService, targetUser); 376 } 377 } 378 379 /** 380 * Sends a new outgoing call ordered broadcast so that third party apps can cancel the 381 * placement of the call or redirect it to a different number. 382 * 383 * @param originalCallIntent The original call intent. 384 * @param number Call number that was stored in the original call intent. 385 * @param receiverRequired Whether or not the result from the ordered broadcast should be 386 * processed using a {@link NewOutgoingCallIntentBroadcaster}. 387 * @param targetUser User that the broadcast sent to. 388 */ broadcastIntent( Intent originalCallIntent, String number, boolean receiverRequired, UserHandle targetUser)389 private void broadcastIntent( 390 Intent originalCallIntent, 391 String number, 392 boolean receiverRequired, 393 UserHandle targetUser) { 394 Intent broadcastIntent = new Intent(Intent.ACTION_NEW_OUTGOING_CALL); 395 if (number != null) { 396 broadcastIntent.putExtra(Intent.EXTRA_PHONE_NUMBER, number); 397 } 398 399 // Force receivers of this broadcast intent to run at foreground priority because we 400 // want to finish processing the broadcast intent as soon as possible. 401 broadcastIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND 402 | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); 403 Log.v(this, "Broadcasting intent: %s.", broadcastIntent); 404 405 checkAndCopyProviderExtras(originalCallIntent, broadcastIntent); 406 407 final BroadcastOptions options = BroadcastOptions.makeBasic(); 408 options.setBackgroundActivityStartsAllowed(true); 409 mContext.sendOrderedBroadcastAsUser( 410 broadcastIntent, 411 targetUser, 412 android.Manifest.permission.PROCESS_OUTGOING_CALLS, 413 AppOpsManager.OP_PROCESS_OUTGOING_CALLS, 414 options.toBundle(), 415 receiverRequired ? new NewOutgoingCallBroadcastIntentReceiver() : null, 416 null, // scheduler 417 Activity.RESULT_OK, // initialCode 418 number, // initialData: initial value for the result data (number to be modified) 419 null); // initialExtras 420 } 421 422 /** 423 * Copy all the expected extras set when a 3rd party gateway provider is to be used, from the 424 * source intent to the destination one. 425 * 426 * @param src Intent which may contain the provider's extras. 427 * @param dst Intent where a copy of the extras will be added if applicable. 428 */ checkAndCopyProviderExtras(Intent src, Intent dst)429 public void checkAndCopyProviderExtras(Intent src, Intent dst) { 430 if (src == null) { 431 return; 432 } 433 if (hasGatewayProviderExtras(src)) { 434 dst.putExtra(EXTRA_GATEWAY_PROVIDER_PACKAGE, 435 src.getStringExtra(EXTRA_GATEWAY_PROVIDER_PACKAGE)); 436 dst.putExtra(EXTRA_GATEWAY_URI, 437 src.getStringExtra(EXTRA_GATEWAY_URI)); 438 Log.d(this, "Found and copied gateway provider extras to broadcast intent."); 439 return; 440 } 441 442 Log.d(this, "No provider extras found in call intent."); 443 } 444 445 /** 446 * Check if valid gateway provider information is stored as extras in the intent 447 * 448 * @param intent to check for 449 * @return true if the intent has all the gateway information extras needed. 450 */ hasGatewayProviderExtras(Intent intent)451 private boolean hasGatewayProviderExtras(Intent intent) { 452 final String name = intent.getStringExtra(EXTRA_GATEWAY_PROVIDER_PACKAGE); 453 final String uriString = intent.getStringExtra(EXTRA_GATEWAY_URI); 454 455 return !TextUtils.isEmpty(name) && !TextUtils.isEmpty(uriString); 456 } 457 getGatewayUriFromString(String gatewayUriString)458 private static Uri getGatewayUriFromString(String gatewayUriString) { 459 return TextUtils.isEmpty(gatewayUriString) ? null : Uri.parse(gatewayUriString); 460 } 461 462 /** 463 * Extracts gateway provider information from a provided intent.. 464 * 465 * @param intent to extract gateway provider information from. 466 * @param trueHandle The actual call handle that the user is trying to dial 467 * @return GatewayInfo object containing extracted gateway provider information as well as 468 * the actual handle the user is trying to dial. 469 */ getGateWayInfoFromIntent(Intent intent, Uri trueHandle)470 public static GatewayInfo getGateWayInfoFromIntent(Intent intent, Uri trueHandle) { 471 if (intent == null) { 472 return null; 473 } 474 475 // Check if gateway extras are present. 476 String gatewayPackageName = intent.getStringExtra(EXTRA_GATEWAY_PROVIDER_PACKAGE); 477 Uri gatewayUri = getGatewayUriFromString(intent.getStringExtra(EXTRA_GATEWAY_URI)); 478 if (!TextUtils.isEmpty(gatewayPackageName) && gatewayUri != null) { 479 return new GatewayInfo(gatewayPackageName, gatewayUri, trueHandle); 480 } 481 482 return null; 483 } 484 placeOutgoingCallImmediately(Call call, Uri handle, GatewayInfo gatewayInfo, boolean speakerphoneOn, int videoState)485 private void placeOutgoingCallImmediately(Call call, Uri handle, GatewayInfo gatewayInfo, 486 boolean speakerphoneOn, int videoState) { 487 Log.i(this, 488 "Placing call immediately instead of waiting for OutgoingCallBroadcastReceiver"); 489 // Since we are not going to go through "Outgoing call broadcast", make sure 490 // we mark it as ready. 491 mCall.setNewOutgoingCallIntentBroadcastIsDone(); 492 mCallsManager.placeOutgoingCall(call, handle, gatewayInfo, speakerphoneOn, videoState); 493 } 494 launchSystemDialer(Uri handle)495 private void launchSystemDialer(Uri handle) { 496 Intent systemDialerIntent = new Intent(); 497 systemDialerIntent.setComponent(mDefaultDialerCache.getDialtactsSystemDialerComponent()); 498 systemDialerIntent.setAction(Intent.ACTION_DIAL); 499 systemDialerIntent.setData(handle); 500 systemDialerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 501 Log.v(this, "calling startActivity for default dialer: %s", systemDialerIntent); 502 mContext.startActivityAsUser(systemDialerIntent, UserHandle.CURRENT); 503 } 504 505 /** 506 * Check whether or not this is an emergency number, in order to enforce the restriction 507 * that only the CALL_PRIVILEGED and CALL_EMERGENCY intents are allowed to make emergency 508 * calls. 509 * 510 * To prevent malicious 3rd party apps from making emergency calls by passing in an 511 * "invalid" number like "9111234" (that isn't technically an emergency number but might 512 * still result in an emergency call with some networks), we use 513 * isPotentialLocalEmergencyNumber instead of isLocalEmergencyNumber. 514 * 515 * @param number number to inspect in order to determine whether or not an emergency number 516 * is potentially being dialed 517 * @return True if the handle is potentially an emergency number. 518 */ isPotentialEmergencyNumber(String number)519 private boolean isPotentialEmergencyNumber(String number) { 520 Log.v(this, "Checking restrictions for number : %s", Log.pii(number)); 521 if (number == null) return false; 522 try { 523 return mContext.getSystemService(TelephonyManager.class).isPotentialEmergencyNumber( 524 number); 525 } catch (Exception e) { 526 Log.e(this, e, "isPotentialEmergencyNumber: Telephony threw an exception."); 527 return false; 528 } 529 } 530 531 /** 532 * Given a call intent and whether or not the number to dial is an emergency number, determine 533 * the appropriate call intent action. 534 * 535 * @param intent Intent to evaluate 536 * @param isPotentialEmergencyNumber Whether or not the number is potentially an emergency 537 * number. 538 * @return The appropriate action. 539 */ calculateCallIntentAction(Intent intent, boolean isPotentialEmergencyNumber)540 private String calculateCallIntentAction(Intent intent, boolean isPotentialEmergencyNumber) { 541 String action = intent.getAction(); 542 543 /* Change CALL_PRIVILEGED into CALL or CALL_EMERGENCY as needed. */ 544 if (Intent.ACTION_CALL_PRIVILEGED.equals(action)) { 545 if (isPotentialEmergencyNumber) { 546 Log.i(this, "ACTION_CALL_PRIVILEGED is used while the number is a potential" 547 + " emergency number. Using ACTION_CALL_EMERGENCY as an action instead."); 548 action = Intent.ACTION_CALL_EMERGENCY; 549 } else { 550 action = Intent.ACTION_CALL; 551 } 552 Log.v(this, " - updating action from CALL_PRIVILEGED to %s", action); 553 } 554 return action; 555 } 556 getDisconnectTimeoutFromApp(Bundle resultExtras, long defaultTimeout)557 private long getDisconnectTimeoutFromApp(Bundle resultExtras, long defaultTimeout) { 558 if (resultExtras != null) { 559 long disconnectTimeout = resultExtras.getLong( 560 TelecomManager.EXTRA_NEW_OUTGOING_CALL_CANCEL_TIMEOUT, defaultTimeout); 561 if (disconnectTimeout < 0) { 562 disconnectTimeout = 0; 563 } 564 return Math.min(disconnectTimeout, 565 Timeouts.getMaxNewOutgoingCallCancelMillis(mContext.getContentResolver())); 566 } else { 567 return defaultTimeout; 568 } 569 } 570 } 571