blob: 350bf56cebbd08f84ec5986482a5f342a856ed64 [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;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080020import android.content.Context;
Santos Cordon10e68322013-12-12 16:06:56 -080021import android.content.Intent;
22import android.content.res.Configuration;
23import android.os.Bundle;
Santos Cordon523f6052014-02-20 16:39:34 -080024import android.telecomm.CallServiceDescriptor;
25import android.telecomm.TelecommConstants;
Santos Cordon10e68322013-12-12 16:06:56 -080026import android.util.Log;
27import android.widget.Toast;
28
Ben Giladdd8c6082013-12-30 14:44:08 -080029import com.android.telecomm.exceptions.RestrictedCallException;
30
Santos Cordon10e68322013-12-12 16:06:56 -080031/**
32 * Activity that handles system CALL actions and forwards them to {@link CallsManager}.
33 * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY.
Santos Cordon10e68322013-12-12 16:06:56 -080034 */
35public class CallActivity extends Activity {
Ben Gilad1803a832014-01-13 16:58:57 -080036
Santos Cordon10e68322013-12-12 16:06:56 -080037 private static final String TAG = CallActivity.class.getSimpleName();
Ben Giladdd8c6082013-12-30 14:44:08 -080038
39 /** Indicates whether or not debug-level entries should be logged. */
Santos Cordon10e68322013-12-12 16:06:56 -080040 private static boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
41
Ben Giladdd8c6082013-12-30 14:44:08 -080042 private CallsManager mCallsManager = CallsManager.getInstance();
43
Santos Cordon10e68322013-12-12 16:06:56 -080044 /**
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
Santos Cordon523f6052014-02-20 16:39:34 -080072 processIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080073
Santos Cordon523f6052014-02-20 16:39:34 -080074 // This activity does not have associated UI, so close.
Santos Cordon10e68322013-12-12 16:06:56 -080075 finish();
76
77 if (DEBUG) {
78 Log.d(TAG, "onCreate: end");
79 }
80 }
81
82 /**
Santos Cordon523f6052014-02-20 16:39:34 -080083 * Processes intents sent to the activity.
84 *
85 * @param intent The intent.
86 */
87 private void processIntent(Intent intent) {
88 String action = intent.getAction();
89
90 if (Intent.ACTION_CALL.equals(action) ||
91 Intent.ACTION_CALL_PRIVILEGED.equals(action) ||
92 Intent.ACTION_CALL_EMERGENCY.equals(action)) {
93 processOutgoingCallIntent(intent);
94 } else if (TelecommConstants.ACTION_INCOMING_CALL.equals(action)) {
95 processIncomingCallIntent(intent);
96 }
97 }
98
99 /**
Santos Cordon10e68322013-12-12 16:06:56 -0800100 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
101 *
102 * @param intent Call intent containing data about the handle to call.
103 */
Ben Giladdd8c6082013-12-30 14:44:08 -0800104 private void processOutgoingCallIntent(Intent intent) {
105 // TODO(santoscordon): Remove the toast.
Santos Cordon10e68322013-12-12 16:06:56 -0800106 String toastContent = "[" + intent.getAction() + "] " + intent.getDataString();
107 Toast.makeText(this, toastContent, Toast.LENGTH_LONG).show();
Ben Giladdd8c6082013-12-30 14:44:08 -0800108
109 // TODO(gilad): Pull the scheme etc. from the data string as well as any relevant extras
110 // from the intent into structured data and invoke the corresponding CallsManager APIs
111 // based on that. May want to add a static utility to perform that in case the logic is
112 // non-trivial/voluminous.
113 String handle = intent.getDataString();
114 ContactInfo contactInfo = null;
115 try {
Ben Giladd239a032014-02-24 16:42:12 -0800116 mCallsManager.processOutgoingCallIntent(handle, contactInfo);
Ben Giladdd8c6082013-12-30 14:44:08 -0800117 } catch (RestrictedCallException e) {
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800118 // TODO(gilad): Handle or explicitly state to be ignored.
Ben Giladdd8c6082013-12-30 14:44:08 -0800119 }
Santos Cordon10e68322013-12-12 16:06:56 -0800120 }
Santos Cordon523f6052014-02-20 16:39:34 -0800121
122 /**
123 * Processes INCOMING_CALL intents. Grabs the call service informations from the intent extra
124 * and forwards that to the CallsManager to start the incoming call flow.
125 *
126 * @param intent The incoming call intent.
127 */
128 private void processIncomingCallIntent(Intent intent) {
129 CallServiceDescriptor descriptor =
130 intent.getParcelableExtra(TelecommConstants.EXTRA_CALL_SERVICE_DESCRIPTOR);
131 if (descriptor == null) {
132 Log.w(TAG, "Rejecting incoming call due to null descriptor");
133 return;
134 }
135
136 // Notify CallsManager.
137 }
Santos Cordon10e68322013-12-12 16:06:56 -0800138}