Merge "Clean up ringer code." into master-nova
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 7eb4a6f..849c876 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -16,6 +16,7 @@
package com.android.telecomm;
+import android.net.Uri;
import android.telecomm.CallInfo;
import android.telecomm.CallState;
@@ -52,7 +53,7 @@
private CallState mState;
/** The handle with which to establish this call. */
- private String mHandle;
+ private Uri mHandle;
/**
* The call service which is attempted or already connecting this call.
@@ -87,7 +88,7 @@
* @param handle The handle to dial.
* @param contactInfo Information about the entity being called.
*/
- Call(String handle, ContactInfo contactInfo) {
+ Call(Uri handle, ContactInfo contactInfo) {
mId = UUID.randomUUID().toString(); // UUIDs should provide sufficient uniqueness.
mState = CallState.NEW;
mHandle = handle;
@@ -120,11 +121,11 @@
clearCallInfo();
}
- String getHandle() {
+ Uri getHandle() {
return mHandle;
}
- void setHandle(String handle) {
+ void setHandle(Uri handle) {
mHandle = handle;
}
diff --git a/src/com/android/telecomm/CallActivity.java b/src/com/android/telecomm/CallActivity.java
index 2418a0a..06d4267 100644
--- a/src/com/android/telecomm/CallActivity.java
+++ b/src/com/android/telecomm/CallActivity.java
@@ -89,17 +89,8 @@
* @param intent Call intent containing data about the handle to call.
*/
private void processOutgoingCallIntent(Intent intent) {
- // TODO(santoscordon): Remove the toast.
- String toastContent = "[" + intent.getAction() + "] " + intent.getDataString();
- Toast.makeText(this, toastContent, Toast.LENGTH_LONG).show();
-
- // TODO(gilad): Pull the scheme etc. from the data string as well as any relevant extras
- // from the intent into structured data and invoke the corresponding CallsManager APIs
- // based on that. May want to add a static utility to perform that in case the logic is
- // non-trivial/voluminous.
- String handle = intent.getDataString();
ContactInfo contactInfo = null;
- mCallsManager.processOutgoingCallIntent(handle, contactInfo);
+ mCallsManager.processOutgoingCallIntent(intent.getData(), contactInfo);
}
/**
diff --git a/src/com/android/telecomm/CallLogManager.java b/src/com/android/telecomm/CallLogManager.java
index de9b301..718c685 100644
--- a/src/com/android/telecomm/CallLogManager.java
+++ b/src/com/android/telecomm/CallLogManager.java
@@ -97,7 +97,7 @@
* {@link android.provider.CallLog.Calls#MISSED_TYPE}
*/
private void logCall(Call call, int callLogType) {
- String number = call.getHandle();
+ Uri number = call.getHandle();
final long creationTime = call.getCreationTimeInMilliseconds();
final long age = call.getAgeInMilliseconds();
@@ -160,16 +160,18 @@
* @return the phone number to be logged.
*/
private String getLogNumber(Call call) {
- String handle = call.getHandle();
+ Uri handle = call.getHandle();
if (handle == null) {
return null;
}
- if (!PhoneNumberUtils.isUriNumber(handle)) {
- handle = PhoneNumberUtils.stripSeparators(handle);
+ // TODO: Add support for SIP numbers.
+ String handleString = handle.toString();
+ if (!PhoneNumberUtils.isUriNumber(handleString)) {
+ handleString = PhoneNumberUtils.stripSeparators(handleString);
}
- return handle;
+ return handleString;
}
/**
diff --git a/src/com/android/telecomm/CallServiceRepository.java b/src/com/android/telecomm/CallServiceRepository.java
index 2abc8fe..40a1e7b 100644
--- a/src/com/android/telecomm/CallServiceRepository.java
+++ b/src/com/android/telecomm/CallServiceRepository.java
@@ -57,11 +57,7 @@
/** Used to run code (e.g. messages, Runnables) on the main (UI) thread. */
private final Handler mHandler = new Handler(Looper.getMainLooper());
- /**
- * Used to interrupt lookup cycles that didn't terminate naturally within the allowed
- * period, see {@link Timeouts#getProviderLookupMs()}.
- */
- private final Runnable mLookupTerminator = new Runnable() {
+ private final Runnable mTimeoutLookupTerminator = new Runnable() {
@Override
public void run() {
Log.d(CallServiceRepository.this, "Timed out processing providers");
@@ -80,22 +76,16 @@
private boolean mIsLookupInProgress = false;
/**
- * Stores the names of the providers to bind to in one lookup cycle. The set size represents
- * the number of call-service providers this repository expects to hear back from upon
- * initiating call-service lookups, see initiateLookup. Whenever all providers respond before
- * the lookup timeout occurs, the complete set of (available) call services is passed to the
- * switchboard for further processing of outgoing calls etc. When the timeout occurs before all
- * responses are received, the partial (potentially empty) set gets passed (to the switchboard)
- * instead. Entries are removed from this set as providers are processed.
+ * Stores the names of the providers to bind to in one lookup cycle. During lookup two things
+ * can happen:
+ * - lookup can succeed, in this case this set will be empty at the end of the lookup.
+ * - lookup can timeout, in this case any outstanding providers will be discarded.
*/
private final Set<ComponentName> mOutstandingProviders = Sets.newHashSet();
/**
- * The map of call-service wrappers keyed by their ComponentName. Used to ensure at most one
- * instance exists per call-service type at any given time. Populated during lookup cycles to
- * include all-known ICallService implementations (i.e. wrappers thereof) and then updated to
- * include only active call services (ones that are associated with one or more active calls)
- * upon {@link #purgeInactiveCallServices()} invocations.
+ * The map of call-service wrappers keyed by their ComponentName. This is passed back to the
+ * switchboard once lookup is complete.
*/
private final Map<ComponentName, CallServiceWrapper> mCallServices = Maps.newHashMap();
@@ -148,8 +138,8 @@
Log.i(this, "Found %d implementations of ICallServiceProvider.",
mOutstandingProviders.size());
- // Schedule a lookup terminator to run after Timeouts.getProviderLookupMs() milliseconds.
- mHandler.postDelayed(mLookupTerminator, Timeouts.getProviderLookupMs());
+ // Schedule a timeout.
+ mHandler.postDelayed(mTimeoutLookupTerminator, Timeouts.getProviderLookupMs());
}
/**
@@ -247,11 +237,9 @@
}
/**
- * Processes the {@link CallServiceDescriptor}s for the specified provider, and performs the
- * necessary bookkeeping to potentially return control to the switchboard before the timeout
- * for the current lookup cycle.
+ * Creates {@link CallServiceWrapper}s from the given {@link CallServiceDescriptor}s.
*
- * @param provider The provider associated with callServices.
+ * @param provider The provider associated with call services.
* @param callServiceDescriptors The set of call service descriptors to process.
*/
private void processCallServices(
@@ -275,16 +263,15 @@
removeOutstandingProvider(providerName);
} else {
- Log.i(this,
- "Unexpected call services from %s in lookup %s", providerName, mLookupId);
+ Log.i(this, "Unexpected call services from %s in lookup %s", providerName, mLookupId);
}
}
/**
- * Creates the call service for the specified call-service descriptor and saves newly-created
- * entries into {@link #mCallServices}. Does nothing upon already-registered entries.
+ * Creates a call-service wrapper from the given call-service descriptor if no cached instance
+ * exists.
*
- * @param descriptor The call service descriptor.
+ * @param descriptor The call-service descriptor.
*/
private void registerCallService(CallServiceDescriptor descriptor) {
Preconditions.checkNotNull(descriptor);
@@ -318,10 +305,10 @@
}
/**
- * Timeouts the current lookup cycle, see LookupTerminator.
+ * Terminates the current lookup cycle, either due to a timeout or completed lookup.
*/
private void terminateLookup() {
- mHandler.removeCallbacks(mLookupTerminator);
+ mHandler.removeCallbacks(mTimeoutLookupTerminator);
mOutstandingProviders.clear();
updateSwitchboard();
diff --git a/src/com/android/telecomm/CallServiceWrapper.java b/src/com/android/telecomm/CallServiceWrapper.java
index 5585fc7..d69aa96 100644
--- a/src/com/android/telecomm/CallServiceWrapper.java
+++ b/src/com/android/telecomm/CallServiceWrapper.java
@@ -32,8 +32,6 @@
* Wrapper for {@link ICallService}s, handles binding to {@link ICallService} and keeps track of
* when the object can safely be unbound. Other classes should not use {@link ICallService} directly
* and instead should use this class to invoke methods of {@link ICallService}.
- * TODO(santoscordon): Keep track of when the service can be safely unbound.
- * TODO(santoscordon): Look into combining with android.telecomm.CallService.
*/
final class CallServiceWrapper extends ServiceBinder<ICallService> {
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 2f1b764..26f7ac1 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
+import android.net.Uri;
import android.os.Bundle;
import android.telecomm.CallService;
import android.telecomm.CallServiceDescriptor;
@@ -130,7 +131,7 @@
Log.d(this, "handleSuccessfulIncomingCall");
Preconditions.checkState(call.getState() == CallState.RINGING);
- String handle = call.getHandle();
+ Uri handle = call.getHandle();
ContactInfo contactInfo = call.getContactInfo();
for (IncomingCallValidator validator : mIncomingCallValidators) {
if (!validator.isValid(handle, contactInfo)) {
@@ -160,7 +161,7 @@
* @param handle The handle to dial.
* @param contactInfo Information about the entity being called.
*/
- void processOutgoingCallIntent(String handle, ContactInfo contactInfo) {
+ void processOutgoingCallIntent(Uri handle, ContactInfo contactInfo) {
for (OutgoingCallValidator validator : mOutgoingCallValidators) {
if (!validator.isValid(handle, contactInfo)) {
// TODO(gilad): Display an error message.
diff --git a/src/com/android/telecomm/IncomingCallValidator.java b/src/com/android/telecomm/IncomingCallValidator.java
index 75ad10b..769eae7 100644
--- a/src/com/android/telecomm/IncomingCallValidator.java
+++ b/src/com/android/telecomm/IncomingCallValidator.java
@@ -16,6 +16,8 @@
package com.android.telecomm;
+import android.net.Uri;
+
/**
* Implementations can be used to reject incoming calls based on arbitrary restrictions across call
* services (e.g. suppressing calls from certain phone numbers regardless if they are received over
@@ -23,5 +25,5 @@
*/
public interface IncomingCallValidator {
- boolean isValid(String handle, ContactInfo contactInfo);
+ boolean isValid(Uri handle, ContactInfo contactInfo);
}
diff --git a/src/com/android/telecomm/IncomingCallsManager.java b/src/com/android/telecomm/IncomingCallsManager.java
index 3b6365f..0493df8 100644
--- a/src/com/android/telecomm/IncomingCallsManager.java
+++ b/src/com/android/telecomm/IncomingCallsManager.java
@@ -26,10 +26,7 @@
import java.util.Map;
/**
- * Utility class to retrieve details of an incoming call after receiving an incoming-call intent,
- * see {@link CallActivity}. Binds with the specified call services and requests details of incoming
- * calls. Upon receipt of the details, yields execution back to the switchboard to complete the
- * incoming sequence. The entire process is timeboxed to protect against unresponsive call services.
+ * Used to retrieve details about an incoming call. This is invoked after an incoming call intent.
*/
final class IncomingCallsManager {
@@ -48,8 +45,7 @@
}
/**
- * Retrieves details of an incoming call through its associated call service (asynchronously).
- * Starts the timeout sequence in case the call service is unresponsive.
+ * Retrieves details of an incoming call through its associated call service.
*
* @param call The call object.
* @param extras The optional extras passed with the incoming call intent (to be returned to
diff --git a/src/com/android/telecomm/OutgoingCallValidator.java b/src/com/android/telecomm/OutgoingCallValidator.java
index 0553b58..288d37e 100644
--- a/src/com/android/telecomm/OutgoingCallValidator.java
+++ b/src/com/android/telecomm/OutgoingCallValidator.java
@@ -16,6 +16,8 @@
package com.android.telecomm;
+import android.net.Uri;
+
/**
* Implementations can be used to suppress certain classes of outgoing calls based on arbitrary
* restrictions across call services (e.g. black-listing some phone numbers regardless if these
@@ -27,5 +29,5 @@
*/
public interface OutgoingCallValidator {
- boolean isValid(String handle, ContactInfo contactInfo);
+ boolean isValid(Uri handle, ContactInfo contactInfo);
}
diff --git a/src/com/android/telecomm/ThreadUtil.java b/src/com/android/telecomm/ThreadUtil.java
index 3d5a498..35b4c29 100644
--- a/src/com/android/telecomm/ThreadUtil.java
+++ b/src/com/android/telecomm/ThreadUtil.java
@@ -19,8 +19,7 @@
import android.os.Looper;
/**
- * A utility class which helps organize callers' threads. This class cannot be instantiated; callers
- * should use the static methods.
+ * Helper methods to deal with threading related tasks.
*/
public final class ThreadUtil {
private static final String TAG = ThreadUtil.class.getSimpleName();
diff --git a/src/com/android/telecomm/Timeouts.java b/src/com/android/telecomm/Timeouts.java
index 05c26db..0fab3c4 100644
--- a/src/com/android/telecomm/Timeouts.java
+++ b/src/com/android/telecomm/Timeouts.java
@@ -1,4 +1,18 @@
-// Copyright 2014 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2014 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;
diff --git a/tests/src/com/android/telecomm/testcallservice/TestCallService.java b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
index 237705f..d3c44a8 100644
--- a/tests/src/com/android/telecomm/testcallservice/TestCallService.java
+++ b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
@@ -18,6 +18,7 @@
import android.content.Intent;
import android.media.MediaPlayer;
+import android.net.Uri;
import android.os.Bundle;
import android.telecomm.CallInfo;
import android.telecomm.CallService;
@@ -83,7 +84,7 @@
Preconditions.checkNotNull(callInfo.getHandle());
// Is compatible if the handle doesn't start with 7.
- boolean isCompatible = !callInfo.getHandle().startsWith("7");
+ boolean isCompatible = !callInfo.getHandle().getSchemeSpecificPart().startsWith("7");
// Tell CallsManager whether this call service can place the call (is compatible).
// Returning positively on setCompatibleWith() doesn't guarantee that we will be chosen
@@ -119,7 +120,7 @@
Log.i(TAG, "setIncomingCallId(" + callId + ", " + extras + ")");
// Use dummy number for testing incoming calls.
- String handle = "5551234";
+ Uri handle = Uri.fromParts("tel", "5551234", null);
CallInfo callInfo = new CallInfo(callId, CallState.RINGING, handle);
mTelecommAdapter.notifyIncomingCall(callInfo);