Add InCallCall class to communicate with InCallService

Change-Id: I3916e33e184f57bb6e58ed93a26b866d3ce0e7df
This commit is contained in:
Sailesh Nepal
2014-04-05 16:44:55 -07:00
parent 1782d21ce4
commit 6043793d3e
9 changed files with 245 additions and 174 deletions

View File

@@ -25011,21 +25011,31 @@ package android.telecomm {
method public void unholdCall(java.lang.String);
}
public final class InCallCall implements android.os.Parcelable {
method public int describeContents();
method public int getCapabilities();
method public long getConnectTimeMillis();
method public android.telecomm.CallServiceDescriptor getCurrentCallServiceDescriptor();
method public int getDisconnectCause();
method public android.telecomm.GatewayInfo getGatewayInfo();
method public android.net.Uri getHandle();
method public android.telecomm.CallServiceDescriptor getHandoffCallServiceDescriptor();
method public java.lang.String getId();
method public android.telecomm.CallState getState();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
}
public abstract class InCallService extends android.app.Service {
ctor protected InCallService();
method protected abstract void addCall(android.telecomm.CallInfo);
method protected abstract void addCall(android.telecomm.InCallCall);
method protected final android.telecomm.InCallAdapter getAdapter();
method protected void onAdapterAttached(android.telecomm.InCallAdapter);
method protected abstract void onAudioStateChanged(android.telecomm.CallAudioState);
method public final android.os.IBinder onBind(android.content.Intent);
method protected abstract void setActive(java.lang.String);
method protected abstract void setDialing(java.lang.String);
method protected abstract void setDisconnected(java.lang.String, int);
method protected abstract void setHandoffEnabled(java.lang.String, boolean);
method protected abstract void setOnHold(java.lang.String);
method protected abstract void setPostDial(java.lang.String, java.lang.String);
method protected abstract void setPostDialWait(java.lang.String, java.lang.String);
method protected abstract void setRinging(java.lang.String);
method protected abstract void updateCall(android.telecomm.InCallCall);
}
public final class TelecommConstants {

View File

@@ -22,7 +22,6 @@ import android.os.Parcel;
import android.os.Parcelable;
import java.util.Date;
import java.util.UUID;
/**
* A parcelable holder class of Call information data. This class is intended for transfering call
@@ -32,7 +31,7 @@ import java.util.UUID;
public final class CallInfo implements Parcelable {
/**
* Unique identifier for the call as a UUID string.
* Unique identifier for the call.
*/
private final String mId;
@@ -61,18 +60,6 @@ public final class CallInfo implements Parcelable {
/** The descriptor for the call service currently routing this call. */
private final CallServiceDescriptor mCurrentCallServiceDescriptor;
// There are 4 timestamps that are important to a call:
// 1) Created timestamp - The time at which the user explicitly chose to make the call.
// 2) Connected timestamp - The time at which a call service confirms that it has connected
// this call. This happens through a method-call to either newOutgoingCall or newIncomingCall
// on CallServiceAdapter. Generally this should coincide roughly to the user physically
// hearing/seeing a ring.
// TODO(santoscordon): Consider renaming Call-active to better match the others.
// 3) Call-active timestamp - The time at which the call switches to the active state. This
// happens when the user answers an incoming call or an outgoing call was answered by the
// other party.
// 4) Disconnected timestamp - The time at which the call was disconnected.
public CallInfo(String id, CallState state, Uri handle) {
this(id, state, handle, null, Bundle.EMPTY, null);
}
@@ -141,16 +128,10 @@ public final class CallInfo implements Parcelable {
return mCurrentCallServiceDescriptor;
}
//
// Parceling related code below here.
//
/**
* Responsible for creating CallInfo objects for deserialized Parcels.
*/
public static final Parcelable.Creator<CallInfo> CREATOR =
new Parcelable.Creator<CallInfo> () {
public static final Parcelable.Creator<CallInfo> CREATOR = new Parcelable.Creator<CallInfo> () {
@Override
public CallInfo createFromParcel(Parcel source) {
String id = source.readString();

View File

@@ -68,10 +68,8 @@ public abstract class CallService extends Service {
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SET_CALL_SERVICE_ADAPTER:
CallServiceAdapter adapter =
new CallServiceAdapter((ICallServiceAdapter) msg.obj);
mAdapter = adapter;
onAdapterAttached(adapter);
mAdapter = new CallServiceAdapter((ICallServiceAdapter) msg.obj);
onAdapterAttached(mAdapter);
break;
case MSG_IS_COMPATIBLE_WITH:
isCompatibleWith((CallInfo) msg.obj);

View File

@@ -108,6 +108,21 @@ public final class CallServiceDescriptor implements Parcelable {
return mNetworkType;
}
/** {@inheritDoc} */
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof CallServiceDescriptor)) {
return false;
}
CallServiceDescriptor descriptor = (CallServiceDescriptor) obj;
return mCallServiceId.equals(descriptor.mCallServiceId) &&
mComponentName.equals(descriptor.mComponentName) &&
mNetworkType == descriptor.mNetworkType;
}
/**
* @param context {@link Context} to use for the construction of the {@link Builder}.
* @return A new {@link Builder} instance.

View File

@@ -50,10 +50,9 @@ public abstract class CallServiceSelector extends Service {
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SET_CALL_SERVICE_SELECTOR_ADAPTER:
CallServiceSelectorAdapter adapter = new CallServiceSelectorAdapter(
mAdapter = new CallServiceSelectorAdapter(
(ICallServiceSelectorAdapter) msg.obj);
mAdapter = adapter;
onAdapterAttached(adapter);
onAdapterAttached(mAdapter);
break;
case MSG_SELECT:
SomeArgs args = (SomeArgs) msg.obj;

View File

@@ -0,0 +1,19 @@
/*
* 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 android.telecomm;
parcelable InCallCall;

View File

@@ -0,0 +1,159 @@
/*
* 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 android.telecomm;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.DisconnectCause;
import java.util.Date;
import java.util.UUID;
/**
* Information about a call that is used between InCallService and Telecomm.
*/
public final class InCallCall implements Parcelable {
private final String mId;
private final CallState mState;
private final int mDisconnectCause;
private final int mCapabilities;
private final long mConnectTimeMillis;
private final Uri mHandle;
private final GatewayInfo mGatewayInfo;
private final CallServiceDescriptor mCurrentCallServiceDescriptor;
private final CallServiceDescriptor mHandoffCallServiceDescriptor;
/** @hide */
public InCallCall(
String id,
CallState state,
int disconnectCause,
int capabilities,
long connectTimeMillis,
Uri handle,
GatewayInfo gatewayInfo,
CallServiceDescriptor descriptor,
CallServiceDescriptor handoffDescriptor) {
mId = id;
mState = state;
mDisconnectCause = disconnectCause;
mCapabilities = capabilities;
mConnectTimeMillis = connectTimeMillis;
mHandle = handle;
mGatewayInfo = gatewayInfo;
mCurrentCallServiceDescriptor = descriptor;
mHandoffCallServiceDescriptor = handoffDescriptor;
}
/** The unique ID of the call. */
public String getId() {
return mId;
}
/** The current state of the call. */
public CallState getState() {
return mState;
}
/**
* Reason for disconnection, values are defined in {@link DisconnectCause}. Valid when call
* state is {@link CallState.DISCONNECTED}.
*/
public int getDisconnectCause() {
return mDisconnectCause;
}
// Bit mask of actions a call supports, values are defined in {@link CallCapabilities}.
public int getCapabilities() {
return mCapabilities;
}
/** The time that the call switched to the active state. */
public long getConnectTimeMillis() {
return mConnectTimeMillis;
}
/** The endpoint to which the call is connected. */
public Uri getHandle() {
return mHandle;
}
/** Gateway information for the call. */
public GatewayInfo getGatewayInfo() {
return mGatewayInfo;
}
/** The descriptor for the call service currently routing this call. */
public CallServiceDescriptor getCurrentCallServiceDescriptor() {
return mCurrentCallServiceDescriptor;
}
/**
* The descriptor for the call service that this call is being switched to, null if handoff is
* not in progress.
*/
public CallServiceDescriptor getHandoffCallServiceDescriptor() {
return mHandoffCallServiceDescriptor;
}
/** Responsible for creating InCallCall objects for deserialized Parcels. */
public static final Parcelable.Creator<InCallCall> CREATOR =
new Parcelable.Creator<InCallCall> () {
@Override
public InCallCall createFromParcel(Parcel source) {
String id = source.readString();
CallState state = CallState.valueOf(source.readString());
int disconnectCause = source.readInt();
int capabilities = source.readInt();
long connectTimeMillis = source.readLong();
ClassLoader classLoader = InCallCall.class.getClassLoader();
Uri handle = source.readParcelable(classLoader);
GatewayInfo gatewayInfo = source.readParcelable(classLoader);
CallServiceDescriptor descriptor = source.readParcelable(classLoader);
CallServiceDescriptor handoffDescriptor = source.readParcelable(classLoader);
return new InCallCall(id, state, disconnectCause, capabilities, connectTimeMillis,
handle, gatewayInfo, descriptor, handoffDescriptor);
}
@Override
public InCallCall[] newArray(int size) {
return new InCallCall[size];
}
};
/** {@inheritDoc} */
@Override
public int describeContents() {
return 0;
}
/** Writes InCallCall object into a Parcel. */
@Override
public void writeToParcel(Parcel destination, int flags) {
destination.writeString(mId);
destination.writeString(mState.name());
destination.writeInt(mDisconnectCause);
destination.writeInt(mCapabilities);
destination.writeLong(mConnectTimeMillis);
destination.writeParcelable(mHandle, 0);
destination.writeParcelable(mGatewayInfo, 0);
destination.writeParcelable(mCurrentCallServiceDescriptor, 0);
destination.writeParcelable(mHandoffCallServiceDescriptor, 0);
}
}

View File

@@ -38,15 +38,10 @@ import com.android.internal.telecomm.IInCallService;
public abstract class InCallService extends Service {
private static final int MSG_SET_IN_CALL_ADAPTER = 1;
private static final int MSG_ADD_CALL = 2;
private static final int MSG_SET_ACTIVE = 3;
private static final int MSG_SET_DISCONNECTED = 4;
private static final int MSG_SET_HOLD = 5;
private static final int MSG_UPDATE_CALL = 3;
private static final int MSG_SET_POST_DIAL = 4;
private static final int MSG_SET_POST_DIAL_WAIT = 5;
private static final int MSG_ON_AUDIO_STATE_CHANGED = 6;
private static final int MSG_SET_DIALING = 7;
private static final int MSG_SET_RINGING = 8;
private static final int MSG_SET_POST_DIAL = 9;
private static final int MSG_SET_POST_DIAL_WAIT = 10;
private static final int MSG_SET_HANDOFF_ENABLED = 11;
/** Default Handler used to consolidate binder method calls onto a single thread. */
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
@@ -54,21 +49,14 @@ public abstract class InCallService extends Service {
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_SET_IN_CALL_ADAPTER:
InCallAdapter adapter = new InCallAdapter((IInCallAdapter) msg.obj);
mAdapter = adapter;
onAdapterAttached(adapter);
mAdapter = new InCallAdapter((IInCallAdapter) msg.obj);
onAdapterAttached(mAdapter);
break;
case MSG_ADD_CALL:
addCall((CallInfo) msg.obj);
addCall((InCallCall) msg.obj);
break;
case MSG_SET_ACTIVE:
setActive((String) msg.obj);
break;
case MSG_SET_DIALING:
setDialing((String) msg.obj);
break;
case MSG_SET_RINGING:
setRinging((String) msg.obj);
case MSG_UPDATE_CALL:
updateCall((InCallCall) msg.obj);
break;
case MSG_SET_POST_DIAL: {
SomeArgs args = (SomeArgs) msg.obj;
@@ -92,18 +80,9 @@ public abstract class InCallService extends Service {
}
break;
}
case MSG_SET_DISCONNECTED:
setDisconnected((String) msg.obj, msg.arg1);
break;
case MSG_SET_HOLD:
setOnHold((String) msg.obj);
break;
case MSG_ON_AUDIO_STATE_CHANGED:
onAudioStateChanged((CallAudioState) msg.obj);
break;
case MSG_SET_HANDOFF_ENABLED:
setHandoffEnabled((String) msg.obj, msg.arg1 == 1 ? true : false);
break;
default:
break;
}
@@ -120,42 +99,14 @@ public abstract class InCallService extends Service {
/** {@inheritDoc} */
@Override
public void addCall(CallInfo callInfo) {
mHandler.obtainMessage(MSG_ADD_CALL, callInfo).sendToTarget();
public void addCall(InCallCall call) {
mHandler.obtainMessage(MSG_ADD_CALL, call).sendToTarget();
}
/** {@inheritDoc} */
@Override
public void setActive(String callId) {
mHandler.obtainMessage(MSG_SET_ACTIVE, callId).sendToTarget();
}
/** {@inheritDoc} */
@Override
public void setDisconnected(String callId, int disconnectCause) {
mHandler.obtainMessage(MSG_SET_DISCONNECTED, disconnectCause, 0, callId).sendToTarget();
}
/** {@inheritDoc} */
@Override
public void setOnHold(String callId) {
mHandler.obtainMessage(MSG_SET_HOLD, callId).sendToTarget();
}
/** {@inheritDoc} */
@Override
public void onAudioStateChanged(CallAudioState audioState) {
mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, audioState).sendToTarget();
}
@Override
public void setDialing(String callId) {
mHandler.obtainMessage(MSG_SET_DIALING, callId).sendToTarget();
}
@Override
public void setRinging(String callId) {
mHandler.obtainMessage(MSG_SET_RINGING, callId).sendToTarget();
public void updateCall(InCallCall call) {
mHandler.obtainMessage(MSG_UPDATE_CALL, call).sendToTarget();
}
@Override
@@ -174,10 +125,10 @@ public abstract class InCallService extends Service {
mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget();
}
/** {@inheritDoc} */
@Override
public void setHandoffEnabled(String callId, boolean isHandoffEnabled) {
mHandler.obtainMessage(MSG_SET_HANDOFF_ENABLED, isHandoffEnabled ? 1 : 0, 0,
callId).sendToTarget();
public void onAudioStateChanged(CallAudioState audioState) {
mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, audioState).sendToTarget();
}
}
@@ -212,75 +163,25 @@ public abstract class InCallService extends Service {
/**
* Indicates to the in-call app that a new call has been created and an appropriate
* user-interface should be built and shown to notify the user. Information about the call
* including its current state is passed in through the callInfo object.
* user-interface should be built and shown to notify the user.
*
* @param callInfo Information about the new call.
* @param call Information about the new call.
*/
protected abstract void addCall(CallInfo callInfo);
protected abstract void addCall(InCallCall call);
/**
* Indicates to the in-call app that the specified call is currently connected to another party
* and a communication channel is open between them. Normal transitions are to
* {@link #setDisconnected(String,int)} when the call is complete.
* Call when information about a call has changed.
*
* @param callId The identifier of the call changing state.
* @param call Information about the new call.
*/
protected abstract void setActive(String callId);
/**
* Indicates to the in-call app that the specified call is outgoing and in the dialing state.
* Normal transition are to {@link #setActive(String)} if the call was answered,
* {@link #setPostDial(String,String)} if the dialed number includes a post-dial DTMF string, or
* {@link #setDisconnected(String,int)} if the call was disconnected immediately.
*
* @param callId The identifier of the call changing state.
*/
protected abstract void setDialing(String callId);
/**
* Indicates to the in-call app that the specified call is incoming and the user still has the
* option of answering, rejecting, or doing nothing with the call. This state is usually
* associated with some type of audible ringtone. Normal transitions are to
* {@link #setActive(String)} if the call is answered, or {@link #setDisconnected(String,int)}
* if the call is not answered or is otherwise disconnected for some reason.
*
* @param callId The identifier of the call changing state.
*/
protected abstract void setRinging(String callId);
/**
* Indicates to the in-call app that a call has been moved to the
* {@link CallState#DISCONNECTED} and the user should be notified.
*
* @param callId The identifier of the call that was disconnected.
* @param disconnectCause The reason for the disconnection, any of
* {@link android.telephony.DisconnectCause}.
*/
protected abstract void setDisconnected(String callId, int disconnectCause);
/**
* Indicates to the in-call app that a call has been moved to the
* {@link android.telecomm.CallState#ON_HOLD} state and the user should be notified.
*
* @param callId The identifier of the call that was put on hold.
*/
protected abstract void setOnHold(String callId);
/**
* Called when the audio state changes.
*
* @param audioState The new {@link CallAudioState}.
*/
protected abstract void onAudioStateChanged(CallAudioState audioState);
protected abstract void updateCall(InCallCall call);
/**
* Indicates to the in-call app that the specified call is active but in a "post-dial" state
* where Telecomm is now sending some dual-tone multi-frequency signaling (DTMF) tones appended
* to the dialed number. Normal transitions are to {@link #setPostDialWait(String,String)} when
* the post-dial string requires user confirmation to proceed, {@link #setActive(String)} when
* the post-dial tones are completed, or {@link #setDisconnected(String,int)} if the call is
* disconnected.
* the post-dial tones are completed.
*
* @param callId The identifier of the call changing state.
* @param remaining The remaining postdial string to be dialed.
@@ -300,10 +201,9 @@ public abstract class InCallService extends Service {
protected abstract void setPostDialWait(String callId, String remaining);
/**
* Called when the call's handoff state has changed.
* Called when the audio state changes.
*
* @param callId The identifier of the call whose handoff state was changed.
* @param isHandoffEnabled True if handoff is enabled.
* @param audioState The new {@link CallAudioState}.
*/
protected abstract void setHandoffEnabled(String callId, boolean isHandoffEnabled);
protected abstract void onAudioStateChanged(CallAudioState audioState);
}

View File

@@ -17,7 +17,7 @@
package com.android.internal.telecomm;
import android.telecomm.CallAudioState;
import android.telecomm.CallInfo;
import android.telecomm.InCallCall;
import com.android.internal.telecomm.IInCallAdapter;
@@ -31,23 +31,13 @@ import com.android.internal.telecomm.IInCallAdapter;
oneway interface IInCallService {
void setInCallAdapter(in IInCallAdapter inCallAdapter);
void addCall(in CallInfo callInfo);
void addCall(in InCallCall call);
void setActive(String callId);
void setDisconnected(String callId, int disconnectCause);
void setDialing(in String callId);
void setOnHold(String callId);
void onAudioStateChanged(in CallAudioState audioState);
void setRinging(String callId);
void updateCall(in InCallCall call);
void setPostDial(String callId, String remaining);
void setPostDialWait(String callId, String remaining);
void setHandoffEnabled(String callId, boolean isHandoffEnabled);
void onAudioStateChanged(in CallAudioState audioState);
}