Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 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 |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 6 | * |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 8 | * |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 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. |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 15 | package android.telecom; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 16 | |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 17 | import android.annotation.SystemApi; |
| 18 | import android.content.ComponentName; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Yorke Lee | 3e56ba1 | 2015-04-23 12:32:36 -0700 | [diff] [blame] | 20 | import android.content.Intent; |
Nancy Chen | b2299c1 | 2014-10-29 18:22:11 -0700 | [diff] [blame] | 21 | import android.net.Uri; |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 23 | import android.os.RemoteException; |
| 24 | import android.os.ServiceManager; |
Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 25 | import android.telephony.TelephonyManager; |
Anthony Lee | 6727926 | 2014-10-27 11:28:40 -0700 | [diff] [blame] | 26 | import android.text.TextUtils; |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 27 | import android.util.Log; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 28 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 29 | import com.android.internal.telecom.ITelecomService; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 30 | |
Jay Shrauner | 7746a94 | 2014-08-26 12:15:15 -0700 | [diff] [blame] | 31 | import java.util.ArrayList; |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 32 | import java.util.Collections; |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 33 | import java.util.List; |
| 34 | |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 35 | /** |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 36 | * Provides access to information about active calls and registration/call-management functionality. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 37 | * Apps can use methods in this class to determine the current call state. |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 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. |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 46 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 47 | public class TelecomManager { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 48 | |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 49 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 50 | * Activity action: Starts the UI for handing an incoming call. This intent starts the in-call |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 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 |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 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 |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 57 | * {@link android.telecom.ConnectionService} that Telecom should bind to. Telecom will then |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 58 | * ask the connection service for more information about the call prior to showing any UI. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 59 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 60 | public static final String ACTION_INCOMING_CALL = "android.telecom.action.INCOMING_CALL"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 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 | /** |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 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. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 80 | */ |
Santos Cordon | 895d4b8 | 2015-06-25 16:41:48 -0700 | [diff] [blame] | 81 | public static final String ACTION_CONFIGURE_PHONE_ACCOUNT = |
| 82 | "android.telecom.action.CONFIGURE_PHONE_ACCOUNT"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Andrew Lee | 873cfbf | 2015-02-26 15:22:00 -0800 | [diff] [blame] | 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 | /** |
Yorke Lee | 3818a89 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 91 | * The {@link android.content.Intent} action used to show the call settings page. |
| 92 | */ |
| 93 | public static final String ACTION_SHOW_CALL_SETTINGS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 94 | "android.telecom.action.SHOW_CALL_SETTINGS"; |
Yorke Lee | 3818a89 | 2014-07-21 15:57:17 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
Andrew Lee | 866080f | 2015-02-19 12:05:33 -0800 | [diff] [blame] | 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 | /** |
Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 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 = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 107 | "android.telecom.action.CHANGE_PHONE_ACCOUNTS"; |
Evan Charlton | 6d8604f | 2014-09-04 12:38:17 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Santos Cordon | c66f3ba | 2015-02-27 15:22:07 -0800 | [diff] [blame] | 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 | /** |
Yorke Lee | 1011f48 | 2015-04-23 15:58:27 -0700 | [diff] [blame] | 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 | /** |
Yorke Lee | 107c4ce | 2015-06-15 12:08:24 -0700 | [diff] [blame] | 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 | /** |
Yorke Lee | 1011f48 | 2015-04-23 15:58:27 -0700 | [diff] [blame] | 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 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 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. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 153 | */ |
| 154 | public static final String EXTRA_START_CALL_WITH_SPEAKERPHONE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 155 | "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 158 | * Optional extra for {@link android.content.Intent#ACTION_CALL} containing an integer that |
| 159 | * determines the desired video state for an outgoing call. |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 160 | * Valid options: |
Yorke Lee | 32f2473 | 2015-05-12 16:18:03 -0700 | [diff] [blame] | 161 | * {@link VideoProfile#STATE_AUDIO_ONLY}, |
| 162 | * {@link VideoProfile#STATE_BIDIRECTIONAL}, |
| 163 | * {@link VideoProfile#STATE_RX_ENABLED}, |
| 164 | * {@link VideoProfile#STATE_TX_ENABLED}. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 165 | */ |
| 166 | public static final String EXTRA_START_CALL_WITH_VIDEO_STATE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 167 | "android.telecom.extra.START_CALL_WITH_VIDEO_STATE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 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. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 173 | * <p class="note"> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 174 | * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 175 | */ |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 176 | public static final String EXTRA_PHONE_ACCOUNT_HANDLE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 177 | "android.telecom.extra.PHONE_ACCOUNT_HANDLE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
Tyler Gunn | 335ff2e | 2015-07-30 14:18:33 -0700 | [diff] [blame] | 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 | /** |
Yorke Lee | 04ea7d3 | 2015-06-05 15:59:18 -0700 | [diff] [blame] | 187 | * The extra used by a {@link ConnectionService} to provide the handle of the caller that |
| 188 | * has initiated a new incoming call. |
| 189 | */ |
Yorke Lee | 02fb5bc | 2015-06-09 12:27:36 -0700 | [diff] [blame] | 190 | public static final String EXTRA_INCOMING_CALL_ADDRESS = |
| 191 | "android.telecom.extra.INCOMING_CALL_ADDRESS"; |
Yorke Lee | 04ea7d3 | 2015-06-05 15:59:18 -0700 | [diff] [blame] | 192 | |
| 193 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 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}. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 197 | */ |
| 198 | public static final String EXTRA_INCOMING_CALL_EXTRAS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 199 | "android.telecom.extra.INCOMING_CALL_EXTRAS"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 200 | |
| 201 | /** |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 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 |
Santos Cordon | 7a060d5 | 2015-06-19 14:52:04 -0700 | [diff] [blame] | 205 | * {@code Call.Details} and passed to the {@link ConnectionService} when placing the call. |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 206 | */ |
| 207 | public static final String EXTRA_OUTGOING_CALL_EXTRAS = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 208 | "android.telecom.extra.OUTGOING_CALL_EXTRAS"; |
Nancy Chen | 10798dc | 2014-08-08 14:00:25 -0700 | [diff] [blame] | 209 | |
| 210 | /** |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 211 | * @hide |
| 212 | */ |
| 213 | public static final String EXTRA_UNKNOWN_CALL_HANDLE = |
| 214 | "android.telecom.extra.UNKNOWN_CALL_HANDLE"; |
| 215 | |
| 216 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 217 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 218 | * containing the disconnect code. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 219 | */ |
| 220 | public static final String EXTRA_CALL_DISCONNECT_CAUSE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 221 | "android.telecom.extra.CALL_DISCONNECT_CAUSE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 222 | |
| 223 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 224 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 225 | * containing the disconnect message. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 226 | */ |
| 227 | public static final String EXTRA_CALL_DISCONNECT_MESSAGE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 228 | "android.telecom.extra.CALL_DISCONNECT_MESSAGE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 229 | |
| 230 | /** |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 231 | * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED} |
| 232 | * containing the component name of the associated connection service. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 233 | * @hide |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 234 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 235 | @SystemApi |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 236 | public static final String EXTRA_CONNECTION_SERVICE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 237 | "android.telecom.extra.CONNECTION_SERVICE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 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 = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 250 | "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE"; |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 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 = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 261 | "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS"; |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 262 | |
| 263 | /** |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 264 | * The number which the party on the other side of the line will see (and use to return the |
| 265 | * call). |
| 266 | * <p> |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 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. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 270 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 271 | public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 272 | |
| 273 | /** |
Santos Cordon | f2600eb | 2015-06-22 15:02:20 -0700 | [diff] [blame] | 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 | /** |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 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. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 329 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 330 | * @see #EXTRA_CURRENT_TTY_MODE |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 331 | * @hide |
| 332 | */ |
| 333 | public static final String ACTION_CURRENT_TTY_MODE_CHANGED = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 334 | "android.telecom.action.CURRENT_TTY_MODE_CHANGED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 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 = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 347 | "android.telecom.intent.extra.CURRENT_TTY_MODE"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 348 | |
| 349 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 350 | * Broadcast intent action indicating that the TTY preferred operating mode has changed. An |
| 351 | * intent extra provides the new mode as an int. |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 352 | * |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 353 | * @see #EXTRA_TTY_PREFERRED_MODE |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 354 | * @hide |
| 355 | */ |
| 356 | public static final String ACTION_TTY_PREFERRED_MODE_CHANGED = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 357 | "android.telecom.action.TTY_PREFERRED_MODE_CHANGED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 358 | |
| 359 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 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} |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 363 | * |
| 364 | * @hide |
| 365 | */ |
| 366 | public static final String EXTRA_TTY_PREFERRED_MODE = |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 367 | "android.telecom.intent.extra.TTY_PREFERRED"; |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 368 | |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 369 | /** |
Bryce Lee | 5e4dd3e | 2015-08-03 16:59:10 -0700 | [diff] [blame] | 370 | * Broadcast intent action for letting custom component know to show the missed call |
| 371 | * notification. |
| 372 | * @hide |
| 373 | */ |
| 374 | @SystemApi |
| 375 | public static final String ACTION_SHOW_MISSED_CALLS_NOTIFICATION = |
| 376 | "android.telecom.action.SHOW_MISSED_CALLS_NOTIFICATION"; |
| 377 | |
| 378 | /** |
| 379 | * The number of calls associated with the notification. |
| 380 | * @hide |
| 381 | */ |
| 382 | @SystemApi |
| 383 | public static final String EXTRA_NOTIFICATION_COUNT = |
| 384 | "android.telecom.extra.NOTIFICATION_COUNT"; |
| 385 | |
| 386 | /** |
| 387 | * The number associated with the missed calls. This number is only relevant |
| 388 | * when EXTRA_NOTIFICATION_COUNT is 1. |
| 389 | * @hide |
| 390 | */ |
| 391 | @SystemApi |
| 392 | public static final String EXTRA_NOTIFICATION_PHONE_NUMBER = |
| 393 | "android.telecom.extra.NOTIFICATION_PHONE_NUMBER"; |
| 394 | |
| 395 | /** |
Bryce Lee | 8d41d1d | 2015-08-10 07:40:42 -0700 | [diff] [blame^] | 396 | * The intent to clear missed calls. |
| 397 | * @hide |
| 398 | */ |
| 399 | @SystemApi |
| 400 | public static final String EXTRA_CLEAR_MISSED_CALLS_INTENT = |
| 401 | "android.telecom.extra.CLEAR_MISSED_CALLS_INTENT"; |
| 402 | |
| 403 | /** |
| 404 | * The intent to call back a missed call. |
| 405 | * @hide |
| 406 | */ |
| 407 | @SystemApi |
| 408 | public static final String EXTRA_CALL_BACK_INTENT = |
| 409 | "android.telecom.extra.CALL_BACK_INTENT"; |
| 410 | |
| 411 | /** |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 412 | * The following 4 constants define how properties such as phone numbers and names are |
| 413 | * displayed to the user. |
| 414 | */ |
| 415 | |
Santos Cordon | ed769ae | 2015-05-13 18:47:38 -0700 | [diff] [blame] | 416 | /** |
| 417 | * Indicates that the address or number of a call is allowed to be displayed for caller ID. |
| 418 | */ |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 419 | public static final int PRESENTATION_ALLOWED = 1; |
| 420 | |
Santos Cordon | ed769ae | 2015-05-13 18:47:38 -0700 | [diff] [blame] | 421 | /** |
| 422 | * Indicates that the address or number of a call is blocked by the other party. |
| 423 | */ |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 424 | public static final int PRESENTATION_RESTRICTED = 2; |
| 425 | |
Santos Cordon | ed769ae | 2015-05-13 18:47:38 -0700 | [diff] [blame] | 426 | /** |
| 427 | * Indicates that the address or number of a call is not specified or known by the carrier. |
| 428 | */ |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 429 | public static final int PRESENTATION_UNKNOWN = 3; |
| 430 | |
Santos Cordon | ed769ae | 2015-05-13 18:47:38 -0700 | [diff] [blame] | 431 | /** |
| 432 | * Indicates that the address or number of a call belongs to a pay phone. |
| 433 | */ |
Nancy Chen | 9d568c0 | 2014-09-08 14:17:59 -0700 | [diff] [blame] | 434 | public static final int PRESENTATION_PAYPHONE = 4; |
| 435 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 436 | private static final String TAG = "TelecomManager"; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 437 | |
| 438 | private final Context mContext; |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 439 | |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 440 | /** |
| 441 | * @hide |
| 442 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 443 | public static TelecomManager from(Context context) { |
| 444 | return (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); |
Yorke Lee | b4ce143 | 2014-06-09 13:53:23 -0700 | [diff] [blame] | 445 | } |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 446 | |
| 447 | /** |
| 448 | * @hide |
| 449 | */ |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 450 | public TelecomManager(Context context) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 451 | Context appContext = context.getApplicationContext(); |
| 452 | if (appContext != null) { |
| 453 | mContext = appContext; |
| 454 | } else { |
| 455 | mContext = context; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | /** |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 460 | * Return the {@link PhoneAccount} which will be used to place outgoing calls to addresses with |
| 461 | * the specified {@code uriScheme}. This {@link PhoneAccount} will always be a member of the |
| 462 | * list which is returned from invoking {@link #getCallCapablePhoneAccounts()}. The specific |
| 463 | * account returned depends on the following priorities: |
| 464 | * <ul> |
| 465 | * <li> If the user-selected default {@link PhoneAccount} supports the specified scheme, it will |
| 466 | * be returned. |
| 467 | * </li> |
| 468 | * <li> If there exists only one {@link PhoneAccount} that supports the specified scheme, it |
| 469 | * will be returned. |
| 470 | * </li> |
| 471 | * </ul> |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 472 | * <p> |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 473 | * If no {@link PhoneAccount} fits the criteria above, this method will return {@code null}. |
| 474 | * |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 475 | * @param uriScheme The URI scheme. |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 476 | * @return The {@link PhoneAccountHandle} corresponding to the account to be used. |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 477 | */ |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 478 | public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 479 | try { |
| 480 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 481 | return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme, |
| 482 | mContext.getOpPackageName()); |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 483 | } |
| 484 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 485 | Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e); |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 486 | } |
| 487 | return null; |
| 488 | } |
| 489 | |
| 490 | /** |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 491 | * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone |
| 492 | * calls. This {@code PhoneAccount} will always be a member of the list which is returned from |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 493 | * calling {@link #getCallCapablePhoneAccounts()} |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 494 | * <p> |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 495 | * Apps must be prepared for this method to return {@code null}, indicating that there currently |
| 496 | * exists no user-chosen default {@code PhoneAccount}. |
| 497 | * |
| 498 | * @return The user outgoing phone account selected by the user. |
Jay Shrauner | 225ccad | 2015-04-15 15:51:15 -0700 | [diff] [blame] | 499 | * @hide |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 500 | */ |
| 501 | public PhoneAccountHandle getUserSelectedOutgoingPhoneAccount() { |
| 502 | try { |
| 503 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 504 | return getTelecomService().getUserSelectedOutgoingPhoneAccount(); |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 505 | } |
| 506 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 507 | Log.e(TAG, "Error calling ITelecomService#getUserSelectedOutgoingPhoneAccount", e); |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 508 | } |
| 509 | return null; |
| 510 | } |
| 511 | |
| 512 | /** |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 513 | * Sets the user-chosen default for making outgoing phone calls. |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 514 | * @hide |
| 515 | */ |
Andrew Lee | d4abbfb | 2014-09-03 14:58:27 -0700 | [diff] [blame] | 516 | public void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle accountHandle) { |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 517 | try { |
| 518 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 519 | getTelecomService().setUserSelectedOutgoingPhoneAccount(accountHandle); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 520 | } |
| 521 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 522 | Log.e(TAG, "Error calling ITelecomService#setUserSelectedOutgoingPhoneAccount"); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
| 526 | /** |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 527 | * Returns the current SIM call manager. Apps must be prepared for this method to return |
| 528 | * {@code null}, indicating that there currently exists no user-chosen default |
| 529 | * {@code PhoneAccount}. |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 530 | * |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 531 | * @return The phone account handle of the current sim call manager. |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 532 | */ |
| 533 | public PhoneAccountHandle getSimCallManager() { |
| 534 | try { |
| 535 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 536 | return getTelecomService().getSimCallManager(); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 537 | } |
| 538 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 539 | Log.e(TAG, "Error calling ITelecomService#getSimCallManager"); |
Andrew Lee | 59cac3a | 2014-08-28 16:50:10 -0700 | [diff] [blame] | 540 | } |
| 541 | return null; |
| 542 | } |
| 543 | |
| 544 | /** |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 545 | * Returns the current SIM call manager for the specified user. Apps must be prepared for this |
| 546 | * method to return {@code null}, indicating that there currently exists no user-chosen default |
| 547 | * {@code PhoneAccount}. |
| 548 | * |
| 549 | * @return The phone account handle of the current sim call manager. |
| 550 | * |
| 551 | * @hide |
| 552 | */ |
| 553 | public PhoneAccountHandle getSimCallManager(int userId) { |
| 554 | try { |
| 555 | if (isServiceConnected()) { |
| 556 | return getTelecomService().getSimCallManagerForUser(userId); |
| 557 | } |
| 558 | } catch (RemoteException e) { |
| 559 | Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser"); |
| 560 | } |
| 561 | return null; |
| 562 | } |
| 563 | |
| 564 | /** |
Evan Charlton | eb0a8d5 | 2014-09-04 12:03:34 -0700 | [diff] [blame] | 565 | * Returns the current connection manager. Apps must be prepared for this method to return |
| 566 | * {@code null}, indicating that there currently exists no user-chosen default |
| 567 | * {@code PhoneAccount}. |
| 568 | * |
| 569 | * @return The phone account handle of the current connection manager. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 570 | * @hide |
Evan Charlton | eb0a8d5 | 2014-09-04 12:03:34 -0700 | [diff] [blame] | 571 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 572 | @SystemApi |
Evan Charlton | eb0a8d5 | 2014-09-04 12:03:34 -0700 | [diff] [blame] | 573 | public PhoneAccountHandle getConnectionManager() { |
| 574 | return getSimCallManager(); |
| 575 | } |
| 576 | |
| 577 | /** |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 578 | * Returns a list of the {@link PhoneAccountHandle}s which can be used to make and receive phone |
| 579 | * calls which support the specified URI scheme. |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 580 | * <P> |
| 581 | * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which |
| 582 | * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with |
| 583 | * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs |
| 584 | * such as {@code sip:example@sipexample.com}). |
| 585 | * |
| 586 | * @param uriScheme The URI scheme. |
| 587 | * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 588 | * @hide |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 589 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 590 | @SystemApi |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 591 | public List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(String uriScheme) { |
| 592 | try { |
| 593 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 594 | return getTelecomService().getPhoneAccountsSupportingScheme(uriScheme, |
| 595 | mContext.getOpPackageName()); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 596 | } |
| 597 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 598 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsSupportingScheme", e); |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 599 | } |
| 600 | return new ArrayList<>(); |
| 601 | } |
| 602 | |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 603 | |
| 604 | /** |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 605 | * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone |
| 606 | * calls. The returned list includes only those accounts which have been explicitly enabled |
| 607 | * by the user. |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 608 | * |
| 609 | * @see #EXTRA_PHONE_ACCOUNT_HANDLE |
| 610 | * @return A list of {@code PhoneAccountHandle} objects. |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 611 | */ |
| 612 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts() { |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 613 | return getCallCapablePhoneAccounts(false); |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Returns a list of {@link PhoneAccountHandle}s including those which have not been enabled |
| 618 | * by the user. |
| 619 | * |
| 620 | * @return A list of {@code PhoneAccountHandle} objects. |
| 621 | * @hide |
| 622 | */ |
| 623 | public List<PhoneAccountHandle> getCallCapablePhoneAccounts(boolean includeDisabledAccounts) { |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 624 | try { |
| 625 | if (isServiceConnected()) { |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 626 | return getTelecomService().getCallCapablePhoneAccounts( |
| 627 | includeDisabledAccounts, mContext.getOpPackageName()); |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 628 | } |
| 629 | } catch (RemoteException e) { |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 630 | Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" + |
| 631 | includeDisabledAccounts + ")", e); |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 632 | } |
| 633 | return new ArrayList<>(); |
| 634 | } |
| 635 | |
Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 636 | /** |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 637 | * Returns a list of all {@link PhoneAccount}s registered for the calling package. |
| 638 | * |
| 639 | * @return A list of {@code PhoneAccountHandle} objects. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 640 | * @hide |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 641 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 642 | @SystemApi |
Nancy Chen | 513c892 | 2014-09-17 14:47:20 -0700 | [diff] [blame] | 643 | public List<PhoneAccountHandle> getPhoneAccountsForPackage() { |
| 644 | try { |
| 645 | if (isServiceConnected()) { |
| 646 | return getTelecomService().getPhoneAccountsForPackage(mContext.getPackageName()); |
| 647 | } |
| 648 | } catch (RemoteException e) { |
| 649 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccountsForPackage", e); |
| 650 | } |
| 651 | return null; |
| 652 | } |
| 653 | |
| 654 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 655 | * Return the {@link PhoneAccount} for a specified {@link PhoneAccountHandle}. Object includes |
| 656 | * resources which can be used in a user interface. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 657 | * |
Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 658 | * @param account The {@link PhoneAccountHandle}. |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 659 | * @return The {@link PhoneAccount} object. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 660 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 661 | public PhoneAccount getPhoneAccount(PhoneAccountHandle account) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 662 | try { |
| 663 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 664 | return getTelecomService().getPhoneAccount(account); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 665 | } |
| 666 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 667 | Log.e(TAG, "Error calling ITelecomService#getPhoneAccount", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 668 | } |
| 669 | return null; |
| 670 | } |
| 671 | |
| 672 | /** |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 673 | * Returns a count of all {@link PhoneAccount}s. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 674 | * |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 675 | * @return The count of {@link PhoneAccount}s. |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 676 | * @hide |
| 677 | */ |
| 678 | @SystemApi |
| 679 | public int getAllPhoneAccountsCount() { |
| 680 | try { |
| 681 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 682 | return getTelecomService().getAllPhoneAccountsCount(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 683 | } |
| 684 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 685 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountsCount", e); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 686 | } |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Returns a list of all {@link PhoneAccount}s. |
| 692 | * |
| 693 | * @return All {@link PhoneAccount}s. |
| 694 | * @hide |
| 695 | */ |
| 696 | @SystemApi |
| 697 | public List<PhoneAccount> getAllPhoneAccounts() { |
| 698 | try { |
| 699 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 700 | return getTelecomService().getAllPhoneAccounts(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 701 | } |
| 702 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 703 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccounts", e); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 704 | } |
| 705 | return Collections.EMPTY_LIST; |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Returns a list of all {@link PhoneAccountHandle}s. |
| 710 | * |
| 711 | * @return All {@link PhoneAccountHandle}s. |
| 712 | * @hide |
| 713 | */ |
| 714 | @SystemApi |
| 715 | public List<PhoneAccountHandle> getAllPhoneAccountHandles() { |
| 716 | try { |
| 717 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 718 | return getTelecomService().getAllPhoneAccountHandles(); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 719 | } |
| 720 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 721 | Log.e(TAG, "Error calling ITelecomService#getAllPhoneAccountHandles", e); |
Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 722 | } |
| 723 | return Collections.EMPTY_LIST; |
| 724 | } |
| 725 | |
| 726 | /** |
Santos Cordon | d9e614f | 2014-10-28 13:10:36 -0700 | [diff] [blame] | 727 | * Register a {@link PhoneAccount} for use by the system. When registering |
| 728 | * {@link PhoneAccount}s, existing registrations will be overwritten if the |
| 729 | * {@link PhoneAccountHandle} matches that of a {@link PhoneAccount} which is already |
| 730 | * registered. Once registered, the {@link PhoneAccount} is listed to the user as an option |
| 731 | * when placing calls. The user may still need to enable the {@link PhoneAccount} within |
| 732 | * the phone app settings before the account is usable. |
| 733 | * <p> |
| 734 | * A {@link SecurityException} will be thrown if an app tries to register a |
| 735 | * {@link PhoneAccountHandle} where the package name specified within |
| 736 | * {@link PhoneAccountHandle#getComponentName()} does not match the package name of the app. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 737 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 738 | * @param account The complete {@link PhoneAccount}. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 739 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 740 | public void registerPhoneAccount(PhoneAccount account) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 741 | try { |
| 742 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 743 | getTelecomService().registerPhoneAccount(account); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 744 | } |
| 745 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 746 | Log.e(TAG, "Error calling ITelecomService#registerPhoneAccount", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
| 750 | /** |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 751 | * Remove a {@link PhoneAccount} registration from the system. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 752 | * |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 753 | * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 754 | */ |
Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 755 | public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 756 | try { |
| 757 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 758 | getTelecomService().unregisterPhoneAccount(accountHandle); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 759 | } |
| 760 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 761 | Log.e(TAG, "Error calling ITelecomService#unregisterPhoneAccount", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
| 765 | /** |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 766 | * Remove all Accounts that belong to the calling package from the system. |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 767 | * @hide |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 768 | */ |
Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 769 | @SystemApi |
Yorke Lee | 0604427 | 2015-04-14 15:16:59 -0700 | [diff] [blame] | 770 | public void clearPhoneAccounts() { |
| 771 | clearAccounts(); |
| 772 | } |
| 773 | /** |
| 774 | * Remove all Accounts that belong to the calling package from the system. |
| 775 | * @deprecated Use {@link #clearPhoneAccounts()} instead. |
| 776 | * @hide |
| 777 | */ |
| 778 | @SystemApi |
Nancy Chen | 7ab1dc4 | 2014-09-09 18:18:26 -0700 | [diff] [blame] | 779 | public void clearAccounts() { |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 780 | try { |
| 781 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 782 | getTelecomService().clearAccounts(mContext.getPackageName()); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 783 | } |
| 784 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 785 | Log.e(TAG, "Error calling ITelecomService#clearAccounts", e); |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
| 789 | /** |
Anthony Lee | 6727926 | 2014-10-27 11:28:40 -0700 | [diff] [blame] | 790 | * Remove all Accounts that belong to the specified package from the system. |
| 791 | * @hide |
| 792 | */ |
| 793 | public void clearAccountsForPackage(String packageName) { |
| 794 | try { |
| 795 | if (isServiceConnected() && !TextUtils.isEmpty(packageName)) { |
| 796 | getTelecomService().clearAccounts(packageName); |
| 797 | } |
| 798 | } catch (RemoteException e) { |
Nancy Chen | 5cf2784 | 2015-01-24 23:30:27 -0800 | [diff] [blame] | 799 | Log.e(TAG, "Error calling ITelecomService#clearAccountsForPackage", e); |
Anthony Lee | 6727926 | 2014-10-27 11:28:40 -0700 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
Yorke Lee | 1011f48 | 2015-04-23 15:58:27 -0700 | [diff] [blame] | 803 | |
Anthony Lee | 6727926 | 2014-10-27 11:28:40 -0700 | [diff] [blame] | 804 | /** |
Yorke Lee | 1011f48 | 2015-04-23 15:58:27 -0700 | [diff] [blame] | 805 | * @deprecated - Use {@link TelecomManager#getDefaultDialerPackage} to directly access |
| 806 | * the default dialer's package name instead. |
Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 807 | * @hide |
| 808 | */ |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 809 | @SystemApi |
| 810 | public ComponentName getDefaultPhoneApp() { |
| 811 | try { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 812 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 813 | return getTelecomService().getDefaultPhoneApp(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 814 | } |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 815 | } catch (RemoteException e) { |
| 816 | Log.e(TAG, "RemoteException attempting to get the default phone app.", e); |
| 817 | } |
| 818 | return null; |
| 819 | } |
| 820 | |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 821 | /** |
Yorke Lee | 1011f48 | 2015-04-23 15:58:27 -0700 | [diff] [blame] | 822 | * Used to determine the currently selected default dialer package. |
| 823 | * |
| 824 | * @return package name for the default dialer package or null if no package has been |
| 825 | * selected as the default dialer. |
| 826 | */ |
| 827 | public String getDefaultDialerPackage() { |
| 828 | try { |
| 829 | if (isServiceConnected()) { |
| 830 | return getTelecomService().getDefaultDialerPackage(); |
| 831 | } |
| 832 | } catch (RemoteException e) { |
| 833 | Log.e(TAG, "RemoteException attempting to get the default dialer package name.", e); |
| 834 | } |
| 835 | return null; |
| 836 | } |
| 837 | |
| 838 | /** |
Yorke Lee | 107c4ce | 2015-06-15 12:08:24 -0700 | [diff] [blame] | 839 | * Used to set the default dialer package. |
| 840 | * |
| 841 | * @param packageName to set the default dialer to.. |
| 842 | * |
| 843 | * @result {@code true} if the default dialer was successfully changed, {@code false} if |
| 844 | * the specified package does not correspond to an installed dialer, or is already |
| 845 | * the default dialer. |
| 846 | * |
| 847 | * Requires permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE} |
| 848 | * Requires permission: {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} |
| 849 | * |
| 850 | * @hide |
| 851 | */ |
| 852 | public boolean setDefaultDialer(String packageName) { |
| 853 | try { |
| 854 | if (isServiceConnected()) { |
| 855 | return getTelecomService().setDefaultDialer(packageName); |
| 856 | } |
| 857 | } catch (RemoteException e) { |
| 858 | Log.e(TAG, "RemoteException attempting to set the default dialer.", e); |
| 859 | } |
| 860 | return false; |
| 861 | } |
| 862 | |
| 863 | /** |
Yorke Lee | 1011f48 | 2015-04-23 15:58:27 -0700 | [diff] [blame] | 864 | * Used to determine the dialer package that is preloaded on the system partition. |
| 865 | * |
| 866 | * @return package name for the system dialer package or null if no system dialer is preloaded. |
| 867 | * @hide |
| 868 | */ |
| 869 | public String getSystemDialerPackage() { |
| 870 | try { |
| 871 | if (isServiceConnected()) { |
| 872 | return getTelecomService().getSystemDialerPackage(); |
| 873 | } |
| 874 | } catch (RemoteException e) { |
| 875 | Log.e(TAG, "RemoteException attempting to get the system dialer package name.", e); |
| 876 | } |
| 877 | return null; |
| 878 | } |
| 879 | |
| 880 | /** |
Nancy Chen | 443e501 | 2014-10-15 15:48:21 -0700 | [diff] [blame] | 881 | * Return whether a given phone number is the configured voicemail number for a |
| 882 | * particular phone account. |
| 883 | * |
| 884 | * @param accountHandle The handle for the account to check the voicemail number against |
| 885 | * @param number The number to look up. |
Nancy Chen | 443e501 | 2014-10-15 15:48:21 -0700 | [diff] [blame] | 886 | */ |
Nancy Chen | 443e501 | 2014-10-15 15:48:21 -0700 | [diff] [blame] | 887 | public boolean isVoiceMailNumber(PhoneAccountHandle accountHandle, String number) { |
| 888 | try { |
| 889 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 890 | return getTelecomService().isVoiceMailNumber(accountHandle, number, |
| 891 | mContext.getOpPackageName()); |
Nancy Chen | 443e501 | 2014-10-15 15:48:21 -0700 | [diff] [blame] | 892 | } |
| 893 | } catch (RemoteException e) { |
Nancy Chen | 5cf2784 | 2015-01-24 23:30:27 -0800 | [diff] [blame] | 894 | Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e); |
Nancy Chen | 443e501 | 2014-10-15 15:48:21 -0700 | [diff] [blame] | 895 | } |
| 896 | return false; |
| 897 | } |
| 898 | |
| 899 | /** |
Yorke Lee | 49e2d46 | 2015-04-15 16:14:22 -0700 | [diff] [blame] | 900 | * Return the voicemail number for a given phone account. |
Nancy Chen | 8c066f7 | 2014-12-03 15:18:08 -0800 | [diff] [blame] | 901 | * |
Yorke Lee | 49e2d46 | 2015-04-15 16:14:22 -0700 | [diff] [blame] | 902 | * @param accountHandle The handle for the phone account. |
| 903 | * @return The voicemail number for the phone account, and {@code null} if one has not been |
| 904 | * configured. |
Nancy Chen | 8c066f7 | 2014-12-03 15:18:08 -0800 | [diff] [blame] | 905 | */ |
Yorke Lee | 49e2d46 | 2015-04-15 16:14:22 -0700 | [diff] [blame] | 906 | public String getVoiceMailNumber(PhoneAccountHandle accountHandle) { |
Nancy Chen | 8c066f7 | 2014-12-03 15:18:08 -0800 | [diff] [blame] | 907 | try { |
| 908 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 909 | return getTelecomService().getVoiceMailNumber(accountHandle, |
| 910 | mContext.getOpPackageName()); |
Nancy Chen | 8c066f7 | 2014-12-03 15:18:08 -0800 | [diff] [blame] | 911 | } |
| 912 | } catch (RemoteException e) { |
Nancy Chen | 5cf2784 | 2015-01-24 23:30:27 -0800 | [diff] [blame] | 913 | Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e); |
Nancy Chen | 8c066f7 | 2014-12-03 15:18:08 -0800 | [diff] [blame] | 914 | } |
Yorke Lee | 49e2d46 | 2015-04-15 16:14:22 -0700 | [diff] [blame] | 915 | return null; |
Nancy Chen | 8c066f7 | 2014-12-03 15:18:08 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /** |
Nancy Chen | 5cf2784 | 2015-01-24 23:30:27 -0800 | [diff] [blame] | 919 | * Return the line 1 phone number for given phone account. |
| 920 | * |
| 921 | * @param accountHandle The handle for the account retrieve a number for. |
| 922 | * @return A string representation of the line 1 phone number. |
Nancy Chen | 5cf2784 | 2015-01-24 23:30:27 -0800 | [diff] [blame] | 923 | */ |
Nancy Chen | 5cf2784 | 2015-01-24 23:30:27 -0800 | [diff] [blame] | 924 | public String getLine1Number(PhoneAccountHandle accountHandle) { |
| 925 | try { |
| 926 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 927 | return getTelecomService().getLine1Number(accountHandle, |
| 928 | mContext.getOpPackageName()); |
Nancy Chen | 5cf2784 | 2015-01-24 23:30:27 -0800 | [diff] [blame] | 929 | } |
| 930 | } catch (RemoteException e) { |
| 931 | Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e); |
| 932 | } |
| 933 | return null; |
| 934 | } |
| 935 | |
| 936 | /** |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 937 | * Returns whether there is an ongoing phone call (can be in dialing, ringing, active or holding |
| 938 | * states). |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 939 | * <p> |
| 940 | * Requires permission: {@link android.Manifest.permission#READ_PHONE_STATE} |
| 941 | * </p> |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 942 | */ |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 943 | public boolean isInCall() { |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 944 | try { |
| 945 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 946 | return getTelecomService().isInCall(mContext.getOpPackageName()); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 947 | } |
| 948 | } catch (RemoteException e) { |
Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 949 | Log.e(TAG, "RemoteException calling isInCall().", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 950 | } |
| 951 | return false; |
| 952 | } |
| 953 | |
| 954 | /** |
Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 955 | * Returns one of the following constants that represents the current state of Telecom: |
| 956 | * |
| 957 | * {@link TelephonyManager#CALL_STATE_RINGING} |
| 958 | * {@link TelephonyManager#CALL_STATE_OFFHOOK} |
| 959 | * {@link TelephonyManager#CALL_STATE_IDLE} |
Yorke Lee | 7c72c2d | 2014-10-28 14:12:02 -0700 | [diff] [blame] | 960 | * |
| 961 | * Note that this API does not require the |
| 962 | * {@link android.Manifest.permission#READ_PHONE_STATE} permission. This is intentional, to |
| 963 | * preserve the behavior of {@link TelephonyManager#getCallState()}, which also did not require |
| 964 | * the permission. |
Yorke Lee | 2ae312e | 2014-09-12 17:58:48 -0700 | [diff] [blame] | 965 | * @hide |
| 966 | */ |
| 967 | @SystemApi |
| 968 | public int getCallState() { |
| 969 | try { |
| 970 | if (isServiceConnected()) { |
| 971 | return getTelecomService().getCallState(); |
| 972 | } |
| 973 | } catch (RemoteException e) { |
| 974 | Log.d(TAG, "RemoteException calling getCallState().", e); |
| 975 | } |
| 976 | return TelephonyManager.CALL_STATE_IDLE; |
| 977 | } |
| 978 | |
| 979 | /** |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 980 | * Returns whether there currently exists is a ringing incoming-call. |
| 981 | * |
| 982 | * @hide |
| 983 | */ |
| 984 | @SystemApi |
| 985 | public boolean isRinging() { |
| 986 | try { |
| 987 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 988 | return getTelecomService().isRinging(mContext.getOpPackageName()); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 989 | } |
| 990 | } catch (RemoteException e) { |
| 991 | Log.e(TAG, "RemoteException attempting to get ringing state of phone app.", e); |
| 992 | } |
| 993 | return false; |
| 994 | } |
| 995 | |
| 996 | /** |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 997 | * Ends an ongoing call. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 998 | * TODO: L-release - need to convert all invocations of ITelecomService#endCall to use this |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 999 | * method (clockwork & gearhead). |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1000 | * @hide |
| 1001 | */ |
| 1002 | @SystemApi |
| 1003 | public boolean endCall() { |
| 1004 | try { |
| 1005 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1006 | return getTelecomService().endCall(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1007 | } |
| 1008 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1009 | Log.e(TAG, "Error calling ITelecomService#endCall", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1010 | } |
| 1011 | return false; |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * If there is a ringing incoming call, this method accepts the call on behalf of the user. |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1016 | * TODO: L-release - need to convert all invocation of ITelecmmService#answerRingingCall to use |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 1017 | * this method (clockwork & gearhead). |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1018 | * |
| 1019 | * @hide |
| 1020 | */ |
| 1021 | @SystemApi |
| 1022 | public void acceptRingingCall() { |
| 1023 | try { |
| 1024 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1025 | getTelecomService().acceptRingingCall(); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1026 | } |
| 1027 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1028 | Log.e(TAG, "Error calling ITelecomService#acceptRingingCall", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * Silences the ringer if a ringing call exists. |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1034 | */ |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1035 | public void silenceRinger() { |
| 1036 | try { |
| 1037 | if (isServiceConnected()) { |
Yorke Lee | f1a349b | 2015-04-29 16:16:50 -0700 | [diff] [blame] | 1038 | getTelecomService().silenceRinger(mContext.getOpPackageName()); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1039 | } |
| 1040 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1041 | Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 1045 | /** |
| 1046 | * Returns whether TTY is supported on this device. |
| 1047 | * |
| 1048 | * @hide |
| 1049 | */ |
| 1050 | @SystemApi |
| 1051 | public boolean isTtySupported() { |
| 1052 | try { |
| 1053 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1054 | return getTelecomService().isTtySupported(mContext.getOpPackageName()); |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 1055 | } |
| 1056 | } catch (RemoteException e) { |
| 1057 | Log.e(TAG, "RemoteException attempting to get TTY supported state.", e); |
| 1058 | } |
| 1059 | return false; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * Returns the current TTY mode of the device. For TTY to be on the user must enable it in |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 1064 | * settings and have a wired headset plugged in. |
| 1065 | * Valid modes are: |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1066 | * - {@link TelecomManager#TTY_MODE_OFF} |
| 1067 | * - {@link TelecomManager#TTY_MODE_FULL} |
| 1068 | * - {@link TelecomManager#TTY_MODE_HCO} |
| 1069 | * - {@link TelecomManager#TTY_MODE_VCO} |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 1070 | * @hide |
| 1071 | */ |
| 1072 | public int getCurrentTtyMode() { |
| 1073 | try { |
| 1074 | if (isServiceConnected()) { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1075 | return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName()); |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 1076 | } |
| 1077 | } catch (RemoteException e) { |
| 1078 | Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e); |
| 1079 | } |
Evan Charlton | 1019719 | 2014-07-19 15:00:29 -0700 | [diff] [blame] | 1080 | return TTY_MODE_OFF; |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 1083 | /** |
| 1084 | * Registers a new incoming call. A {@link ConnectionService} should invoke this method when it |
| 1085 | * has an incoming call. The specified {@link PhoneAccountHandle} must have been registered |
Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 1086 | * with {@link #registerPhoneAccount}. Once invoked, this method will cause the system to bind |
| 1087 | * to the {@link ConnectionService} associated with the {@link PhoneAccountHandle} and request |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 1088 | * additional information about the call (See |
| 1089 | * {@link ConnectionService#onCreateIncomingConnection}) before starting the incoming call UI. |
| 1090 | * |
| 1091 | * @param phoneAccount A {@link PhoneAccountHandle} registered with |
| 1092 | * {@link #registerPhoneAccount}. |
| 1093 | * @param extras A bundle that will be passed through to |
| 1094 | * {@link ConnectionService#onCreateIncomingConnection}. |
| 1095 | */ |
| 1096 | public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) { |
| 1097 | try { |
| 1098 | if (isServiceConnected()) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1099 | getTelecomService().addNewIncomingCall( |
Santos Cordon | 96efb48 | 2014-07-19 14:57:05 -0700 | [diff] [blame] | 1100 | phoneAccount, extras == null ? new Bundle() : extras); |
| 1101 | } |
| 1102 | } catch (RemoteException e) { |
| 1103 | Log.e(TAG, "RemoteException adding a new incoming call: " + phoneAccount, e); |
| 1104 | } |
| 1105 | } |
| 1106 | |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1107 | /** |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 1108 | * Registers a new unknown call with Telecom. This can only be called by the system Telephony |
| 1109 | * service. This is invoked when Telephony detects a new unknown connection that was neither |
| 1110 | * a new incoming call, nor an user-initiated outgoing call. |
| 1111 | * |
| 1112 | * @param phoneAccount A {@link PhoneAccountHandle} registered with |
| 1113 | * {@link #registerPhoneAccount}. |
| 1114 | * @param extras A bundle that will be passed through to |
| 1115 | * {@link ConnectionService#onCreateIncomingConnection}. |
| 1116 | * @hide |
| 1117 | */ |
| 1118 | @SystemApi |
| 1119 | public void addNewUnknownCall(PhoneAccountHandle phoneAccount, Bundle extras) { |
| 1120 | try { |
| 1121 | if (isServiceConnected()) { |
| 1122 | getTelecomService().addNewUnknownCall( |
| 1123 | phoneAccount, extras == null ? new Bundle() : extras); |
| 1124 | } |
| 1125 | } catch (RemoteException e) { |
| 1126 | Log.e(TAG, "RemoteException adding a new unknown call: " + phoneAccount, e); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | /** |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1131 | * Processes the specified dial string as an MMI code. |
| 1132 | * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". |
| 1133 | * Some of these sequences launch special behavior through handled by Telephony. |
Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 1134 | * This method uses the default subscription. |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1135 | * <p> |
| 1136 | * Requires that the method-caller be set as the system dialer app. |
| 1137 | * </p> |
| 1138 | * |
| 1139 | * @param dialString The digits to dial. |
| 1140 | * @return True if the digits were processed as an MMI code, false otherwise. |
| 1141 | */ |
| 1142 | public boolean handleMmi(String dialString) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1143 | ITelecomService service = getTelecomService(); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1144 | if (service != null) { |
| 1145 | try { |
Yorke Lee | f1a349b | 2015-04-29 16:16:50 -0700 | [diff] [blame] | 1146 | return service.handlePinMmi(dialString, mContext.getOpPackageName()); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1147 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1148 | Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1149 | } |
| 1150 | } |
| 1151 | return false; |
| 1152 | } |
| 1153 | |
| 1154 | /** |
Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 1155 | * Processes the specified dial string as an MMI code. |
| 1156 | * MMI codes are any sequence of characters entered into the dialpad that contain a "*" or "#". |
| 1157 | * Some of these sequences launch special behavior through handled by Telephony. |
| 1158 | * <p> |
| 1159 | * Requires that the method-caller be set as the system dialer app. |
| 1160 | * </p> |
| 1161 | * |
| 1162 | * @param accountHandle The handle for the account the MMI code should apply to. |
| 1163 | * @param dialString The digits to dial. |
| 1164 | * @return True if the digits were processed as an MMI code, false otherwise. |
Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 1165 | */ |
Yorke Lee | 0604427 | 2015-04-14 15:16:59 -0700 | [diff] [blame] | 1166 | public boolean handleMmi(String dialString, PhoneAccountHandle accountHandle) { |
Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 1167 | ITelecomService service = getTelecomService(); |
| 1168 | if (service != null) { |
| 1169 | try { |
Yorke Lee | f1a349b | 2015-04-29 16:16:50 -0700 | [diff] [blame] | 1170 | return service.handlePinMmiForPhoneAccount(accountHandle, dialString, |
| 1171 | mContext.getOpPackageName()); |
Nancy Chen | 95e8a67 | 2014-10-16 18:38:21 -0700 | [diff] [blame] | 1172 | } catch (RemoteException e) { |
| 1173 | Log.e(TAG, "Error calling ITelecomService#handlePinMmi", e); |
| 1174 | } |
| 1175 | } |
| 1176 | return false; |
| 1177 | } |
| 1178 | |
| 1179 | /** |
Nancy Chen | b2299c1 | 2014-10-29 18:22:11 -0700 | [diff] [blame] | 1180 | * @param accountHandle The handle for the account to derive an adn query URI for or |
| 1181 | * {@code null} to return a URI which will use the default account. |
| 1182 | * @return The URI (with the content:// scheme) specific to the specified {@link PhoneAccount} |
| 1183 | * for the the content retrieve. |
| 1184 | */ |
| 1185 | public Uri getAdnUriForPhoneAccount(PhoneAccountHandle accountHandle) { |
| 1186 | ITelecomService service = getTelecomService(); |
| 1187 | if (service != null && accountHandle != null) { |
| 1188 | try { |
Yorke Lee | f1a349b | 2015-04-29 16:16:50 -0700 | [diff] [blame] | 1189 | return service.getAdnUriForPhoneAccount(accountHandle, mContext.getOpPackageName()); |
Nancy Chen | b2299c1 | 2014-10-29 18:22:11 -0700 | [diff] [blame] | 1190 | } catch (RemoteException e) { |
| 1191 | Log.e(TAG, "Error calling ITelecomService#getAdnUriForPhoneAccount", e); |
| 1192 | } |
| 1193 | } |
| 1194 | return Uri.parse("content://icc/adn"); |
| 1195 | } |
| 1196 | |
| 1197 | /** |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1198 | * Removes the missed-call notification if one is present. |
| 1199 | * <p> |
| 1200 | * Requires that the method-caller be set as the system dialer app. |
| 1201 | * </p> |
| 1202 | */ |
| 1203 | public void cancelMissedCallsNotification() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1204 | ITelecomService service = getTelecomService(); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1205 | if (service != null) { |
| 1206 | try { |
Yorke Lee | f1a349b | 2015-04-29 16:16:50 -0700 | [diff] [blame] | 1207 | service.cancelMissedCallsNotification(mContext.getOpPackageName()); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1208 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1209 | Log.e(TAG, "Error calling ITelecomService#cancelMissedCallsNotification", e); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * Brings the in-call screen to the foreground if there is an ongoing call. If there is |
| 1216 | * currently no ongoing call, then this method does nothing. |
| 1217 | * <p> |
| 1218 | * Requires that the method-caller be set as the system dialer app or have the |
| 1219 | * {@link android.Manifest.permission#READ_PHONE_STATE} permission. |
| 1220 | * </p> |
| 1221 | * |
| 1222 | * @param showDialpad Brings up the in-call dialpad as part of showing the in-call screen. |
| 1223 | */ |
| 1224 | public void showInCallScreen(boolean showDialpad) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1225 | ITelecomService service = getTelecomService(); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1226 | if (service != null) { |
| 1227 | try { |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 1228 | service.showInCallScreen(showDialpad, mContext.getOpPackageName()); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1229 | } catch (RemoteException e) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1230 | Log.e(TAG, "Error calling ITelecomService#showCallScreen", e); |
Nancy Chen | 0eb1e40 | 2014-08-21 22:52:29 -0700 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | |
Yorke Lee | 3e56ba1 | 2015-04-23 12:32:36 -0700 | [diff] [blame] | 1235 | /** |
| 1236 | * Places a new outgoing call to the provided address using the system telecom service with |
| 1237 | * the specified extras. |
| 1238 | * |
| 1239 | * This method is equivalent to placing an outgoing call using {@link Intent#ACTION_CALL}, |
| 1240 | * except that the outgoing call will always be sent via the system telecom service. If |
| 1241 | * method-caller is either the user selected default dialer app or preloaded system dialer |
| 1242 | * app, then emergency calls will also be allowed. |
| 1243 | * |
| 1244 | * Requires permission: {@link android.Manifest.permission#CALL_PHONE} |
| 1245 | * |
| 1246 | * Usage example: |
| 1247 | * <pre> |
| 1248 | * Uri uri = Uri.fromParts("tel", "12345", null); |
| 1249 | * Bundle extras = new Bundle(); |
| 1250 | * extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true); |
| 1251 | * telecomManager.placeCall(uri, extras); |
| 1252 | * </pre> |
| 1253 | * |
Santos Cordon | 7a060d5 | 2015-06-19 14:52:04 -0700 | [diff] [blame] | 1254 | * The following keys are supported in the supplied extras. |
| 1255 | * <ul> |
| 1256 | * <li>{@link #EXTRA_OUTGOING_CALL_EXTRAS}</li> |
| 1257 | * <li>{@link #EXTRA_PHONE_ACCOUNT_HANDLE}</li> |
| 1258 | * <li>{@link #EXTRA_START_CALL_WITH_SPEAKERPHONE}</li> |
| 1259 | * <li>{@link #EXTRA_START_CALL_WITH_VIDEO_STATE}</li> |
| 1260 | * </ul> |
| 1261 | * |
Yorke Lee | 3e56ba1 | 2015-04-23 12:32:36 -0700 | [diff] [blame] | 1262 | * @param address The address to make the call to. |
| 1263 | * @param extras Bundle of extras to use with the call. |
| 1264 | */ |
| 1265 | public void placeCall(Uri address, Bundle extras) { |
| 1266 | ITelecomService service = getTelecomService(); |
| 1267 | if (service != null) { |
Yorke Lee | a5d5c1d | 2015-05-05 16:25:55 -0700 | [diff] [blame] | 1268 | if (address == null) { |
| 1269 | Log.w(TAG, "Cannot place call to empty address."); |
| 1270 | } |
Yorke Lee | 3e56ba1 | 2015-04-23 12:32:36 -0700 | [diff] [blame] | 1271 | try { |
Yorke Lee | a5d5c1d | 2015-05-05 16:25:55 -0700 | [diff] [blame] | 1272 | service.placeCall(address, extras == null ? new Bundle() : extras, |
| 1273 | mContext.getOpPackageName()); |
Yorke Lee | 3e56ba1 | 2015-04-23 12:32:36 -0700 | [diff] [blame] | 1274 | } catch (RemoteException e) { |
| 1275 | Log.e(TAG, "Error calling ITelecomService#placeCall", e); |
| 1276 | } |
| 1277 | } |
| 1278 | } |
| 1279 | |
Santos Cordon | 91371dc | 2015-05-08 13:52:09 -0700 | [diff] [blame] | 1280 | /** |
| 1281 | * Enables and disables specified phone account. |
| 1282 | * |
| 1283 | * @param handle Handle to the phone account. |
| 1284 | * @param isEnabled Enable state of the phone account. |
| 1285 | * @hide |
| 1286 | */ |
| 1287 | @SystemApi |
| 1288 | public void enablePhoneAccount(PhoneAccountHandle handle, boolean isEnabled) { |
| 1289 | ITelecomService service = getTelecomService(); |
| 1290 | if (service != null) { |
| 1291 | try { |
| 1292 | service.enablePhoneAccount(handle, isEnabled); |
| 1293 | } catch (RemoteException e) { |
| 1294 | Log.e(TAG, "Error enablePhoneAbbount", e); |
| 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1299 | private ITelecomService getTelecomService() { |
| 1300 | return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); |
Santos Cordon | 6c7a388 | 2014-06-25 15:30:08 -0700 | [diff] [blame] | 1301 | } |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1302 | |
| 1303 | private boolean isServiceConnected() { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1304 | boolean isConnected = getTelecomService() != null; |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1305 | if (!isConnected) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1306 | Log.w(TAG, "Telecom Service not found."); |
Santos Cordon | 9eb4593 | 2014-06-27 12:28:43 -0700 | [diff] [blame] | 1307 | } |
| 1308 | return isConnected; |
| 1309 | } |
Evan Charlton | 235c159 | 2014-09-05 15:41:23 +0000 | [diff] [blame] | 1310 | } |