diff --git a/api/current.txt b/api/current.txt index 5e14236875fbe..165dbf53d5934 100644 --- a/api/current.txt +++ b/api/current.txt @@ -28320,10 +28320,15 @@ package android.telecomm { method public java.lang.CharSequence getLabel(); method public java.lang.CharSequence getShortDescription(); method public java.lang.String getSubscriptionNumber(); + method public java.util.List getSupportedUriSchemes(); + method public boolean supportsUriScheme(java.lang.String); method public void writeToParcel(android.os.Parcel, int); field public static final int CAPABILITY_CONNECTION_MANAGER = 1; // 0x1 field public static final int CAPABILITY_SIM_SUBSCRIPTION = 4; // 0x4 field public static final android.os.Parcelable.Creator CREATOR; + field public static final java.lang.String SCHEME_SIP = "sip"; + field public static final java.lang.String SCHEME_TEL = "tel"; + field public static final java.lang.String SCHEME_VOICEMAIL = "voicemail"; } public static class PhoneAccount.Builder { @@ -28336,6 +28341,8 @@ package android.telecomm { method public android.telecomm.PhoneAccount.Builder withLabel(java.lang.CharSequence); method public android.telecomm.PhoneAccount.Builder withShortDescription(java.lang.CharSequence); method public android.telecomm.PhoneAccount.Builder withSubscriptionNumber(java.lang.String); + method public android.telecomm.PhoneAccount.Builder withSupportedUriScheme(java.lang.String); + method public android.telecomm.PhoneAccount.Builder withSupportedUriSchemes(java.util.List); } public class PhoneAccountHandle implements android.os.Parcelable { @@ -28464,9 +28471,10 @@ package android.telecomm { method public void addNewIncomingCall(android.telecomm.PhoneAccountHandle, android.os.Bundle); method public void cancelMissedCallsNotification(); method public void clearAccounts(java.lang.String); - method public android.telecomm.PhoneAccountHandle getDefaultOutgoingPhoneAccount(); + method public android.telecomm.PhoneAccountHandle getDefaultOutgoingPhoneAccount(java.lang.String); method public java.util.List getEnabledPhoneAccounts(); method public android.telecomm.PhoneAccount getPhoneAccount(android.telecomm.PhoneAccountHandle); + method public java.util.List getPhoneAccountsSupportingScheme(java.lang.String); method public boolean handleMmi(java.lang.String); method public boolean hasMultipleEnabledAccounts(); method public boolean isInCall(); diff --git a/telecomm/java/android/telecomm/PhoneAccount.java b/telecomm/java/android/telecomm/PhoneAccount.java index 5b4640930bc12..1d61a6e679363 100644 --- a/telecomm/java/android/telecomm/PhoneAccount.java +++ b/telecomm/java/android/telecomm/PhoneAccount.java @@ -23,7 +23,12 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; +import android.text.TextUtils; +import java.lang.String; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.MissingResourceException; /** @@ -77,6 +82,21 @@ public class PhoneAccount implements Parcelable { */ public static final int CAPABILITY_VIDEO_CALLING = 0x8; + /** + * URI scheme for telephone number URIs. + */ + public static final String SCHEME_TEL = "tel"; + + /** + * URI scheme for voicemail URIs. + */ + public static final String SCHEME_VOICEMAIL = "voicemail"; + + /** + * URI scheme for SIP URIs. + */ + public static final String SCHEME_SIP = "sip"; + private final PhoneAccountHandle mAccountHandle; private final Uri mHandle; private final String mSubscriptionNumber; @@ -84,6 +104,7 @@ public class PhoneAccount implements Parcelable { private final int mIconResId; private final CharSequence mLabel; private final CharSequence mShortDescription; + private final List mSupportedUriSchemes; public static class Builder { private PhoneAccountHandle mAccountHandle; @@ -93,6 +114,7 @@ public class PhoneAccount implements Parcelable { private int mIconResId; private CharSequence mLabel; private CharSequence mShortDescription; + private List mSupportedUriSchemes = new ArrayList(); public Builder() {} @@ -131,7 +153,40 @@ public class PhoneAccount implements Parcelable { return this; } + /** + * Specifies an additional URI scheme supported by the {@link PhoneAccount}. + * + * @param uriScheme The URI scheme. + * @return The Builder. + */ + public Builder withSupportedUriScheme(String uriScheme) { + if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { + this.mSupportedUriSchemes.add(uriScheme); + } + return this; + } + + /** + * Specifies additional URI schemes supported by the {@link PhoneAccount}. + * + * @param uriSchemes The URI schemes. + * @return The Builder. + */ + public Builder withSupportedUriSchemes(List uriSchemes) { + if (uriSchemes != null && !uriSchemes.isEmpty()) { + for (String uriScheme : uriSchemes) { + withSupportedUriScheme(uriScheme); + } + } + return this; + } + public PhoneAccount build() { + // If no supported URI schemes were defined, assume "tel" is supported. + if (mSupportedUriSchemes.isEmpty()) { + withSupportedUriScheme(SCHEME_TEL); + } + return new PhoneAccount( mAccountHandle, mHandle, @@ -139,7 +194,8 @@ public class PhoneAccount implements Parcelable { mCapabilities, mIconResId, mLabel, - mShortDescription); + mShortDescription, + mSupportedUriSchemes); } } @@ -150,7 +206,8 @@ public class PhoneAccount implements Parcelable { int capabilities, int iconResId, CharSequence label, - CharSequence shortDescription) { + CharSequence shortDescription, + List supportedUriSchemes) { mAccountHandle = account; mHandle = handle; mSubscriptionNumber = subscriptionNumber; @@ -158,6 +215,7 @@ public class PhoneAccount implements Parcelable { mIconResId = iconResId; mLabel = label; mShortDescription = shortDescription; + mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); } public static Builder builder() { return new Builder(); } @@ -227,6 +285,36 @@ public class PhoneAccount implements Parcelable { return mShortDescription; } + /** + * The URI schemes supported by this {@code PhoneAccount}. + * + * @return The URI schemes. + */ + public List getSupportedUriSchemes() { + return mSupportedUriSchemes; + } + + /** + * Determines if the {@link PhoneAccount} supports calls to/from handles with a specified URI + * scheme. + * + * @param uriScheme The URI scheme to check. + * @return {@code True} if the {@code PhoneAccount} supports calls to/from handles with the + * specified URI scheme. + */ + public boolean supportsUriScheme(String uriScheme) { + if (mSupportedUriSchemes == null || uriScheme == null) { + return false; + } + + for (String scheme : mSupportedUriSchemes) { + if (scheme != null && scheme.equals(uriScheme)) { + return true; + } + } + return false; + } + /** * The icon resource ID for the icon of this {@code PhoneAccount}. * @@ -281,6 +369,7 @@ public class PhoneAccount implements Parcelable { out.writeInt(mIconResId); out.writeCharSequence(mLabel); out.writeCharSequence(mShortDescription); + out.writeList(mSupportedUriSchemes); } public static final Creator CREATOR @@ -297,6 +386,8 @@ public class PhoneAccount implements Parcelable { }; private PhoneAccount(Parcel in) { + ClassLoader classLoader = PhoneAccount.class.getClassLoader(); + mAccountHandle = in.readParcelable(getClass().getClassLoader()); mHandle = in.readParcelable(getClass().getClassLoader()); mSubscriptionNumber = in.readString(); @@ -304,5 +395,9 @@ public class PhoneAccount implements Parcelable { mIconResId = in.readInt(); mLabel = in.readCharSequence(); mShortDescription = in.readCharSequence(); + + List supportedUriSchemes = new ArrayList<>(); + in.readList(supportedUriSchemes, classLoader); + mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); } } diff --git a/telecomm/java/android/telecomm/TelecommManager.java b/telecomm/java/android/telecomm/TelecommManager.java index 224328802c6a4..071b719fba1f5 100644 --- a/telecomm/java/android/telecomm/TelecommManager.java +++ b/telecomm/java/android/telecomm/TelecommManager.java @@ -258,8 +258,8 @@ public class TelecommManager { /** * Return the {@link PhoneAccount} which is the user-chosen default for making outgoing phone - * calls. This {@code PhoneAccount} will always be a member of the list which is returned from - * calling {@link #getEnabledPhoneAccounts()}. + * calls with a specified URI scheme. This {@code PhoneAccount} will always be a member of the + * list which is returned from calling {@link #getEnabledPhoneAccounts()}. *

* Apps must be prepared for this method to return {@code null}, indicating that there currently * exists no user-chosen default {@code PhoneAccount}. In this case, apps wishing to initiate a @@ -272,11 +272,13 @@ public class TelecommManager { * {@code Intent} with no {@link TelecommManager#EXTRA_PHONE_ACCOUNT_HANDLE} is valid, and * subsequent steps in the phone call flow are responsible for presenting the user with an * affordance, if necessary, to choose a {@code PhoneAccount}. + * + * @param uriScheme The URI scheme. */ - public PhoneAccountHandle getDefaultOutgoingPhoneAccount() { + public PhoneAccountHandle getDefaultOutgoingPhoneAccount(String uriScheme) { try { if (isServiceConnected()) { - return getTelecommService().getDefaultOutgoingPhoneAccount(); + return getTelecommService().getDefaultOutgoingPhoneAccount(uriScheme); } } catch (RemoteException e) { Log.e(TAG, "Error calling ITelecommService#getDefaultOutgoingPhoneAccount", e); @@ -365,6 +367,29 @@ public class TelecommManager { return new ArrayList<>(); } + /** + * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone + * calls which support the specified URI scheme. + *

+ * For example, invoking with {@code "tel"} will find all {@link PhoneAccountHandle}s which + * support telephone calls (e.g. URIs such as {@code tel:555-555-1212}). Invoking with + * {@code "sip"} will find all {@link PhoneAccountHandle}s which support SIP calls (e.g. URIs + * such as {@code sip:example@sipexample.com}). + * + * @param uriScheme The URI scheme. + * @return A list of {@code PhoneAccountHandle} objects supporting the URI scheme. + */ + public List getPhoneAccountsSupportingScheme(String uriScheme) { + try { + if (isServiceConnected()) { + return getTelecommService().getPhoneAccountsSupportingScheme(uriScheme); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#getPhoneAccountsSupportingScheme", e); + } + return new ArrayList<>(); + } + /** * Determine whether the device has more than one account registered and enabled. * diff --git a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl index 131307a4e3b29..a6ab3ac03e2db 100644 --- a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl +++ b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl @@ -37,7 +37,7 @@ interface ITelecommService { /** * @see TelecommServiceImpl#getDefaultOutgoingPhoneAccount */ - PhoneAccountHandle getDefaultOutgoingPhoneAccount(); + PhoneAccountHandle getDefaultOutgoingPhoneAccount(in String uriScheme); /** * @see TelecommServiceImpl#setDefaultOutgoingPhoneAccount @@ -50,7 +50,12 @@ interface ITelecommService { List getOutgoingPhoneAccounts(); /** - * @see TelecommServiceImpl#getPhoneAccount + * @see TelecommManager#getPhoneAccountsSupportingScheme + */ + List getPhoneAccountsSupportingScheme(in String uriScheme); + + /** + * @see TelecommManager#getPhoneAccount */ PhoneAccount getPhoneAccount(in PhoneAccountHandle account);