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