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