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