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; |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 26 | import android.telecomm.PhoneAccountHandle; |
Evan Charlton | b35fc31 | 2014-07-19 15:02:55 -0700 | [diff] [blame] | 27 | import android.telecomm.TelecommManager; |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 28 | import android.telecomm.TelecommManager; |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 29 | import android.telephony.PhoneNumberUtils; |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame^] | 30 | import android.telephony.TelephonyManager; |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 31 | import android.text.TextUtils; |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Activity that handles system CALL actions and forwards them to {@link CallsManager}. |
| 35 | * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY. |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 36 | * |
| 37 | * Pre-L, the only way apps were were allowed to make outgoing emergency calls was the |
| 38 | * ACTION_CALL_PRIVILEGED action (which requires the system only CALL_PRIVILEGED permission). |
| 39 | * |
| 40 | * In L, any app that has the CALL_PRIVILEGED permission can continue to make outgoing emergency |
| 41 | * calls via ACTION_CALL_PRIVILEGED. |
| 42 | * |
| 43 | * In addition, the default dialer (identified via {@link TelecommManager#getDefaultPhoneApp()} |
| 44 | * will also be granted the ability to make emergency outgoing calls using the CALL action. In |
| 45 | * order to do this, it must call startActivityForResult on the CALL intent to allow its package |
| 46 | * name to be passed to {@link CallActivity}. Calling startActivity will continue to work on all |
| 47 | * non-emergency numbers just like it did pre-L. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 48 | */ |
| 49 | public class CallActivity extends Activity { |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 50 | private CallsManager mCallsManager = CallsManager.getInstance(); |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame^] | 51 | private boolean mIsVoiceCapable; |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 52 | |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 53 | /** |
| 54 | * {@inheritDoc} |
| 55 | * |
| 56 | * This method is the single point of entry for the CALL intent, which is used by built-in apps |
| 57 | * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls. |
| 58 | */ |
| 59 | @Override |
| 60 | protected void onCreate(Bundle bundle) { |
| 61 | super.onCreate(bundle); |
| 62 | |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame^] | 63 | mIsVoiceCapable = isVoiceCapable(); |
| 64 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 65 | // 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] | 66 | // the in-call UI and error dialog or potentially a call-type selection dialog. |
| 67 | // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this |
| 68 | // is still desired and add back if necessary. Currently, the activity is set to NoDisplay |
| 69 | // theme which means it shows no UI. |
| 70 | |
| 71 | Intent intent = getIntent(); |
| 72 | Configuration configuration = getResources().getConfiguration(); |
| 73 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 74 | Log.d(this, "onCreate: this = %s, bundle = %s", this, bundle); |
| 75 | Log.d(this, " - intent = %s", intent); |
| 76 | Log.d(this, " - configuration = %s", configuration); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 77 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 78 | // TODO: Figure out if there is something to restore from bundle. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 79 | // See OutgoingCallBroadcaster in services/Telephony for more. |
| 80 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 81 | processIntent(intent); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 82 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 83 | // This activity does not have associated UI, so close. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 84 | finish(); |
| 85 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 86 | Log.d(this, "onCreate: end"); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 90 | * Processes intents sent to the activity. |
| 91 | * |
| 92 | * @param intent The intent. |
| 93 | */ |
| 94 | private void processIntent(Intent intent) { |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame^] | 95 | // Ensure call intents are not processed on devices that are not capable of calling. |
| 96 | if (!mIsVoiceCapable) { |
| 97 | setResult(RESULT_CANCELED); |
| 98 | return; |
| 99 | } |
| 100 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 101 | String action = intent.getAction(); |
| 102 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 103 | // TODO: Check for non-voice capable devices before reading any intents. |
| 104 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 105 | if (Intent.ACTION_CALL.equals(action) || |
| 106 | Intent.ACTION_CALL_PRIVILEGED.equals(action) || |
| 107 | Intent.ACTION_CALL_EMERGENCY.equals(action)) { |
| 108 | processOutgoingCallIntent(intent); |
Evan Charlton | b35fc31 | 2014-07-19 15:02:55 -0700 | [diff] [blame] | 109 | } else if (TelecommManager.ACTION_INCOMING_CALL.equals(action)) { |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 110 | processIncomingCallIntent(intent); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 115 | * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents. |
| 116 | * |
| 117 | * @param intent Call intent containing data about the handle to call. |
| 118 | */ |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 119 | private void processOutgoingCallIntent(Intent intent) { |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame^] | 120 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 121 | String uriString = intent.getData().getSchemeSpecificPart(); |
| 122 | Uri handle = Uri.fromParts( |
| 123 | PhoneNumberUtils.isUriNumber(uriString) ? "sip" : "tel", uriString, null); |
| 124 | PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra( |
| 125 | TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE); |
| 126 | |
| 127 | // Send to CallsManager to ensure the InCallUI gets kicked off before the broadcast returns |
| 128 | Call call = mCallsManager.startOutgoingCall(handle, phoneAccountHandle); |
| 129 | |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 130 | NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster( |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 131 | mCallsManager, call, intent, isDefaultDialer()); |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 132 | final boolean success = broadcaster.processIntent(); |
| 133 | setResult(success ? RESULT_OK : RESULT_CANCELED); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 134 | } |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 135 | |
| 136 | /** |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 137 | * Processes INCOMING_CALL intents. Grabs the connection service information from the intent |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 138 | * 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] | 139 | * |
| 140 | * @param intent The incoming call intent. |
| 141 | */ |
| 142 | private void processIncomingCallIntent(Intent intent) { |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 143 | PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra( |
| 144 | TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE); |
| 145 | if (phoneAccountHandle == null) { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 146 | Log.w(this, "Rejecting incoming call due to null phone account"); |
| 147 | return; |
| 148 | } |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 149 | if (phoneAccountHandle.getComponentName() == null) { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 150 | Log.w(this, "Rejecting incoming call due to null component name"); |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 154 | Bundle clientExtras = null; |
Evan Charlton | b35fc31 | 2014-07-19 15:02:55 -0700 | [diff] [blame] | 155 | if (intent.hasExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS)) { |
| 156 | clientExtras = intent.getBundleExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS); |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 157 | } |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 158 | if (clientExtras == null) { |
| 159 | clientExtras = Bundle.EMPTY; |
| 160 | } |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 161 | |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 162 | Log.d(this, "Processing incoming call from connection service [%s]", |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 163 | phoneAccountHandle.getComponentName()); |
| 164 | mCallsManager.processIncomingCallIntent(phoneAccountHandle, clientExtras); |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 165 | } |
Yorke Lee | cce5deb | 2014-06-18 11:27:42 -0700 | [diff] [blame] | 166 | |
| 167 | private boolean isDefaultDialer() { |
| 168 | final String packageName = getCallingPackage(); |
| 169 | if (TextUtils.isEmpty(packageName)) { |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | final TelecommManager telecommManager = |
| 174 | (TelecommManager) getSystemService(Context.TELECOMM_SERVICE); |
| 175 | final ComponentName defaultPhoneApp = telecommManager.getDefaultPhoneApp(); |
| 176 | return (defaultPhoneApp != null |
| 177 | && TextUtils.equals(defaultPhoneApp.getPackageName(), packageName)); |
| 178 | } |
Tyler Gunn | 8ad2d8d | 2014-08-13 14:37:16 -0700 | [diff] [blame^] | 179 | |
| 180 | /** |
| 181 | * Returns whether the device is voice-capable (e.g. a phone vs a tablet). |
| 182 | * |
| 183 | * @return {@code True} if the device is voice-capable. |
| 184 | */ |
| 185 | private boolean isVoiceCapable() { |
| 186 | return getApplicationContext().getResources().getBoolean( |
| 187 | com.android.internal.R.bool.config_voice_capable); |
| 188 | } |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 189 | } |