Merge "Make comments easier to read" into master-nova
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 0b60c4a..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;
}
@@ -271,6 +272,28 @@
}
/**
+ * Puts the call on hold if it is currently active.
+ */
+ void hold() {
+ Preconditions.checkNotNull(mCallService);
+
+ if (mState == CallState.ACTIVE) {
+ mCallService.hold(mId);
+ }
+ }
+
+ /**
+ * Releases the call from hold if it is currently active.
+ */
+ void unhold() {
+ Preconditions.checkNotNull(mCallService);
+
+ if (mState == CallState.ON_HOLD) {
+ mCallService.unhold(mId);
+ }
+ }
+
+ /**
* @return An object containing read-only information about this call.
*/
CallInfo toCallInfo() {
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/CallServiceAdapter.java b/src/com/android/telecomm/CallServiceAdapter.java
index 1e830d5..e30d338 100644
--- a/src/com/android/telecomm/CallServiceAdapter.java
+++ b/src/com/android/telecomm/CallServiceAdapter.java
@@ -172,6 +172,16 @@
});
}
+ /** {@inheritDoc} */
+ @Override public void setOnHold(final String callId) {
+ checkValidCallId(callId);
+ mHandler.post(new Runnable() {
+ @Override public void run() {
+ mCallsManager.markCallAsOnHold(callId);
+ }
+ });
+ }
+
/**
* Adds the specified call ID to the list of pending outgoing call IDs.
* TODO(gilad): Consider passing the call processor (instead of the ID) both here and in the
diff --git a/src/com/android/telecomm/CallServiceWrapper.java b/src/com/android/telecomm/CallServiceWrapper.java
index a1a247a..d69aa96 100644
--- a/src/com/android/telecomm/CallServiceWrapper.java
+++ b/src/com/android/telecomm/CallServiceWrapper.java
@@ -144,6 +144,28 @@
}
}
+ /** See {@link ICallService#hold}. */
+ public void hold(String callId) {
+ if (isServiceValid("hold")) {
+ try {
+ mServiceInterface.hold(callId);
+ } catch (RemoteException e) {
+ Log.e(this, e, "Failed to put on hold for call %s", callId);
+ }
+ }
+ }
+
+ /** See {@link ICallService#unhold}. */
+ public void unhold(String callId) {
+ if (isServiceValid("unhold")) {
+ try {
+ mServiceInterface.unhold(callId);
+ } catch (RemoteException e) {
+ Log.e(this, e, "Failed to remove from hold for call %s", callId);
+ }
+ }
+ }
+
/**
* Starts retrieval of details for an incoming call. Details are returned through the
* call-service adapter using the specified call ID. Upon failure, the specified error callback
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 4b4de71..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.
@@ -258,6 +259,40 @@
audioManager.abandonAudioFocusForCall();
}
+ /**
+ * Instructs Telecomm to put the specified call on hold. Intended to be invoked by the
+ * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
+ * the user hitting the hold button during an active call.
+ *
+ * @param callId The ID of the call.
+ */
+ void holdCall(String callId) {
+ Call call = mCalls.get(callId);
+ if (call == null) {
+ Log.w(this, "Unknown call (%s) asked to be put on hold", callId);
+ } else {
+ Log.d(this, "Putting call on hold: (%s)", callId);
+ call.hold();
+ }
+ }
+
+ /**
+ * Instructs Telecomm to release the specified call from hold. Intended to be invoked by
+ * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered
+ * by the user hitting the hold button during a held call.
+ *
+ * @param callId The ID of the call
+ */
+ void unholdCall(String callId) {
+ Call call = mCalls.get(callId);
+ if (call == null) {
+ Log.w(this, "Unknown call (%s) asked to be removed from hold", callId);
+ } else {
+ Log.d(this, "Removing call from hold: (%s)", callId);
+ call.unhold();
+ }
+ }
+
void markCallAsRinging(String callId) {
setCallState(callId, CallState.RINGING);
}
@@ -282,6 +317,13 @@
audioManager.setSpeakerphoneOn(false);
}
+ void markCallAsOnHold(String callId) {
+ setCallState(callId, CallState.ON_HOLD);
+
+ // Notify the in-call UI
+ mInCallController.markCallAsOnHold(callId);
+ }
+
/**
* Marks the specified call as DISCONNECTED and notifies the in-call app. If this was the last
* live call, then also disconnect from the in-call controller.
@@ -382,6 +424,7 @@
switch (call.getState()) {
case DIALING:
case ACTIVE:
+ case ON_HOLD:
callState = TelephonyManager.EXTRA_STATE_OFFHOOK;
break;
diff --git a/src/com/android/telecomm/InCallAdapter.java b/src/com/android/telecomm/InCallAdapter.java
index 7232abf..37dc3b9 100644
--- a/src/com/android/telecomm/InCallAdapter.java
+++ b/src/com/android/telecomm/InCallAdapter.java
@@ -68,4 +68,24 @@
}
});
}
+
+ /** {@inheritDoc} */
+ @Override
+ public void holdCall(final String callId) {
+ mHandler.post(new Runnable() {
+ @Override public void run() {
+ mCallsManager.holdCall(callId);
+ }
+ });
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void unholdCall(final String callId) {
+ mHandler.post(new Runnable() {
+ @Override public void run() {
+ mCallsManager.unholdCall(callId);
+ }
+ });
+ }
}
diff --git a/src/com/android/telecomm/InCallController.java b/src/com/android/telecomm/InCallController.java
index 4da9190..4f863c5 100644
--- a/src/com/android/telecomm/InCallController.java
+++ b/src/com/android/telecomm/InCallController.java
@@ -141,6 +141,17 @@
}
}
+ void markCallAsOnHold(String callId) {
+ try {
+ if (mInCallService != null) {
+ Log.i(this, "Mark call as HOLD: %s", callId);
+ mInCallService.setOnHold(callId);
+ }
+ } catch (RemoteException e) {
+ Log.e(this, e, "Exception attempting to markCallAsHeld.");
+ }
+ }
+
/**
* Unbinds an existing bound connection to the in-call app.
*/
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/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/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 4cbaf71..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);
@@ -148,6 +149,20 @@
/** {@inheritDoc} */
@Override
+ public void hold(String callId) {
+ Log.i(TAG, "hold(" + callId + ")");
+ mTelecommAdapter.setOnHold(callId);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void unhold(String callId) {
+ Log.i(TAG, "unhold(" + callId + ")");
+ mTelecommAdapter.setActive(callId);
+ }
+
+ /** {@inheritDoc} */
+ @Override
public boolean onUnbind(Intent intent) {
mMediaPlayer = null;