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