blob: 0e66d321b7cacfcbea03190b2b6f9bc0656b9ad8 [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 -080025
26/**
27 * Activity that handles system CALL actions and forwards them to {@link CallsManager}.
28 * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY.
Santos Cordon10e68322013-12-12 16:06:56 -080029 */
30public class CallActivity extends Activity {
Yorke Leed362fe32014-06-19 22:24:28 +000031
Ben Giladdd8c6082013-12-30 14:44:08 -080032 private CallsManager mCallsManager = CallsManager.getInstance();
33
Santos Cordon10e68322013-12-12 16:06:56 -080034 /**
35 * {@inheritDoc}
36 *
37 * This method is the single point of entry for the CALL intent, which is used by built-in apps
38 * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls.
39 */
40 @Override
41 protected void onCreate(Bundle bundle) {
42 super.onCreate(bundle);
43
44 // TODO(santoscordon): This activity will be displayed until the next screen which could be
45 // the in-call UI and error dialog or potentially a call-type selection dialog.
46 // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this
47 // is still desired and add back if necessary. Currently, the activity is set to NoDisplay
48 // theme which means it shows no UI.
49
50 Intent intent = getIntent();
51 Configuration configuration = getResources().getConfiguration();
52
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080053 Log.d(this, "onCreate: this = %s, bundle = %s", this, bundle);
54 Log.d(this, " - intent = %s", intent);
55 Log.d(this, " - configuration = %s", configuration);
Santos Cordon10e68322013-12-12 16:06:56 -080056
57 // TODO(santoscordon): Figure out if there is something to restore from bundle.
58 // See OutgoingCallBroadcaster in services/Telephony for more.
59
Santos Cordon523f6052014-02-20 16:39:34 -080060 processIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080061
Santos Cordon523f6052014-02-20 16:39:34 -080062 // This activity does not have associated UI, so close.
Santos Cordon10e68322013-12-12 16:06:56 -080063 finish();
64
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080065 Log.d(this, "onCreate: end");
Santos Cordon10e68322013-12-12 16:06:56 -080066 }
67
68 /**
Santos Cordon523f6052014-02-20 16:39:34 -080069 * Processes intents sent to the activity.
70 *
71 * @param intent The intent.
72 */
73 private void processIntent(Intent intent) {
74 String action = intent.getAction();
75
Santos Cordona0e5f1a2014-03-31 21:43:00 -070076 // TODO: Check for non-voice capable devices before reading any intents.
77
Santos Cordon523f6052014-02-20 16:39:34 -080078 if (Intent.ACTION_CALL.equals(action) ||
79 Intent.ACTION_CALL_PRIVILEGED.equals(action) ||
80 Intent.ACTION_CALL_EMERGENCY.equals(action)) {
81 processOutgoingCallIntent(intent);
82 } else if (TelecommConstants.ACTION_INCOMING_CALL.equals(action)) {
83 processIncomingCallIntent(intent);
84 }
85 }
86
87 /**
Santos Cordon10e68322013-12-12 16:06:56 -080088 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
89 *
90 * @param intent Call intent containing data about the handle to call.
91 */
Ben Giladdd8c6082013-12-30 14:44:08 -080092 private void processOutgoingCallIntent(Intent intent) {
Ben Giladdd8c6082013-12-30 14:44:08 -080093 ContactInfo contactInfo = null;
Yorke Lee33501632014-03-17 19:24:12 -070094 NewOutgoingCallIntentBroadcaster broadcaster =
Yorke Leed362fe32014-06-19 22:24:28 +000095 new NewOutgoingCallIntentBroadcaster(mCallsManager, contactInfo, intent);
96 broadcaster.processIntent();
Santos Cordon10e68322013-12-12 16:06:56 -080097 }
Santos Cordon523f6052014-02-20 16:39:34 -080098
99 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700100 * Processes INCOMING_CALL intents. Grabs the connection service informations from the intent
101 * extra and forwards that to the CallsManager to start the incoming call flow.
Santos Cordon523f6052014-02-20 16:39:34 -0800102 *
103 * @param intent The incoming call intent.
104 */
105 private void processIncomingCallIntent(Intent intent) {
106 CallServiceDescriptor descriptor =
107 intent.getParcelableExtra(TelecommConstants.EXTRA_CALL_SERVICE_DESCRIPTOR);
108 if (descriptor == null) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800109 Log.w(this, "Rejecting incoming call due to null descriptor");
Santos Cordon523f6052014-02-20 16:39:34 -0800110 return;
111 }
112
Evan Charltona05805b2014-03-05 08:21:46 -0800113 Bundle clientExtras = Bundle.EMPTY;
114 if (intent.hasExtra(TelecommConstants.EXTRA_INCOMING_CALL_EXTRAS)) {
115 clientExtras = intent.getBundleExtra(TelecommConstants.EXTRA_INCOMING_CALL_EXTRAS);
116 }
117
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700118 Log.d(this, "Processing incoming call from connection service [%s]", descriptor);
Evan Charltona05805b2014-03-05 08:21:46 -0800119 mCallsManager.processIncomingCallIntent(descriptor, clientExtras);
Santos Cordon523f6052014-02-20 16:39:34 -0800120 }
Santos Cordon10e68322013-12-12 16:06:56 -0800121}