/* * 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.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; 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; /** * 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}. *
* {@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 connection service * implementation Telecom will use to interact with the app. */ public class PhoneAccount implements Parcelable { /** * Flag indicating that this {@code PhoneAccount} can act as a connection manager for * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount} * will be allowed to manage phone calls including using its own proprietary phone-call * implementation (like VoIP calling) to make calls instead of the telephony stack. *
* When a user opts to place a call using the SIM-based telephony stack, the * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first * if the user has explicitly selected it to be used as the default connection manager. *
* See {@link #getCapabilities} * @hide */ @SystemApi public static final int CAPABILITY_CONNECTION_MANAGER = 0x1; /** * Flag indicating that this {@code PhoneAccount} can make phone calls in place of * 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 * or place calls from the built-in telephony stack. *
* See {@link #getCapabilities} *
* {@hide} */ @SystemApi public static final int CAPABILITY_CALL_PROVIDER = 0x2; /** * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM * subscription. *
* Only the Android framework can register a {@code PhoneAccount} having this capability. *
* See {@link #getCapabilities} */ public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; /** * Flag indicating that this {@code PhoneAccount} is capable of placing video calls. *
* See {@link #getCapabilities} */ 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. *
* See {@link #getCapabilities} */ public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; /** * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This * should only be used by system apps (and will be ignored for all other apps trying to use it). *
* See {@link #getCapabilities}
* @hide
*/
@SystemApi
public static final int CAPABILITY_MULTI_USER = 0x20;
/**
* 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";
/**
* Indicating no icon tint is set.
*/
public static final int NO_ICON_TINT = 0;
/**
* Indicating no hightlight color is set.
*/
public static final int NO_HIGHLIGHT_COLOR = 0;
/**
* Indicating no resource ID is set.
*/
public static final int NO_RESOURCE_ID = -1;
private final PhoneAccountHandle mAccountHandle;
private final Uri mAddress;
private final Uri mSubscriptionAddress;
private final int mCapabilities;
private final int mIconResId;
private final String mIconPackageName;
private final Bitmap mIconBitmap;
private final int mIconTint;
private final int mHighlightColor;
private final CharSequence mLabel;
private final CharSequence mShortDescription;
private final List
*
* @return The subscription number, suitable for display to the user.
*/
public Uri getSubscriptionAddress() {
return mSubscriptionAddress;
}
/**
* The capabilities of this {@code PhoneAccount}.
*
* @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
*/
public int getCapabilities() {
return mCapabilities;
}
/**
* 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}.
*/
public CharSequence getLabel() {
return mLabel;
}
/**
* A short paragraph describing this {@code PhoneAccount}.
*
* @return A description for this {@code PhoneAccount}.
*/
public CharSequence getShortDescription() {
return mShortDescription;
}
/**
* The URI schemes supported by this {@code PhoneAccount}.
*
* @return The URI schemes.
*/
public List
* 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.
*
* Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
*
* @return A resource ID.
*/
public int getIconResId() {
return mIconResId;
}
/**
* The package name from which to load the icon of this {@code PhoneAccount}.
*
* If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from
* the package in the {@link ComponentName} of the {@link #getAccountHandle()}.
*
* Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}.
*
* @return A package name.
*/
public String getIconPackageName() {
return mIconPackageName;
}
/**
* A tint to apply to the icon of this {@code PhoneAccount}.
*
* @return A hexadecimal color value.
*/
public int getIconTint() {
return mIconTint;
}
/**
* A literal icon bitmap to represent this {@code PhoneAccount} in a user interface.
*
* If this property is specified, it is to be considered the preferred icon. Otherwise, the
* resource specified by {@link #getIconResId()} should be used.
*
* Clients wishing to display a {@code PhoneAccount} should use
* {@link #createIconDrawable(Context)}.
*
* @return A bitmap.
*/
public Bitmap getIconBitmap() {
return mIconBitmap;
}
/**
* A highlight color to use in displaying information about this {@code PhoneAccount}.
*
* @return A hexadecimal color value.
*/
public int getHighlightColor() {
return mHighlightColor;
}
/**
* 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 createIconDrawable(Context context) {
if (mIconBitmap != null) {
return new BitmapDrawable(context.getResources(), mIconBitmap);
}
if (mIconResId != 0) {
try {
Context packageContext = context.createPackageContext(mIconPackageName, 0);
try {
Drawable iconDrawable = packageContext.getDrawable(mIconResId);
if (mIconTint != NO_ICON_TINT) {
iconDrawable.setTint(mIconTint);
}
return iconDrawable;
} catch (NotFoundException | MissingResourceException e) {
Log.e(this, e, "Cannot find icon %d in package %s",
mIconResId, mIconPackageName);
}
} catch (PackageManager.NameNotFoundException e) {
Log.w(this, "Cannot find package %s", mIconPackageName);
}
}
return new ColorDrawable(Color.TRANSPARENT);
}
//
// Parcelable implementation
//
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
if (mAccountHandle == null) {
out.writeInt(0);
} else {
out.writeInt(1);
mAccountHandle.writeToParcel(out, flags);
}
if (mAddress == null) {
out.writeInt(0);
} else {
out.writeInt(1);
mAddress.writeToParcel(out, flags);
}
if (mSubscriptionAddress == null) {
out.writeInt(0);
} else {
out.writeInt(1);
mSubscriptionAddress.writeToParcel(out, flags);
}
out.writeInt(mCapabilities);
out.writeInt(mIconResId);
out.writeString(mIconPackageName);
if (mIconBitmap == null) {
out.writeInt(0);
} else {
out.writeInt(1);
mIconBitmap.writeToParcel(out, flags);
}
out.writeInt(mIconTint);
out.writeInt(mHighlightColor);
out.writeCharSequence(mLabel);
out.writeCharSequence(mShortDescription);
out.writeStringList(mSupportedUriSchemes);
}
public static final Creator