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; |
| 20 | import android.content.Intent; |
| 21 | import android.content.res.Configuration; |
| 22 | import android.os.Bundle; |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame^] | 23 | import android.telecomm.PhoneAccount; |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 24 | import android.telecomm.TelecommConstants; |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Activity that handles system CALL actions and forwards them to {@link CallsManager}. |
| 28 | * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 29 | */ |
| 30 | public class CallActivity extends Activity { |
Yorke Lee | d362fe3 | 2014-06-19 22:24:28 +0000 | [diff] [blame] | 31 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 32 | private CallsManager mCallsManager = CallsManager.getInstance(); |
| 33 | |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 34 | /** |
| 35 | * {@inheritDoc} |
| 36 | * |
| 37 | * This method is the single point of entry for the CALL intent, which is used by built-in apps |
| 38 | * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls. |
| 39 | */ |
| 40 | @Override |
| 41 | protected void onCreate(Bundle bundle) { |
| 42 | super.onCreate(bundle); |
| 43 | |
| 44 | // TODO(santoscordon): This activity will be displayed until the next screen which could be |
| 45 | // the in-call UI and error dialog or potentially a call-type selection dialog. |
| 46 | // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this |
| 47 | // is still desired and add back if necessary. Currently, the activity is set to NoDisplay |
| 48 | // theme which means it shows no UI. |
| 49 | |
| 50 | Intent intent = getIntent(); |
| 51 | Configuration configuration = getResources().getConfiguration(); |
| 52 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 53 | Log.d(this, "onCreate: this = %s, bundle = %s", this, bundle); |
| 54 | Log.d(this, " - intent = %s", intent); |
| 55 | Log.d(this, " - configuration = %s", configuration); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 56 | |
| 57 | // TODO(santoscordon): Figure out if there is something to restore from bundle. |
| 58 | // See OutgoingCallBroadcaster in services/Telephony for more. |
| 59 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 60 | processIntent(intent); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 61 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 62 | // This activity does not have associated UI, so close. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 63 | finish(); |
| 64 | |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 65 | Log.d(this, "onCreate: end"); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 69 | * Processes intents sent to the activity. |
| 70 | * |
| 71 | * @param intent The intent. |
| 72 | */ |
| 73 | private void processIntent(Intent intent) { |
| 74 | String action = intent.getAction(); |
| 75 | |
Santos Cordon | a0e5f1a | 2014-03-31 21:43:00 -0700 | [diff] [blame] | 76 | // TODO: Check for non-voice capable devices before reading any intents. |
| 77 | |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 78 | if (Intent.ACTION_CALL.equals(action) || |
| 79 | Intent.ACTION_CALL_PRIVILEGED.equals(action) || |
| 80 | Intent.ACTION_CALL_EMERGENCY.equals(action)) { |
| 81 | processOutgoingCallIntent(intent); |
| 82 | } else if (TelecommConstants.ACTION_INCOMING_CALL.equals(action)) { |
| 83 | processIncomingCallIntent(intent); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 88 | * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents. |
| 89 | * |
| 90 | * @param intent Call intent containing data about the handle to call. |
| 91 | */ |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 92 | private void processOutgoingCallIntent(Intent intent) { |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 93 | NewOutgoingCallIntentBroadcaster broadcaster = |
Yorke Lee | 6f3f7af | 2014-07-11 10:59:46 -0700 | [diff] [blame] | 94 | new NewOutgoingCallIntentBroadcaster(mCallsManager, intent); |
Yorke Lee | d362fe3 | 2014-06-19 22:24:28 +0000 | [diff] [blame] | 95 | broadcaster.processIntent(); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 96 | } |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 97 | |
| 98 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 99 | * Processes INCOMING_CALL intents. Grabs the connection service informations from the intent |
| 100 | * 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] | 101 | * |
| 102 | * @param intent The incoming call intent. |
| 103 | */ |
| 104 | private void processIncomingCallIntent(Intent intent) { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame^] | 105 | PhoneAccount phoneAccount = intent.getParcelableExtra( |
| 106 | TelecommConstants.EXTRA_PHONE_ACCOUNT); |
| 107 | if (phoneAccount == null) { |
| 108 | Log.w(this, "Rejecting incoming call due to null phone account"); |
| 109 | return; |
| 110 | } |
| 111 | if (phoneAccount.getComponentName() == null) { |
| 112 | Log.w(this, "Rejecting incoming call due to null component name"); |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 113 | return; |
| 114 | } |
| 115 | |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 116 | Bundle clientExtras = Bundle.EMPTY; |
| 117 | if (intent.hasExtra(TelecommConstants.EXTRA_INCOMING_CALL_EXTRAS)) { |
| 118 | clientExtras = intent.getBundleExtra(TelecommConstants.EXTRA_INCOMING_CALL_EXTRAS); |
| 119 | } |
| 120 | |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame^] | 121 | Log.d(this, "Processing incoming call from connection service [%s]", |
| 122 | phoneAccount.getComponentName()); |
| 123 | mCallsManager.processIncomingCallIntent(phoneAccount, clientExtras); |
Santos Cordon | 523f605 | 2014-02-20 16:39:34 -0800 | [diff] [blame] | 124 | } |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 125 | } |