Merge "Adding answer/reject API support to Telecomm." into master-nova
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 53d6aaa..92f7443 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -148,10 +148,13 @@
</intent-filter>
</activity-alias>
- <receiver android:name="TelecommReceiver" android:exported="true">
+ <activity-alias android:name="IncomingCallActivity"
+ android:targetActivity="CallActivity"
+ android:exported="true">
<intent-filter>
- <action android:name="com.android.telecomm.CONNECT_CALL_SERVICE" />
+ <action android:name="com.android.telecomm.INCOMING_CALL" />
</intent-filter>
- </receiver>
+ </activity-alias>
+
</application>
</manifest>
diff --git a/src/com/android/telecomm/CallActivity.java b/src/com/android/telecomm/CallActivity.java
index 1f1d778..350bf56 100644
--- a/src/com/android/telecomm/CallActivity.java
+++ b/src/com/android/telecomm/CallActivity.java
@@ -21,6 +21,8 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
+import android.telecomm.CallServiceDescriptor;
+import android.telecomm.TelecommConstants;
import android.util.Log;
import android.widget.Toast;
@@ -67,9 +69,9 @@
// TODO(santoscordon): Figure out if there is something to restore from bundle.
// See OutgoingCallBroadcaster in services/Telephony for more.
- processOutgoingCallIntent(intent);
+ processIntent(intent);
- // TODO(santoscordon): Remove this finish() once this app does more than just show a toast.
+ // This activity does not have associated UI, so close.
finish();
if (DEBUG) {
@@ -78,6 +80,23 @@
}
/**
+ * Processes intents sent to the activity.
+ *
+ * @param intent The intent.
+ */
+ private void processIntent(Intent intent) {
+ String action = intent.getAction();
+
+ if (Intent.ACTION_CALL.equals(action) ||
+ Intent.ACTION_CALL_PRIVILEGED.equals(action) ||
+ Intent.ACTION_CALL_EMERGENCY.equals(action)) {
+ processOutgoingCallIntent(intent);
+ } else if (TelecommConstants.ACTION_INCOMING_CALL.equals(action)) {
+ processIncomingCallIntent(intent);
+ }
+ }
+
+ /**
* Processes CALL, CALL_PRIVILEGED, and CALL_EMERGENCY intents.
*
* @param intent Call intent containing data about the handle to call.
@@ -94,13 +113,26 @@
String handle = intent.getDataString();
ContactInfo contactInfo = null;
try {
- // we use the application context because the lifetime of the call services bound on
- // this context extends beyond the life of this activity.
- Context context = getApplicationContext();
-
- mCallsManager.processOutgoingCallIntent(handle, contactInfo, context);
+ mCallsManager.processOutgoingCallIntent(handle, contactInfo);
} catch (RestrictedCallException e) {
// TODO(gilad): Handle or explicitly state to be ignored.
}
}
+
+ /**
+ * Processes INCOMING_CALL intents. Grabs the call service informations from the intent extra
+ * and forwards that to the CallsManager to start the incoming call flow.
+ *
+ * @param intent The incoming call intent.
+ */
+ private void processIncomingCallIntent(Intent intent) {
+ CallServiceDescriptor descriptor =
+ intent.getParcelableExtra(TelecommConstants.EXTRA_CALL_SERVICE_DESCRIPTOR);
+ if (descriptor == null) {
+ Log.w(TAG, "Rejecting incoming call due to null descriptor");
+ return;
+ }
+
+ // Notify CallsManager.
+ }
}
diff --git a/src/com/android/telecomm/CallServiceProviderWrapper.java b/src/com/android/telecomm/CallServiceProviderWrapper.java
index 0b993d8..dcd64c4 100644
--- a/src/com/android/telecomm/CallServiceProviderWrapper.java
+++ b/src/com/android/telecomm/CallServiceProviderWrapper.java
@@ -17,7 +17,6 @@
package com.android.telecomm;
import android.content.ComponentName;
-import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.telecomm.ICallServiceLookupResponse;
@@ -30,7 +29,6 @@
* {@link ICallServiceProvider} directly and instead should use this class to invoke methods of
* {@link ICallServiceProvider}.
* TODO(santoscordon): Keep track of when the service can be safely unbound.
- * TODO(santoscordon): Look into combining with android.telecomm.CallServiceProvider.
*/
public class CallServiceProviderWrapper extends ServiceBinder<ICallServiceProvider> {
/**
@@ -45,11 +43,6 @@
private ICallServiceProvider mServiceInterface;
/**
- * The class to notify when binding succeeds or fails.
- */
- private final CallServiceRepository mRepository;
-
- /**
* Creates a call-service provider for the specified component.
*
* @param componentName The component name of the service to bind to.
@@ -59,7 +52,6 @@
ComponentName componentName, CallServiceRepository repository) {
super(CALL_SERVICE_PROVIDER_ACTION, componentName);
- mRepository = repository;
}
/** {@inheritDoc} */
diff --git a/src/com/android/telecomm/CallServiceRepository.java b/src/com/android/telecomm/CallServiceRepository.java
index f73beda..038a345 100644
--- a/src/com/android/telecomm/CallServiceRepository.java
+++ b/src/com/android/telecomm/CallServiceRepository.java
@@ -72,13 +72,12 @@
private int mLookupId = 0;
/**
- * Map of {@link CallServiceProviderWrapper}s keyed by their ComponentName. Used as a cache for
- * call services. Entries are added to the cache as part of the lookup sequence. Every call
- * service found will have an entry in the cache. The cache is cleaned up periodically to
- * remove any call services (bound or unbound) which are no longer needed because they have no
- * associated calls. After a cleanup, the only entries in the cache should be call services
- * with existing calls. During the lookup, we will always use a cached version of a call service
- * if one exists.
+ * Map of {@link CallServiceProviderWrapper}s keyed by their ComponentName. Gets populated as
+ * the first step in the lookup cycle with all provider implementations that exist on the
+ * device. For each provider, we attempt to get a cached instance from this map and if no such
+ * instance exists, a new provider wrapper is created. At the end of the lookup cycle, providers
+ * are unbound, but are kept in this map for use in the next lookup cycle.
+ * TODO(santoscordon): Limit entries to those which the user has explicitly allowed.
*/
private Map<ComponentName, CallServiceProviderWrapper> mProviderCache = Maps.newHashMap();
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index d79669a..0afb6e0 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -16,7 +16,6 @@
package com.android.telecomm;
-import android.content.Context;
import android.telecomm.CallServiceDescriptor;
import android.telecomm.CallState;
import android.util.Log;
@@ -111,9 +110,8 @@
*
* @param handle The handle to dial.
* @param contactInfo Information about the entity being called.
- * @param context The application context.
*/
- void processOutgoingCallIntent(String handle, ContactInfo contactInfo, Context context)
+ void processOutgoingCallIntent(String handle, ContactInfo contactInfo)
throws RestrictedCallException {
for (OutgoingCallValidator validator : mOutgoingCallValidators) {
diff --git a/src/com/android/telecomm/OutgoingCallProcessor.java b/src/com/android/telecomm/OutgoingCallProcessor.java
index 9fbcbbe..a78f951 100644
--- a/src/com/android/telecomm/OutgoingCallProcessor.java
+++ b/src/com/android/telecomm/OutgoingCallProcessor.java
@@ -265,7 +265,7 @@
mCallService.call(mCall.toCallInfo());
}
@Override public void onFailure() {
- attemptNextSelector();
+ attemptNextCallService();
}
};
mCallService.bind(callback);
diff --git a/src/com/android/telecomm/ServiceBinder.java b/src/com/android/telecomm/ServiceBinder.java
index 101b940..1c797ca 100644
--- a/src/com/android/telecomm/ServiceBinder.java
+++ b/src/com/android/telecomm/ServiceBinder.java
@@ -130,8 +130,8 @@
return true;
}
+ mCallbacks.add(callback);
if (mServiceConnection == null) {
- mCallbacks.add(callback);
Intent serviceIntent = new Intent(mServiceAction).setComponent(mComponentName);
ServiceConnection connection = new ServiceBinderConnection();
diff --git a/src/com/android/telecomm/TelecommReceiver.java b/src/com/android/telecomm/TelecommReceiver.java
deleted file mode 100644
index 342ef20..0000000
--- a/src/com/android/telecomm/TelecommReceiver.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.telecomm;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.telecomm.CallServiceDescriptor;
-import android.util.Log;
-
-import com.google.common.base.Strings;
-
-/**
- * Receiver for public intents relating to Telecomm.
- *
- * TODO(gilad): Unify the incoming/outgoing approach to use startActivity in both cases thereby
- * eliminating the incoming logic below, as well as this class as a whole.
- */
-public class TelecommReceiver extends BroadcastReceiver {
-
- private static final String TAG = TelecommReceiver.class.getSimpleName();
-
- /**
- * Action used by call services to notify Telecomm that there is an incoming call. This intent
- * starts the incoming call sequence which will ultimately connect to the call service described
- * in the intent extras. A new call object along with the token (also provided in the intent
- * extras) will ultimately be sent to the call service indicating that Telecomm has received its
- * incoming call.
- * Extras used: {@link #EXTRA_CALL_SERVICE_DESCRIPTOR}, {@link #EXTRA_INCOMING_CALL_TOKEN}
- * TODO(santoscordon): As this gets finalized, this should eventually move to TelecommConstants.
- * TODO(santoscordon): Expose a new service like TelephonyManager for Telecomm and expose
- * a method for incoming calls instead of forcing the call service to build and send an Intent.
- */
- public static final String ACTION_INCOMING_CALL = "com.android.telecomm.INCOMING_CALL";
-
- /**
- * The {@link CallServiceDescriptor} describing the call service for an incoming call.
- */
- static final String EXTRA_CALL_SERVICE_DESCRIPTOR = "com.android.telecomm.CALL_SERVICE_DESCRIPTOR";
-
- /**
- * A String-based token used to identify the incoming call. Telecomm will use this token when
- * providing a call object to the call service so that the call service can map the call object
- * with the appropriate incoming call. Telecomm does not use or manipulate this token in any
- * way; it simply passes it through to the call service. Cannot be empty or null.
- */
- static final String EXTRA_INCOMING_CALL_TOKEN = "com.android.telecomm.INCOMING_CALL_TOKEN";
-
- private CallsManager mCallsManager = CallsManager.getInstance();
-
- /** {@inheritDoc} */
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (ACTION_INCOMING_CALL.equals(action)) {
- handleIncomingCall(intent);
- }
- }
-
- /**
- * Notifies CallsManager that a call service has an incoming call and it should start the
- * incoming call sequence.
- *
- * @param intent The incoming call intent.
- */
- private void handleIncomingCall(Intent intent) {
- CallServiceDescriptor descriptor = intent.getParcelableExtra(EXTRA_CALL_SERVICE_DESCRIPTOR);
- if (descriptor == null) {
- Log.w(TAG, "Rejecting incoming call due to null descriptor");
- return;
- }
-
- String token = Strings.emptyToNull(intent.getStringExtra(EXTRA_INCOMING_CALL_TOKEN));
- if (token == null) {
- Log.w(TAG, "Rejecting incoming call due to null token");
- }
-
- // TODO(santoscordon): Notify CallsManager.
- }
-}