Merge "Add audio mode APIs" into master-nova

This commit is contained in:
Sailesh Nepal
2014-03-25 00:17:01 +00:00
committed by Android (Google) Code Review
9 changed files with 313 additions and 18 deletions

View File

@@ -24624,6 +24624,21 @@ package android.speech.tts {
package android.telecomm {
public final class CallAudioState implements android.os.Parcelable {
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
field public static int ROUTE_ALL;
field public static int ROUTE_BLUETOOTH;
field public static int ROUTE_EARPIECE;
field public static int ROUTE_SPEAKER;
field public static int ROUTE_WIRED_HEADSET;
field public static int ROUTE_WIRED_OR_EARPIECE;
field public final boolean isMuted;
field public final int route;
field public final int supportedRouteMask;
}
public final class CallInfo implements android.os.Parcelable {
ctor public CallInfo(java.lang.String, android.telecomm.CallState, android.net.Uri);
method public int describeContents();
@@ -24645,6 +24660,7 @@ package android.telecomm {
method public final android.os.IBinder getBinder();
method public abstract void hold(java.lang.String);
method public abstract void isCompatibleWith(android.telecomm.CallInfo);
method public abstract void onAudioStateChanged(java.lang.String, android.telecomm.CallAudioState);
method public final android.os.IBinder onBind(android.content.Intent);
method public abstract void reject(java.lang.String);
method public abstract void setCallServiceAdapter(android.telecomm.CallServiceAdapter);
@@ -24732,13 +24748,16 @@ package android.telecomm {
method public void answerCall(java.lang.String);
method public void disconnectCall(java.lang.String);
method public void holdCall(java.lang.String);
method public void mute(boolean);
method public void rejectCall(java.lang.String);
method public void setAudioRoute(int);
method public void unholdCall(java.lang.String);
}
public abstract class InCallService extends android.app.Service {
ctor protected InCallService();
method protected abstract void addCall(android.telecomm.CallInfo);
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 setDisconnected(java.lang.String);

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 CallAudioState;

View File

@@ -0,0 +1,160 @@
/*
* 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 android.telecomm;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Locale;
/**
* Encapsulates all audio states during a call.
*/
public final class CallAudioState implements Parcelable {
/** Direct the audio stream through the device's earpiece. */
public static int ROUTE_EARPIECE = 0x00000001;
/** Direct the audio stream through Bluetooth. */
public static int ROUTE_BLUETOOTH = 0x00000002;
/** Direct the audio stream through a wired headset. */
public static int ROUTE_WIRED_HEADSET = 0x00000004;
/** Direct the audio stream through the device's spakerphone. */
public static int ROUTE_SPEAKER = 0x00000008;
/**
* Direct the audio stream through the device's earpiece or wired headset if one is
* connected.
*/
public static int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET;
/** Bit mask of all possible audio routes. */
public static int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET |
ROUTE_SPEAKER;
/** True if the call is muted, false otherwise. */
public final boolean isMuted;
/** The route to use for the audio stream. */
public final int route;
/** Bit vector of all routes supported by this call. */
public final int supportedRouteMask;
/** @hide */
public CallAudioState(boolean isMuted, int route, int supportedRouteMask) {
this.isMuted = isMuted;
this.route = route;
this.supportedRouteMask = supportedRouteMask;
}
/** @hide */
public CallAudioState(CallAudioState state) {
isMuted = state.isMuted;
route = state.route;
supportedRouteMask = state.supportedRouteMask;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof CallAudioState)) {
return false;
}
CallAudioState state = (CallAudioState) obj;
return isMuted == state.isMuted && route == state.route &&
supportedRouteMask == state.supportedRouteMask;
}
@Override
public String toString() {
return String.format(Locale.US,
"[CallAudioState isMuted: %b, route; %s, supportedRouteMask: %s]",
isMuted, audioRouteToString(route), audioRouteToString(supportedRouteMask));
}
/** @hide */
public static String audioRouteToString(int route) {
if (route == 0 || (route & ~ROUTE_ALL) != 0x0) {
return "UNKNOWN";
}
StringBuffer buffer = new StringBuffer();
if ((route & ROUTE_EARPIECE) == ROUTE_EARPIECE) {
listAppend(buffer, "EARPIECE");
}
if ((route & ROUTE_BLUETOOTH) == ROUTE_BLUETOOTH) {
listAppend(buffer, "BLUETOOTH");
}
if ((route & ROUTE_WIRED_HEADSET) == ROUTE_WIRED_HEADSET) {
listAppend(buffer, "WIRED_HEADSET");
}
if ((route & ROUTE_SPEAKER) == ROUTE_SPEAKER) {
listAppend(buffer, "SPEAKER");
}
return buffer.toString();
}
private static void listAppend(StringBuffer buffer, String str) {
if (buffer.length() > 0) {
buffer.append(", ");
}
buffer.append(str);
}
/**
* Responsible for creating CallAudioState objects for deserialized Parcels.
*/
public static final Parcelable.Creator<CallAudioState> CREATOR =
new Parcelable.Creator<CallAudioState> () {
@Override
public CallAudioState createFromParcel(Parcel source) {
boolean isMuted = source.readByte() == 0 ? false : true;
int route = source.readInt();
int supportedRouteMask = source.readInt();
return new CallAudioState(isMuted, route, supportedRouteMask);
}
@Override
public CallAudioState[] newArray(int size) {
return new CallAudioState[size];
}
};
/**
* {@inheritDoc}
*/
@Override
public int describeContents() {
return 0;
}
/**
* Writes CallAudioState object into a serializeable Parcel.
*/
@Override
public void writeToParcel(Parcel destination, int flags) {
destination.writeByte((byte) (isMuted ? 1 : 0));
destination.writeInt(route);
destination.writeInt(supportedRouteMask);
}
}

View File

@@ -46,6 +46,18 @@ import com.android.internal.telecomm.ICallServiceAdapter;
*/
public abstract class CallService extends Service {
private static final int MSG_SET_CALL_SERVICE_ADAPTER = 1;
private static final int MSG_IS_COMPATIBLE_WITH = 2;
private static final int MSG_CALL = 3;
private static final int MSG_ABORT = 4;
private static final int MSG_SET_INCOMING_CALL_ID = 5;
private static final int MSG_ANSWER = 6;
private static final int MSG_REJECT = 7;
private static final int MSG_DISCONNECT = 8;
private static final int MSG_HOLD = 9;
private static final int MSG_UNHOLD = 10;
private static final int MSG_ON_AUDIO_STATE_CHANGED = 11;
/**
* Default Handler used to consolidate binder method calls onto a single thread.
*/
@@ -67,7 +79,7 @@ public abstract class CallService extends Service {
case MSG_ABORT:
abort((String) msg.obj);
break;
case MSG_SET_INCOMING_CALL_ID:
case MSG_SET_INCOMING_CALL_ID: {
SomeArgs args = (SomeArgs) msg.obj;
try {
String callId = (String) args.arg1;
@@ -77,6 +89,7 @@ public abstract class CallService extends Service {
args.recycle();
}
break;
}
case MSG_ANSWER:
answer((String) msg.obj);
break;
@@ -92,6 +105,17 @@ public abstract class CallService extends Service {
case MSG_UNHOLD:
unhold((String) msg.obj);
break;
case MSG_ON_AUDIO_STATE_CHANGED: {
SomeArgs args = (SomeArgs) msg.obj;
try {
String callId = (String) args.arg1;
CallAudioState audioState = (CallAudioState) args.arg2;
onAudioStateChanged(callId, audioState);
} finally {
args.recycle();
}
break;
}
default:
break;
}
@@ -155,24 +179,15 @@ public abstract class CallService extends Service {
public void unhold(String callId) {
mMessageHandler.obtainMessage(MSG_UNHOLD, callId).sendToTarget();
}
}
// Only used internally by this class.
// Binder method calls on this service can occur on multiple threads. These messages are used
// in conjunction with {@link #mMessageHandler} to ensure that all callbacks are handled on a
// single thread. Keeping it on a single thread allows CallService implementations to avoid
// needing multi-threaded code in their own callback routines.
private static final int
MSG_SET_CALL_SERVICE_ADAPTER = 1,
MSG_IS_COMPATIBLE_WITH = 2,
MSG_CALL = 3,
MSG_ABORT = 4,
MSG_SET_INCOMING_CALL_ID = 5,
MSG_ANSWER = 6,
MSG_REJECT = 7,
MSG_DISCONNECT = 8,
MSG_HOLD = 9,
MSG_UNHOLD = 10;
@Override
public void onAudioStateChanged(String callId, CallAudioState audioState) {
SomeArgs args = SomeArgs.obtain();
args.arg1 = callId;
args.arg2 = audioState;
mMessageHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, args).sendToTarget();
}
}
/**
* Message handler for consolidating binder callbacks onto a single thread.
@@ -290,4 +305,12 @@ public abstract class CallService extends Service {
* @param callId The ID of the call to unhold.
*/
public abstract void unhold(String callId);
/**
* Called when the audio state changes.
*
* @param activeCallId The identifier of the call that was active during the state change.
* @param audioState The new {@link CallAudioState}.
*/
public abstract void onAudioStateChanged(String activeCallId, CallAudioState audioState);
}

View File

@@ -102,4 +102,28 @@ public final class InCallAdapter {
} catch (RemoteException e) {
}
}
/**
* Mute the microphone.
*
* @param shouldMute True if the microphone should be muted.
*/
public void mute(boolean shouldMute) {
try {
mAdapter.mute(shouldMute);
} catch (RemoteException e) {
}
}
/**
* Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}.
*
* @param route The audio route to use.
*/
public void setAudioRoute(int route) {
try {
mAdapter.setAudioRoute(route);
} catch (RemoteException e) {
}
}
}

View File

@@ -40,6 +40,7 @@ public abstract class InCallService extends Service {
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_ON_AUDIO_STATE_CHANGED = 6;
/** Default Handler used to consolidate binder method calls onto a single thread. */
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
@@ -61,6 +62,9 @@ public abstract class InCallService extends Service {
break;
case MSG_SET_HOLD:
setOnHold((String) msg.obj);
break;
case MSG_ON_AUDIO_STATE_CHANGED:
onAudioStateChanged((CallAudioState) msg.obj);
default:
break;
}
@@ -98,6 +102,12 @@ public abstract class InCallService extends Service {
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();
}
}
private final InCallServiceBinder mBinder;
@@ -153,4 +163,11 @@ public abstract class InCallService extends Service {
* @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);
}

View File

@@ -17,6 +17,7 @@
package com.android.internal.telecomm;
import android.os.Bundle;
import android.telecomm.CallAudioState;
import android.telecomm.CallInfo;
import com.android.internal.telecomm.ICallServiceAdapter;
@@ -136,4 +137,12 @@ oneway interface ICallService {
* @param callId The identifier of the call to remove from hold.
*/
void unhold(String callId);
/**
* Called when the audio state changes.
*
* @param activeCallId The identifier of the call that was active during the state change.
* @param audioState The new {@link CallAudioState}.
*/
void onAudioStateChanged(String activeCallId, in CallAudioState audioState);
}

View File

@@ -16,6 +16,8 @@
package com.android.internal.telecomm;
import android.telecomm.CallAudioState;
/**
* Receives commands from {@link IInCallService} implementations which should be executed by
* Telecomm. When Telecomm binds to a {@link IInCallService}, an instance of this class is given to
@@ -67,4 +69,18 @@ oneway interface IInCallAdapter {
* @param callId The identifier of the call to release from hold.
*/
void unholdCall(String callId);
/**
* Mute the microphone.
*
* @param shouldMute True if the microphone should be muted.
*/
void mute(boolean shouldMute);
/**
* Sets the audio route (speaker, bluetooth, etc...). See {@link CallAudioState}.
*
* @param route The audio route to use.
*/
void setAudioRoute(int route);
}

View File

@@ -16,6 +16,7 @@
package com.android.internal.telecomm;
import android.telecomm.CallAudioState;
import android.telecomm.CallInfo;
import com.android.internal.telecomm.IInCallAdapter;
@@ -74,4 +75,11 @@ oneway interface IInCallService {
* @param callId The identifier of the call that was put on hold.
*/
void setOnHold(String callId);
/**
* Called when the audio state changes.
*
* @param audioState The new {@link CallAudioState}.
*/
void onAudioStateChanged(in CallAudioState audioState);
}