blob: 06cc9cb6dc07afa912ad45db14314ddcb23f6201 [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;
Nancy Chen0d3076c2014-07-30 14:45:44 -070024import android.net.Uri;
Santos Cordon10e68322013-12-12 16:06:56 -080025import android.os.Bundle;
Evan Charlton89176372014-07-19 18:23:09 -070026import android.telecomm.PhoneAccountHandle;
Evan Charltonb35fc312014-07-19 15:02:55 -070027import android.telecomm.TelecommManager;
Nancy Chen0d3076c2014-07-30 14:45:44 -070028import android.telephony.PhoneNumberUtils;
Tyler Gunn8ad2d8d2014-08-13 14:37:16 -070029import android.telephony.TelephonyManager;
Yorke Leecce5deb2014-06-18 11:27:42 -070030import android.text.TextUtils;
Santos Cordon10e68322013-12-12 16:06:56 -080031
32/**
33 * Activity that handles system CALL actions and forwards them to {@link CallsManager}.
34 * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY.
Yorke Leecce5deb2014-06-18 11:27:42 -070035 *
36 * Pre-L, the only way apps were were allowed to make outgoing emergency calls was the
37 * ACTION_CALL_PRIVILEGED action (which requires the system only CALL_PRIVILEGED permission).
38 *
39 * In L, any app that has the CALL_PRIVILEGED permission can continue to make outgoing emergency
40 * calls via ACTION_CALL_PRIVILEGED.
41 *
42 * In addition, the default dialer (identified via {@link TelecommManager#getDefaultPhoneApp()}
43 * will also be granted the ability to make emergency outgoing calls using the CALL action. In
44 * order to do this, it must call startActivityForResult on the CALL intent to allow its package
45 * name to be passed to {@link CallActivity}. Calling startActivity will continue to work on all
46 * non-emergency numbers just like it did pre-L.
Santos Cordon10e68322013-12-12 16:06:56 -080047 */
48public class CallActivity extends Activity {
Ben Giladdd8c6082013-12-30 14:44:08 -080049 private CallsManager mCallsManager = CallsManager.getInstance();
Tyler Gunn8ad2d8d2014-08-13 14:37:16 -070050 private boolean mIsVoiceCapable;
Ben Giladdd8c6082013-12-30 14:44:08 -080051
Santos Cordon10e68322013-12-12 16:06:56 -080052 /**
53 * {@inheritDoc}
54 *
55 * This method is the single point of entry for the CALL intent, which is used by built-in apps
56 * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls.
57 */
58 @Override
59 protected void onCreate(Bundle bundle) {
60 super.onCreate(bundle);
61
Tyler Gunn8ad2d8d2014-08-13 14:37:16 -070062 mIsVoiceCapable = isVoiceCapable();
63
Santos Cordondf399862014-08-06 04:39:15 -070064 // TODO: This activity will be displayed until the next screen which could be
Santos Cordon10e68322013-12-12 16:06:56 -080065 // the in-call UI and error dialog or potentially a call-type selection dialog.
66 // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this
67 // is still desired and add back if necessary. Currently, the activity is set to NoDisplay
68 // theme which means it shows no UI.
69
70 Intent intent = getIntent();
71 Configuration configuration = getResources().getConfiguration();
72
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080073 Log.d(this, "onCreate: this = %s, bundle = %s", this, bundle);
74 Log.d(this, " - intent = %s", intent);
75 Log.d(this, " - configuration = %s", configuration);
Santos Cordon10e68322013-12-12 16:06:56 -080076
Santos Cordondf399862014-08-06 04:39:15 -070077 // TODO: Figure out if there is something to restore from bundle.
Santos Cordon10e68322013-12-12 16:06:56 -080078 // See OutgoingCallBroadcaster in services/Telephony for more.
79
Santos Cordon523f6052014-02-20 16:39:34 -080080 processIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080081
Santos Cordon523f6052014-02-20 16:39:34 -080082 // This activity does not have associated UI, so close.
Santos Cordon10e68322013-12-12 16:06:56 -080083 finish();
84
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080085 Log.d(this, "onCreate: end");
Santos Cordon10e68322013-12-12 16:06:56 -080086 }
87
88 /**
Santos Cordon523f6052014-02-20 16:39:34 -080089 * Processes intents sent to the activity.
90 *
91 * @param intent The intent.
92 */
93 private void processIntent(Intent intent) {
Tyler Gunn8ad2d8d2014-08-13 14:37:16 -070094 // Ensure call intents are not processed on devices that are not capable of calling.
95 if (!mIsVoiceCapable) {
96 setResult(RESULT_CANCELED);
97 return;
98 }
99
Santos Cordon523f6052014-02-20 16:39:34 -0800100 String action = intent.getAction();
101
Santos Cordona0e5f1a2014-03-31 21:43:00 -0700102 // TODO: Check for non-voice capable devices before reading any intents.
103
Santos Cordon523f6052014-02-20 16:39:34 -0800104 if (Intent.ACTION_CALL.equals(action) ||
105 Intent.ACTION_CALL_PRIVILEGED.equals(action) ||
106 Intent.ACTION_CALL_EMERGENCY.equals(action)) {
107 processOutgoingCallIntent(intent);
Evan Charltonb35fc312014-07-19 15:02:55 -0700108 } else if (TelecommManager.ACTION_INCOMING_CALL.equals(action)) {
Santos Cordon523f6052014-02-20 16:39:34 -0800109 processIncomingCallIntent(intent);
110 }
111 }
112
113 /**
Santos Cordon10e68322013-12-12 16:06:56 -0800114 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
115 *
116 * @param intent Call intent containing data about the handle to call.
117 */
Ben Giladdd8c6082013-12-30 14:44:08 -0800118 private void processOutgoingCallIntent(Intent intent) {
Tyler Gunn8ad2d8d2014-08-13 14:37:16 -0700119
Nancy Chen0d3076c2014-07-30 14:45:44 -0700120 String uriString = intent.getData().getSchemeSpecificPart();
121 Uri handle = Uri.fromParts(
122 PhoneNumberUtils.isUriNumber(uriString) ? "sip" : "tel", uriString, null);
123 PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(
124 TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE);
125
Nancy Chena9d91da2014-08-12 14:31:06 -0700126 Bundle clientExtras = null;
127 if (intent.hasExtra(TelecommManager.EXTRA_OUTGOING_CALL_EXTRAS)) {
128 clientExtras = intent.getBundleExtra(TelecommManager.EXTRA_OUTGOING_CALL_EXTRAS);
129 }
130 if (clientExtras == null) {
131 clientExtras = Bundle.EMPTY;
132 }
133
Nancy Chen0d3076c2014-07-30 14:45:44 -0700134 // Send to CallsManager to ensure the InCallUI gets kicked off before the broadcast returns
Nancy Chena9d91da2014-08-12 14:31:06 -0700135 Call call = mCallsManager.startOutgoingCall(handle, phoneAccountHandle, clientExtras);
Nancy Chen0d3076c2014-07-30 14:45:44 -0700136
Yorke Leecce5deb2014-06-18 11:27:42 -0700137 NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster(
Nancy Chen0d3076c2014-07-30 14:45:44 -0700138 mCallsManager, call, intent, isDefaultDialer());
Yorke Leecce5deb2014-06-18 11:27:42 -0700139 final boolean success = broadcaster.processIntent();
140 setResult(success ? RESULT_OK : RESULT_CANCELED);
Santos Cordon10e68322013-12-12 16:06:56 -0800141 }
Santos Cordon523f6052014-02-20 16:39:34 -0800142
143 /**
Evan Charlton89176372014-07-19 18:23:09 -0700144 * Processes INCOMING_CALL intents. Grabs the connection service information from the intent
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700145 * extra and forwards that to the CallsManager to start the incoming call flow.
Santos Cordon523f6052014-02-20 16:39:34 -0800146 *
147 * @param intent The incoming call intent.
148 */
149 private void processIncomingCallIntent(Intent intent) {
Evan Charlton89176372014-07-19 18:23:09 -0700150 PhoneAccountHandle phoneAccountHandle = intent.getParcelableExtra(
151 TelecommManager.EXTRA_PHONE_ACCOUNT_HANDLE);
152 if (phoneAccountHandle == null) {
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700153 Log.w(this, "Rejecting incoming call due to null phone account");
154 return;
155 }
Evan Charlton89176372014-07-19 18:23:09 -0700156 if (phoneAccountHandle.getComponentName() == null) {
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700157 Log.w(this, "Rejecting incoming call due to null component name");
Santos Cordon523f6052014-02-20 16:39:34 -0800158 return;
159 }
160
Sailesh Nepal664837f2014-07-14 16:31:51 -0700161 Bundle clientExtras = null;
Evan Charltonb35fc312014-07-19 15:02:55 -0700162 if (intent.hasExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS)) {
163 clientExtras = intent.getBundleExtra(TelecommManager.EXTRA_INCOMING_CALL_EXTRAS);
Evan Charltona05805b2014-03-05 08:21:46 -0800164 }
Sailesh Nepal664837f2014-07-14 16:31:51 -0700165 if (clientExtras == null) {
166 clientExtras = Bundle.EMPTY;
167 }
Evan Charltona05805b2014-03-05 08:21:46 -0800168
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700169 Log.d(this, "Processing incoming call from connection service [%s]",
Evan Charlton89176372014-07-19 18:23:09 -0700170 phoneAccountHandle.getComponentName());
171 mCallsManager.processIncomingCallIntent(phoneAccountHandle, clientExtras);
Santos Cordon523f6052014-02-20 16:39:34 -0800172 }
Yorke Leecce5deb2014-06-18 11:27:42 -0700173
174 private boolean isDefaultDialer() {
175 final String packageName = getCallingPackage();
176 if (TextUtils.isEmpty(packageName)) {
177 return false;
178 }
179
180 final TelecommManager telecommManager =
181 (TelecommManager) getSystemService(Context.TELECOMM_SERVICE);
182 final ComponentName defaultPhoneApp = telecommManager.getDefaultPhoneApp();
183 return (defaultPhoneApp != null
184 && TextUtils.equals(defaultPhoneApp.getPackageName(), packageName));
185 }
Tyler Gunn8ad2d8d2014-08-13 14:37:16 -0700186
187 /**
188 * Returns whether the device is voice-capable (e.g. a phone vs a tablet).
189 *
190 * @return {@code True} if the device is voice-capable.
191 */
192 private boolean isVoiceCapable() {
193 return getApplicationContext().getResources().getBoolean(
194 com.android.internal.R.bool.config_voice_capable);
195 }
Santos Cordon10e68322013-12-12 16:06:56 -0800196}