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