blob: 54424e41e4e55e0ccac2779cdb464ae8f16bfad4 [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;
23import android.util.Log;
24import android.widget.Toast;
25
Ben Giladdd8c6082013-12-30 14:44:08 -080026import com.android.telecomm.exceptions.CallServiceUnavailableException;
27import com.android.telecomm.exceptions.RestrictedCallException;
28
Santos Cordon10e68322013-12-12 16:06:56 -080029/**
30 * Activity that handles system CALL actions and forwards them to {@link CallsManager}.
31 * Handles all three CALL action types: CALL, CALL_PRIVILEGED, and CALL_EMERGENCY.
32 * TODO(santoscordon): Connect with CallsManager.
33 */
34public class CallActivity extends Activity {
Ben Giladdd8c6082013-12-30 14:44:08 -080035 /** Used to identify log entries by this class. */
Santos Cordon10e68322013-12-12 16:06:56 -080036 private static final String TAG = CallActivity.class.getSimpleName();
Ben Giladdd8c6082013-12-30 14:44:08 -080037
38 /** Indicates whether or not debug-level entries should be logged. */
Santos Cordon10e68322013-12-12 16:06:56 -080039 private static boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
40
Ben Giladdd8c6082013-12-30 14:44:08 -080041 private CallsManager mCallsManager = CallsManager.getInstance();
42
Santos Cordon10e68322013-12-12 16:06:56 -080043 /**
44 * {@inheritDoc}
45 *
46 * This method is the single point of entry for the CALL intent, which is used by built-in apps
47 * like Contacts & Dialer, as well as 3rd party apps to initiate outgoing calls.
48 */
49 @Override
50 protected void onCreate(Bundle bundle) {
51 super.onCreate(bundle);
52
53 // TODO(santoscordon): This activity will be displayed until the next screen which could be
54 // the in-call UI and error dialog or potentially a call-type selection dialog.
55 // Traditionally, this has been a black screen with a spinner. We need to reevaluate if this
56 // is still desired and add back if necessary. Currently, the activity is set to NoDisplay
57 // theme which means it shows no UI.
58
59 Intent intent = getIntent();
60 Configuration configuration = getResources().getConfiguration();
61
62 if (DEBUG) {
63 Log.d(TAG, "onCreate: this = " + this + ", bundle= " + bundle);
64 Log.d(TAG, " - intent = " + intent);
65 Log.d(TAG, " - configuration = " + configuration);
66 }
67
68 // TODO(santoscordon): Figure out if there is something to restore from bundle.
69 // See OutgoingCallBroadcaster in services/Telephony for more.
70
Ben Giladdd8c6082013-12-30 14:44:08 -080071 processOutgoingCallIntent(intent);
Santos Cordon10e68322013-12-12 16:06:56 -080072
73 // TODO(santoscordon): Remove this finish() once this app does more than just show a toast.
74 finish();
75
76 if (DEBUG) {
77 Log.d(TAG, "onCreate: end");
78 }
79 }
80
81 /**
82 * Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
83 *
84 * @param intent Call intent containing data about the handle to call.
85 */
Ben Giladdd8c6082013-12-30 14:44:08 -080086 private void processOutgoingCallIntent(Intent intent) {
87 // TODO(santoscordon): Remove the toast.
Santos Cordon10e68322013-12-12 16:06:56 -080088 String toastContent = "[" + intent.getAction() + "] " + intent.getDataString();
89 Toast.makeText(this, toastContent, Toast.LENGTH_LONG).show();
Ben Giladdd8c6082013-12-30 14:44:08 -080090
91 // TODO(gilad): Pull the scheme etc. from the data string as well as any relevant extras
92 // from the intent into structured data and invoke the corresponding CallsManager APIs
93 // based on that. May want to add a static utility to perform that in case the logic is
94 // non-trivial/voluminous.
95 String handle = intent.getDataString();
96 ContactInfo contactInfo = null;
97 try {
98 mCallsManager.processOutgoingCallIntent(handle, contactInfo);
99 } catch (RestrictedCallException e) {
100 // TODO(gilad): Handle or explicitly state to be ignored.
101 } catch (CallServiceUnavailableException e) {
102 // TODO(gilad): Handle or explicitly state to be ignored. If both should be ignored, consider
103 // extending from the same base class and simplify the handling code to a single catch clause.
104 }
Santos Cordon10e68322013-12-12 16:06:56 -0800105 }
106}