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; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 20 | import android.content.Context; |
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; |
| 24 | import android.util.Log; |
| 25 | import android.widget.Toast; |
| 26 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 27 | import com.android.telecomm.exceptions.CallServiceUnavailableException; |
| 28 | import com.android.telecomm.exceptions.RestrictedCallException; |
| 29 | |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 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. |
| 33 | * TODO(santoscordon): Connect with CallsManager. |
| 34 | */ |
| 35 | public class CallActivity extends Activity { |
Ben Gilad | 1803a83 | 2014-01-13 16:58:57 -0800 | [diff] [blame^] | 36 | |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 37 | private static final String TAG = CallActivity.class.getSimpleName(); |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 38 | |
| 39 | /** Indicates whether or not debug-level entries should be logged. */ |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 40 | private static boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 41 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 42 | private CallsManager mCallsManager = CallsManager.getInstance(); |
| 43 | |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 44 | /** |
| 45 | * {@inheritDoc} |
| 46 | * |
| 47 | * This method is the single point of entry for the CALL intent, which is used by built-in apps |
| 48 | * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls. |
| 49 | */ |
| 50 | @Override |
| 51 | protected void onCreate(Bundle bundle) { |
| 52 | super.onCreate(bundle); |
| 53 | |
| 54 | // TODO(santoscordon): This activity will be displayed until the next screen which could be |
| 55 | // the in-call UI and error dialog or potentially a call-type selection dialog. |
| 56 | // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this |
| 57 | // is still desired and add back if necessary. Currently, the activity is set to NoDisplay |
| 58 | // theme which means it shows no UI. |
| 59 | |
| 60 | Intent intent = getIntent(); |
| 61 | Configuration configuration = getResources().getConfiguration(); |
| 62 | |
| 63 | if (DEBUG) { |
| 64 | Log.d(TAG, "onCreate: this = " + this + ", bundle= " + bundle); |
| 65 | Log.d(TAG, " - intent = " + intent); |
| 66 | Log.d(TAG, " - configuration = " + configuration); |
| 67 | } |
| 68 | |
| 69 | // TODO(santoscordon): Figure out if there is something to restore from bundle. |
| 70 | // See OutgoingCallBroadcaster in services/Telephony for more. |
| 71 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 72 | processOutgoingCallIntent(intent); |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 73 | |
| 74 | // TODO(santoscordon): Remove this finish() once this app does more than just show a toast. |
| 75 | finish(); |
| 76 | |
| 77 | if (DEBUG) { |
| 78 | Log.d(TAG, "onCreate: end"); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents. |
| 84 | * |
| 85 | * @param intent Call intent containing data about the handle to call. |
| 86 | */ |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 87 | private void processOutgoingCallIntent(Intent intent) { |
| 88 | // TODO(santoscordon): Remove the toast. |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 89 | String toastContent = "[" + intent.getAction() + "] " + intent.getDataString(); |
| 90 | Toast.makeText(this, toastContent, Toast.LENGTH_LONG).show(); |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 91 | |
| 92 | // TODO(gilad): Pull the scheme etc. from the data string as well as any relevant extras |
| 93 | // from the intent into structured data and invoke the corresponding CallsManager APIs |
| 94 | // based on that. May want to add a static utility to perform that in case the logic is |
| 95 | // non-trivial/voluminous. |
| 96 | String handle = intent.getDataString(); |
| 97 | ContactInfo contactInfo = null; |
| 98 | try { |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 99 | // we use the application context because the lifetime of the call services bound on |
| 100 | // this context extends beyond the life of this activity. |
| 101 | Context context = getApplicationContext(); |
| 102 | |
| 103 | mCallsManager.processOutgoingCallIntent(handle, contactInfo, context); |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 104 | } catch (RestrictedCallException e) { |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 105 | // TODO(gilad): Handle or explicitly state to be ignored. |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 106 | } catch (CallServiceUnavailableException e) { |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 107 | // TODO(gilad): Handle or explicitly state to be ignored. If both should be ignored, |
| 108 | // consider extending from the same base class and simplify the handling code to a |
| 109 | // single catch clause. |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 110 | } |
Santos Cordon | 10e6832 | 2013-12-12 16:06:56 -0800 | [diff] [blame] | 111 | } |
| 112 | } |