blob: 3479001bf7c05ac2a9e5671b97b06db1e3e374aa [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 Lee31a94e32014-06-18 11:27:42 -070020import android.content.ComponentName;
Santos Cordon10e68322013-12-12 16:06:56 -080021import android.content.Intent;
22import android.content.res.Configuration;
23import android.os.Bundle;
Santos Cordon523f6052014-02-20 16:39:34 -080024import android.telecomm.CallServiceDescriptor;
Yorke Lee31a94e32014-06-18 11:27:42 -070025import android.telecomm.PhoneApplication;
Santos Cordon523f6052014-02-20 16:39:34 -080026import android.telecomm.TelecommConstants;
Yorke Lee31a94e32014-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 Lee31a94e32014-06-18 11:27:42 -070033 *
34 * Pre-L, only the system dialer was allowed to make outgoing emergency calls via the
35 * CALL_PRIVILEGED action (which requires the system only CALL_PRIVILEGED permission).
36 *
37 * In L, the system dialer can continue to make outgoing emergency calls via CALL_PRIVILEGED.
38 * Also, the user-selected default dialer and the system dialer will be granted the ability to make
39 * emergency outgoing calls using the CALL action. In order to do this, they must call
40 * startActivityForResult on the CALL intent to allow their package name to be passed to
41 * {@link CallActivity}. Calling startActivity will continue to work on all non-emergency numbers
42 * just like it did pre-L.
Santos Cordon10e68322013-12-12 16:06:56 -080043 */
44public class CallActivity extends Activity {
Ben Giladdd8c6082013-12-30 14:44:08 -080045 private CallsManager mCallsManager = CallsManager.getInstance();
46
Santos Cordon10e68322013-12-12 16:06:56 -080047 /**
48 * {@inheritDoc}
49 *
50 * This method is the single point of entry for the CALL intent, which is used by built-in apps
51 * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls.
52 */
53 @Override
54 protected void onCreate(Bundle bundle) {
55 super.onCreate(bundle);
56
57 // TODO(santoscordon): This activity will be displayed until the next screen which could be
58 // the in-call UI and error dialog or potentially a call-type selection dialog.
59 // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this
60 // is still desired and add back if necessary. Currently, the activity is set to NoDisplay
61 // theme which means it shows no UI.
62
63 Intent intent = getIntent();
64 Configuration configuration = getResources().getConfiguration();
65
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080066 Log.d(this, "onCreate: this = %s, bundle = %s", this, bundle);
67 Log.d(this, " - intent = %s", intent);
68 Log.d(this, " - configuration = %s", configuration);
Santos Cordon10e68322013-12-12 16:06:56 -080069
70 // TODO(santoscordon): Figure out if there is something to restore from bundle.
71 // See OutgoingCallBroadcaster in services/Telephony for more.
72
Santos Cordon523f6052014-02-20 16:39:34 -080073 processIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080074
Santos Cordon523f6052014-02-20 16:39:34 -080075 // This activity does not have associated UI, so close.
Santos Cordon10e68322013-12-12 16:06:56 -080076 finish();
77
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080078 Log.d(this, "onCreate: end");
Santos Cordon10e68322013-12-12 16:06:56 -080079 }
80
81 /**
Santos Cordon523f6052014-02-20 16:39:34 -080082 * Processes intents sent to the activity.
83 *
84 * @param intent The intent.
85 */
86 private void processIntent(Intent intent) {
87 String action = intent.getAction();
88
Santos Cordona0e5f1a2014-03-31 21:43:00 -070089 // TODO: Check for non-voice capable devices before reading any intents.
90
Santos Cordon523f6052014-02-20 16:39:34 -080091 if (Intent.ACTION_CALL.equals(action) ||
92 Intent.ACTION_CALL_PRIVILEGED.equals(action) ||
93 Intent.ACTION_CALL_EMERGENCY.equals(action)) {
94 processOutgoingCallIntent(intent);
95 } else if (TelecommConstants.ACTION_INCOMING_CALL.equals(action)) {
96 processIncomingCallIntent(intent);
97 }
98 }
99
100 /**
Santos Cordon10e68322013-12-12 16:06:56 -0800101 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
102 *
103 * @param intent Call intent containing data about the handle to call.
104 */
Ben Giladdd8c6082013-12-30 14:44:08 -0800105 private void processOutgoingCallIntent(Intent intent) {
Ben Giladdd8c6082013-12-30 14:44:08 -0800106 ContactInfo contactInfo = null;
Yorke Lee33501632014-03-17 19:24:12 -0700107 NewOutgoingCallIntentBroadcaster broadcaster =
Yorke Lee31a94e32014-06-18 11:27:42 -0700108 new NewOutgoingCallIntentBroadcaster(mCallsManager, contactInfo, intent,
109 isDefaultOrSystemDialer());
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 /**
115 * Processes INCOMING_CALL intents. Grabs the call service informations from the intent extra
116 * and forwards that to the CallsManager to start the incoming call flow.
117 *
118 * @param intent The incoming call intent.
119 */
120 private void processIncomingCallIntent(Intent intent) {
121 CallServiceDescriptor descriptor =
122 intent.getParcelableExtra(TelecommConstants.EXTRA_CALL_SERVICE_DESCRIPTOR);
123 if (descriptor == null) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800124 Log.w(this, "Rejecting incoming call due to null descriptor");
Santos Cordon523f6052014-02-20 16:39:34 -0800125 return;
126 }
127
Evan Charltona05805b2014-03-05 08:21:46 -0800128 Bundle clientExtras = Bundle.EMPTY;
129 if (intent.hasExtra(TelecommConstants.EXTRA_INCOMING_CALL_EXTRAS)) {
130 clientExtras = intent.getBundleExtra(TelecommConstants.EXTRA_INCOMING_CALL_EXTRAS);
131 }
132
Sailesh Nepalf1c191d2014-03-07 18:17:39 -0800133 Log.d(this, "Processing incoming call from call service [%s]", descriptor);
Evan Charltona05805b2014-03-05 08:21:46 -0800134 mCallsManager.processIncomingCallIntent(descriptor, clientExtras);
Santos Cordon523f6052014-02-20 16:39:34 -0800135 }
Yorke Lee31a94e32014-06-18 11:27:42 -0700136
137 private boolean isDefaultOrSystemDialer() {
138 final String packageName = getCallingPackage();
139 if (TextUtils.isEmpty(packageName)) {
140 return false;
141 }
142
143 final ComponentName defaultPhoneApp = PhoneApplication.getDefaultPhoneApplication(this);
144 if (defaultPhoneApp != null) {
145 if (TextUtils.equals(defaultPhoneApp.getPackageName(), packageName)) {
146 return true;
147 }
148 }
149
150 TelecommManager telecommManager = (TelecommManager) getSystemService(TELECOMM_SERVICE);
151 final ComponentName systemPhoneApp = telecommManager.getSystemPhoneApplication();
152 if (systemPhoneApp != null) {
153 return TextUtils.equals(systemPhoneApp.getPackageName(), packageName);
154 } else {
155 return false;
156 }
157 }
Santos Cordon10e68322013-12-12 16:06:56 -0800158}