summaryrefslogtreecommitdiffstats
path: root/telecomm/java/android/telecom/PhoneAccount.java
diff options
context:
space:
mode:
Diffstat (limited to 'telecomm/java/android/telecom/PhoneAccount.java')
-rw-r--r--telecomm/java/android/telecom/PhoneAccount.java199
1 files changed, 173 insertions, 26 deletions
diff --git a/telecomm/java/android/telecom/PhoneAccount.java b/telecomm/java/android/telecom/PhoneAccount.java
index 67b6328..3fc1d3d 100644
--- a/telecomm/java/android/telecom/PhoneAccount.java
+++ b/telecomm/java/android/telecom/PhoneAccount.java
@@ -16,10 +16,14 @@
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.net.Uri;
import android.os.Parcel;
@@ -33,11 +37,15 @@ import java.util.List;
import java.util.MissingResourceException;
/**
- * Describes a distinct account, line of service or call placement method that the system
- * can use to place phone calls.
- * @hide
+ * Represents a distinct method to place or receive a phone call. Apps which can place calls and
+ * want those calls to be integrated into the dialer and in-call UI should build an instance of
+ * this class and register it with the system using {@link TelecomManager#registerPhoneAccount}.
+ * <p>
+ * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with
+ * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app
+ * should supply a valid {@link PhoneAccountHandle} that references the {@link ConnectionService}
+ * implementation Telecom will use to interact with the app.
*/
-@SystemApi
public class PhoneAccount implements Parcelable {
/**
@@ -59,7 +67,7 @@ public class PhoneAccount implements Parcelable {
* traditional SIM-based telephony calls. This account will be treated as a distinct method
* for placing calls alongside the traditional SIM-based telephony stack. This flag is
* distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage
- * calls from or use the built-in telephony stack to place its calls.
+ * or place calls from the built-in telephony stack.
* <p>
* See {@link #getCapabilities}
* <p>
@@ -118,22 +126,32 @@ public class PhoneAccount implements Parcelable {
private final Uri mSubscriptionAddress;
private final int mCapabilities;
private final int mIconResId;
+ private final String mIconPackageName;
+ private final Bitmap mIconBitmap;
private final int mColor;
private final CharSequence mLabel;
private final CharSequence mShortDescription;
private final List<String> mSupportedUriSchemes;
+ /**
+ * 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 mIconResId;
+ private String mIconPackageName;
+ private Bitmap mIconBitmap;
private int mColor = NO_COLOR;
private CharSequence mLabel;
private CharSequence mShortDescription;
private List<String> mSupportedUriSchemes = new ArrayList<String>();
+ /**
+ * Creates a builder with the specified {@link PhoneAccountHandle} and label.
+ */
public Builder(PhoneAccountHandle accountHandle, CharSequence label) {
this.mAccountHandle = accountHandle;
this.mLabel = label;
@@ -151,37 +169,97 @@ public class PhoneAccount implements Parcelable {
mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
mCapabilities = phoneAccount.getCapabilities();
mIconResId = phoneAccount.getIconResId();
+ mIconPackageName = phoneAccount.getIconPackageName();
+ mIconBitmap = phoneAccount.getIconBitmap();
mColor = phoneAccount.getColor();
mLabel = phoneAccount.getLabel();
mShortDescription = phoneAccount.getShortDescription();
mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes());
}
+ /**
+ * Sets the address. See {@link PhoneAccount#getAddress}.
+ *
+ * @param value The address of the phone account.
+ * @return The builder.
+ */
public Builder setAddress(Uri value) {
this.mAddress = value;
return this;
}
+ /**
+ * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}.
+ *
+ * @param value The subscription address.
+ * @return The builder.
+ */
public Builder setSubscriptionAddress(Uri value) {
this.mSubscriptionAddress = value;
return this;
}
+ /**
+ * Sets the capabilities. See {@link PhoneAccount#getCapabilities}.
+ *
+ * @param value The capabilities to set.
+ * @return The builder.
+ */
public Builder setCapabilities(int value) {
this.mCapabilities = value;
return this;
}
+ /**
+ * Sets the icon resource ID. See {@link PhoneAccount#getIconResId}.
+ *
+ * @param value The resource ID of the icon.
+ * @return The builder.
+ */
public Builder setIconResId(int value) {
this.mIconResId = value;
return this;
}
+ /**
+ * Sets the icon package name. See {@link PhoneAccount#getIconPackageName}.
+ *
+ * @param value The name of the package from which to load the icon.
+ * @return The builder.
+ */
+ public Builder setIconPackageName(String value) {
+ this.mIconPackageName = value;
+ return this;
+ }
+
+ /**
+ * Sets the icon bitmap. See {@link PhoneAccount#getIconBitmap}.
+ *
+ * @param value The icon bitmap.
+ * @return The builder.
+ */
+ public Builder setIconBitmap(Bitmap value) {
+ this.mIconBitmap = value;
+ return this;
+ }
+
+ /**
+ * Sets the color. See {@link PhoneAccount#getColor}.
+ *
+ * @param value The resource ID of the icon.
+ * @return The builder.
+ */
public Builder setColor(int value) {
this.mColor = value;
return this;
}
+ /**
+ * Sets the short description. See {@link PhoneAccount#getShortDescription}.
+ *
+ * @param value The short description.
+ * @return The builder.
+ */
public Builder setShortDescription(CharSequence value) {
this.mShortDescription = value;
return this;
@@ -191,7 +269,7 @@ public class PhoneAccount implements Parcelable {
* Specifies an additional URI scheme supported by the {@link PhoneAccount}.
*
* @param uriScheme The URI scheme.
- * @return The Builder.
+ * @return The builder.
* @hide
*/
public Builder addSupportedUriScheme(String uriScheme) {
@@ -205,7 +283,7 @@ public class PhoneAccount implements Parcelable {
* Specifies the URI schemes supported by the {@link PhoneAccount}.
*
* @param uriSchemes The URI schemes.
- * @return The Builder.
+ * @return The builder.
*/
public Builder setSupportedUriSchemes(List<String> uriSchemes) {
mSupportedUriSchemes.clear();
@@ -235,6 +313,8 @@ public class PhoneAccount implements Parcelable {
mSubscriptionAddress,
mCapabilities,
mIconResId,
+ mIconPackageName,
+ mIconBitmap,
mColor,
mLabel,
mShortDescription,
@@ -248,6 +328,8 @@ public class PhoneAccount implements Parcelable {
Uri subscriptionAddress,
int capabilities,
int iconResId,
+ String iconPackageName,
+ Bitmap iconBitmap,
int color,
CharSequence label,
CharSequence shortDescription,
@@ -257,6 +339,8 @@ public class PhoneAccount implements Parcelable {
mSubscriptionAddress = subscriptionAddress;
mCapabilities = capabilities;
mIconResId = iconResId;
+ mIconPackageName = iconPackageName;
+ mIconBitmap = iconBitmap;
mColor = color;
mLabel = label;
mShortDescription = shortDescription;
@@ -302,6 +386,9 @@ public class PhoneAccount implements Parcelable {
* The raw callback number used for this {@code PhoneAccount}, as distinct from
* {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered
* as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration
+ * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)}
+ * has been used to alter the callback number.
+ * <p>
*
* @return The subscription number, suitable for display to the user.
*/
@@ -379,6 +466,12 @@ public class PhoneAccount implements Parcelable {
/**
* The icon resource ID for the icon of this {@code PhoneAccount}.
+ * <p>
+ * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer
+ * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it
+ * leads to less resource usage.
+ * <p>
+ * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}.
*
* @return A resource ID.
*/
@@ -387,6 +480,20 @@ public class PhoneAccount implements Parcelable {
}
/**
+ * The package name from which to load the icon of this {@code PhoneAccount}.
+ * <p>
+ * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
+ * the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
+ * <p>
+ * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}.
+ *
+ * @return A package name.
+ */
+ public String getIconPackageName() {
+ return mIconPackageName;
+ }
+
+ /**
* A highlight color to use in displaying information about this {@code PhoneAccount}.
*
* @return A hexadecimal color value.
@@ -396,30 +503,51 @@ public class PhoneAccount implements Parcelable {
}
/**
- * An icon to represent this {@code PhoneAccount} in a user interface.
+ * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
+ * <p>
+ * If this property is specified, it is to be considered the preferred icon. Otherwise, the
+ * resource specified by {@link #getIconResId()} should be used.
+ * <p>
+ * Clients wishing to display a {@code PhoneAccount} should use {@link #getIcon(Context)}.
*
- * @return An icon for this {@code PhoneAccount}.
+ * @return A bitmap.
*/
- public Drawable getIcon(Context context) {
- return getIcon(context, mIconResId);
+ public Bitmap getIconBitmap() {
+ return mIconBitmap;
}
- private Drawable getIcon(Context context, int resId) {
- Context packageContext;
- try {
- packageContext = context.createPackageContext(
- mAccountHandle.getComponentName().getPackageName(), 0);
- } catch (PackageManager.NameNotFoundException e) {
- Log.w(this, "Cannot find package %s", mAccountHandle.getComponentName().getPackageName());
- return null;
+ /**
+ * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
+ * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and
+ * {@link #getIconBitmap()} as necessary.
+ *
+ * @param context A {@code Context} to use for loading {@code Drawable}s.
+ *
+ * @return An icon for this {@code PhoneAccount}.
+ */
+ public Drawable getIcon(Context context) {
+ if (mIconBitmap != null) {
+ return new BitmapDrawable(context.getResources(), mIconBitmap);
}
- try {
- return packageContext.getDrawable(resId);
- } catch (NotFoundException|MissingResourceException e) {
- Log.e(this, e, "Cannot find icon %d in package %s",
- resId, mAccountHandle.getComponentName().getPackageName());
- return null;
+
+ if (mIconResId != 0) {
+ String packageName = mIconPackageName == null
+ ? mAccountHandle.getComponentName().getPackageName()
+ : mIconPackageName;
+
+ try {
+ Context packageContext = context.createPackageContext(packageName, 0);
+ try {
+ return packageContext.getDrawable(mIconResId);
+ } catch (NotFoundException | MissingResourceException e) {
+ Log.e(this, e, "Cannot find icon %d in package %s", mIconResId, packageName);
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.w(this, "Cannot find package %s", packageName);
+ }
}
+
+ return new ColorDrawable(Color.TRANSPARENT);
}
//
@@ -438,6 +566,8 @@ public class PhoneAccount implements Parcelable {
out.writeParcelable(mSubscriptionAddress, 0);
out.writeInt(mCapabilities);
out.writeInt(mIconResId);
+ out.writeString(mIconPackageName);
+ out.writeParcelable(mIconBitmap, 0);
out.writeInt(mColor);
out.writeCharSequence(mLabel);
out.writeCharSequence(mShortDescription);
@@ -465,6 +595,8 @@ public class PhoneAccount implements Parcelable {
mSubscriptionAddress = in.readParcelable(getClass().getClassLoader());
mCapabilities = in.readInt();
mIconResId = in.readInt();
+ mIconPackageName = in.readString();
+ mIconBitmap = in.readParcelable(getClass().getClassLoader());
mColor = in.readInt();
mLabel = in.readCharSequence();
mShortDescription = in.readCharSequence();
@@ -473,4 +605,19 @@ public class PhoneAccount implements Parcelable {
in.readList(supportedUriSchemes, classLoader);
mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes);
}
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder().append("[PhoneAccount: ")
+ .append(mAccountHandle)
+ .append(" Capabilities: ")
+ .append(mCapabilities)
+ .append(" Schemes: ");
+ for (String scheme : mSupportedUriSchemes) {
+ sb.append(scheme)
+ .append(" ");
+ }
+ sb.append("]");
+ return sb.toString();
+ }
}