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