Files
frameworks_base/telecomm/java/android/telecomm/PhoneAccount.java
Sailesh Nepal e7ef59a77d Add Connection.setStatusHints
This CL allows a connection to specify a status hint. The hint
contains a label and icon that can be displayed in the InCallUI.
For example, wifi calling can set a wifi icon and ssid.

Change-Id: I125628b74784d2303b9a429038a9f7ee604f241e
2014-07-08 21:54:03 -07:00

223 lines
6.9 KiB
Java

/*
* 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.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.telephony.Rlog;
import android.util.DisplayMetrics;
import android.util.Log;
import java.util.MissingResourceException;
import java.util.Objects;
/**
* Represents a distinct account, line of service or call placement method that
* the system can use to place phone calls.
*/
public final class PhoneAccount implements Parcelable {
private static final int NO_DENSITY = -1;
private static final String LOG_TAG = "Account";
private final ComponentName mComponentName;
private final String mId;
private final Uri mHandle;
private final String mLabel;
private final String mShortDescription;
private final boolean mIsEnabled;
private final boolean mIsSystemDefault;
public PhoneAccount(
ComponentName componentName,
String id,
Uri handle,
String label,
String shortDescription,
boolean isEnabled,
boolean isSystemDefault) {
mComponentName = componentName;
mId = id;
mHandle = handle;
mLabel = label;
mShortDescription = shortDescription;
mIsSystemDefault = isSystemDefault;
mIsEnabled = isEnabled;
}
/**
* The {@code ComponentName} of the {@link android.telecomm.ConnectionService} which is
* responsible for making phone calls using this {@code PhoneAccount}.
*
* @return A suitable {@code ComponentName}.
*/
public ComponentName getComponentName() {
return mComponentName;
}
/**
* A unique identifier for this {@code PhoneAccount}, generated by and meaningful to the
* {@link android.telecomm.ConnectionService} that created it.
*
* @return A unique identifier for this {@code PhoneAccount}.
*/
public String getId() {
return mId;
}
/**
* The handle (e.g., a phone number) associated with this {@code PhoneAccount}. This represents
* the destination from which outgoing calls using this {@code PhoneAccount} will appear to come
* from, if applicable, and the destination to which incoming calls using this
* {@code PhoneAccount} may be addressed.
*
* @return A handle expressed as a {@code Uri}, for example, a phone number.
*/
public Uri getHandle() {
return mHandle;
}
/**
* A short string label describing this {@code PhoneAccount}.
*
* @param context The invoking {@code Context}, used for retrieving resources.
*
* TODO(ihab): If don't need context, remove param
*
* @return A label for this {@code PhoneAccount}.
*/
public String getLabel(Context context) {
return mLabel;
}
/**
* A short paragraph describing this {@code PhoneAccount}.
*
* @param context The invoking {@code Context}, used for retrieving resources.
*
* TODO(ihab): If don't need context, remove param
*
* @return A description for this {@code PhoneAccount}.
*/
public String getShortDescription(Context context) {
return mShortDescription;
}
// TODO(ihab): Representation of the icons
//
// Refactor to pass a Bitmap (scale it at runtime), but if they don't pass one, fall
// back to the android:icon attr in the manifest (<service /> first, <application /> second)
/**
* An icon to represent this {@code PhoneAccount} in a user interface.
*
* @param context The invoking {@code Context}, used for retrieving resources.
*
* @return An icon for this {@code PhoneAccount}.
*/
public Drawable getIcon(Context context) {
return null; // TODO(ihab): See above
}
/**
* An icon to represent this {@code PhoneAccount} in a user interface.
*
* @param context The invoking {@code Context}, used for retrieving resources.
* @param density A display density from {@link DisplayMetrics}.
*
* @return An icon for this {@code PhoneAccount}.
*/
public Drawable getIcon(Context context, int density) {
return null; // TODO(ihab): See above
}
/**
* Whether this {@code PhoneAccount} is enabled for use.
*
* @return {@code true} if this {@code PhoneAccount} is enabled.
*/
public boolean isEnabled() {
return mIsEnabled;
}
/**
* Whether this {@code PhoneAccount} is the system default.
*
* @return {@code true} if this {@code PhoneAccount} is the system default.
*/
public boolean isSystemDefault() {
return mIsSystemDefault;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(mComponentName, flags);
out.writeString(mId);
out.writeString(mHandle != null ? mHandle.toString() : "");
out.writeString(mLabel);
out.writeString(mShortDescription);
out.writeInt(mIsEnabled ? 1 : 0);
out.writeInt(mIsSystemDefault ? 1 : 0);
}
public static final Creator<PhoneAccount> CREATOR
= new Creator<PhoneAccount>() {
public PhoneAccount createFromParcel(Parcel in) {
return new PhoneAccount(in);
}
public PhoneAccount[] newArray(int size) {
return new PhoneAccount[size];
}
};
private PhoneAccount(Parcel in) {
mComponentName = in.readParcelable(getClass().getClassLoader());
mId = in.readString();
String uriString = in.readString();
mHandle = uriString.length() > 0 ? Uri.parse(uriString) : null;
mLabel = in.readString();
mShortDescription = in.readString();
mIsEnabled = in.readInt() == 1;
mIsSystemDefault = in.readInt() == 1;
}
@Override
public boolean equals(Object other) {
return
other instanceof PhoneAccount &&
Objects.equals(mComponentName, ((PhoneAccount) other).mComponentName) &&
Objects.equals(mId, ((PhoneAccount) other).mId);
}
@Override
public int hashCode() {
return Objects.hashCode(mComponentName) + Objects.hashCode(mId);
}
}