diff options
author | Tyler Gunn <tgunn@google.com> | 2014-09-03 18:12:57 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-03 18:12:58 +0000 |
commit | 65bd3eaad6827301ca2230ee23c53ed8cce5e182 (patch) | |
tree | 11a58a198fca718e95cf1152ea9c0636936559bb /telecomm | |
parent | 897b59e394715f6f36553c1eff82a367a9984a6d (diff) | |
parent | f5b29dc8cb7ec19232c6499ac41e5cd267ebd6f1 (diff) | |
download | frameworks_base-65bd3eaad6827301ca2230ee23c53ed8cce5e182.zip frameworks_base-65bd3eaad6827301ca2230ee23c53ed8cce5e182.tar.gz frameworks_base-65bd3eaad6827301ca2230ee23c53ed8cce5e182.tar.bz2 |
Merge "Add supported URI scheme to PhoneAccounts. (1/4)" into lmp-dev
Diffstat (limited to 'telecomm')
3 files changed, 133 insertions, 8 deletions
diff --git a/telecomm/java/android/telecomm/PhoneAccount.java b/telecomm/java/android/telecomm/PhoneAccount.java index 5b46409..1d61a6e 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<String> 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<String> mSupportedUriSchemes = new ArrayList<String>(); 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<String> 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<String> 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(); } @@ -228,6 +286,36 @@ public class PhoneAccount implements Parcelable { } /** + * The URI schemes supported by this {@code PhoneAccount}. + * + * @return The URI schemes. + */ + public List<String> 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}. * * @return A resource ID. @@ -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<PhoneAccount> 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<String> 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 2243288..071b719 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()}. * <p> * 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); @@ -366,6 +368,29 @@ public class TelecommManager { } /** + * Returns a list of {@link PhoneAccountHandle}s which can be used to make and receive phone + * calls which support the specified URI scheme. + * <P> + * 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<PhoneAccountHandle> 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. * * @return {@code true} if the device has more than one account registered and enabled and diff --git a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl index 131307a..a6ab3ac 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<PhoneAccountHandle> getOutgoingPhoneAccounts(); /** - * @see TelecommServiceImpl#getPhoneAccount + * @see TelecommManager#getPhoneAccountsSupportingScheme + */ + List<PhoneAccountHandle> getPhoneAccountsSupportingScheme(in String uriScheme); + + /** + * @see TelecommManager#getPhoneAccount */ PhoneAccount getPhoneAccount(in PhoneAccountHandle account); |