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