diff options
| author | Tyler Gunn <tgunn@google.com> | 2014-09-08 09:52:22 -0700 |
|---|---|---|
| committer | Tyler Gunn <tgunn@google.com> | 2014-09-11 17:13:51 +0000 |
| commit | a1ed7d10942cea97147dee8d79cee737766e539a (patch) | |
| tree | 643f28dd0ddf66ecb9cd63549a62e2d028dd1ae9 /telecomm | |
| parent | 4823aecef3d7170008003f18fb4f13c385efefc7 (diff) | |
| download | frameworks_base-a1ed7d10942cea97147dee8d79cee737766e539a.zip frameworks_base-a1ed7d10942cea97147dee8d79cee737766e539a.tar.gz frameworks_base-a1ed7d10942cea97147dee8d79cee737766e539a.tar.bz2 | |
Allowing enable/disable of phone accounts. (1/3)
- added "hasCapabilities" method on PhoneAccount.
- added CAPABILITY_PLACE_EMERGENCY_CALLS.
- added isEnabled method builder constructor to initialize from an
existing PhoneAccount.
Bug: 17306514
Bug: 17408536
Change-Id: I57de508b4adcf207f3b29cab449bfc634db80153
Diffstat (limited to 'telecomm')
3 files changed, 193 insertions, 10 deletions
diff --git a/telecomm/java/android/telecomm/PhoneAccount.java b/telecomm/java/android/telecomm/PhoneAccount.java index f709a86..b37c144 100644 --- a/telecomm/java/android/telecomm/PhoneAccount.java +++ b/telecomm/java/android/telecomm/PhoneAccount.java @@ -83,6 +83,25 @@ public class PhoneAccount implements Parcelable { public static final int CAPABILITY_VIDEO_CALLING = 0x8; /** + * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. + * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. + * <p> + * See {@link #getCapabilities} + */ + public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; + + /** + * Flag indicating that this {@code PhoneAccount} is always enabled and cannot be disabled by + * the user. + * This capability is reserved for important {@code PhoneAccount}s such as the emergency calling + * only {@code PhoneAccount}. + * <p> + * See {@link #getCapabilities} + * @hide + */ + public static final int CAPABILITY_ALWAYS_ENABLED = 0x20; + + /** * URI scheme for telephone number URIs. */ public static final String SCHEME_TEL = "tel"; @@ -105,6 +124,7 @@ public class PhoneAccount implements Parcelable { private final CharSequence mLabel; private final CharSequence mShortDescription; private final List<String> mSupportedUriSchemes; + private final boolean mIsEnabled; public static class Builder { private PhoneAccountHandle mAccountHandle; @@ -115,12 +135,31 @@ public class PhoneAccount implements Parcelable { private CharSequence mLabel; private CharSequence mShortDescription; private List<String> mSupportedUriSchemes = new ArrayList<String>(); + private boolean mIsEnabled = false; public Builder(PhoneAccountHandle accountHandle, CharSequence label) { this.mAccountHandle = accountHandle; this.mLabel = label; } + /** + * Creates an instance of the {@link PhoneAccount.Builder} from an existing + * {@link PhoneAccount}. + * + * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. + */ + public Builder(PhoneAccount phoneAccount) { + mAccountHandle = phoneAccount.getAccountHandle(); + mAddress = phoneAccount.getAddress(); + mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); + mCapabilities = phoneAccount.getCapabilities(); + mIconResId = phoneAccount.getIconResId(); + mLabel = phoneAccount.getLabel(); + mShortDescription = phoneAccount.getShortDescription(); + mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); + mIsEnabled = phoneAccount.isEnabled(); + } + public Builder setAddress(Uri value) { this.mAddress = value; return this; @@ -177,6 +216,24 @@ public class PhoneAccount implements Parcelable { return this; } + /** + * Specifies whether the {@link PhoneAccount} is enabled or not. {@link PhoneAccount}s are + * by default not enabled. + * + * @param value {@code True} if the {@link PhoneAccount} is enabled. + * @return The Builder. + * @hide + */ + public Builder setEnabled(boolean value) { + this.mIsEnabled = value; + return this; + } + + /** + * Creates an instance of a {@link PhoneAccount} based on the current builder settings. + * + * @return The {@link PhoneAccount}. + */ public PhoneAccount build() { // If no supported URI schemes were defined, assume "tel" is supported. if (mSupportedUriSchemes.isEmpty()) { @@ -191,7 +248,8 @@ public class PhoneAccount implements Parcelable { mIconResId, mLabel, mShortDescription, - mSupportedUriSchemes); + mSupportedUriSchemes, + mIsEnabled); } } @@ -203,7 +261,8 @@ public class PhoneAccount implements Parcelable { int iconResId, CharSequence label, CharSequence shortDescription, - List<String> supportedUriSchemes) { + List<String> supportedUriSchemes, + boolean enabled) { mAccountHandle = account; mAddress = address; mSubscriptionAddress = subscriptionAddress; @@ -212,6 +271,7 @@ public class PhoneAccount implements Parcelable { mLabel = label; mShortDescription = shortDescription; mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); + mIsEnabled = enabled; } public static Builder builder( @@ -221,6 +281,14 @@ public class PhoneAccount implements Parcelable { } /** + * Returns a builder initialized with the current {@link PhoneAccount} instance. + * + * @return The builder. + * @hide + */ + public Builder toBuilder() { return new Builder(this); } + + /** * The unique identifier of this {@code PhoneAccount}. * * @return A {@code PhoneAccountHandle}. @@ -265,6 +333,17 @@ public class PhoneAccount implements Parcelable { } /** + * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in + * bit mask. + * + * @param capability The capabilities to check. + * @return {@code True} if the phone account has the capability. + */ + public boolean hasCapabilities(int capability) { + return (mCapabilities & capability) == capability; + } + + /** * A short label describing a {@code PhoneAccount}. * * @return A label for this {@code PhoneAccount}. @@ -313,6 +392,15 @@ public class PhoneAccount implements Parcelable { } /** + * Determines whether this {@code PhoneAccount} is enabled. + * + * @return {@code True} if this {@code PhoneAccount} is enabled.. + */ + public boolean isEnabled() { + return mIsEnabled; + } + + /** * The icon resource ID for the icon of this {@code PhoneAccount}. * * @return A resource ID. @@ -367,6 +455,7 @@ public class PhoneAccount implements Parcelable { out.writeCharSequence(mLabel); out.writeCharSequence(mShortDescription); out.writeList(mSupportedUriSchemes); + out.writeInt(mIsEnabled ? 1 : 0); } public static final Creator<PhoneAccount> CREATOR @@ -396,5 +485,6 @@ public class PhoneAccount implements Parcelable { List<String> supportedUriSchemes = new ArrayList<>(); in.readList(supportedUriSchemes, classLoader); mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); + mIsEnabled = in.readInt() == 1; } } diff --git a/telecomm/java/android/telecomm/TelecommManager.java b/telecomm/java/android/telecomm/TelecommManager.java index 41ba787..9b8c536 100644 --- a/telecomm/java/android/telecomm/TelecommManager.java +++ b/telecomm/java/android/telecomm/TelecommManager.java @@ -25,6 +25,7 @@ import android.util.Log; import com.android.internal.telecomm.ITelecommService; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -347,8 +348,8 @@ public class TelecommManager { } /** - * Return a list of {@link PhoneAccountHandle}s which can be used to make and receive phone - * calls. + * Return a list of enabled {@link PhoneAccountHandle}s which can be used to make and receive + * phone calls. * * @see #EXTRA_PHONE_ACCOUNT_HANDLE * @return A list of {@code PhoneAccountHandle} objects. @@ -356,10 +357,10 @@ public class TelecommManager { public List<PhoneAccountHandle> getEnabledPhoneAccounts() { try { if (isServiceConnected()) { - return getTelecommService().getOutgoingPhoneAccounts(); + return getTelecommService().getEnabledPhoneAccounts(); } } catch (RemoteException e) { - Log.e(TAG, "Error calling ITelecommService#getOutgoingPhoneAccounts", e); + Log.e(TAG, "Error calling ITelecommService#getEnabledPhoneAccounts", e); } return new ArrayList<>(); } @@ -425,8 +426,8 @@ 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. + * Returns a list of the enabled {@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 @@ -476,6 +477,78 @@ public class TelecommManager { } /** + * Returns a count of enabled and disabled {@link PhoneAccount}s. + * + * @return The count of enabled and disabled {@link PhoneAccount}s. + * @hide + */ + @SystemApi + public int getAllPhoneAccountsCount() { + try { + if (isServiceConnected()) { + return getTelecommService().getAllPhoneAccountsCount(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountsCount", e); + } + return 0; + } + + /** + * Returns a list of all {@link PhoneAccount}s. + * + * @return All {@link PhoneAccount}s. + * @hide + */ + @SystemApi + public List<PhoneAccount> getAllPhoneAccounts() { + try { + if (isServiceConnected()) { + return getTelecommService().getAllPhoneAccounts(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccounts", e); + } + return Collections.EMPTY_LIST; + } + + /** + * Returns a list of all {@link PhoneAccountHandle}s. + * + * @return All {@link PhoneAccountHandle}s. + * @hide + */ + @SystemApi + public List<PhoneAccountHandle> getAllPhoneAccountHandles() { + try { + if (isServiceConnected()) { + return getTelecommService().getAllPhoneAccountHandles(); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#getAllPhoneAccountHandles", e); + } + return Collections.EMPTY_LIST; + } + + /** + * Enables or disables a {@link PhoneAccount}. + * + * @param account The {@link PhoneAccountHandle} to enable or disable. + * @param isEnabled {@code True} if the phone account should be enabled. + * @hide + */ + @SystemApi + public void setPhoneAccountEnabled(PhoneAccountHandle account, boolean isEnabled) { + try { + if (isServiceConnected()) { + getTelecommService().setPhoneAccountEnabled(account, isEnabled); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecommService#setPhoneAccountEnabled", e); + } + } + + /** * Register a {@link PhoneAccount} for use by the system. * * @param account The complete {@link PhoneAccount}. diff --git a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl index 6ab78c4..30f2801 100644 --- a/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl +++ b/telecomm/java/com/android/internal/telecomm/ITelecommService.aidl @@ -50,9 +50,9 @@ interface ITelecommService { void setUserSelectedOutgoingPhoneAccount(in PhoneAccountHandle account); /** - * @see TelecommServiceImpl#getOutgoingPhoneAccounts + * @see TelecommServiceImpl#getEnabledPhoneAccounts */ - List<PhoneAccountHandle> getOutgoingPhoneAccounts(); + List<PhoneAccountHandle> getEnabledPhoneAccounts(); /** * @see TelecommManager#getPhoneAccountsSupportingScheme @@ -65,6 +65,21 @@ interface ITelecommService { PhoneAccount getPhoneAccount(in PhoneAccountHandle account); /** + * @see TelecommManager#getAllPhoneAccountsCount + */ + int getAllPhoneAccountsCount(); + + /** + * @see TelecommManager#getAllPhoneAccounts + */ + List<PhoneAccount> getAllPhoneAccounts(); + + /** + * @see TelecommManager#getAllPhoneAccountHandles + */ + List<PhoneAccountHandle> getAllPhoneAccountHandles(); + + /** * @see TelecommServiceImpl#getSimCallManager */ PhoneAccountHandle getSimCallManager(); @@ -80,6 +95,11 @@ interface ITelecommService { List<PhoneAccountHandle> getSimCallManagers(); /** + * @see TelecommServiceImpl#setPhoneAccountEnabled + */ + void setPhoneAccountEnabled(in PhoneAccountHandle account, in boolean isEnabled); + + /** * @see TelecommServiceImpl#registerPhoneAccount */ void registerPhoneAccount(in PhoneAccount metadata); |
