Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.telecomm; |
| 18 | |
| 19 | import android.app.Activity; |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.content.res.Configuration; |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 24 | import android.net.Uri; |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
Yorke Lee | 35bcc89 | 2014-08-13 15:27:16 -0700 | [diff] [blame] | 26 | import android.os.UserManager; |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 27 | import android.telecomm.PhoneAccountHandle; |
Evan Charlton | b35fc31 | 2014-07-19 15:02:55 -0700 | [diff] [blame] | 28 | import android.telecomm.TelecommManager; |
Yorke Lee | d725587 | 2014-08-25 15:03:51 -0700 | [diff] [blame^] | 29 | import android.telephony.DisconnectCause; |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 30 | import android.telephony.PhoneNumberUtils; |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 31 | import android.text.TextUtils; |
Yorke Lee | 35bcc89 | 2014-08-13 15:27:16 -0700 | [diff] [blame] | 32 | import android.widget.Toast; |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Activity that handles system CALL actions and forwards them to {@link CallsManager}. |
| 36 | * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY. |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 37 | * |
| 38 | * Pre-L, the only way apps were were allowed to make outgoing emergency calls was the |
| 39 | * ACTION_CALL_PRIVILEGED action (which requires the system only CALL_PRIVILEGED permission). |
| 40 | * |
| 41 | * In L, any app that has the CALL_PRIVILEGED permission can continue to make outgoing emergency |
| 42 | * calls via ACTION_CALL_PRIVILEGED. |
| 43 | * |
| 44 | * In addition, the default dialer (identified via {@link TelecommManager#getDefaultPhoneApp()} |
| 45 | * will also be granted the ability to make emergency outgoing calls using the CALL action. In |
| 46 | * order to do this, it must call startActivityForResult on the CALL intent to allow its package |
| 47 | * name to be passed to {@link CallActivity}. Calling startActivity will continue to work on all |
| 48 | * non-emergency numbers just like it did pre-L. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 49 | */ |
| 50 | public class CallActivity extends Activity { |
Yorke Lee | d725587 | 2014-08-25 15:03:51 -0700 | [diff] [blame^] | 51 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 52 | private CallsManager mCallsManager = CallsManager.getInstance(); |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame] | 53 | private boolean mIsVoiceCapable; |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 54 | |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 55 | /** |
| 56 | * {@inheritDoc} |
| 57 | * |
| 58 | * This method is the single point of entry for the CALL intent, which is used by built-in apps |
| 59 | * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls. |
| 60 | */ |
| 61 | @Override |
| 62 | protected void onCreate(Bundle bundle) { |
| 63 | super.onCreate(bundle); |
| 64 | |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame] | 65 | mIsVoiceCapable = isVoiceCapable(); |
| 66 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 67 | // TODO: This activity will be displayed until the next screen which could be |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 68 | // the in-call UI and error dialog or potentially a call-type selection dialog. |
| 69 | // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this |
| 70 | // is still desired and add back if necessary. Currently, the activity is set to NoDisplay |
| 71 | // theme which means it shows no UI. |
| 72 | |
| 73 | Intent intent = getIntent(); |
| 74 | Configuration configuration = getResources().getConfiguration(); |
| 75 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 76 | Log.d(this, "onCreate: this = %s, bundle = %s", this, bundle); |
| 77 | Log.d(this, " - intent = %s", intent); |
| 78 | Log.d(this, " - configuration = %s", configuration); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 79 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 80 | // TODO: Figure out if there is something to restore from bundle. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 81 | // See OutgoingCallBroadcaster in services/Telephony for more. |
| 82 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 83 | processIntent(intent); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 84 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 85 | // This activity does not have associated UI, so close. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 86 | finish(); |
| 87 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 88 | Log.d(this, "onCreate: end"); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 92 | * Processes intents sent to the activity. |
| 93 | * |
| 94 | * @param intent The intent. |
| 95 | */ |
| 96 | private void processIntent(Intent intent) { |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame] | 97 | // Ensure call intents are not processed on devices that are not capable of calling. |
| 98 | if (!mIsVoiceCapable) { |
| 99 | setResult(RESULT_CANCELED); |
| 100 | return; |
| 101 | } |
| 102 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 103 | String action = intent.getAction(); |
| 104 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 105 | // TODO: Check for non-voice capable devices before reading any intents. |
| 106 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 107 | if (Intent.ACTION_CALL.equals(action) || |
| 108 | Intent.ACTION_CALL_PRIVILEGED.equals(action) || |
| 109 | Intent.ACTION_CALL_EMERGENCY.equals(action)) { |
| 110 | processOutgoingCallIntent(intent); |
Evan Charlton | b35fc31 | 2014-07-19 15:02:55 -0700 | [diff] [blame] | 111 | } else if (TelecommManager.ACTION_INCOMING_CALL.equals(action)) { |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 112 | processIncomingCallIntent(intent); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /** |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 117 | * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents. |
| 118 | * |
| 119 | * @param intent Call intent containing data about the handle to call. |
| 120 | */ |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 121 | private void processOutgoingCallIntent(Intent intent) { |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 122 | String uriString = intent.getData().getSchemeSpecificPart(); |
| 123 | Uri handle = Uri.fromParts( |
| 124 | PhoneNumberUtils.isUriNumber(uriString) ? "sip" : "tel", uriString, null); |
Yorke Lee | 35bcc89 | 2014-08-13 15:27:16 -0700 | [diff] [blame] | 125 | |
| 126 | UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); |
| 127 | if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS) |
| 128 | && !TelephonyUtil.shouldProcessAsEmergency(this, handle)) { |
| 129 | // Only emergency calls are allowed for users with the DISALLOW_OUTGOING_CALLS |
| 130 | // restriction. |
| 131 | Toast.makeText(this, getResources().getString(R.string.outgoing_call_not_allowed), |
| 132 | Toast.LENGTH_SHORT).show(); |
| 133 | Log.d(this, "Rejecting non-emergency phone call due to DISALLOW_OUTGOING_CALLS " |
| 134 | + "restriction"); |
| 135 | return; |
| 136 | } |
| 137 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 138 | PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra( |
| 139 | TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE); |
| 140 | |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 141 | Bundle clientExtras = null; |
| 142 | if (intent.hasExtra(TelecommManager.EXTRA_OUTGOING_CALL_EXTRAS)) { |
| 143 | clientExtras = intent.getBundleExtra(TelecommManager.EXTRA_OUTGOING_CALL_EXTRAS); |
| 144 | } |
| 145 | if (clientExtras == null) { |
| 146 | clientExtras = Bundle.EMPTY; |
| 147 | } |
| 148 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 149 | // Send to CallsManager to ensure the InCallUI gets kicked off before the broadcast returns |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 150 | Call call = mCallsManager.startOutgoingCall(handle, phoneAccountHandle, clientExtras); |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 151 | |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 152 | NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster( |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 153 | mCallsManager, call, intent, isDefaultDialer()); |
Yorke Lee | d725587 | 2014-08-25 15:03:51 -0700 | [diff] [blame^] | 154 | final int result = broadcaster.processIntent(); |
| 155 | final boolean success = result == DisconnectCause.NOT_DISCONNECTED; |
| 156 | |
Yorke Lee | e6b42e9 | 2014-08-22 16:41:17 -0700 | [diff] [blame] | 157 | if (!success && call != null) { |
Yorke Lee | d725587 | 2014-08-25 15:03:51 -0700 | [diff] [blame^] | 158 | disconnectCallAndShowErrorDialog(call, result); |
Yorke Lee | e6b42e9 | 2014-08-22 16:41:17 -0700 | [diff] [blame] | 159 | } |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 160 | setResult(success ? RESULT_OK : RESULT_CANCELED); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 161 | } |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 162 | |
| 163 | /** |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 164 | * Processes INCOMING_CALL intents. Grabs the connection service information from the intent |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 165 | * extra and forwards that to the CallsManager to start the incoming call flow. |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 166 | * |
| 167 | * @param intent The incoming call intent. |
| 168 | */ |
| 169 | private void processIncomingCallIntent(Intent intent) { |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 170 | PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra( |
| 171 | TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE); |
| 172 | if (phoneAccountHandle == null) { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 173 | Log.w(this, "Rejecting incoming call due to null phone account"); |
| 174 | return; |
| 175 | } |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 176 | if (phoneAccountHandle.getComponentName() == null) { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 177 | Log.w(this, "Rejecting incoming call due to null component name"); |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 181 | Bundle clientExtras = null; |
Evan Charlton | b35fc31 | 2014-07-19 15:02:55 -0700 | [diff] [blame] | 182 | if (intent.hasExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS)) { |
| 183 | clientExtras = intent.getBundleExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS); |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 184 | } |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 185 | if (clientExtras == null) { |
| 186 | clientExtras = Bundle.EMPTY; |
| 187 | } |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 188 | |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 189 | Log.d(this, "Processing incoming call from connection service [%s]", |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 190 | phoneAccountHandle.getComponentName()); |
| 191 | mCallsManager.processIncomingCallIntent(phoneAccountHandle, clientExtras); |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 192 | } |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 193 | |
| 194 | private boolean isDefaultDialer() { |
| 195 | final String packageName = getCallingPackage(); |
| 196 | if (TextUtils.isEmpty(packageName)) { |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | final TelecommManager telecommManager = |
| 201 | (TelecommManager) getSystemService(Context.TELECOMM_SERVICE); |
| 202 | final ComponentName defaultPhoneApp = telecommManager.getDefaultPhoneApp(); |
| 203 | return (defaultPhoneApp != null |
| 204 | && TextUtils.equals(defaultPhoneApp.getPackageName(), packageName)); |
| 205 | } |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * Returns whether the device is voice-capable (e.g. a phone vs a tablet). |
| 209 | * |
| 210 | * @return {@code True} if the device is voice-capable. |
| 211 | */ |
| 212 | private boolean isVoiceCapable() { |
| 213 | return getApplicationContext().getResources().getBoolean( |
| 214 | com.android.internal.R.bool.config_voice_capable); |
| 215 | } |
Yorke Lee | d725587 | 2014-08-25 15:03:51 -0700 | [diff] [blame^] | 216 | |
| 217 | private void disconnectCallAndShowErrorDialog(Call call, int errorCode) { |
| 218 | call.disconnect(); |
| 219 | final Intent errorIntent = new Intent(this, ErrorDialogActivity.class); |
| 220 | int errorMessageId = -1; |
| 221 | switch (errorCode) { |
| 222 | case DisconnectCause.INVALID_NUMBER: |
| 223 | errorMessageId = R.string.outgoing_call_error_no_phone_number_supplied; |
| 224 | break; |
| 225 | case DisconnectCause.VOICEMAIL_NUMBER_MISSING: |
| 226 | errorIntent.putExtra(ErrorDialogActivity.SHOW_MISSING_VOICEMAIL_NO_DIALOG_EXTRA, |
| 227 | true); |
| 228 | break; |
| 229 | } |
| 230 | if (errorMessageId != -1) { |
| 231 | errorIntent.putExtra(ErrorDialogActivity.ERROR_MESSAGE_ID_EXTRA, errorMessageId); |
| 232 | } |
| 233 | startActivity(errorIntent); |
| 234 | } |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 235 | } |