blob: 04a9ff14ba3ff8cdad7e9887e9ca783d572eebf1 [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;
Sailesh Nepal905dfba2014-07-14 08:20:41 -070023import android.telecomm.PhoneAccount;
Evan Charltonb35fc312014-07-19 15:02:55 -070024import android.telecomm.TelecommManager;
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);
Evan Charltonb35fc312014-07-19 15:02:55 -070082 } else if (TelecommManager.ACTION_INCOMING_CALL.equals(action)) {
Santos Cordon523f6052014-02-20 16:39:34 -080083 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) {
Yorke Lee33501632014-03-17 19:24:12 -070093 NewOutgoingCallIntentBroadcaster broadcaster =
Yorke Lee6f3f7af2014-07-11 10:59:46 -070094 new NewOutgoingCallIntentBroadcaster(mCallsManager, intent);
Yorke Leed362fe32014-06-19 22:24:28 +000095 broadcaster.processIntent();
Santos Cordon10e68322013-12-12 16:06:56 -080096 }
Santos Cordon523f6052014-02-20 16:39:34 -080097
98 /**
Sailesh Nepalc92c4362014-07-04 18:33:21 -070099 * Processes INCOMING_CALL intents. Grabs the connection service informations from the intent
100 * extra and forwards that to the CallsManager to start the incoming call flow.
Santos Cordon523f6052014-02-20 16:39:34 -0800101 *
102 * @param intent The incoming call intent.
103 */
104 private void processIncomingCallIntent(Intent intent) {
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700105 PhoneAccount phoneAccount = intent.getParcelableExtra(
Evan Charltonb35fc312014-07-19 15:02:55 -0700106 TelecommManager.EXTRA_PHONE_ACCOUNT);
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700107 if (phoneAccount == null) {
108 Log.w(this, "Rejecting incoming call due to null phone account");
109 return;
110 }
111 if (phoneAccount.getComponentName() == null) {
112 Log.w(this, "Rejecting incoming call due to null component name");
Santos Cordon523f6052014-02-20 16:39:34 -0800113 return;
114 }
115
Sailesh Nepal664837f2014-07-14 16:31:51 -0700116 Bundle clientExtras = null;
Evan Charltonb35fc312014-07-19 15:02:55 -0700117 if (intent.hasExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS)) {
118 clientExtras = intent.getBundleExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS);
Evan Charltona05805b2014-03-05 08:21:46 -0800119 }
Sailesh Nepal664837f2014-07-14 16:31:51 -0700120 if (clientExtras == null) {
121 clientExtras = Bundle.EMPTY;
122 }
Evan Charltona05805b2014-03-05 08:21:46 -0800123
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700124 Log.d(this, "Processing incoming call from connection service [%s]",
125 phoneAccount.getComponentName());
126 mCallsManager.processIncomingCallIntent(phoneAccount, clientExtras);
Santos Cordon523f6052014-02-20 16:39:34 -0800127 }
Santos Cordon10e68322013-12-12 16:06:56 -0800128}