Replace CallServiceSelectors with Subscriptions (2/3)
Remove CallServiceSelectors and replace them with comprehensive
support for Subscriptions as the means of selecting ways of making
phone calls. After this change, a ConnectionService is not a
semantically meaningful "way of making a call" -- it's more like the
mechanism whereby the Android system communicates with a 3rd party
process to ask for phone services. We anticipate each process having
only one ConnectionService.
Change-Id: I11258709b014d2fd3eed98a521227c200027018f
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index bf0f349..a6ec347 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -129,11 +129,6 @@
private CallServiceWrapper mCallService;
/**
- * The call-service selector for this call.
- */
- private CallServiceSelectorWrapper mCallServiceSelector;
-
- /**
* The set of call services that were attempted in the process of placing/switching this call
* but turned out unsuitable. Only used in the context of call switching.
*/
@@ -179,7 +174,6 @@
// TODO(santoscordon): The repositories should be changed into singleton types.
private CallServiceRepository mCallServiceRepository;
- private CallServiceSelectorRepository mSelectorRepository;
/** Caller information retrieved from the latest contact query. */
private CallerInfo mCallerInfo;
@@ -447,31 +441,6 @@
}
}
- CallServiceSelectorWrapper getCallServiceSelector() {
- return mCallServiceSelector;
- }
-
- void setCallServiceSelector(CallServiceSelectorWrapper selector) {
- Preconditions.checkNotNull(selector);
-
- clearCallServiceSelector();
-
- selector.incrementAssociatedCallCount();
- mCallServiceSelector = selector;
- mCallServiceSelector.addCall(this);
- }
-
- void clearCallServiceSelector() {
- if (mCallServiceSelector != null) {
- CallServiceSelectorWrapper selectorTemp = mCallServiceSelector;
- mCallServiceSelector = null;
- selectorTemp.removeCall(this);
-
- // See comment on {@link #clearCallService}.
- decrementAssociatedCallCount(selectorTemp);
- }
- }
-
/**
* Starts the incoming call flow through the switchboard. When switchboard completes, it will
* invoke handle[Un]SuccessfulIncomingCall.
@@ -557,7 +526,6 @@
mOutgoingCallProcessor = new OutgoingCallProcessor(
this,
Switchboard.getInstance().getCallServiceRepository(),
- Switchboard.getInstance().getSelectorRepository(),
new AsyncResultCallback<Boolean>() {
@Override
public void onResult(Boolean wasCallPlaced, int errorCode, String errorMsg) {
@@ -587,7 +555,6 @@
}
clearCallService();
- clearCallServiceSelector();
}
/**
diff --git a/src/com/android/telecomm/CallServiceSelectorRepository.java b/src/com/android/telecomm/CallServiceSelectorRepository.java
deleted file mode 100644
index 0a8deb6..0000000
--- a/src/com/android/telecomm/CallServiceSelectorRepository.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 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;
-
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.telecomm.TelecommConstants;
-
-import com.android.internal.telecomm.ICallServiceSelector;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Helper class to retrieve {@link ICallServiceSelector} implementations on the device and
- * asynchronously bind to them.
- */
-final class CallServiceSelectorRepository extends BaseRepository<CallServiceSelectorWrapper> {
-
- /** {@inheritDoc} */
- @Override
- protected void onLookupServices(LookupCallback<CallServiceSelectorWrapper> callback) {
- ThreadUtil.checkOnMainThread();
-
- List<ComponentName> selectorNames = getSelectorNames();
- List<CallServiceSelectorWrapper> foundSelectors = Lists.newLinkedList();
-
- // Register any new selectors.
- for (ComponentName name : selectorNames) {
- CallServiceSelectorWrapper selector = getService(name, null);
-
- if (TelephonyUtil.isTelephonySelector(selector)) {
- // Add telephony selectors to the end to serve as a fallback.
- foundSelectors.add(selector);
- } else {
- // TODO(sail): Need a way to order selectors.
- foundSelectors.add(0, selector);
- }
- }
- Log.i(this, "Found %d implementations of ICallServiceSelector", selectorNames.size());
- callback.onComplete(foundSelectors);
- }
-
- /** {@inheritDoc} */
- @Override
- protected CallServiceSelectorWrapper onCreateNewServiceWrapper(
- ComponentName componentName, Object param) {
-
- return new CallServiceSelectorWrapper(componentName, CallsManager.getInstance());
- }
-
- /**
- * Returns the list containing the (component) names of all known ICallServiceSelector
- * implementations or the empty list upon no available selectors.
- */
- private List<ComponentName> getSelectorNames() {
- // The list of selector names to return to the caller, may be populated below.
- List<ComponentName> selectorNames = Lists.newArrayList();
-
- PackageManager packageManager = TelecommApp.getInstance().getPackageManager();
- Intent intent = new Intent(TelecommConstants.ACTION_CALL_SERVICE_SELECTOR);
- for (ResolveInfo entry : packageManager.queryIntentServices(intent, 0)) {
- ServiceInfo serviceInfo = entry.serviceInfo;
- if (serviceInfo != null) {
- // The entry resolves to a proper service, add it to the list of selector names.
- ComponentName componentName =
- new ComponentName(serviceInfo.packageName, serviceInfo.name);
- selectorNames.add(componentName);
- }
- }
-
- return selectorNames;
- }
-}
diff --git a/src/com/android/telecomm/CallServiceSelectorWrapper.java b/src/com/android/telecomm/CallServiceSelectorWrapper.java
deleted file mode 100644
index 05d540a..0000000
--- a/src/com/android/telecomm/CallServiceSelectorWrapper.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright 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;
-
-import android.content.ComponentName;
-
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.RemoteException;
-import android.telecomm.CallInfo;
-import android.telecomm.CallServiceDescriptor;
-import android.telecomm.TelecommConstants;
-import android.telephony.DisconnectCause;
-
-import com.android.internal.os.SomeArgs;
-import com.android.internal.telecomm.ICallServiceSelector;
-import com.android.internal.telecomm.ICallServiceSelectorAdapter;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Wrapper for {@link ICallServiceSelector}s, handles binding and keeps track of when the object can
- * safely be unbound.
- */
-final class CallServiceSelectorWrapper extends ServiceBinder<ICallServiceSelector> {
-
- private final class Adapter extends ICallServiceSelectorAdapter.Stub {
- private static final int MSG_SET_SELECTED_CALL_SERVICES = 0;
- private static final int MSG_CANCEL_OUTGOING_CALL = 1;
- private static final int MSG_SET_HANDOFF_INFO = 2;
-
- private final Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case MSG_SET_SELECTED_CALL_SERVICES: {
- SomeArgs args = (SomeArgs) msg.obj;
- try {
- String callId = (String) args.arg1;
- if (mPendingSelects.containsKey(callId)) {
- @SuppressWarnings("unchecked")
- List<CallServiceDescriptor> descriptors =
- (List<CallServiceDescriptor>) args.arg2;
- mPendingSelects.remove(callId).onResult(descriptors, 0, null);
- } else {
- Log.w(this, "setSelectedCallServices: unknown call: %s, id: %s",
- callId, args.arg1);
- }
- } finally {
- args.recycle();
- }
- break;
- }
- case MSG_CANCEL_OUTGOING_CALL: {
- Call call = mCallIdMapper.getCall(msg.obj);
- if (call != null) {
- call.abort();
- } else {
- Log.w(this, "cancelOutgoingCall: unknown call: %s, id: %s", call,
- msg.obj);
- }
- break;
- }
- case MSG_SET_HANDOFF_INFO: {
- SomeArgs args = (SomeArgs) msg.obj;
- try {
- Call call = mCallIdMapper.getCall(args.arg1);
- Uri handle = (Uri) args.arg2;
- Bundle extras = (Bundle) args.arg3;
- if (call != null) {
- mCallsManager.setHandoffInfo(call, handle, extras);
- } else {
- Log.w(this, "setHandoffInfo: unknown call: %s, id: %s",
- call, args.arg1);
- }
- } finally {
- args.recycle();
- }
- break;
- }
- }
- }
- };
-
- @Override
- public void setSelectedCallServices(String callId,
- List<CallServiceDescriptor> descriptors) {
- mCallIdMapper.checkValidCallId(callId);
- SomeArgs args = SomeArgs.obtain();
- args.arg1 = callId;
- args.arg2 = descriptors;
- mHandler.obtainMessage(MSG_SET_SELECTED_CALL_SERVICES, args).sendToTarget();
- }
-
- @Override
- public void cancelOutgoingCall(String callId) {
- mCallIdMapper.checkValidCallId(callId);
- mHandler.obtainMessage(MSG_CANCEL_OUTGOING_CALL, callId).sendToTarget();
- }
-
- @Override
- public void setHandoffInfo(String callId, Uri handle, Bundle extras) {
- mCallIdMapper.checkValidCallId(callId);
- SomeArgs args = SomeArgs.obtain();
- args.arg1 = callId;
- args.arg2 = handle;
- args.arg3 = extras;
- mHandler.obtainMessage(MSG_SET_HANDOFF_INFO, args).sendToTarget();
- }
- }
-
- private final Binder mBinder = new Binder();
- private final CallIdMapper mCallIdMapper = new CallIdMapper("CallServiceSelector");
- private final Adapter mAdapter = new Adapter();
- private final CallsManager mCallsManager;
- private final Map<String, AsyncResultCallback<List<CallServiceDescriptor>>> mPendingSelects =
- new HashMap<>();
-
- private ICallServiceSelector mSelectorInterface;
-
- /**
- * Creates a call-service selector for the specified component using the specified action to
- * bind to it.
- *
- * @param action The action used to bind to the selector.
- * @param componentName The component name of the service.
- * @param callsManager The calls manager.
- */
- CallServiceSelectorWrapper(
- String action, ComponentName componentName, CallsManager callsManager) {
-
- super(action, componentName);
- mCallsManager = callsManager;
- }
-
- /**
- * Creates a call-service selector for specified component and uses
- * {@link TelecommConstants#ACTION_CALL_SERVICE_SELECTOR} as the action to bind.
- *
- * @param componentName The component name of the service.
- * @param callsManager The calls manager.
- */
- CallServiceSelectorWrapper(ComponentName componentName, CallsManager callsManager) {
- this(TelecommConstants.ACTION_CALL_SERVICE_SELECTOR, componentName, callsManager);
- }
-
- /**
- * Retrieves the sorted set of call services that are preferred by this selector. Upon failure,
- * the error callback is invoked. Can be invoked even when the call service is unbound.
- *
- * @param call The call being placed using the {@link CallService}s.
- * @param descriptors The descriptors of the available {@link CallService}s with which to place
- * the call.
- * @param resultCallback The callback on which to return the result.
- */
- void select(
- final Call call,
- final List<CallServiceDescriptor> descriptors,
- final AsyncResultCallback<List<CallServiceDescriptor>> resultCallback) {
-
- BindCallback callback = new BindCallback() {
- @Override
- public void onSuccess() {
- String callId = mCallIdMapper.getCallId(call);
- mPendingSelects.put(callId, resultCallback);
-
- try {
- CallInfo callInfo = call.toCallInfo(mCallIdMapper.getCallId(call));
- mSelectorInterface.select(callInfo, descriptors);
- } catch (RemoteException e) {
- mCallIdMapper.removeCall(call);
- mPendingSelects.get(callId).onResult(
- null, DisconnectCause.ERROR_UNSPECIFIED, e.toString());
- }
- }
-
- @Override
- public void onFailure() {
- resultCallback.onResult(null, DisconnectCause.ERROR_UNSPECIFIED, null);
- }
- };
-
- mBinder.bind(callback);
- }
-
- void addCall(Call call) {
- mCallIdMapper.addCall(call);
- onCallUpdated(call.toCallInfo(mCallIdMapper.getCallId(call)));
- }
-
- void removeCall(Call call) {
- String callId = mCallIdMapper.getCallId(call);
- mCallIdMapper.removeCall(call);
- onCallRemoved(callId);
- }
-
- /** {@inheritDoc} */
- @Override
- protected void setServiceInterface(IBinder binder) {
- if (binder == null) {
- mSelectorInterface = null;
- } else {
- mSelectorInterface = ICallServiceSelector.Stub.asInterface(binder);
- setCallServiceSelectorAdapter(mAdapter);
- }
- }
-
- private void setCallServiceSelectorAdapter(ICallServiceSelectorAdapter adapter) {
- if (isServiceValid("setCallServiceSelectorAdapter")) {
- try {
- mSelectorInterface.setCallServiceSelectorAdapter(adapter);
- } catch (RemoteException e) {
- }
- }
- }
-
- private void onCallUpdated(final CallInfo callInfo) {
- BindCallback callback = new BindCallback() {
- @Override
- public void onSuccess() {
- if (isServiceValid("onCallUpdated")) {
- try {
- mSelectorInterface.onCallUpdated(callInfo);
- } catch (RemoteException e) {
- }
- }
- }
-
- @Override
- public void onFailure() {
- }
- };
- mBinder.bind(callback);
- }
-
- private void onCallRemoved(final String callId) {
- BindCallback callback = new BindCallback() {
- @Override
- public void onSuccess() {
- if (isServiceValid("onCallRemoved")) {
- try {
- mSelectorInterface.onCallRemoved(callId);
- } catch (RemoteException e) {
- }
- }
- }
-
- @Override
- public void onFailure() {
- }
- };
- mBinder.bind(callback);
- }
-}
diff --git a/src/com/android/telecomm/CallServiceWrapper.java b/src/com/android/telecomm/CallServiceWrapper.java
index 4462cff..4ebce23 100644
--- a/src/com/android/telecomm/CallServiceWrapper.java
+++ b/src/com/android/telecomm/CallServiceWrapper.java
@@ -218,8 +218,6 @@
Call childCall = mCallIdMapper.getCall(args.arg1);
if (childCall != null) {
String conferenceCallId = (String) args.arg2;
- Log.d(this, "setIsConferenced %s, %s", childCall, conferenceCallId);
-
if (conferenceCallId == null) {
childCall.setParentCall(null);
} else {
@@ -244,9 +242,6 @@
SomeArgs args = (SomeArgs) msg.obj;
try {
String callId = (String) args.arg1;
- Log.d(this, "addConferenceCall attempt %s, %s",
- callId, mPendingConferenceCalls);
-
Call conferenceCall = mCallIdMapper.getCall(callId);
if (mPendingConferenceCalls.remove(conferenceCall)) {
Log.v(this, "confirming conf call %s", conferenceCall);
@@ -265,13 +260,8 @@
/** {@inheritDoc} */
@Override
- public void setIsCompatibleWith(String callId, boolean isCompatible) {
- Log.wtf(this, "Not expected.");
- }
-
- /** {@inheritDoc} */
- @Override
public void notifyIncomingCall(CallInfo callInfo) {
+ logIncoming("notifyIncomingCall %s", callInfo);
mCallIdMapper.checkValidCallId(callInfo.getId());
mHandler.obtainMessage(MSG_NOTIFY_INCOMING_CALL, callInfo).sendToTarget();
}
@@ -279,7 +269,7 @@
/** {@inheritDoc} */
@Override
public void handleSuccessfulOutgoingCall(String callId) {
- Log.d(this, "handleSuccessfulOutgoingCall %s", callId);
+ logIncoming("handleSuccessfulOutgoingCall %s", callId);
mCallIdMapper.checkValidCallId(callId);
mHandler.obtainMessage(MSG_HANDLE_SUCCESSFUL_OUTGOING_CALL, callId).sendToTarget();
}
@@ -290,8 +280,8 @@
ConnectionRequest request,
int errorCode,
String errorMsg) {
+ logIncoming("handleFailedOutgoingCall %s %d %s", request, errorCode, errorMsg);
mCallIdMapper.checkValidCallId(request.getCallId());
- Log.d(this, "handleFailedOutgoingCall %s", request.getCallId());
SomeArgs args = SomeArgs.obtain();
args.arg1 = request.getCallId();
args.argi1 = errorCode;
@@ -302,6 +292,7 @@
/** {@inheritDoc} */
@Override
public void setActive(String callId) {
+ logIncoming("setActive %s", callId);
mCallIdMapper.checkValidCallId(callId);
mHandler.obtainMessage(MSG_SET_ACTIVE, callId).sendToTarget();
}
@@ -309,6 +300,7 @@
/** {@inheritDoc} */
@Override
public void setRinging(String callId) {
+ logIncoming("setRinging %s", callId);
mCallIdMapper.checkValidCallId(callId);
mHandler.obtainMessage(MSG_SET_RINGING, callId).sendToTarget();
}
@@ -316,6 +308,7 @@
/** {@inheritDoc} */
@Override
public void setDialing(String callId) {
+ logIncoming("setDialing %s", callId);
mCallIdMapper.checkValidCallId(callId);
mHandler.obtainMessage(MSG_SET_DIALING, callId).sendToTarget();
}
@@ -324,6 +317,7 @@
@Override
public void setDisconnected(
String callId, int disconnectCause, String disconnectMessage) {
+ logIncoming("setDisconnected %s %d %s", callId, disconnectCause, disconnectMessage);
mCallIdMapper.checkValidCallId(callId);
SomeArgs args = SomeArgs.obtain();
args.arg1 = callId;
@@ -335,6 +329,7 @@
/** {@inheritDoc} */
@Override
public void setOnHold(String callId) {
+ logIncoming("setOnHold %s", callId);
mCallIdMapper.checkValidCallId(callId);
mHandler.obtainMessage(MSG_SET_ON_HOLD, callId).sendToTarget();
}
@@ -342,6 +337,7 @@
/** {@inheritDoc} */
@Override
public void setRequestingRingback(String callId, boolean ringback) {
+ logIncoming("setRequestingRingback %s %b", callId, ringback);
mCallIdMapper.checkValidCallId(callId);
SomeArgs args = SomeArgs.obtain();
args.arg1 = callId;
@@ -352,12 +348,13 @@
/** ${inheritDoc} */
@Override
public void removeCall(String callId) {
+ logIncoming("removeCall %s", callId);
}
/** ${inheritDoc} */
@Override
public void setCanConference(String callId, boolean canConference) {
- Log.d(this, "setCanConference(%s, %b)", callId, canConference);
+ logIncoming("setCanConference %s %b", callId, canConference);
mHandler.obtainMessage(MSG_CAN_CONFERENCE, canConference ? 1 : 0, 0, callId)
.sendToTarget();
}
@@ -365,6 +362,7 @@
/** ${inheritDoc} */
@Override
public void setIsConferenced(String callId, String conferenceCallId) {
+ logIncoming("setIsConferenced %s %s", callId, conferenceCallId);
SomeArgs args = SomeArgs.obtain();
args.arg1 = callId;
args.arg2 = conferenceCallId;
@@ -374,6 +372,7 @@
/** ${InheritDoc} */
@Override
public void addConferenceCall(String callId, CallInfo callInfo) {
+ logIncoming("addConferenceCall %s %s", callId, callInfo);
mCallIdMapper.checkValidCallId(callId);
SomeArgs args = SomeArgs.obtain();
args.arg1 = callId;
@@ -383,6 +382,7 @@
@Override
public void onPostDialWait(String callId, String remaining) throws RemoteException {
+ logIncoming("onPostDialWait %s %s", callId, remaining);
mCallIdMapper.checkValidCallId(callId);
SomeArgs args = SomeArgs.obtain();
args.arg1 = callId;
@@ -393,6 +393,7 @@
/** {@inheritDoc} */
@Override
public void handoffCall(String callId) {
+ logIncoming("handoffCall %s", callId);
mCallIdMapper.checkValidCallId(callId);
mHandler.obtainMessage(MSG_HANDOFF_CALL, callId).sendToTarget();
}
@@ -434,6 +435,7 @@
private void setCallServiceAdapter(ICallServiceAdapter callServiceAdapter) {
if (isServiceValid("setCallServiceAdapter")) {
try {
+ logOutgoing("setCallServiceAdapter %s", callServiceAdapter);
mServiceInterface.setCallServiceAdapter(callServiceAdapter);
} catch (RemoteException e) {
}
@@ -454,6 +456,7 @@
try {
CallInfo callInfo = call.toCallInfo(callId);
+ logOutgoing("call %s", callInfo);
mServiceInterface.call(callInfo);
} catch (RemoteException e) {
mPendingOutgoingCalls.remove(callId).onResult(
@@ -478,6 +481,7 @@
// If still bound, tell the call service to abort.
if (isServiceValid("abort")) {
try {
+ logOutgoing("abort %s", callId);
mServiceInterface.abort(callId);
} catch (RemoteException e) {
}
@@ -490,6 +494,7 @@
void hold(Call call) {
if (isServiceValid("hold")) {
try {
+ logOutgoing("hold %s", mCallIdMapper.getCallId(call));
mServiceInterface.hold(mCallIdMapper.getCallId(call));
} catch (RemoteException e) {
}
@@ -500,6 +505,7 @@
void unhold(Call call) {
if (isServiceValid("unhold")) {
try {
+ logOutgoing("unhold %s", mCallIdMapper.getCallId(call));
mServiceInterface.unhold(mCallIdMapper.getCallId(call));
} catch (RemoteException e) {
}
@@ -510,6 +516,8 @@
void onAudioStateChanged(Call activeCall, CallAudioState audioState) {
if (isServiceValid("onAudioStateChanged")) {
try {
+ logOutgoing("onAudioStateChanged %s %s",
+ mCallIdMapper.getCallId(activeCall), audioState);
mServiceInterface.onAudioStateChanged(mCallIdMapper.getCallId(activeCall),
audioState);
} catch (RemoteException e) {
@@ -535,6 +543,8 @@
if (isServiceValid("setIncomingCallId")) {
mPendingIncomingCalls.add(call);
try {
+ logOutgoing("setIncomingCallId %s %s",
+ mCallIdMapper.getCallId(call), extras);
mServiceInterface.setIncomingCallId(mCallIdMapper.getCallId(call),
extras);
} catch (RemoteException e) {
@@ -555,6 +565,7 @@
void disconnect(Call call) {
if (isServiceValid("disconnect")) {
try {
+ logOutgoing("disconnect %s", mCallIdMapper.getCallId(call));
mServiceInterface.disconnect(mCallIdMapper.getCallId(call));
} catch (RemoteException e) {
}
@@ -565,6 +576,7 @@
void answer(Call call) {
if (isServiceValid("answer")) {
try {
+ logOutgoing("answer %s", mCallIdMapper.getCallId(call));
mServiceInterface.answer(mCallIdMapper.getCallId(call));
} catch (RemoteException e) {
}
@@ -575,6 +587,7 @@
void reject(Call call) {
if (isServiceValid("reject")) {
try {
+ logOutgoing("reject %s", mCallIdMapper.getCallId(call));
mServiceInterface.reject(mCallIdMapper.getCallId(call));
} catch (RemoteException e) {
}
@@ -585,6 +598,7 @@
void playDtmfTone(Call call, char digit) {
if (isServiceValid("playDtmfTone")) {
try {
+ logOutgoing("playDtmfTone %s %c", mCallIdMapper.getCallId(call), digit);
mServiceInterface.playDtmfTone(mCallIdMapper.getCallId(call), digit);
} catch (RemoteException e) {
}
@@ -595,6 +609,7 @@
void stopDtmfTone(Call call) {
if (isServiceValid("stopDtmfTone")) {
try {
+ logOutgoing("stopDtmfTone %s", mCallIdMapper.getCallId(call));
mServiceInterface.stopDtmfTone(mCallIdMapper.getCallId(call));
} catch (RemoteException e) {
}
@@ -630,6 +645,7 @@
void onPostDialContinue(Call call, boolean proceed) {
if (isServiceValid("onPostDialContinue")) {
try {
+ logOutgoing("onPostDialContinue %s %b", mCallIdMapper.getCallId(call), proceed);
mServiceInterface.onPostDialContinue(mCallIdMapper.getCallId(call), proceed);
} catch (RemoteException ignored) {
}
@@ -650,6 +666,9 @@
}
}, Timeouts.getConferenceCallExpireMillis());
+ logOutgoing("conference %s %s",
+ mCallIdMapper.getCallId(conferenceCall),
+ mCallIdMapper.getCallId(call));
mServiceInterface.conference(
mCallIdMapper.getCallId(conferenceCall),
mCallIdMapper.getCallId(call));
@@ -661,6 +680,7 @@
void splitFromConference(Call call) {
if (isServiceValid("splitFromConference")) {
try {
+ logOutgoing("splitFromConference %s", mCallIdMapper.getCallId(call));
mServiceInterface.splitFromConference(mCallIdMapper.getCallId(call));
} catch (RemoteException ignored) {
}
@@ -711,4 +731,12 @@
mCallIdMapper.clear();
}
+
+ private void logIncoming(String msg, Object... params) {
+ Log.d(this, "CallService -> Telecomm: " + msg, params);
+ }
+
+ private void logOutgoing(String msg, Object... params) {
+ Log.d(this, "Telecomm -> CallService: " + msg, params);
+ }
}
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 5753d18..d5ddedc 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -475,7 +475,6 @@
originalCall.getHandoffHandle(), originalCall.getGatewayInfo(), false, false);
tempCall.setOriginalCall(originalCall);
tempCall.setExtras(originalCall.getExtras());
- tempCall.setCallServiceSelector(originalCall.getCallServiceSelector());
mPendingHandoffCalls.add(tempCall);
tempCall.addListener(this);
@@ -680,7 +679,6 @@
call.removeListener(this);
call.clearCallService();
- call.clearCallServiceSelector();
boolean shouldNotify = false;
if (mCalls.contains(call)) {
diff --git a/src/com/android/telecomm/EmergencyCallServiceSelector.java b/src/com/android/telecomm/EmergencyCallServiceSelector.java
deleted file mode 100644
index 40ff11e..0000000
--- a/src/com/android/telecomm/EmergencyCallServiceSelector.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 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;
-
-import android.net.Uri;
-import android.telecomm.CallInfo;
-import android.telecomm.CallServiceDescriptor;
-import android.telecomm.CallServiceSelector;
-import android.telecomm.CallServiceSelectorAdapter;
-import android.telephony.PhoneNumberUtils;
-
-import com.google.common.collect.Lists;
-
-import java.util.List;
-
-/**
- * Selects call-services which can place emergency calls. For emergency handles, this selector is
- * always the first selector attempted when placing a call, see
- * {@link Switchboard#processNewOutgoingCall}. If this is ever invoked for a non-emergency handle,
- * this selector returns zero call services so that call-service selection continues to the next
- * selector. For emergency calls, it selects telephony's PSTN call services so that they are the
- * first ones to try to place the call.
- */
-public class EmergencyCallServiceSelector extends CallServiceSelector {
-
- /**
- * Returns true if the handle passed in is to a potential emergency number.
- */
- static boolean shouldUseSelector(Uri handle) {
- return PhoneNumberUtils.isPotentialLocalEmergencyNumber(
- TelecommApp.getInstance(), handle.getSchemeSpecificPart());
- }
-
- /** {@inheritDoc} */
- @Override
- protected void select(CallInfo callInfo, List<CallServiceDescriptor> descriptors) {
- List<CallServiceDescriptor> selectedDescriptors = Lists.newArrayList();
-
- // We check to see if the handle is potentially for an emergency call. *Potentially* means
- // that we match both the full number and prefix (e.g., "911444" matches 911). After the
- // call is made, the telephony call services will inform us of the actual number that was
- // connected, which would be 911. This is why we check *potential* APIs before, but use the
- // exact {@link PhoneNumberUtils#isLocalEmergencyNumber} once the call is connected.
- if (shouldUseSelector(callInfo.getHandle())) {
- // Search for and return the pstn call services if found.
- for (CallServiceDescriptor descriptor : descriptors) {
- // TODO(santoscordon): Consider adding some type of CAN_MAKE_EMERGENCY_CALLS
- // capability for call services and relying on that. Also consider combining this
- // with a permission so that we can check that instead of relying on hardcoded
- // paths.
- if (TelephonyUtil.isPstnCallService(descriptor)) {
- selectedDescriptors.add(descriptor);
- }
- }
- }
-
- getAdapter().setSelectedCallServices(callInfo.getId(), selectedDescriptors);
- }
-}
diff --git a/src/com/android/telecomm/OutgoingCallProcessor.java b/src/com/android/telecomm/OutgoingCallProcessor.java
index 366307c..625366f 100644
--- a/src/com/android/telecomm/OutgoingCallProcessor.java
+++ b/src/com/android/telecomm/OutgoingCallProcessor.java
@@ -16,15 +16,15 @@
package com.android.telecomm;
-import android.content.ComponentName;
+import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.telecomm.CallServiceDescriptor;
import android.telephony.DisconnectCause;
+import android.telephony.PhoneNumberUtils;
import com.android.telecomm.BaseRepository.LookupCallback;
import com.google.android.collect.Sets;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import java.util.ArrayList;
@@ -70,8 +70,6 @@
private final CallServiceRepository mCallServiceRepository;
- private final CallServiceSelectorRepository mSelectorRepository;
-
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -93,13 +91,6 @@
*/
private Iterator<CallServiceDescriptor> mCallServiceDescriptorIterator;
- /**
- * The list of currently-available call-service selector implementations.
- */
- private Collection<CallServiceSelectorWrapper> mSelectors;
-
- private Iterator<CallServiceSelectorWrapper> mSelectorIterator;
-
private AsyncResultCallback<Boolean> mResultCallback;
private boolean mIsAborted = false;
@@ -109,21 +100,17 @@
private String mLastErrorMsg = null;
/**
- * Persists the specified parameters and iterates through the prioritized list of selectors
- * passing to each selector (read-only versions of) the call object and all available call-
- * service descriptors. Stops once a matching selector is found. Calls with no matching
- * selectors will eventually be killed by the cleanup/monitor switchboard handler, which will
- * in turn call the abort method of this processor via {@link OutgoingCallsManager}.
+ * Persists the specified parameters and iterates through the prioritized list of call
+ * services. Stops once a matching call service is found. Calls with no matching
+ * call service will eventually be killed by the cleanup/monitor switchboard handler.
*
* @param call The call to place.
* @param callServiceRepository
- * @param selectorRepository
* @param resultCallback The callback on which to return the result.
*/
OutgoingCallProcessor(
Call call,
CallServiceRepository callServiceRepository,
- CallServiceSelectorRepository selectorRepository,
AsyncResultCallback<Boolean> resultCallback) {
ThreadUtil.checkOnMainThread();
@@ -131,7 +118,6 @@
mCall = call;
mResultCallback = resultCallback;
mCallServiceRepository = callServiceRepository;
- mSelectorRepository = selectorRepository;
}
/**
@@ -150,20 +136,6 @@
setCallServices(services);
}
});
-
- if (mCall.getCallServiceSelector() == null) {
- // Lookup selectors
- mSelectorRepository.lookupServices(
- new LookupCallback<CallServiceSelectorWrapper>() {
- @Override
- public void onComplete(
- Collection<CallServiceSelectorWrapper> selectors) {
- setSelectors(selectors);
- }
- });
- } else {
- setSelectors(ImmutableList.of(mCall.getCallServiceSelector()));
- }
}
}
@@ -235,23 +207,6 @@
}
/**
- * Persists the ordered-list of call-service descriptor as selected by the current selector and
- * starts iterating through the corresponding call services continuing the attempt to place the
- * call.
- *
- * @param descriptors The (ordered) list of call-service descriptor.
- */
- void processSelectedCallServices(List<CallServiceDescriptor> descriptors) {
- Log.v(this, "processSelectedCallServices");
- if (descriptors == null || descriptors.isEmpty()) {
- attemptNextSelector();
- } else if (mCallServiceDescriptorIterator == null) {
- mCallServiceDescriptorIterator = descriptors.iterator();
- attemptNextCallService();
- }
- }
-
- /**
* Sets the call services to attempt for this outgoing call.
*
* @param callServices The call services.
@@ -267,96 +222,15 @@
mCallServicesById.put(descriptor.getCallServiceId(), callService);
}
- onLookupComplete();
- }
+ adjustCallServiceDescriptorsForEmergency();
- /**
- * Sets the selectors to attemnpt for this outgoing call.
- *
- * @param selectors The call-service selectors.
- */
- private void setSelectors(Collection<CallServiceSelectorWrapper> selectors) {
- mSelectors = adjustForEmergencyCalls(selectors);
- onLookupComplete();
- }
-
- private void onLookupComplete() {
- if (!mIsAborted && mSelectors != null && mCallServiceDescriptors != null) {
- if (mSelectorIterator == null) {
- mSelectorIterator = mSelectors.iterator();
- attemptNextSelector();
- }
- }
- }
-
- /**
- * Updates the specified collection of selectors to accomodate for emergency calls and any
- * preferred selectors specified in the call object.
- *
- * @param selectors The selectors found through the selector repository.
- */
- private Collection<CallServiceSelectorWrapper> adjustForEmergencyCalls(
- Collection<CallServiceSelectorWrapper> selectors) {
- boolean useEmergencySelector =
- EmergencyCallServiceSelector.shouldUseSelector(mCall.getHandle());
- Log.d(this, "processNewOutgoingCall, isEmergency=%b", useEmergencySelector);
-
- if (useEmergencySelector) {
- // This is potentially an emergency call so add the emergency selector before the
- // other selectors.
- ImmutableList.Builder<CallServiceSelectorWrapper> selectorsBuilder =
- ImmutableList.builder();
-
- ComponentName componentName = new ComponentName(
- TelecommApp.getInstance(), EmergencyCallServiceSelector.class);
- CallServiceSelectorWrapper emergencySelector =
- new CallServiceSelectorWrapper(
- componentName.flattenToShortString(),
- componentName,
- CallsManager.getInstance());
-
- selectorsBuilder.add(emergencySelector);
- selectorsBuilder.addAll(selectors);
- selectors = selectorsBuilder.build();
- }
-
- return selectors;
- }
-
- /**
- * Attempts to place the call using the next selector, no-op if no other selectors
- * are available.
- */
- private void attemptNextSelector() {
- Log.v(this, "attemptNextSelector, mIsAborted: %b", mIsAborted);
- if (mIsAborted) {
- return;
- }
-
- if (mSelectorIterator.hasNext()) {
- CallServiceSelectorWrapper selector = mSelectorIterator.next();
- mCall.setCallServiceSelector(selector);
- selector.select(mCall, mCallServiceDescriptors,
- new AsyncResultCallback<List<CallServiceDescriptor>>() {
- @Override
- public void onResult(
- List<CallServiceDescriptor> descriptors,
- int errorCode, String errorMsg) {
- processSelectedCallServices(descriptors);
- }
- });
- } else {
- Log.v(this, "attemptNextSelector, no more selectors, failing");
- mCall.clearCallServiceSelector();
- sendResult(false, mLastErrorCode, mLastErrorMsg);
- }
+ mCallServiceDescriptorIterator = mCallServiceDescriptors.iterator();
+ attemptNextCallService();
}
/**
* Attempts to place the call using the call service specified by the next call-service
- * descriptor of mCallServiceDescriptorIterator. If there are no more call services to
- * attempt, the process continues to the next call-service selector via
- * {@link #attemptNextSelector}.
+ * descriptor of mCallServiceDescriptorIterator.
*/
private void attemptNextCallService() {
Log.v(this, "attemptNextCallService, mIsAborted: %b", mIsAborted);
@@ -397,9 +271,10 @@
});
}
} else {
+ Log.v(this, "attemptNextCallService, no more service descriptors, failing");
mCallServiceDescriptorIterator = null;
mCall.clearCallService();
- attemptNextSelector();
+ sendResult(false, mLastErrorCode, mLastErrorMsg);
}
}
@@ -413,4 +288,22 @@
Log.wtf(this, "Attempting to return outgoing result twice for call %s", mCall);
}
}
+
+ // If we are possibly attempting to call a local emergency number, ensure that the
+ // plain PSTN call service, if it exists, is attempted first.
+ private void adjustCallServiceDescriptorsForEmergency() {
+ if (shouldProcessAsEmergency(mCall.getHandle())) {
+ for (int i = 0; i < mCallServiceDescriptors.size(); i++) {
+ if (TelephonyUtil.isPstnCallService(mCallServiceDescriptors.get(i))) {
+ mCallServiceDescriptors.add(0, mCallServiceDescriptors.remove(i));
+ return;
+ }
+ }
+ }
+ }
+
+ private boolean shouldProcessAsEmergency(Uri handle) {
+ return PhoneNumberUtils.isPotentialLocalEmergencyNumber(
+ TelecommApp.getInstance(), handle.getSchemeSpecificPart());
+ }
}
diff --git a/src/com/android/telecomm/Switchboard.java b/src/com/android/telecomm/Switchboard.java
index 834bf44..7c6d44d 100644
--- a/src/com/android/telecomm/Switchboard.java
+++ b/src/com/android/telecomm/Switchboard.java
@@ -34,8 +34,7 @@
import java.util.Set;
/**
- * Switchboard is responsible for:
- * - gathering the {@link CallServiceWrapper}s and {@link CallServiceSelectorWrapper}s through
+ * Switchboard is responsible for gathering the {@link CallServiceWrapper}s through
* which to place outgoing calls
*/
final class Switchboard {
@@ -46,8 +45,6 @@
private final CallServiceRepository mCallServiceRepository;
- private final CallServiceSelectorRepository mSelectorRepository;
-
/** Singleton accessor. */
static Switchboard getInstance() {
return sInstance;
@@ -60,7 +57,6 @@
ThreadUtil.checkOnMainThread();
mIncomingCallsManager = new IncomingCallsManager();
- mSelectorRepository = new CallServiceSelectorRepository();
mCallServiceRepository =
new CallServiceRepository(mIncomingCallsManager);
}
@@ -69,10 +65,6 @@
return mCallServiceRepository;
}
- CallServiceSelectorRepository getSelectorRepository() {
- return mSelectorRepository;
- }
-
/**
* Retrieves details about the incoming call through the incoming call manager.
*
diff --git a/src/com/android/telecomm/TelephonyUtil.java b/src/com/android/telecomm/TelephonyUtil.java
index 4ea46d9..a8cfb3e 100644
--- a/src/com/android/telecomm/TelephonyUtil.java
+++ b/src/com/android/telecomm/TelephonyUtil.java
@@ -31,24 +31,16 @@
private static final String TELEPHONY_PACKAGE_NAME =
"com.android.phone";
- private static final String GSM_CALL_SERVICE_CLASS_NAME =
- "com.android.services.telephony.GsmConnectionService";
-
- private static final String CDMA_CALL_SERVICE_CLASS_NAME =
- "com.android.services.telephony.CdmaConnectionService";
+ private static final String PSTN_CALL_SERVICE_CLASS_NAME =
+ "com.android.services.telephony.PstnConnectionService";
private TelephonyUtil() {}
- static boolean isTelephonySelector(CallServiceSelectorWrapper selector) {
- return selector.getComponentName().getPackageName().equals(TELEPHONY_PACKAGE_NAME);
- }
-
static boolean isPstnCallService(CallServiceDescriptor descriptor) {
ComponentName componentName = descriptor.getServiceComponent();
if (TELEPHONY_PACKAGE_NAME.equals(componentName.getPackageName())) {
String className = componentName.getClassName();
- return GSM_CALL_SERVICE_CLASS_NAME.equals(className) ||
- CDMA_CALL_SERVICE_CLASS_NAME.equals(className);
+ return PSTN_CALL_SERVICE_CLASS_NAME.equals(className);
}
return false;
@@ -60,8 +52,7 @@
*/
static boolean isCurrentlyPSTNCall(Call call) {
if (Log.DEBUG) {
- verifyCallServiceExists(GSM_CALL_SERVICE_CLASS_NAME);
- verifyCallServiceExists(CDMA_CALL_SERVICE_CLASS_NAME);
+ verifyCallServiceExists(PSTN_CALL_SERVICE_CLASS_NAME);
}
CallServiceWrapper callService = call.getCallService();