diff options
author | 2016-11-30 16:06:42 -0800 | |
---|---|---|
committer | 2016-12-01 17:18:35 -0800 | |
commit | 4e22d6dc453de8e15e19e842c189522796c1cf80 (patch) | |
tree | f776eab84cd85bbb72e6200a996f6ffcac3be681 | |
parent | 75bf81458e8f7dd0213581d54a342ec05f13fbcf (diff) |
Add ability to set supported audio routes on phone accounts and connection
The set audio routes are used by Telecom to restrict where the audio may
be routed to. For example, an account can specify that calls may not be
routed over bluetooth headsets, which will prevent a new call from being
routed to this source.
This is a cherry-pick of abandoned ag/1521009.
Bug: 32958838
Change-Id: Idd5e4d38b157f11454f3d991385644f2f384596e
-rw-r--r-- | telecomm/java/android/telecom/Call.java | 10 | ||||
-rw-r--r-- | telecomm/java/android/telecom/CallAudioState.java | 8 | ||||
-rw-r--r-- | telecomm/java/android/telecom/Connection.java | 33 | ||||
-rw-r--r-- | telecomm/java/android/telecom/ConnectionService.java | 2 | ||||
-rw-r--r-- | telecomm/java/android/telecom/ParcelableCall.java | 11 | ||||
-rw-r--r-- | telecomm/java/android/telecom/ParcelableConnection.java | 10 | ||||
-rw-r--r-- | telecomm/java/android/telecom/PhoneAccount.java | 76 |
7 files changed, 136 insertions, 14 deletions
diff --git a/telecomm/java/android/telecom/Call.java b/telecomm/java/android/telecom/Call.java index 62625bdf953e..58c500244d3b 100644 --- a/telecomm/java/android/telecom/Call.java +++ b/telecomm/java/android/telecom/Call.java @@ -324,6 +324,7 @@ public final class Call { private final PhoneAccountHandle mAccountHandle; private final int mCallCapabilities; private final int mCallProperties; + private final int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL; private final DisconnectCause mDisconnectCause; private final long mConnectTimeMillis; private final GatewayInfo mGatewayInfo; @@ -536,6 +537,15 @@ public final class Call { } /** + * @return a bitmask of the audio routes available for the call. + * + * @hide + */ + public int getSupportedAudioRoutes() { + return mSupportedAudioRoutes; + } + + /** * @return For a {@link #STATE_DISCONNECTED} {@code Call}, the disconnect cause expressed * by {@link android.telecom.DisconnectCause}. */ diff --git a/telecomm/java/android/telecom/CallAudioState.java b/telecomm/java/android/telecom/CallAudioState.java index 2b1672209a3d..f601d8b545ac 100644 --- a/telecomm/java/android/telecom/CallAudioState.java +++ b/telecomm/java/android/telecom/CallAudioState.java @@ -44,8 +44,12 @@ public final class CallAudioState implements Parcelable { */ public static final int ROUTE_WIRED_OR_EARPIECE = ROUTE_EARPIECE | ROUTE_WIRED_HEADSET; - /** Bit mask of all possible audio routes. */ - private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET | + /** + * Bit mask of all possible audio routes. + * + * @hide + **/ + public static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET | ROUTE_SPEAKER; private final boolean isMuted; diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java index 8f9c7585ced6..6cf98281b527 100644 --- a/telecomm/java/android/telecom/Connection.java +++ b/telecomm/java/android/telecom/Connection.java @@ -722,6 +722,7 @@ public abstract class Connection extends Conferenceable { public void onDestroyed(Connection c) {} public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {} public void onConnectionPropertiesChanged(Connection c, int properties) {} + public void onSupportedAudioRoutesChanged(Connection c, int supportedAudioRoutes) {} public void onVideoProviderChanged( Connection c, VideoProvider videoProvider) {} public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {} @@ -1428,6 +1429,7 @@ public abstract class Connection extends Conferenceable { private boolean mRingbackRequested = false; private int mConnectionCapabilities; private int mConnectionProperties; + private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL; private VideoProvider mVideoProvider; private boolean mAudioModeIsVoip; private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED; @@ -1708,6 +1710,15 @@ public abstract class Connection extends Conferenceable { } /** + * Returns the connection's supported audio routes. + * + * @hide + */ + public final int getSupportedAudioRoutes() { + return mSupportedAudioRoutes; + } + + /** * Sets the value of the {@link #getAddress()} property. * * @param address The new address. @@ -1929,6 +1940,28 @@ public abstract class Connection extends Conferenceable { } /** + * Sets the supported audio routes. + * + * @param supportedAudioRoutes the supported audio routes as a bitmask. + * See {@link CallAudioState} + * @hide + */ + public final void setSupportedAudioRoutes(int supportedAudioRoutes) { + if ((supportedAudioRoutes + & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_SPEAKER)) == 0) { + throw new IllegalArgumentException( + "supported audio routes must include either speaker or earpiece"); + } + + if (mSupportedAudioRoutes != supportedAudioRoutes) { + mSupportedAudioRoutes = supportedAudioRoutes; + for (Listener l : mListeners) { + l.onSupportedAudioRoutesChanged(this, mSupportedAudioRoutes); + } + } + } + + /** * Tears down the Connection object. */ public final void destroy() { diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java index dd55ca9f1f19..f7822325c4cb 100644 --- a/telecomm/java/android/telecom/ConnectionService.java +++ b/telecomm/java/android/telecom/ConnectionService.java @@ -776,6 +776,7 @@ public abstract class ConnectionService extends Service { connection.getState(), connection.getConnectionCapabilities(), connection.getConnectionProperties(), + connection.getSupportedAudioRoutes(), connection.getAddress(), connection.getAddressPresentation(), connection.getCallerDisplayName(), @@ -1175,6 +1176,7 @@ public abstract class ConnectionService extends Service { connection.getState(), connection.getConnectionCapabilities(), connection.getConnectionProperties(), + connection.getSupportedAudioRoutes(), connection.getAddress(), connection.getAddressPresentation(), connection.getCallerDisplayName(), diff --git a/telecomm/java/android/telecom/ParcelableCall.java b/telecomm/java/android/telecom/ParcelableCall.java index 4a6fd7c16c1a..f7a6595241e0 100644 --- a/telecomm/java/android/telecom/ParcelableCall.java +++ b/telecomm/java/android/telecom/ParcelableCall.java @@ -39,6 +39,7 @@ public final class ParcelableCall implements Parcelable { private final List<String> mCannedSmsResponses; private final int mCapabilities; private final int mProperties; + private final int mSupportedAudioRoutes; private final long mConnectTimeMillis; private final Uri mHandle; private final int mHandlePresentation; @@ -64,6 +65,7 @@ public final class ParcelableCall implements Parcelable { List<String> cannedSmsResponses, int capabilities, int properties, + int supportedAudioRoutes, long connectTimeMillis, Uri handle, int handlePresentation, @@ -86,6 +88,7 @@ public final class ParcelableCall implements Parcelable { mCannedSmsResponses = cannedSmsResponses; mCapabilities = capabilities; mProperties = properties; + mSupportedAudioRoutes = supportedAudioRoutes; mConnectTimeMillis = connectTimeMillis; mHandle = handle; mHandlePresentation = handlePresentation; @@ -137,6 +140,11 @@ public final class ParcelableCall implements Parcelable { /** Bitmask of properties of the call. */ public int getProperties() { return mProperties; } + /** Bitmask of supported routes of the call */ + public int getSupportedAudioRoutes() { + return mSupportedAudioRoutes; + } + /** The time that the call switched to the active state. */ public long getConnectTimeMillis() { return mConnectTimeMillis; @@ -292,6 +300,7 @@ public final class ParcelableCall implements Parcelable { source.readList(conferenceableCallIds, classLoader); Bundle intentExtras = source.readBundle(classLoader); Bundle extras = source.readBundle(classLoader); + int supportedAudioRoutes = source.readInt(); return new ParcelableCall( id, state, @@ -299,6 +308,7 @@ public final class ParcelableCall implements Parcelable { cannedSmsResponses, capabilities, properties, + supportedAudioRoutes, connectTimeMillis, handle, handlePresentation, @@ -355,6 +365,7 @@ public final class ParcelableCall implements Parcelable { destination.writeList(mConferenceableCallIds); destination.writeBundle(mIntentExtras); destination.writeBundle(mExtras); + destination.writeInt(mSupportedAudioRoutes); } @Override diff --git a/telecomm/java/android/telecom/ParcelableConnection.java b/telecomm/java/android/telecom/ParcelableConnection.java index 540f388384bb..e9dba686ff82 100644 --- a/telecomm/java/android/telecom/ParcelableConnection.java +++ b/telecomm/java/android/telecom/ParcelableConnection.java @@ -37,6 +37,7 @@ public final class ParcelableConnection implements Parcelable { private final int mState; private final int mConnectionCapabilities; private final int mConnectionProperties; + private final int mSupportedAudioRoutes; private final Uri mAddress; private final int mAddressPresentation; private final String mCallerDisplayName; @@ -57,6 +58,7 @@ public final class ParcelableConnection implements Parcelable { int state, int capabilities, int properties, + int supportedAudioRoutes, Uri address, int addressPresentation, String callerDisplayName, @@ -74,6 +76,7 @@ public final class ParcelableConnection implements Parcelable { mState = state; mConnectionCapabilities = capabilities; mConnectionProperties = properties; + mSupportedAudioRoutes = supportedAudioRoutes; mAddress = address; mAddressPresentation = addressPresentation; mCallerDisplayName = callerDisplayName; @@ -117,6 +120,10 @@ public final class ParcelableConnection implements Parcelable { return mConnectionProperties; } + public int getSupportedAudioRoutes() { + return mSupportedAudioRoutes; + } + public Uri getHandle() { return mAddress; } @@ -210,12 +217,14 @@ public final class ParcelableConnection implements Parcelable { source.readStringList(conferenceableConnectionIds); Bundle extras = Bundle.setDefusable(source.readBundle(classLoader), true); int properties = source.readInt(); + int supportedAudioRoutes = source.readInt(); return new ParcelableConnection( phoneAccount, state, capabilities, properties, + supportedAudioRoutes, address, addressPresentation, callerDisplayName, @@ -264,5 +273,6 @@ public final class ParcelableConnection implements Parcelable { destination.writeStringList(mConferenceableConnectionIds); destination.writeBundle(mExtras); destination.writeInt(mConnectionProperties); + destination.writeInt(mSupportedAudioRoutes); } } diff --git a/telecomm/java/android/telecom/PhoneAccount.java b/telecomm/java/android/telecom/PhoneAccount.java index 473e39457f58..692dfb73b59b 100644 --- a/telecomm/java/android/telecom/PhoneAccount.java +++ b/telecomm/java/android/telecom/PhoneAccount.java @@ -17,15 +17,6 @@ package android.telecom; import android.annotation.SystemApi; -import android.content.ComponentName; -import android.content.Context; -import android.content.pm.PackageManager; -import android.content.res.Resources.NotFoundException; -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Bundle; @@ -37,7 +28,6 @@ import java.lang.String; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.MissingResourceException; /** * Represents a distinct method to place or receive a phone call. Apps which can place calls and @@ -217,6 +207,7 @@ public final class PhoneAccount implements Parcelable { private final CharSequence mLabel; private final CharSequence mShortDescription; private final List<String> mSupportedUriSchemes; + private final int mSupportedAudioRoutes; private final Icon mIcon; private final Bundle mExtras; private boolean mIsEnabled; @@ -226,10 +217,12 @@ public final class PhoneAccount implements Parcelable { * Helper class for creating a {@link PhoneAccount}. */ public static class Builder { + private PhoneAccountHandle mAccountHandle; private Uri mAddress; private Uri mSubscriptionAddress; private int mCapabilities; + private int mSupportedAudioRoutes = CallAudioState.ROUTE_ALL; private int mHighlightColor = NO_HIGHLIGHT_COLOR; private CharSequence mLabel; private CharSequence mShortDescription; @@ -266,6 +259,7 @@ public final class PhoneAccount implements Parcelable { mIsEnabled = phoneAccount.isEnabled(); mExtras = phoneAccount.getExtras(); mGroupId = phoneAccount.getGroupId(); + mSupportedAudioRoutes = phoneAccount.getSupportedAudioRoutes(); } /** @@ -411,6 +405,18 @@ public final class PhoneAccount implements Parcelable { } /** + * Sets the audio routes supported by this {@link PhoneAccount}. + * + * @param routes bit mask of available routes. + * @return The builder. + * @hide + */ + public Builder setSupportedAudioRoutes(int routes) { + mSupportedAudioRoutes = routes; + return this; + } + + /** * Creates an instance of a {@link PhoneAccount} based on the current builder settings. * * @return The {@link PhoneAccount}. @@ -432,6 +438,7 @@ public final class PhoneAccount implements Parcelable { mShortDescription, mSupportedUriSchemes, mExtras, + mSupportedAudioRoutes, mIsEnabled, mGroupId); } @@ -448,6 +455,7 @@ public final class PhoneAccount implements Parcelable { CharSequence shortDescription, List<String> supportedUriSchemes, Bundle extras, + int supportedAudioRoutes, boolean isEnabled, String groupId) { mAccountHandle = account; @@ -460,6 +468,7 @@ public final class PhoneAccount implements Parcelable { mShortDescription = shortDescription; mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); mExtras = extras; + mSupportedAudioRoutes = supportedAudioRoutes; mIsEnabled = isEnabled; mGroupId = groupId; } @@ -533,6 +542,17 @@ public final class PhoneAccount implements Parcelable { } /** + * Determines if this {@code PhoneAccount} has routes specified by the passed in bit mask. + * + * @param route The routes to check. + * @return {@code true} if the phone account has the routes. + * @hide + */ + public boolean hasAudioRoutes(int routes) { + return (mSupportedAudioRoutes & routes) == routes; + } + + /** * A short label describing a {@code PhoneAccount}. * * @return A label for this {@code PhoneAccount}. @@ -572,6 +592,15 @@ public final class PhoneAccount implements Parcelable { } /** + * The audio routes supported by this {@code PhoneAccount}. + * + * @hide + */ + public int getSupportedAudioRoutes() { + return mSupportedAudioRoutes; + } + + /** * The icon to represent this {@code PhoneAccount}. * * @return The icon. @@ -687,6 +716,7 @@ public final class PhoneAccount implements Parcelable { out.writeByte((byte) (mIsEnabled ? 1 : 0)); out.writeBundle(mExtras); out.writeString(mGroupId); + out.writeInt(mSupportedAudioRoutes); } public static final Creator<PhoneAccount> CREATOR @@ -731,6 +761,7 @@ public final class PhoneAccount implements Parcelable { mIsEnabled = in.readByte() == 1; mExtras = in.readBundle(); mGroupId = in.readString(); + mSupportedAudioRoutes = in.readInt(); } @Override @@ -740,7 +771,9 @@ public final class PhoneAccount implements Parcelable { .append("] PhoneAccount: ") .append(mAccountHandle) .append(" Capabilities: ") - .append(capabilitiesToString(mCapabilities)) + .append(capabilitiesToString()) + .append(" Audio Routes: ") + .append(audioRoutesToString()) .append(" Schemes: "); for (String scheme : mSupportedUriSchemes) { sb.append(scheme) @@ -760,7 +793,7 @@ public final class PhoneAccount implements Parcelable { * @param capabilities The capabilities bitmask. * @return String representation of the capabilities bitmask. */ - private String capabilitiesToString(int capabilities) { + private String capabilitiesToString() { StringBuilder sb = new StringBuilder(); if (hasCapabilities(CAPABILITY_VIDEO_CALLING)) { sb.append("Video "); @@ -794,4 +827,23 @@ public final class PhoneAccount implements Parcelable { } return sb.toString(); } + + private String audioRoutesToString() { + StringBuilder sb = new StringBuilder(); + + if (hasAudioRoutes(CallAudioState.ROUTE_BLUETOOTH)) { + sb.append("B"); + } + if (hasAudioRoutes(CallAudioState.ROUTE_EARPIECE)) { + sb.append("E"); + } + if (hasAudioRoutes(CallAudioState.ROUTE_SPEAKER)) { + sb.append("S"); + } + if (hasAudioRoutes(CallAudioState.ROUTE_WIRED_HEADSET)) { + sb.append("W"); + } + + return sb.toString(); + } } |