From e7ef59a77d55c9802cc7d919f7dd794bd5fea30e Mon Sep 17 00:00:00 2001 From: Sailesh Nepal Date: Tue, 8 Jul 2014 21:48:22 -0700 Subject: [PATCH] Add Connection.setStatusHints This CL allows a connection to specify a status hint. The hint contains a label and icon that can be displayed in the InCallUI. For example, wifi calling can set a wifi icon and ssid. Change-Id: I125628b74784d2303b9a429038a9f7ee604f241e --- api/current.txt | 18 ++- .../java/android/telecomm/Connection.java | 24 ++++ .../android/telecomm/ConnectionService.java | 6 + .../telecomm/ConnectionServiceAdapter.java | 9 ++ .../java/android/telecomm/InCallCall.java | 19 ++- .../java/android/telecomm/PhoneAccount.java | 4 +- .../android/telecomm/RemoteConnection.java | 14 +++ .../telecomm/RemoteConnectionService.java | 8 ++ .../java/android/telecomm/StatusHints.aidl | 22 ++++ .../java/android/telecomm/StatusHints.java | 118 ++++++++++++++++++ .../telecomm/IConnectionServiceAdapter.aidl | 3 + 11 files changed, 241 insertions(+), 4 deletions(-) create mode 100644 telecomm/java/android/telecomm/StatusHints.aidl create mode 100644 telecomm/java/android/telecomm/StatusHints.java diff --git a/api/current.txt b/api/current.txt index f597943420be8..d8b09f0ff1d88 100644 --- a/api/current.txt +++ b/api/current.txt @@ -27618,6 +27618,7 @@ package android.telecomm { method public final android.net.Uri getHandle(); method public final android.telecomm.Connection getParentConnection(); method public final int getState(); + method public final android.telecomm.StatusHints getStatusHints(); method public final boolean isConferenceCapable(); method public final boolean isConferenceConnection(); method public final boolean isRequestingRingback(); @@ -27650,6 +27651,7 @@ package android.telecomm { method public final void setRequestingRingback(boolean); method public final void setRinging(); method public final void setSignal(android.os.Bundle); + method public final void setStatusHints(android.telecomm.StatusHints); method public static java.lang.String stateToString(int); } @@ -27734,6 +27736,7 @@ package android.telecomm { method public android.net.Uri getHandle(); method public java.lang.String getId(); method public android.telecomm.CallState getState(); + method public android.telecomm.StatusHints getStatusHints(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } @@ -27751,7 +27754,7 @@ package android.telecomm { method protected abstract void updateCall(android.telecomm.InCallCall); } - public class PhoneAccount implements android.os.Parcelable { + public final class PhoneAccount implements android.os.Parcelable { ctor public PhoneAccount(android.content.ComponentName, java.lang.String, android.net.Uri, java.lang.String, java.lang.String, boolean, boolean); method public int describeContents(); method public android.content.ComponentName getComponentName(); @@ -27802,6 +27805,7 @@ package android.telecomm { method public java.lang.String getDisconnectMessage(); method public int getFeatures(); method public int getState(); + method public android.telecomm.StatusHints getStatusHints(); method public void hold(); method public void playDtmf(char); method public void postDialContinue(boolean); @@ -27819,6 +27823,7 @@ package android.telecomm { method public abstract void onPostDialWait(android.telecomm.RemoteConnection, java.lang.String); method public abstract void onRequestingRingback(android.telecomm.RemoteConnection, boolean); method public abstract void onSetAudioModeIsVoip(android.telecomm.RemoteConnection, boolean); + method public abstract void onSetStatusHints(android.telecomm.RemoteConnection, android.telecomm.StatusHints); method public abstract void onStateChanged(android.telecomm.RemoteConnection, int); } @@ -27832,6 +27837,17 @@ package android.telecomm { method public abstract void onResult(IN, OUT); } + public final class StatusHints implements android.os.Parcelable { + ctor public StatusHints(android.content.ComponentName, java.lang.String, int); + method public int describeContents(); + method public android.content.ComponentName getComponentName(); + method public android.graphics.drawable.Drawable getIcon(android.content.Context); + method public int getIconId(); + method public java.lang.String getLabel(); + method public void writeToParcel(android.os.Parcel, int); + field public static final android.os.Parcelable.Creator CREATOR; + } + public final class TelecommConstants { ctor public TelecommConstants(); field public static final java.lang.String ACTION_CALL_SERVICE_PROVIDER; diff --git a/telecomm/java/android/telecomm/Connection.java b/telecomm/java/android/telecomm/Connection.java index 213c3c5c55d97..770e3856ce817 100644 --- a/telecomm/java/android/telecomm/Connection.java +++ b/telecomm/java/android/telecomm/Connection.java @@ -45,6 +45,7 @@ public abstract class Connection { void onParentConnectionChanged(Connection c, Connection parent); void onSetCallVideoProvider(Connection c, CallVideoProvider callVideoProvider); void onSetAudioModeIsVoip(Connection c, boolean isVoip); + void onSetStatusHints(Connection c, StatusHints statusHints); } /** @hide */ @@ -85,6 +86,9 @@ public abstract class Connection { @Override public void onSetAudioModeIsVoip(Connection c, boolean isVoip) {} + + @Override + public void onSetStatusHints(Connection c, StatusHints statusHints) {} } public final class State { @@ -109,6 +113,7 @@ public abstract class Connection { private boolean mIsConferenceCapable = false; private Connection mParentConnection; private boolean mAudioModeIsVoip; + private StatusHints mStatusHints; /** * Create a new Connection. @@ -176,6 +181,13 @@ public abstract class Connection { return mAudioModeIsVoip; } + /** + * @return The status hints for this connection. + */ + public final StatusHints getStatusHints() { + return mStatusHints; + } + /** * Assign a listener to be notified of state changes. * @@ -431,6 +443,18 @@ public abstract class Connection { } } + /** + * Sets the label and icon status to display in the in-call UI. + * + * @param statusHints The status label and icon to set. + */ + public final void setStatusHints(StatusHints statusHints) { + mStatusHints = statusHints; + for (Listener l : mListeners) { + l.onSetStatusHints(this, statusHints); + } + } + /** * Notifies this Connection and listeners that the {@link #getCallAudioState()} property * has a new value. diff --git a/telecomm/java/android/telecomm/ConnectionService.java b/telecomm/java/android/telecomm/ConnectionService.java index ba71c06320fd1..905304e3ce4ce 100644 --- a/telecomm/java/android/telecomm/ConnectionService.java +++ b/telecomm/java/android/telecomm/ConnectionService.java @@ -370,6 +370,12 @@ public abstract class ConnectionService extends Service { String id = mIdByConnection.get(c); mAdapter.setAudioModeIsVoip(id, isVoip); } + + @Override + public void onSetStatusHints(Connection c, StatusHints statusHints) { + String id = mIdByConnection.get(c); + mAdapter.setStatusHints(id, statusHints); + } }; /** {@inheritDoc} */ diff --git a/telecomm/java/android/telecomm/ConnectionServiceAdapter.java b/telecomm/java/android/telecomm/ConnectionServiceAdapter.java index 8733316eaed5a..890513f40d084 100644 --- a/telecomm/java/android/telecomm/ConnectionServiceAdapter.java +++ b/telecomm/java/android/telecomm/ConnectionServiceAdapter.java @@ -335,6 +335,15 @@ final class ConnectionServiceAdapter implements DeathRecipient { } } + void setStatusHints(String callId, StatusHints statusHints) { + for (IConnectionServiceAdapter adapter : mAdapters) { + try { + adapter.setStatusHints(callId, statusHints); + } catch (RemoteException e) { + } + } + } + /** * Set the features associated with the given call. * Features are defined in {@link android.telecomm.CallFeatures} and are passed in as a diff --git a/telecomm/java/android/telecomm/InCallCall.java b/telecomm/java/android/telecomm/InCallCall.java index e08d4504bcdbc..539668844a239 100644 --- a/telecomm/java/android/telecomm/InCallCall.java +++ b/telecomm/java/android/telecomm/InCallCall.java @@ -48,6 +48,7 @@ public final class InCallCall implements Parcelable { private final String mParentCallId; private final List mChildCallIds; private final int mFeatures; + private final StatusHints mStatusHints; /** @hide */ public InCallCall( @@ -65,7 +66,8 @@ public final class InCallCall implements Parcelable { ICallVideoProvider callVideoProvider, String parentCallId, List childCallIds, - int features) { + int features, + StatusHints statusHints) { mId = id; mState = state; mDisconnectCauseCode = disconnectCauseCode; @@ -81,6 +83,7 @@ public final class InCallCall implements Parcelable { mParentCallId = parentCallId; mChildCallIds = childCallIds; mFeatures = features; + mStatusHints = statusHints; } /** The unique ID of the call. */ @@ -188,6 +191,15 @@ public final class InCallCall implements Parcelable { return mFeatures; } + /** + * The status label and icon. + * + * @return Status hints. + */ + public StatusHints getStatusHints() { + return mStatusHints; + } + /** Responsible for creating InCallCall objects for deserialized Parcels. */ public static final Parcelable.Creator CREATOR = new Parcelable.Creator () { @@ -212,9 +224,11 @@ public final class InCallCall implements Parcelable { List childCallIds = new ArrayList<>(); source.readList(childCallIds, classLoader); int features = source.readInt(); + StatusHints statusHints = source.readParcelable(classLoader); return new InCallCall(id, state, disconnectCauseCode, disconnectCauseMsg, cannedSmsResponses, capabilities, connectTimeMillis, handle, gatewayInfo, - account, descriptor, callVideoProvider, parentCallId, childCallIds, features); + account, descriptor, callVideoProvider, parentCallId, childCallIds, features, + statusHints); } @Override @@ -248,6 +262,7 @@ public final class InCallCall implements Parcelable { destination.writeString(mParentCallId); destination.writeList(mChildCallIds); destination.writeInt(mFeatures); + destination.writeParcelable(mStatusHints, 0); } @Override diff --git a/telecomm/java/android/telecomm/PhoneAccount.java b/telecomm/java/android/telecomm/PhoneAccount.java index fa7120d3ff285..4e440d8d18c5f 100644 --- a/telecomm/java/android/telecomm/PhoneAccount.java +++ b/telecomm/java/android/telecomm/PhoneAccount.java @@ -34,7 +34,7 @@ import java.util.Objects; * Represents a distinct account, line of service or call placement method that * the system can use to place phone calls. */ -public class PhoneAccount implements Parcelable { +public final class PhoneAccount implements Parcelable { private static final int NO_DENSITY = -1; @@ -169,10 +169,12 @@ public class PhoneAccount implements Parcelable { return mIsSystemDefault; } + @Override public int describeContents() { return 0; } + @Override public void writeToParcel(Parcel out, int flags) { out.writeParcelable(mComponentName, flags); out.writeString(mId); diff --git a/telecomm/java/android/telecomm/RemoteConnection.java b/telecomm/java/android/telecomm/RemoteConnection.java index 2213abef2002b..665a8646432db 100644 --- a/telecomm/java/android/telecomm/RemoteConnection.java +++ b/telecomm/java/android/telecomm/RemoteConnection.java @@ -38,6 +38,7 @@ public final class RemoteConnection { void onPostDialWait(RemoteConnection connection, String remainingDigits); void onFeaturesChanged(RemoteConnection connection, int features); void onSetAudioModeIsVoip(RemoteConnection connection, boolean isVoip); + void onSetStatusHints(RemoteConnection connection, StatusHints statusHints); void onDestroyed(RemoteConnection connection); } @@ -52,6 +53,7 @@ public final class RemoteConnection { private boolean mConnected; private int mFeatures; private boolean mAudioModeIsVoip; + private StatusHints mStatusHints; /** * @hide @@ -91,6 +93,10 @@ public final class RemoteConnection { return mAudioModeIsVoip; } + public StatusHints getStatusHints() { + return mStatusHints; + } + public void abort() { try { if (mConnected) { @@ -266,4 +272,12 @@ public final class RemoteConnection { l.onSetAudioModeIsVoip(this, isVoip); } } + + /** @hide */ + void setStatusHints(StatusHints statusHints) { + mStatusHints = statusHints; + for (Listener l : mListeners) { + l.onSetStatusHints(this, statusHints); + } + } } diff --git a/telecomm/java/android/telecomm/RemoteConnectionService.java b/telecomm/java/android/telecomm/RemoteConnectionService.java index 0b95f52941611..42a9f5f346feb 100644 --- a/telecomm/java/android/telecomm/RemoteConnectionService.java +++ b/telecomm/java/android/telecomm/RemoteConnectionService.java @@ -201,6 +201,14 @@ final class RemoteConnectionService implements DeathRecipient { mConnection.setAudioModeIsVoip(isVoip); } } + + /** ${inheritDoc} */ + @Override + public final void setStatusHints(String connectionId, StatusHints statusHints) { + if (isCurrentConnection(connectionId)) { + mConnection.setStatusHints(statusHints); + } + } }; RemoteConnectionService(ComponentName componentName, IConnectionService connectionService) diff --git a/telecomm/java/android/telecomm/StatusHints.aidl b/telecomm/java/android/telecomm/StatusHints.aidl new file mode 100644 index 0000000000000..22da293da8783 --- /dev/null +++ b/telecomm/java/android/telecomm/StatusHints.aidl @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2008 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; + +/** + * {@hide} + */ +parcelable StatusHints; diff --git a/telecomm/java/android/telecomm/StatusHints.java b/telecomm/java/android/telecomm/StatusHints.java new file mode 100644 index 0000000000000..354dc36c73de0 --- /dev/null +++ b/telecomm/java/android/telecomm/StatusHints.java @@ -0,0 +1,118 @@ +/* + * 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.content.ComponentName; +import android.content.Context; +import android.content.pm.PackageManager; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.DisplayMetrics; + +import java.util.MissingResourceException; + +/** + * Contains status label and icon displayed in the in-call UI. + */ +public final class StatusHints implements Parcelable { + + private final ComponentName mComponentName; + private final String mLabel; + private final int mIconId; + + public StatusHints(ComponentName componentName, String label, int iconId) { + mComponentName = componentName; + mLabel = label; + mIconId = iconId; + } + + /** + * @return A component used to load the icon. + */ + public ComponentName getComponentName() { + return mComponentName; + } + + /** + * @return The label displayed in the in-call UI. + */ + public String getLabel() { + return mLabel; + } + + /** + * @return The icon resource identifier. + */ + public int getIconId() { + return mIconId; + } + + /** + * @return An icon displayed in the in-call UI. + */ + public Drawable getIcon(Context context) { + return getIcon(context, mIconId); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(mComponentName, flags); + out.writeString(mLabel); + out.writeInt(mIconId); + } + + public static final Creator CREATOR + = new Creator() { + public StatusHints createFromParcel(Parcel in) { + return new StatusHints(in); + } + + public StatusHints[] newArray(int size) { + return new StatusHints[size]; + } + }; + + private StatusHints(Parcel in) { + mComponentName = in.readParcelable(getClass().getClassLoader()); + mLabel = in.readString(); + mIconId = in.readInt(); + } + + private Drawable getIcon(Context context, int resId) { + Context packageContext; + try { + packageContext = context.createPackageContext(mComponentName.getPackageName(), 0); + } catch (PackageManager.NameNotFoundException e) { + Log.e(this, e, "Cannot find package %s", mComponentName.getPackageName()); + return null; + } + try { + return packageContext.getResources().getDrawable(resId); + } catch (MissingResourceException e) { + Log.e(this, e, "Cannot find icon %d in package %s", + resId, mComponentName.getPackageName()); + return null; + } + } +} diff --git a/telecomm/java/com/android/internal/telecomm/IConnectionServiceAdapter.aidl b/telecomm/java/com/android/internal/telecomm/IConnectionServiceAdapter.aidl index 29f62b45cfad3..47cc78ecf44ac 100644 --- a/telecomm/java/com/android/internal/telecomm/IConnectionServiceAdapter.aidl +++ b/telecomm/java/com/android/internal/telecomm/IConnectionServiceAdapter.aidl @@ -17,6 +17,7 @@ package com.android.internal.telecomm; import android.telecomm.ConnectionRequest; +import android.telecomm.StatusHints; import com.android.internal.telecomm.ICallVideoProvider; import com.android.internal.telecomm.RemoteServiceCallback; @@ -66,4 +67,6 @@ oneway interface IConnectionServiceAdapter { void setFeatures(String callId, int features); void setAudioModeIsVoip(String callId, boolean isVoip); + + void setStatusHints(String callId, in StatusHints statusHints); }