blob: 7fc027f1270a3130adc5fe0ac95a21e7f683ef8a [file] [log] [blame]
Santos Cordon10e68322013-12-12 16:06:56 -08001/*
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
17package com.android.telecomm;
18
19import android.app.Activity;
20import android.content.Intent;
21import android.content.res.Configuration;
22import android.os.Bundle;
Santos Cordon523f6052014-02-20 16:39:34 -080023import android.telecomm.CallServiceDescriptor;
24import android.telecomm.TelecommConstants;
Santos Cordon10e68322013-12-12 16:06:56 -080025import android.util.Log;
26import 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 Cordon10e68322013-12-12 16:06:56 -080031 */
32public class CallActivity extends Activity {
Ben Gilad1803a832014-01-13 16:58:57 -080033
Santos Cordon10e68322013-12-12 16:06:56 -080034 private static final String TAG = CallActivity.class.getSimpleName();
Ben Giladdd8c6082013-12-30 14:44:08 -080035
36 /** Indicates whether or not debug-level entries should be logged. */
Santos Cordon10e68322013-12-12 16:06:56 -080037 private static boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
38
Ben Giladdd8c6082013-12-30 14:44:08 -080039 private CallsManager mCallsManager = CallsManager.getInstance();
40
Santos Cordon10e68322013-12-12 16:06:56 -080041 /**
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 Cordon523f6052014-02-20 16:39:34 -080069 processIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080070
Santos Cordon523f6052014-02-20 16:39:34 -080071 // This activity does not have associated UI, so close.
Santos Cordon10e68322013-12-12 16:06:56 -080072 finish();
73
74 if (DEBUG) {
75 Log.d(TAG, "onCreate: end");
76 }
77 }
78
79 /**
Santos Cordon523f6052014-02-20 16:39:34 -080080 * 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 Cordon10e68322013-12-12 16:06:56 -080097 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
98 *
99 * @param intent Call intent containing data about the handle to call.
100 */
Ben Giladdd8c6082013-12-30 14:44:08 -0800101 private void processOutgoingCallIntent(Intent intent) {
102 // TODO(santoscordon): Remove the toast.
Santos Cordon10e68322013-12-12 16:06:56 -0800103 String toastContent = "[" + intent.getAction() + "] " + intent.getDataString();
104 Toast.makeText(this, toastContent, Toast.LENGTH_LONG).show();
Ben Giladdd8c6082013-12-30 14:44:08 -0800105
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 Gilada0d9f752014-02-26 11:49:03 -0800112 mCallsManager.processOutgoingCallIntent(handle, contactInfo);
Santos Cordon10e68322013-12-12 16:06:56 -0800113 }
Santos Cordon523f6052014-02-20 16:39:34 -0800114
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 Cordon10e68322013-12-12 16:06:56 -0800131}