blob: eb65c25eb075f078ae573fbbf2887dc0af6f58d2 [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;
Yorke Leecce5deb2014-06-18 11:27:42 -070020import android.content.ComponentName;
21import android.content.Context;
Santos Cordon10e68322013-12-12 16:06:56 -080022import android.content.Intent;
23import android.content.res.Configuration;
24import android.os.Bundle;
Evan Charlton89176372014-07-19 18:23:09 -070025import android.telecomm.PhoneAccountHandle;
Evan Charltonb35fc312014-07-19 15:02:55 -070026import android.telecomm.TelecommManager;
Yorke Leecce5deb2014-06-18 11:27:42 -070027import android.telecomm.TelecommManager;
28import android.text.TextUtils;
Santos Cordon10e68322013-12-12 16:06:56 -080029
30/**
31 * Activity that handles system CALL actions and forwards them to {@link CallsManager}.
32 * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY.
Yorke Leecce5deb2014-06-18 11:27:42 -070033 *
34 * Pre-L, the only way apps were were allowed to make outgoing emergency calls was the
35 * ACTION_CALL_PRIVILEGED action (which requires the system only CALL_PRIVILEGED permission).
36 *
37 * In L, any app that has the CALL_PRIVILEGED permission can continue to make outgoing emergency
38 * calls via ACTION_CALL_PRIVILEGED.
39 *
40 * In addition, the default dialer (identified via {@link TelecommManager#getDefaultPhoneApp()}
41 * will also be granted the ability to make emergency outgoing calls using the CALL action. In
42 * order to do this, it must call startActivityForResult on the CALL intent to allow its package
43 * name to be passed to {@link CallActivity}. Calling startActivity will continue to work on all
44 * non-emergency numbers just like it did pre-L.
Santos Cordon10e68322013-12-12 16:06:56 -080045 */
46public class CallActivity extends Activity {
Ben Giladdd8c6082013-12-30 14:44:08 -080047 private CallsManager mCallsManager = CallsManager.getInstance();
48
Santos Cordon10e68322013-12-12 16:06:56 -080049 /**
50 * {@inheritDoc}
51 *
52 * This method is the single point of entry for the CALL intent, which is used by built-in apps
53 * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls.
54 */
55 @Override
56 protected void onCreate(Bundle bundle) {
57 super.onCreate(bundle);
58
59 // TODO(santoscordon): This activity will be displayed until the next screen which could be
60 // the in-call UI and error dialog or potentially a call-type selection dialog.
61 // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this
62 // is still desired and add back if necessary. Currently, the activity is set to NoDisplay
63 // theme which means it shows no UI.
64
65 Intent intent = getIntent();
66 Configuration configuration = getResources().getConfiguration();
67
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080068 Log.d(this, "onCreate: this = %s, bundle = %s", this, bundle);
69 Log.d(this, " - intent = %s", intent);
70 Log.d(this, " - configuration = %s", configuration);
Santos Cordon10e68322013-12-12 16:06:56 -080071
72 // TODO(santoscordon): Figure out if there is something to restore from bundle.
73 // See OutgoingCallBroadcaster in services/Telephony for more.
74
Santos Cordon523f6052014-02-20 16:39:34 -080075 processIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080076
Santos Cordon523f6052014-02-20 16:39:34 -080077 // This activity does not have associated UI, so close.
Santos Cordon10e68322013-12-12 16:06:56 -080078 finish();
79
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080080 Log.d(this, "onCreate: end");
Santos Cordon10e68322013-12-12 16:06:56 -080081 }
82
83 /**
Santos Cordon523f6052014-02-20 16:39:34 -080084 * Processes intents sent to the activity.
85 *
86 * @param intent The intent.
87 */
88 private void processIntent(Intent intent) {
89 String action = intent.getAction();
90
Santos Cordona0e5f1a2014-03-31 21:43:00 -070091 // TODO: Check for non-voice capable devices before reading any intents.
92
Santos Cordon523f6052014-02-20 16:39:34 -080093 if (Intent.ACTION_CALL.equals(action) ||
94 Intent.ACTION_CALL_PRIVILEGED.equals(action) ||
95 Intent.ACTION_CALL_EMERGENCY.equals(action)) {
96 processOutgoingCallIntent(intent);
Evan Charltonb35fc312014-07-19 15:02:55 -070097 } else if (TelecommManager.ACTION_INCOMING_CALL.equals(action)) {
Santos Cordon523f6052014-02-20 16:39:34 -080098 processIncomingCallIntent(intent);
99 }
100 }
101
102 /**
Santos Cordon10e68322013-12-12 16:06:56 -0800103 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
104 *
105 * @param intent Call intent containing data about the handle to call.
106 */
Ben Giladdd8c6082013-12-30 14:44:08 -0800107 private void processOutgoingCallIntent(Intent intent) {
Yorke Leecce5deb2014-06-18 11:27:42 -0700108 NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster(
109 mCallsManager, intent, isDefaultDialer());
110 final boolean success = broadcaster.processIntent();
111 setResult(success ? RESULT_OK : RESULT_CANCELED);
Santos Cordon10e68322013-12-12 16:06:56 -0800112 }
Santos Cordon523f6052014-02-20 16:39:34 -0800113
114 /**
Evan Charlton89176372014-07-19 18:23:09 -0700115 * Processes INCOMING_CALL intents. Grabs the connection service information from the intent
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700116 * extra and forwards that to the CallsManager to start the incoming call flow.
Santos Cordon523f6052014-02-20 16:39:34 -0800117 *
118 * @param intent The incoming call intent.
119 */
120 private void processIncomingCallIntent(Intent intent) {
Evan Charlton89176372014-07-19 18:23:09 -0700121 PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(
122 TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE);
123 if (phoneAccountHandle == null) {
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700124 Log.w(this, "Rejecting incoming call due to null phone account");
125 return;
126 }
Evan Charlton89176372014-07-19 18:23:09 -0700127 if (phoneAccountHandle.getComponentName() == null) {
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700128 Log.w(this, "Rejecting incoming call due to null component name");
Santos Cordon523f6052014-02-20 16:39:34 -0800129 return;
130 }
131
Sailesh Nepal664837f2014-07-14 16:31:51 -0700132 Bundle clientExtras = null;
Evan Charltonb35fc312014-07-19 15:02:55 -0700133 if (intent.hasExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS)) {
134 clientExtras = intent.getBundleExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS);
Evan Charltona05805b2014-03-05 08:21:46 -0800135 }
Sailesh Nepal664837f2014-07-14 16:31:51 -0700136 if (clientExtras == null) {
137 clientExtras = Bundle.EMPTY;
138 }
Evan Charltona05805b2014-03-05 08:21:46 -0800139
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700140 Log.d(this, "Processing incoming call from connection service [%s]",
Evan Charlton89176372014-07-19 18:23:09 -0700141 phoneAccountHandle.getComponentName());
142 mCallsManager.processIncomingCallIntent(phoneAccountHandle, clientExtras);
Santos Cordon523f6052014-02-20 16:39:34 -0800143 }
Yorke Leecce5deb2014-06-18 11:27:42 -0700144
145 private boolean isDefaultDialer() {
146 final String packageName = getCallingPackage();
147 if (TextUtils.isEmpty(packageName)) {
148 return false;
149 }
150
151 final TelecommManager telecommManager =
152 (TelecommManager) getSystemService(Context.TELECOMM_SERVICE);
153 final ComponentName defaultPhoneApp = telecommManager.getDefaultPhoneApp();
154 return (defaultPhoneApp != null
155 && TextUtils.equals(defaultPhoneApp.getPackageName(), packageName));
156 }
Santos Cordon10e68322013-12-12 16:06:56 -0800157}