blob: 2418a0aaeb58ce50cf6d2f3cd6ed9d067b8b5680 [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.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 Cordon10e68322013-12-12 16:06:56 -080030 */
31public class CallActivity extends Activity {
Ben Gilad1803a832014-01-13 16:58:57 -080032
Ben Giladdd8c6082013-12-30 14:44:08 -080033 private CallsManager mCallsManager = CallsManager.getInstance();
34
Santos Cordon10e68322013-12-12 16:06:56 -080035 /**
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 Nepalf1c191d2014-03-07 18:17:39 -080054 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 Cordon10e68322013-12-12 16:06:56 -080057
58 // TODO(santoscordon): Figure out if there is something to restore from bundle.
59 // See OutgoingCallBroadcaster in services/Telephony for more.
60
Santos Cordon523f6052014-02-20 16:39:34 -080061 processIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080062
Santos Cordon523f6052014-02-20 16:39:34 -080063 // This activity does not have associated UI, so close.
Santos Cordon10e68322013-12-12 16:06:56 -080064 finish();
65
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080066 Log.d(this, "onCreate: end");
Santos Cordon10e68322013-12-12 16:06:56 -080067 }
68
69 /**
Santos Cordon523f6052014-02-20 16:39:34 -080070 * 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 Cordon10e68322013-12-12 16:06:56 -080087 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
88 *
89 * @param intent Call intent containing data about the handle to call.
90 */
Ben Giladdd8c6082013-12-30 14:44:08 -080091 private void processOutgoingCallIntent(Intent intent) {
92 // TODO(santoscordon): Remove the toast.
Santos Cordon10e68322013-12-12 16:06:56 -080093 String toastContent = "[" + intent.getAction() + "] " + intent.getDataString();
94 Toast.makeText(this, toastContent, Toast.LENGTH_LONG).show();
Ben Giladdd8c6082013-12-30 14:44:08 -080095
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 Gilada0d9f752014-02-26 11:49:03 -0800102 mCallsManager.processOutgoingCallIntent(handle, contactInfo);
Santos Cordon10e68322013-12-12 16:06:56 -0800103 }
Santos Cordon523f6052014-02-20 16:39:34 -0800104
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 Nepalf1c191d2014-03-07 18:17:39 -0800115 Log.w(this, "Rejecting incoming call due to null descriptor");
Santos Cordon523f6052014-02-20 16:39:34 -0800116 return;
117 }
118
Evan Charltona05805b2014-03-05 08:21:46 -0800119 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 Nepalf1c191d2014-03-07 18:17:39 -0800124 Log.d(this, "Processing incoming call from call service [%s]", descriptor);
Evan Charltona05805b2014-03-05 08:21:46 -0800125 mCallsManager.processIncomingCallIntent(descriptor, clientExtras);
Santos Cordon523f6052014-02-20 16:39:34 -0800126 }
Santos Cordon10e68322013-12-12 16:06:56 -0800127}