2014-07-09 12:30:52 -07:00
|
|
|
/*
|
|
|
|
* 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.telecomm;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2014-07-17 11:21:19 -07:00
|
|
|
import android.net.Uri;
|
2014-07-09 12:30:52 -07:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
|
|
|
|
import java.util.MissingResourceException;
|
|
|
|
|
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* Provides user interface description information for a {@code PhoneAccount}.
|
2014-07-09 12:30:52 -07:00
|
|
|
*/
|
2014-07-20 12:31:00 -07:00
|
|
|
public class PhoneAccount implements Parcelable {
|
2014-07-17 11:21:19 -07:00
|
|
|
|
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* Flag indicating that this {@code PhoneAccount} can act as a call manager for
|
2014-07-19 18:18:19 -07:00
|
|
|
* traditional SIM-based telephony calls. The {@link ConnectionService} associated with this
|
|
|
|
* phone-account will be allowed to manage SIM-based phone calls including using its own
|
|
|
|
* proprietary phone-call implementation (like VoIP calling) to make calls instead of the
|
|
|
|
* telephony stack.
|
2014-07-17 11:21:19 -07:00
|
|
|
* When a user opts to place a call using the SIM-based telephony stack, the connection-service
|
|
|
|
* associated with this phone-account will be attempted first if the user has explicitly
|
|
|
|
* selected it to be used as the default call-manager.
|
|
|
|
* <p>
|
|
|
|
* See {@link #getCapabilities}
|
|
|
|
*/
|
|
|
|
public static final int CAPABILITY_SIM_CALL_MANAGER = 0x1;
|
|
|
|
|
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* Flag indicating that this {@code PhoneAccount} can make phone calls in place of
|
2014-07-19 18:18:19 -07:00
|
|
|
* 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_SIM_CALL_MANAGER} in that it is not allowed to manage
|
|
|
|
* calls from or use the built-in telephony stack to place its calls.
|
2014-07-17 11:21:19 -07:00
|
|
|
* <p>
|
|
|
|
* See {@link #getCapabilities}
|
2014-07-20 18:09:38 -07:00
|
|
|
*
|
|
|
|
* {@hide}
|
2014-07-17 11:21:19 -07:00
|
|
|
*/
|
|
|
|
public static final int CAPABILITY_CALL_PROVIDER = 0x2;
|
|
|
|
|
2014-07-18 15:53:17 -07:00
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* Flag indicating that this {@code PhoneAccount} represents built-in PSTN SIM
|
2014-07-19 18:18:19 -07:00
|
|
|
* subscription.
|
2014-07-18 15:53:17 -07:00
|
|
|
* <p>
|
|
|
|
* Only the android framework can set this capability on a phone account.
|
|
|
|
*/
|
|
|
|
public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4;
|
|
|
|
|
2014-07-20 12:31:00 -07:00
|
|
|
private final PhoneAccountHandle mAccountHandle;
|
2014-07-17 11:21:19 -07:00
|
|
|
private final Uri mHandle;
|
2014-07-17 16:59:18 -07:00
|
|
|
private final String mSubscriptionNumber;
|
2014-07-17 11:21:19 -07:00
|
|
|
private final int mCapabilities;
|
|
|
|
private final int mIconResId;
|
2014-07-21 18:43:14 +00:00
|
|
|
private final String mLabel;
|
|
|
|
private final String mShortDescription;
|
2014-07-17 07:50:22 -07:00
|
|
|
private boolean mVideoCallingSupported;
|
2014-07-09 12:30:52 -07:00
|
|
|
|
2014-07-20 12:31:00 -07:00
|
|
|
public PhoneAccount(
|
2014-07-19 18:18:19 -07:00
|
|
|
PhoneAccountHandle account,
|
2014-07-17 11:21:19 -07:00
|
|
|
Uri handle,
|
2014-07-17 16:59:18 -07:00
|
|
|
String subscriptionNumber,
|
2014-07-17 11:21:19 -07:00
|
|
|
int capabilities,
|
2014-07-09 12:30:52 -07:00
|
|
|
int iconResId,
|
2014-07-21 18:43:14 +00:00
|
|
|
String label,
|
|
|
|
String shortDescription,
|
2014-07-17 07:50:22 -07:00
|
|
|
boolean supportsVideoCalling) {
|
2014-07-20 12:31:00 -07:00
|
|
|
mAccountHandle = account;
|
2014-07-17 11:21:19 -07:00
|
|
|
mHandle = handle;
|
2014-07-17 16:59:18 -07:00
|
|
|
mSubscriptionNumber = subscriptionNumber;
|
2014-07-17 11:21:19 -07:00
|
|
|
mCapabilities = capabilities;
|
2014-07-09 12:30:52 -07:00
|
|
|
mIconResId = iconResId;
|
|
|
|
mLabel = label;
|
|
|
|
mShortDescription = shortDescription;
|
2014-07-17 07:50:22 -07:00
|
|
|
mVideoCallingSupported = supportsVideoCalling;
|
2014-07-09 12:30:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-19 18:18:19 -07:00
|
|
|
* The {@code PhoneAccountHandle} to which this metadata pertains.
|
2014-07-09 12:30:52 -07:00
|
|
|
*
|
2014-07-19 18:18:19 -07:00
|
|
|
* @return A {@code PhoneAccountHandle}.
|
2014-07-09 12:30:52 -07:00
|
|
|
*/
|
2014-07-20 12:31:00 -07:00
|
|
|
public PhoneAccountHandle getAccountHandle() {
|
|
|
|
return mAccountHandle;
|
2014-07-09 12:30:52 -07:00
|
|
|
}
|
|
|
|
|
2014-07-17 11:21:19 -07:00
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* The handle (e.g., a phone number) associated with this {@code PhoneAccount}. This
|
|
|
|
* represents the destination from which outgoing calls using this {@code PhoneAccount}
|
2014-07-19 18:18:19 -07:00
|
|
|
* will appear to come, if applicable, and the destination to which incoming calls using this
|
2014-07-20 12:31:00 -07:00
|
|
|
* {@code PhoneAccount} may be addressed.
|
2014-07-17 11:21:19 -07:00
|
|
|
*
|
|
|
|
* @return A handle expressed as a {@code Uri}, for example, a phone number.
|
|
|
|
*/
|
|
|
|
public Uri getHandle() {
|
|
|
|
return mHandle;
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:59:18 -07:00
|
|
|
/**
|
|
|
|
* The subscription number associated with the underlying transport. This may differ from the
|
|
|
|
* {@link #getHandle()} number; for example, if the number used to talk to the network is not
|
|
|
|
* the same number that will be on the remote party's caller ID display.
|
|
|
|
*
|
|
|
|
* @return The subscription number, suitable for display to the user.
|
|
|
|
*/
|
|
|
|
public String getSubscriptionNumber() {
|
|
|
|
return mSubscriptionNumber;
|
|
|
|
}
|
|
|
|
|
2014-07-17 11:21:19 -07:00
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* The capabilities of this {@code PhoneAccount}.
|
2014-07-17 11:21:19 -07:00
|
|
|
*
|
2014-07-20 12:31:00 -07:00
|
|
|
* @return A bit field of flags describing this {@code PhoneAccount}'s capabilities.
|
2014-07-17 11:21:19 -07:00
|
|
|
*/
|
|
|
|
public int getCapabilities() {
|
|
|
|
return mCapabilities;
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:30:52 -07:00
|
|
|
/**
|
2014-07-21 18:43:14 +00:00
|
|
|
* A short string label describing a {@code PhoneAccount}.
|
2014-07-09 12:30:52 -07:00
|
|
|
*
|
2014-07-20 12:31:00 -07:00
|
|
|
* @return A label for this {@code PhoneAccount}.
|
2014-07-09 12:30:52 -07:00
|
|
|
*/
|
2014-07-21 18:43:14 +00:00
|
|
|
public String getLabel() {
|
2014-07-09 12:30:52 -07:00
|
|
|
return mLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* A short paragraph describing a {@code PhoneAccount}.
|
2014-07-09 12:30:52 -07:00
|
|
|
*
|
2014-07-20 12:31:00 -07:00
|
|
|
* @return A description for this {@code PhoneAccount}.
|
2014-07-09 12:30:52 -07:00
|
|
|
*/
|
2014-07-21 18:43:14 +00:00
|
|
|
public String getShortDescription() {
|
2014-07-09 12:30:52 -07:00
|
|
|
return mShortDescription;
|
|
|
|
}
|
|
|
|
|
2014-07-17 11:21:19 -07:00
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* The icon resource ID for the icon of this {@code PhoneAccount}.
|
2014-07-17 11:21:19 -07:00
|
|
|
*
|
|
|
|
* @return A resource ID.
|
|
|
|
*/
|
|
|
|
public int getIconResId() {
|
|
|
|
return mIconResId;
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:30:52 -07:00
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* An icon to represent this {@code PhoneAccount} in a user interface.
|
2014-07-09 12:30:52 -07:00
|
|
|
*
|
2014-07-20 12:31:00 -07:00
|
|
|
* @return An icon for this {@code PhoneAccount}.
|
2014-07-09 12:30:52 -07:00
|
|
|
*/
|
|
|
|
public Drawable getIcon(Context context) {
|
|
|
|
return getIcon(context, mIconResId);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Drawable getIcon(Context context, int resId) {
|
|
|
|
Context packageContext;
|
|
|
|
try {
|
|
|
|
packageContext = context.createPackageContext(
|
2014-07-20 12:31:00 -07:00
|
|
|
mAccountHandle.getComponentName().getPackageName(), 0);
|
2014-07-09 12:30:52 -07:00
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
2014-07-20 12:31:00 -07:00
|
|
|
Log.w(this, "Cannot find package %s", mAccountHandle.getComponentName().getPackageName());
|
2014-07-09 12:30:52 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return packageContext.getResources().getDrawable(resId);
|
|
|
|
} catch (MissingResourceException e) {
|
|
|
|
Log.e(this, e, "Cannot find icon %d in package %s",
|
2014-07-20 12:31:00 -07:00
|
|
|
resId, mAccountHandle.getComponentName().getPackageName());
|
2014-07-09 12:30:52 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 07:50:22 -07:00
|
|
|
/**
|
2014-07-20 12:31:00 -07:00
|
|
|
* Determines whether this {@code PhoneAccount} supports video calling.
|
2014-07-17 07:50:22 -07:00
|
|
|
*
|
2014-07-20 12:31:00 -07:00
|
|
|
* @return {@code true} if this {@code PhoneAccount} supports video calling.
|
2014-07-17 07:50:22 -07:00
|
|
|
*/
|
|
|
|
public boolean isVideoCallingSupported() {
|
|
|
|
return mVideoCallingSupported;
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:30:52 -07:00
|
|
|
//
|
|
|
|
// Parcelable implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel out, int flags) {
|
2014-07-20 12:31:00 -07:00
|
|
|
out.writeParcelable(mAccountHandle, 0);
|
2014-07-17 11:21:19 -07:00
|
|
|
out.writeParcelable(mHandle, 0);
|
2014-07-17 16:59:18 -07:00
|
|
|
out.writeString(mSubscriptionNumber);
|
2014-07-17 11:21:19 -07:00
|
|
|
out.writeInt(mCapabilities);
|
2014-07-09 12:30:52 -07:00
|
|
|
out.writeInt(mIconResId);
|
2014-07-21 18:43:14 +00:00
|
|
|
out.writeString(mLabel);
|
|
|
|
out.writeString(mShortDescription);
|
2014-07-17 11:21:19 -07:00
|
|
|
out.writeInt(mVideoCallingSupported ? 1 : 0);
|
2014-07-09 12:30:52 -07:00
|
|
|
}
|
|
|
|
|
2014-07-20 12:31:00 -07:00
|
|
|
public static final Creator<PhoneAccount> CREATOR
|
|
|
|
= new Creator<PhoneAccount>() {
|
2014-07-09 12:30:52 -07:00
|
|
|
@Override
|
2014-07-20 12:31:00 -07:00
|
|
|
public PhoneAccount createFromParcel(Parcel in) {
|
|
|
|
return new PhoneAccount(in);
|
2014-07-09 12:30:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-07-20 12:31:00 -07:00
|
|
|
public PhoneAccount[] newArray(int size) {
|
|
|
|
return new PhoneAccount[size];
|
2014-07-09 12:30:52 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-20 12:31:00 -07:00
|
|
|
private PhoneAccount(Parcel in) {
|
|
|
|
mAccountHandle = in.readParcelable(getClass().getClassLoader());
|
2014-07-17 11:21:19 -07:00
|
|
|
mHandle = in.readParcelable(getClass().getClassLoader());
|
2014-07-17 16:59:18 -07:00
|
|
|
mSubscriptionNumber = in.readString();
|
2014-07-17 11:21:19 -07:00
|
|
|
mCapabilities = in.readInt();
|
2014-07-09 12:30:52 -07:00
|
|
|
mIconResId = in.readInt();
|
2014-07-21 18:43:14 +00:00
|
|
|
mLabel = in.readString();
|
|
|
|
mShortDescription = in.readString();
|
2014-07-17 07:50:22 -07:00
|
|
|
mVideoCallingSupported = in.readInt() == 1;
|
2014-07-09 12:30:52 -07:00
|
|
|
}
|
|
|
|
}
|