Home | History | Annotate | Download | only in telecom
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
      5  * in compliance with the License. You may obtain a copy of the License at
      6  *
      7  * http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the License
     10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
     11  * or implied. See the License for the specific language governing permissions and limitations under
     12  * the License.
     13  */
     14 
     15 package android.telecom;
     16 
     17 import android.annotation.SystemApi;
     18 import android.content.ComponentName;
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.net.Uri;
     22 import android.os.Bundle;
     23 import android.os.RemoteException;
     24 import android.os.ServiceManager;
     25 import android.telephony.TelephonyManager;
     26 import android.text.TextUtils;
     27 import android.util.Log;
     28 
     29 import com.android.internal.telecom.ITelecomService;
     30 
     31 import java.util.ArrayList;
     32 import java.util.Collections;
     33 import java.util.List;
     34 
     35 /**
     36  * Provides access to information about active calls and registration/call-management functionality.
     37  * Apps can use methods in this class to determine the current call state.
     38  * <p>
     39  * Apps do not instantiate this class directly; instead, they retrieve a reference to an instance
     40  * through {@link Context#getSystemService Context.getSystemService(Context.TELECOM_SERVICE)}.
     41  * <p>
     42  * Note that access to some telecom information is permission-protected. Your app cannot access the
     43  * protected information or gain access to protected functionality unless it has the appropriate
     44  * permissions declared in its manifest file. Where permissions apply, they are noted in the method
     45  * descriptions.
     46  */
     47 public class TelecomManager {
     48 
     49     /**
     50      * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call
     51      * UI by notifying the Telecom system that an incoming call exists for a specific call service
     52      * (see {@link android.telecom.ConnectionService}). Telecom reads the Intent extras to find
     53      * and bind to the appropriate {@link android.telecom.ConnectionService} which Telecom will
     54      * ultimately use to control and get information about the call.
     55      * <p>
     56      * Input: get*Extra field {@link #EXTRA_PHONE_ACCOUNT_HANDLE} contains the component name of the
     57      * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then
     58      * ask the connection service for more information about the call prior to showing any UI.
     59      */
     60     public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL";
     61 
     62     /**
     63      * Similar to {@link #ACTION_INCOMING_CALL}, but is used only by Telephony to add a new
     64      * sim-initiated MO call for carrier testing.
     65      * @hide
     66      */
     67     public static final String ACTION_NEW_UNKNOWN_CALL = "android.telecom.action.NEW_UNKNOWN_CALL";
     68 
     69     /**
     70      * An {@link android.content.Intent} action sent by the telecom framework to start a
     71      * configuration dialog for a registered {@link PhoneAccount}. There is no default dialog
     72      * and each app that registers a {@link PhoneAccount} should provide one if desired.
     73      * <p>
     74      * A user can access the list of enabled {@link android.telecom.PhoneAccount}s through the Phone
     75      * app's settings menu. For each entry, the settings app will add a click action. When
     76      * triggered, the click-action will start this intent along with the extra
     77      * {@link #EXTRA_PHONE_ACCOUNT_HANDLE} to indicate the {@link PhoneAccount} to configure. If the
     78      * {@link PhoneAccount} package does not register an {@link android.app.Activity} for this
     79      * intent, then it will not be sent.
     80      */
     81     public static final String ACTION_CONFIGURE_PHONE_ACCOUNT =
     82             "android.telecom.action.CONFIGURE_PHONE_ACCOUNT";
     83 
     84     /**
     85      * The {@link android.content.Intent} action used to show the call accessibility settings page.
     86      */
     87     public static final String ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS =
     88             "android.telecom.action.SHOW_CALL_ACCESSIBILITY_SETTINGS";
     89 
     90     /**
     91      * The {@link android.content.Intent} action used to show the call settings page.
     92      */
     93     public static final String ACTION_SHOW_CALL_SETTINGS =
     94             "android.telecom.action.SHOW_CALL_SETTINGS";
     95 
     96     /**
     97      * The {@link android.content.Intent} action used to show the respond via SMS settings page.
     98      */
     99     public static final String ACTION_SHOW_RESPOND_VIA_SMS_SETTINGS =
    100             "android.telecom.action.SHOW_RESPOND_VIA_SMS_SETTINGS";
    101 
    102     /**
    103      * The {@link android.content.Intent} action used to show the settings page used to configure
    104      * {@link PhoneAccount} preferences.
    105      */
    106     public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
    107             "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
    108 
    109     /**
    110      * The {@link android.content.Intent} action used indicate that a new phone account was
    111      * just registered.
    112      * @hide
    113      */
    114     @SystemApi
    115     public static final String ACTION_PHONE_ACCOUNT_REGISTERED =
    116             "android.telecom.action.PHONE_ACCOUNT_REGISTERED";
    117 
    118     /**
    119      * Activity action: Shows a dialog asking the user whether or not they want to replace the
    120      * current default Dialer with the one specified in
    121      * {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME}.
    122      *
    123      * Usage example:
    124      * <pre>
    125      * Intent intent = new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
    126      * intent.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
    127      *         getActivity().getPackageName());
    128      * startActivity(intent);
    129      * </pre>
    130      */
    131     public static final String ACTION_CHANGE_DEFAULT_DIALER =
    132             "android.telecom.action.CHANGE_DEFAULT_DIALER";
    133 
    134     /**
    135      * Broadcast intent action indicating that the current default dialer has changed.
    136      * The string extra {@link #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME} will contain the
    137      * name of the package that the default dialer was changed to.
    138      *
    139      * @see #EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME
    140      */
    141     public static final String ACTION_DEFAULT_DIALER_CHANGED =
    142             "android.telecom.action.DEFAULT_DIALER_CHANGED";
    143 
    144     /**
    145      * Extra value used to provide the package name for {@link #ACTION_CHANGE_DEFAULT_DIALER}.
    146      */
    147     public static final String EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME =
    148             "android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME";
    149 
    150     /**
    151      * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a boolean that
    152      * determines whether the speakerphone should be automatically turned on for an outgoing call.
    153      */
    154     public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE =
    155             "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
    156 
    157     /**
    158      * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that
    159      * determines the desired video state for an outgoing call.
    160      * Valid options:
    161      * {@link VideoProfile#STATE_AUDIO_ONLY},
    162      * {@link VideoProfile#STATE_BIDIRECTIONAL},
    163      * {@link VideoProfile#STATE_RX_ENABLED},
    164      * {@link VideoProfile#STATE_TX_ENABLED}.
    165      */
    166     public static final String EXTRA_START_CALL_WITH_VIDEO_STATE =
    167             "android.telecom.extra.START_CALL_WITH_VIDEO_STATE";
    168 
    169     /**
    170      * The extra used with an {@link android.content.Intent#ACTION_CALL} and
    171      * {@link android.content.Intent#ACTION_DIAL} {@code Intent} to specify a
    172      * {@link PhoneAccountHandle} to use when making the call.
    173      * <p class="note">
    174      * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
    175      */
    176     public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
    177             "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
    178 
    179     /**
    180      * Optional extra for {@link android.content.Intent#ACTION_CALL} containing a string call
    181      * subject which will be associated with an outgoing call.  Should only be specified if the
    182      * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
    183      */
    184     public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
    185 
    186     /**
    187      * The extra used by a {@link ConnectionService} to provide the handle of the caller that
    188      * has initiated a new incoming call.
    189      */
    190     public static final String EXTRA_INCOMING_CALL_ADDRESS =
    191             "android.telecom.extra.INCOMING_CALL_ADDRESS";
    192 
    193     /**
    194      * Optional extra for {@link #ACTION_INCOMING_CALL} containing a {@link Bundle} which contains
    195      * metadata about the call. This {@link Bundle} will be returned to the
    196      * {@link ConnectionService}.
    197      */
    198     public static final String EXTRA_INCOMING_CALL_EXTRAS =
    199             "android.telecom.extra.INCOMING_CALL_EXTRAS";
    200 
    201     /**
    202      * Optional extra for {@link android.content.Intent#ACTION_CALL} and
    203      * {@link android.content.Intent#ACTION_DIAL} {@code Intent} containing a {@link Bundle}
    204      * which contains metadata about the call. This {@link Bundle} will be saved into
    205      * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call.
    206      */
    207     public static final String EXTRA_OUTGOING_CALL_EXTRAS =
    208             "android.telecom.extra.OUTGOING_CALL_EXTRAS";
    209 
    210     /**
    211      * @hide
    212      */
    213     public static final String EXTRA_UNKNOWN_CALL_HANDLE =
    214             "android.telecom.extra.UNKNOWN_CALL_HANDLE";
    215 
    216     /**
    217      * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
    218      * containing the disconnect code.
    219      */
    220     public static final String EXTRA_CALL_DISCONNECT_CAUSE =
    221             "android.telecom.extra.CALL_DISCONNECT_CAUSE";
    222 
    223     /**
    224      * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
    225      * containing the disconnect message.
    226      */
    227     public static final String EXTRA_CALL_DISCONNECT_MESSAGE =
    228             "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
    229 
    230     /**
    231      * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
    232      * containing the component name of the associated connection service.
    233      * @hide
    234      */
    235     @SystemApi
    236     public static final String EXTRA_CONNECTION_SERVICE =
    237             "android.telecom.extra.CONNECTION_SERVICE";
    238 
    239     /**
    240      * An optional {@link android.content.Intent#ACTION_CALL} intent extra denoting the
    241      * package name of the app specifying an alternative gateway for the call.
    242      * The value is a string.
    243      *
    244      * (The following comment corresponds to the all GATEWAY_* extras)
    245      * An app which sends the {@link android.content.Intent#ACTION_CALL} intent can specify an
    246      * alternative address to dial which is different from the one specified and displayed to
    247      * the user. This alternative address is referred to as the gateway address.
    248      */
    249     public static final String GATEWAY_PROVIDER_PACKAGE =
    250             "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
    251 
    252     /**
    253      * An optional {@link android.content.Intent#ACTION_CALL} intent extra corresponding to the
    254      * original address to dial for the call. This is used when an alternative gateway address is
    255      * provided to recall the original address.
    256      * The value is a {@link android.net.Uri}.
    257      *
    258      * (See {@link #GATEWAY_PROVIDER_PACKAGE} for details)
    259      */
    260     public static final String GATEWAY_ORIGINAL_ADDRESS =
    261             "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
    262 
    263     /**
    264      * The number which the party on the other side of the line will see (and use to return the
    265      * call).
    266      * <p>
    267      * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
    268      * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
    269      * user's expected caller ID.
    270      */
    271     public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
    272 
    273     /**
    274      * A boolean meta-data value indicating whether an {@link InCallService} implements an
    275      * in-call user interface. Dialer implementations (see {@link #getDefaultDialerPackage()}) which
    276      * would also like to replace the in-call interface should set this meta-data to {@code true} in
    277      * the manifest registration of their {@link InCallService}.
    278      */
    279     public static final String METADATA_IN_CALL_SERVICE_UI = "android.telecom.IN_CALL_SERVICE_UI";
    280 
    281     /**
    282      * The dual tone multi-frequency signaling character sent to indicate the dialing system should
    283      * pause for a predefined period.
    284      */
    285     public static final char DTMF_CHARACTER_PAUSE = ',';
    286 
    287     /**
    288      * The dual-tone multi-frequency signaling character sent to indicate the dialing system should
    289      * wait for user confirmation before proceeding.
    290      */
    291     public static final char DTMF_CHARACTER_WAIT = ';';
    292 
    293     /**
    294      * TTY (teletypewriter) mode is off.
    295      *
    296      * @hide
    297      */
    298     public static final int TTY_MODE_OFF = 0;
    299 
    300     /**
    301      * TTY (teletypewriter) mode is on. The speaker is off and the microphone is muted. The user
    302      * will communicate with the remote party by sending and receiving text messages.
    303      *
    304      * @hide
    305      */
    306     public static final int TTY_MODE_FULL = 1;
    307 
    308     /**
    309      * TTY (teletypewriter) mode is in hearing carryover mode (HCO). The microphone is muted but the
    310      * speaker is on. The user will communicate with the remote party by sending text messages and
    311      * hearing an audible reply.
    312      *
    313      * @hide
    314      */
    315     public static final int TTY_MODE_HCO = 2;
    316 
    317     /**
    318      * TTY (teletypewriter) mode is in voice carryover mode (VCO). The speaker is off but the
    319      * microphone is still on. User will communicate with the remote party by speaking and receiving
    320      * text message replies.
    321      *
    322      * @hide
    323      */
    324     public static final int TTY_MODE_VCO = 3;
    325 
    326     /**
    327      * Broadcast intent action indicating that the current TTY mode has changed. An intent extra
    328      * provides this state as an int.
    329      *
    330      * @see #EXTRA_CURRENT_TTY_MODE
    331      * @hide
    332      */
    333     public static final String ACTION_CURRENT_TTY_MODE_CHANGED =
    334             "android.telecom.action.CURRENT_TTY_MODE_CHANGED";
    335 
    336     /**
    337      * The lookup key for an int that indicates the current TTY mode.
    338      * Valid modes are:
    339      * - {@link #TTY_MODE_OFF}
    340      * - {@link #TTY_MODE_FULL}
    341      * - {@link #TTY_MODE_HCO}
    342      * - {@link #TTY_MODE_VCO}
    343      *
    344      * @hide
    345      */
    346     public static final String EXTRA_CURRENT_TTY_MODE =
    347             "android.telecom.intent.extra.CURRENT_TTY_MODE";
    348 
    349     /**
    350      * Broadcast intent action indicating that the TTY preferred operating mode has changed. An
    351      * intent extra provides the new mode as an int.
    352      *
    353      * @see #EXTRA_TTY_PREFERRED_MODE
    354      * @hide
    355      */
    356     public static final String ACTION_TTY_PREFERRED_MODE_CHANGED =
    357             "android.telecom.action.TTY_PREFERRED_MODE_CHANGED";
    358 
    359     /**
    360      * The lookup key for an int that indicates preferred TTY mode. Valid modes are: -
    361      * {@link #TTY_MODE_OFF} - {@link #TTY_MODE_FULL} - {@link #TTY_MODE_HCO} -
    362      * {@link #TTY_MODE_VCO}
    363      *
    364      * @hide
    365      */
    366     public static final String EXTRA_TTY_PREFERRED_MODE =
    367             "android.telecom.intent.extra.TTY_PREFERRED";
    368 
    369     /**
    370      * The following 4 constants define how properties such as phone numbers and names are
    371      * displayed to the user.
    372      */
    373 
    374     /**
    375      * Indicates that the address or number of a call is allowed to be displayed for caller ID.
    376     */
    377     public static final int PRESENTATION_ALLOWED = 1;
    378 
    379     /**
    380      * Indicates that the address or number of a call is blocked by the other party.
    381      */
    382     public static final int PRESENTATION_RESTRICTED = 2;
    383 
    384     /**
    385      * Indicates that the address or number of a call is not specified or known by the carrier.
    386      */
    387     public static final int PRESENTATION_UNKNOWN = 3;
    388 
    389     /**
    390      * Indicates that the address or number of a call belongs to a pay phone.
    391      */
    392     public static final int PRESENTATION_PAYPHONE = 4;
    393 
    394     private static final String TAG = "TelecomManager";
    395 
    396     private final Context mContext;
    397 
    398     /**
    399      * @hide
    400      */
    401     public static TelecomManager from(Context context) {
    402         return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    403     }
    404 
    405     /**
    406      * @hide
    407      */
    408     public TelecomManager(Context context) {
    409         Context appContext = context.getApplicationContext();
    410         if (appContext != null) {
    411             mContext = appContext;
    412         } else {
    413             mContext = context;
    414         }
    415     }
    416 
    417     /**
    418      * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with
    419      * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the
    420      * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific
    421      * account returned depends on the following priorities:
    422      * <ul>
    423      * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will
    424      * be returned.
    425      * </li>
    426      * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it
    427      * will be returned.
    428      * </li>
    429      * </ul>
    430      * <p>
    431      * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}.
    432      *
    433      * @param uriScheme The URI scheme.
    434      * @return The {@link PhoneAccountHandle} corresponding to the account to be used.
    435      */
    436     public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) {
    437         try {
    438             if (isServiceConnected()) {
    439                 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
    440                         mContext.getOpPackageName());
    441             }
    442         } catch (RemoteException e) {
    443             Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
    444         }
    445         return null;
    446     }
    447 
    448     /**
    449      * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone
    450      * calls. This {@code PhoneAccount} will always be a member of the list which is returned from
    451      * calling {@link #getCallCapablePhoneAccounts()}
    452      * <p>
    453      * Apps must be prepared for this method to return {@code null}, indicating that there currently
    454      * exists no user-chosen default {@code PhoneAccount}.
    455      *
    456      * @return The user outgoing phone account selected by the user.
    457      * @hide
    458      */
    459     public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() {
    460         try {
    461             if (isServiceConnected()) {
    462                 return getTelecomService().getUserSelectedOutgoingPhoneAccount();
    463             }
    464         } catch (RemoteException e) {
    465             Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e);
    466         }
    467         return null;
    468     }
    469 
    470     /**
    471      * Sets the user-chosen default for making outgoing phone calls.
    472      * @hide
    473      */
    474     public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) {
    475         try {
    476             if (isServiceConnected()) {
    477                 getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle);
    478             }
    479         } catch (RemoteException e) {
    480             Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount");
    481         }
    482     }
    483 
    484     /**
    485      * Returns the current SIM call manager. Apps must be prepared for this method to return
    486      * {@code null}, indicating that there currently exists no user-chosen default
    487      * {@code PhoneAccount}.
    488      *
    489      * @return The phone account handle of the current sim call manager.
    490      */
    491     public PhoneAccountHandle getSimCallManager() {
    492         try {
    493             if (isServiceConnected()) {
    494                 return getTelecomService().getSimCallManager();
    495             }
    496         } catch (RemoteException e) {
    497             Log.e(TAG, "Error calling ITelecomService#getSimCallManager");
    498         }
    499         return null;
    500     }
    501 
    502     /**
    503      * Returns the current SIM call manager for the specified user. Apps must be prepared for this
    504      * method to return {@code null}, indicating that there currently exists no user-chosen default
    505      * {@code PhoneAccount}.
    506      *
    507      * @return The phone account handle of the current sim call manager.
    508      *
    509      * @hide
    510      */
    511     public PhoneAccountHandle getSimCallManager(int userId) {
    512         try {
    513             if (isServiceConnected()) {
    514                 return getTelecomService().getSimCallManagerForUser(userId);
    515             }
    516         } catch (RemoteException e) {
    517             Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser");
    518         }
    519         return null;
    520     }
    521 
    522     /**
    523      * Returns the current connection manager. Apps must be prepared for this method to return
    524      * {@code null}, indicating that there currently exists no user-chosen default
    525      * {@code PhoneAccount}.
    526      *
    527      * @return The phone account handle of the current connection manager.
    528      * @hide
    529      */
    530     @SystemApi
    531     public PhoneAccountHandle getConnectionManager() {
    532         return getSimCallManager();
    533     }
    534 
    535     /**
    536      * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone
    537      * calls which support the specified URI scheme.
    538      * <P>
    539      * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which
    540      * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}).  Invoking with
    541      * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs
    542      * such as {@code sip:example (at) sipexample.com}).
    543      *
    544      * @param uriScheme The URI scheme.
    545      * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme.
    546      * @hide
    547      */
    548     @SystemApi
    549     public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) {
    550         try {
    551             if (isServiceConnected()) {
    552                 return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme,
    553                         mContext.getOpPackageName());
    554             }
    555         } catch (RemoteException e) {
    556             Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e);
    557         }
    558         return new ArrayList<>();
    559     }
    560 
    561 
    562     /**
    563      * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone
    564      * calls. The returned list includes only those accounts which have been explicitly enabled
    565      * by the user.
    566      *
    567      * @see #EXTRA_PHONE_ACCOUNT_HANDLE
    568      * @return A list of {@code PhoneAccountHandle} objects.
    569      */
    570     public List<PhoneAccountHandle> getCallCapablePhoneAccounts() {
    571         return getCallCapablePhoneAccounts(false);
    572     }
    573 
    574     /**
    575      * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled
    576      * by the user.
    577      *
    578      * @return A list of {@code PhoneAccountHandle} objects.
    579      * @hide
    580      */
    581     public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) {
    582         try {
    583             if (isServiceConnected()) {
    584                 return getTelecomService().getCallCapablePhoneAccounts(
    585                         includeDisabledAccounts, mContext.getOpPackageName());
    586             }
    587         } catch (RemoteException e) {
    588             Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
    589                     includeDisabledAccounts + ")", e);
    590         }
    591         return new ArrayList<>();
    592     }
    593 
    594     /**
    595      *  Returns a list of all {@link PhoneAccount}s registered for the calling package.
    596      *
    597      * @return A list of {@code PhoneAccountHandle} objects.
    598      * @hide
    599      */
    600     @SystemApi
    601     public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
    602         try {
    603             if (isServiceConnected()) {
    604                 return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName());
    605             }
    606         } catch (RemoteException e) {
    607             Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e);
    608         }
    609         return null;
    610     }
    611 
    612     /**
    613      * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes
    614      * resources which can be used in a user interface.
    615      *
    616      * @param account The {@link PhoneAccountHandle}.
    617      * @return The {@link PhoneAccount} object.
    618      */
    619     public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
    620         try {
    621             if (isServiceConnected()) {
    622                 return getTelecomService().getPhoneAccount(account);
    623             }
    624         } catch (RemoteException e) {
    625             Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e);
    626         }
    627         return null;
    628     }
    629 
    630     /**
    631      * Returns a count of all {@link PhoneAccount}s.
    632      *
    633      * @return The count of {@link PhoneAccount}s.
    634      * @hide
    635      */
    636     @SystemApi
    637     public int getAllPhoneAccountsCount() {
    638         try {
    639             if (isServiceConnected()) {
    640                 return getTelecomService().getAllPhoneAccountsCount();
    641             }
    642         } catch (RemoteException e) {
    643             Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e);
    644         }
    645         return 0;
    646     }
    647 
    648     /**
    649      * Returns a list of all {@link PhoneAccount}s.
    650      *
    651      * @return All {@link PhoneAccount}s.
    652      * @hide
    653      */
    654     @SystemApi
    655     public List<PhoneAccount> getAllPhoneAccounts() {
    656         try {
    657             if (isServiceConnected()) {
    658                 return getTelecomService().getAllPhoneAccounts();
    659             }
    660         } catch (RemoteException e) {
    661             Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e);
    662         }
    663         return Collections.EMPTY_LIST;
    664     }
    665 
    666     /**
    667      * Returns a list of all {@link PhoneAccountHandle}s.
    668      *
    669      * @return All {@link PhoneAccountHandle}s.
    670      * @hide
    671      */
    672     @SystemApi
    673     public List<PhoneAccountHandle> getAllPhoneAccountHandles() {
    674         try {
    675             if (isServiceConnected()) {
    676                 return getTelecomService().getAllPhoneAccountHandles();
    677             }
    678         } catch (RemoteException e) {
    679             Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e);
    680         }
    681         return Collections.EMPTY_LIST;
    682     }
    683 
    684     /**
    685      * Register a {@link PhoneAccount} for use by the system. When registering
    686      * {@link PhoneAccount}s, existing registrations will be overwritten if the
    687      * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already
    688      * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option
    689      * when placing calls. The user may still need to enable the {@link PhoneAccount} within
    690      * the phone app settings before the account is usable.
    691      * <p>
    692      * A {@link SecurityException} will be thrown if an app tries to register a
    693      * {@link PhoneAccountHandle} where the package name specified within
    694      * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app.
    695      *
    696      * @param account The complete {@link PhoneAccount}.
    697      */
    698     public void registerPhoneAccount(PhoneAccount account) {
    699         try {
    700             if (isServiceConnected()) {
    701                 getTelecomService().registerPhoneAccount(account);
    702             }
    703         } catch (RemoteException e) {
    704             Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e);
    705         }
    706     }
    707 
    708     /**
    709      * Remove a {@link PhoneAccount} registration from the system.
    710      *
    711      * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
    712      */
    713     public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
    714         try {
    715             if (isServiceConnected()) {
    716                 getTelecomService().unregisterPhoneAccount(accountHandle);
    717             }
    718         } catch (RemoteException e) {
    719             Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e);
    720         }
    721     }
    722 
    723     /**
    724      * Remove all Accounts that belong to the calling package from the system.
    725      * @hide
    726      */
    727     @SystemApi
    728     public void clearPhoneAccounts() {
    729         clearAccounts();
    730     }
    731     /**
    732      * Remove all Accounts that belong to the calling package from the system.
    733      * @deprecated Use {@link #clearPhoneAccounts()} instead.
    734      * @hide
    735      */
    736     @SystemApi
    737     public void clearAccounts() {
    738         try {
    739             if (isServiceConnected()) {
    740                 getTelecomService().clearAccounts(mContext.getPackageName());
    741             }
    742         } catch (RemoteException e) {
    743             Log.e(TAG, "Error calling ITelecomService#clearAccounts", e);
    744         }
    745     }
    746 
    747     /**
    748      * Remove all Accounts that belong to the specified package from the system.
    749      * @hide
    750      */
    751     public void clearAccountsForPackage(String packageName) {
    752         try {
    753             if (isServiceConnected() && !TextUtils.isEmpty(packageName)) {
    754                 getTelecomService().clearAccounts(packageName);
    755             }
    756         } catch (RemoteException e) {
    757             Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e);
    758         }
    759     }
    760 
    761 
    762     /**
    763      * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access
    764      *         the default dialer's package name instead.
    765      * @hide
    766      */
    767     @SystemApi
    768     public ComponentName getDefaultPhoneApp() {
    769         try {
    770             if (isServiceConnected()) {
    771                 return getTelecomService().getDefaultPhoneApp();
    772             }
    773         } catch (RemoteException e) {
    774             Log.e(TAG, "RemoteException attempting to get the default phone app.", e);
    775         }
    776         return null;
    777     }
    778 
    779     /**
    780      * Used to determine the currently selected default dialer package.
    781      *
    782      * @return package name for the default dialer package or null if no package has been
    783      *         selected as the default dialer.
    784      */
    785     public String getDefaultDialerPackage() {
    786         try {
    787             if (isServiceConnected()) {
    788                 return getTelecomService().getDefaultDialerPackage();
    789             }
    790         } catch (RemoteException e) {
    791             Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e);
    792         }
    793         return null;
    794     }
    795 
    796     /**
    797      * Used to set the default dialer package.
    798      *
    799      * @param packageName to set the default dialer to..
    800      *
    801      * @result {@code true} if the default dialer was successfully changed, {@code false} if
    802      *         the specified package does not correspond to an installed dialer, or is already
    803      *         the default dialer.
    804      *
    805      * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE}
    806      * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}
    807      *
    808      * @hide
    809      */
    810     public boolean setDefaultDialer(String packageName) {
    811         try {
    812             if (isServiceConnected()) {
    813                 return getTelecomService().setDefaultDialer(packageName);
    814             }
    815         } catch (RemoteException e) {
    816             Log.e(TAG, "RemoteException attempting to set the default dialer.", e);
    817         }
    818         return false;
    819     }
    820 
    821     /**
    822      * Used to determine the dialer package that is preloaded on the system partition.
    823      *
    824      * @return package name for the system dialer package or null if no system dialer is preloaded.
    825      * @hide
    826      */
    827     public String getSystemDialerPackage() {
    828         try {
    829             if (isServiceConnected()) {
    830                 return getTelecomService().getSystemDialerPackage();
    831             }
    832         } catch (RemoteException e) {
    833             Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e);
    834         }
    835         return null;
    836     }
    837 
    838     /**
    839      * Return whether a given phone number is the configured voicemail number for a
    840      * particular phone account.
    841      *
    842      * @param accountHandle The handle for the account to check the voicemail number against
    843      * @param number The number to look up.
    844      */
    845     public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) {
    846         try {
    847             if (isServiceConnected()) {
    848                 return getTelecomService().isVoiceMailNumber(accountHandle, number,
    849                         mContext.getOpPackageName());
    850             }
    851         } catch (RemoteException e) {
    852             Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
    853         }
    854         return false;
    855     }
    856 
    857     /**
    858      * Return the voicemail number for a given phone account.
    859      *
    860      * @param accountHandle The handle for the phone account.
    861      * @return The voicemail number for the phone account, and {@code null} if one has not been
    862      *         configured.
    863      */
    864     public String getVoiceMailNumber(PhoneAccountHandle accountHandle) {
    865         try {
    866             if (isServiceConnected()) {
    867                 return getTelecomService().getVoiceMailNumber(accountHandle,
    868                         mContext.getOpPackageName());
    869             }
    870         } catch (RemoteException e) {
    871             Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
    872         }
    873         return null;
    874     }
    875 
    876     /**
    877      * Return the line 1 phone number for given phone account.
    878      *
    879      * @param accountHandle The handle for the account retrieve a number for.
    880      * @return A string representation of the line 1 phone number.
    881      */
    882     public String getLine1Number(PhoneAccountHandle accountHandle) {
    883         try {
    884             if (isServiceConnected()) {
    885                 return getTelecomService().getLine1Number(accountHandle,
    886                         mContext.getOpPackageName());
    887             }
    888         } catch (RemoteException e) {
    889             Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
    890         }
    891         return null;
    892     }
    893 
    894     /**
    895      * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding
    896      * states).
    897      * <p>
    898      * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE}
    899      * </p>
    900      */
    901     public boolean isInCall() {
    902         try {
    903             if (isServiceConnected()) {
    904                 return getTelecomService().isInCall(mContext.getOpPackageName());
    905             }
    906         } catch (RemoteException e) {
    907             Log.e(TAG, "RemoteException calling isInCall().", e);
    908         }
    909         return false;
    910     }
    911 
    912     /**
    913      * Returns one of the following constants that represents the current state of Telecom:
    914      *
    915      * {@link TelephonyManager#CALL_STATE_RINGING}
    916      * {@link TelephonyManager#CALL_STATE_OFFHOOK}
    917      * {@link TelephonyManager#CALL_STATE_IDLE}
    918      *
    919      * Note that this API does not require the
    920      * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to
    921      * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require
    922      * the permission.
    923      * @hide
    924      */
    925     @SystemApi
    926     public int getCallState() {
    927         try {
    928             if (isServiceConnected()) {
    929                 return getTelecomService().getCallState();
    930             }
    931         } catch (RemoteException e) {
    932             Log.d(TAG, "RemoteException calling getCallState().", e);
    933         }
    934         return TelephonyManager.CALL_STATE_IDLE;
    935     }
    936 
    937     /**
    938      * Returns whether there currently exists is a ringing incoming-call.
    939      *
    940      * @hide
    941      */
    942     @SystemApi
    943     public boolean isRinging() {
    944         try {
    945             if (isServiceConnected()) {
    946                 return getTelecomService().isRinging(mContext.getOpPackageName());
    947             }
    948         } catch (RemoteException e) {
    949             Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e);
    950         }
    951         return false;
    952     }
    953 
    954     /**
    955      * Ends an ongoing call.
    956      * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this
    957      * method (clockwork & gearhead).
    958      * @hide
    959      */
    960     @SystemApi
    961     public boolean endCall() {
    962         try {
    963             if (isServiceConnected()) {
    964                 return getTelecomService().endCall();
    965             }
    966         } catch (RemoteException e) {
    967             Log.e(TAG, "Error calling ITelecomService#endCall", e);
    968         }
    969         return false;
    970     }
    971 
    972     /**
    973      * If there is a ringing incoming call, this method accepts the call on behalf of the user.
    974      * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use
    975      * this method (clockwork & gearhead).
    976      *
    977      * @hide
    978      */
    979     @SystemApi
    980     public void acceptRingingCall() {
    981         try {
    982             if (isServiceConnected()) {
    983                 getTelecomService().acceptRingingCall();
    984             }
    985         } catch (RemoteException e) {
    986             Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e);
    987         }
    988     }
    989 
    990     /**
    991      * Silences the ringer if a ringing call exists.
    992      */
    993     public void silenceRinger() {
    994         try {
    995             if (isServiceConnected()) {
    996                 getTelecomService().silenceRinger(mContext.getOpPackageName());
    997             }
    998         } catch (RemoteException e) {
    999             Log.e(TAG, "Error calling ITelecomService#silenceRinger", e);
   1000         }
   1001     }
   1002 
   1003     /**
   1004      * Returns whether TTY is supported on this device.
   1005      *
   1006      * @hide
   1007      */
   1008     @SystemApi
   1009     public boolean isTtySupported() {
   1010         try {
   1011             if (isServiceConnected()) {
   1012                 return getTelecomService().isTtySupported(mContext.getOpPackageName());
   1013             }
   1014         } catch (RemoteException e) {
   1015             Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
   1016         }
   1017         return false;
   1018     }
   1019 
   1020     /**
   1021      * Returns the current TTY mode of the device. For TTY to be on the user must enable it in
   1022      * settings and have a wired headset plugged in.
   1023      * Valid modes are:
   1024      * - {@link TelecomManager#TTY_MODE_OFF}
   1025      * - {@link TelecomManager#TTY_MODE_FULL}
   1026      * - {@link TelecomManager#TTY_MODE_HCO}
   1027      * - {@link TelecomManager#TTY_MODE_VCO}
   1028      * @hide
   1029      */
   1030     public int getCurrentTtyMode() {
   1031         try {
   1032             if (isServiceConnected()) {
   1033                 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName());
   1034             }
   1035         } catch (RemoteException e) {
   1036             Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
   1037         }
   1038         return TTY_MODE_OFF;
   1039     }
   1040 
   1041     /**
   1042      * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it
   1043      * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered
   1044      * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind
   1045      * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request
   1046      * additional information about the call (See
   1047      * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI.
   1048      *
   1049      * @param phoneAccount A {@link PhoneAccountHandle} registered with
   1050      *            {@link #registerPhoneAccount}.
   1051      * @param extras A bundle that will be passed through to
   1052      *            {@link ConnectionService#onCreateIncomingConnection}.
   1053      */
   1054     public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
   1055         try {
   1056             if (isServiceConnected()) {
   1057                 getTelecomService().addNewIncomingCall(
   1058                         phoneAccount, extras == null ? new Bundle() : extras);
   1059             }
   1060         } catch (RemoteException e) {
   1061             Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e);
   1062         }
   1063     }
   1064 
   1065     /**
   1066      * Registers a new unknown call with Telecom. This can only be called by the system Telephony
   1067      * service. This is invoked when Telephony detects a new unknown connection that was neither
   1068      * a new incoming call, nor an user-initiated outgoing call.
   1069      *
   1070      * @param phoneAccount A {@link PhoneAccountHandle} registered with
   1071      *            {@link #registerPhoneAccount}.
   1072      * @param extras A bundle that will be passed through to
   1073      *            {@link ConnectionService#onCreateIncomingConnection}.
   1074      * @hide
   1075      */
   1076     @SystemApi
   1077     public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) {
   1078         try {
   1079             if (isServiceConnected()) {
   1080                 getTelecomService().addNewUnknownCall(
   1081                         phoneAccount, extras == null ? new Bundle() : extras);
   1082             }
   1083         } catch (RemoteException e) {
   1084             Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e);
   1085         }
   1086     }
   1087 
   1088     /**
   1089      * Processes the specified dial string as an MMI code.
   1090      * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
   1091      * Some of these sequences launch special behavior through handled by Telephony.
   1092      * This method uses the default subscription.
   1093      * <p>
   1094      * Requires that the method-caller be set as the system dialer app.
   1095      * </p>
   1096      *
   1097      * @param dialString The digits to dial.
   1098      * @return True if the digits were processed as an MMI code, false otherwise.
   1099      */
   1100     public boolean handleMmi(String dialString) {
   1101         ITelecomService service = getTelecomService();
   1102         if (service != null) {
   1103             try {
   1104                 return service.handlePinMmi(dialString, mContext.getOpPackageName());
   1105             } catch (RemoteException e) {
   1106                 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
   1107             }
   1108         }
   1109         return false;
   1110     }
   1111 
   1112     /**
   1113      * Processes the specified dial string as an MMI code.
   1114      * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#".
   1115      * Some of these sequences launch special behavior through handled by Telephony.
   1116      * <p>
   1117      * Requires that the method-caller be set as the system dialer app.
   1118      * </p>
   1119      *
   1120      * @param accountHandle The handle for the account the MMI code should apply to.
   1121      * @param dialString The digits to dial.
   1122      * @return True if the digits were processed as an MMI code, false otherwise.
   1123      */
   1124     public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) {
   1125         ITelecomService service = getTelecomService();
   1126         if (service != null) {
   1127             try {
   1128                 return service.handlePinMmiForPhoneAccount(accountHandle, dialString,
   1129                         mContext.getOpPackageName());
   1130             } catch (RemoteException e) {
   1131                 Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e);
   1132             }
   1133         }
   1134         return false;
   1135     }
   1136 
   1137     /**
   1138      * @param accountHandle The handle for the account to derive an adn query URI for or
   1139      * {@code null} to return a URI which will use the default account.
   1140      * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount}
   1141      * for the the content retrieve.
   1142      */
   1143     public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) {
   1144         ITelecomService service = getTelecomService();
   1145         if (service != null && accountHandle != null) {
   1146             try {
   1147                 return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName());
   1148             } catch (RemoteException e) {
   1149                 Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e);
   1150             }
   1151         }
   1152         return Uri.parse("content://icc/adn");
   1153     }
   1154 
   1155     /**
   1156      * Removes the missed-call notification if one is present.
   1157      * <p>
   1158      * Requires that the method-caller be set as the system dialer app.
   1159      * </p>
   1160      */
   1161     public void cancelMissedCallsNotification() {
   1162         ITelecomService service = getTelecomService();
   1163         if (service != null) {
   1164             try {
   1165                 service.cancelMissedCallsNotification(mContext.getOpPackageName());
   1166             } catch (RemoteException e) {
   1167                 Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e);
   1168             }
   1169         }
   1170     }
   1171 
   1172     /**
   1173      * Brings the in-call screen to the foreground if there is an ongoing call. If there is
   1174      * currently no ongoing call, then this method does nothing.
   1175      * <p>
   1176      * Requires that the method-caller be set as the system dialer app or have the
   1177      * {@link android.Manifest.permission#READ_PHONE_STATE} permission.
   1178      * </p>
   1179      *
   1180      * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen.
   1181      */
   1182     public void showInCallScreen(boolean showDialpad) {
   1183         ITelecomService service = getTelecomService();
   1184         if (service != null) {
   1185             try {
   1186                 service.showInCallScreen(showDialpad, mContext.getOpPackageName());
   1187             } catch (RemoteException e) {
   1188                 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
   1189             }
   1190         }
   1191     }
   1192 
   1193     /**
   1194      * Places a new outgoing call to the provided address using the system telecom service with
   1195      * the specified extras.
   1196      *
   1197      * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL},
   1198      * except that the outgoing call will always be sent via the system telecom service. If
   1199      * method-caller is either the user selected default dialer app or preloaded system dialer
   1200      * app, then emergency calls will also be allowed.
   1201      *
   1202      * Requires permission: {@link android.Manifest.permission#CALL_PHONE}
   1203      *
   1204      * Usage example:
   1205      * <pre>
   1206      * Uri uri = Uri.fromParts("tel", "12345", null);
   1207      * Bundle extras = new Bundle();
   1208      * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
   1209      * telecomManager.placeCall(uri, extras);
   1210      * </pre>
   1211      *
   1212      * The following keys are supported in the supplied extras.
   1213      * <ul>
   1214      *   <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li>
   1215      *   <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li>
   1216      *   <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li>
   1217      *   <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li>
   1218      * </ul>
   1219      *
   1220      * @param address The address to make the call to.
   1221      * @param extras Bundle of extras to use with the call.
   1222      */
   1223     public void placeCall(Uri address, Bundle extras) {
   1224         ITelecomService service = getTelecomService();
   1225         if (service != null) {
   1226             if (address == null) {
   1227                 Log.w(TAG, "Cannot place call to empty address.");
   1228             }
   1229             try {
   1230                 service.placeCall(address, extras == null ? new Bundle() : extras,
   1231                         mContext.getOpPackageName());
   1232             } catch (RemoteException e) {
   1233                 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
   1234             }
   1235         }
   1236     }
   1237 
   1238     /**
   1239      * Enables and disables specified phone account.
   1240      *
   1241      * @param handle Handle to the phone account.
   1242      * @param isEnabled Enable state of the phone account.
   1243      * @hide
   1244      */
   1245     @SystemApi
   1246     public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) {
   1247         ITelecomService service = getTelecomService();
   1248         if (service != null) {
   1249             try {
   1250                 service.enablePhoneAccount(handle, isEnabled);
   1251             } catch (RemoteException e) {
   1252                 Log.e(TAG, "Error enablePhoneAbbount", e);
   1253             }
   1254         }
   1255     }
   1256 
   1257     private ITelecomService getTelecomService() {
   1258         return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE));
   1259     }
   1260 
   1261     private boolean isServiceConnected() {
   1262         boolean isConnected = getTelecomService() != null;
   1263         if (!isConnected) {
   1264             Log.w(TAG, "Telecom Service not found.");
   1265         }
   1266         return isConnected;
   1267     }
   1268 }
   1269