| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.telecomm; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.pm.PackageManager; |
| 21 | import android.graphics.drawable.Drawable; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 23 | import android.os.Parcel; |
| 24 | import android.os.Parcelable; |
| 25 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 26 | import java.util.MissingResourceException; |
| 27 | |
| 28 | /** |
| 29 | * Provides user interface description information for a {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 30 | * |
| 31 | * TODO: Per feedback from API Council, rename to "PhoneAccount". See also comment on class |
| 32 | * PhoneAccount. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 33 | */ |
| 34 | public class PhoneAccountMetadata implements Parcelable { |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Flag indicating that this {@code PhoneAccount} can act as a call manager for traditional |
| 38 | * SIM-based telephony calls. The {@link ConnectionService} associated with this phone-account |
| 39 | * will be allowed to manage SIM-based phone calls including using its own proprietary |
| 40 | * phone-call implementation (like VoIP calling) to make calls instead of the telephony stack. |
| 41 | * When a user opts to place a call using the SIM-based telephony stack, the connection-service |
| 42 | * associated with this phone-account will be attempted first if the user has explicitly |
| 43 | * selected it to be used as the default call-manager. |
| 44 | * <p> |
| 45 | * See {@link #getCapabilities} |
| 46 | */ |
| 47 | public static final int CAPABILITY_SIM_CALL_MANAGER = 0x1; |
| 48 | |
| 49 | /** |
| 50 | * Flag indicating that this {@code PhoneAccount} can make phone calls in place of traditional |
| 51 | * SIM-based telephony calls. This account will be treated as a distinct method for placing |
| 52 | * calls alongside the traditional SIM-based telephony stack. This flag is distinct from |
| 53 | * {@link #CAPABILITY_SIM_CALL_MANAGER} in that it is not allowed to manage calls from or use |
| 54 | * the built-in telephony stack to place its calls. |
| 55 | * <p> |
| 56 | * See {@link #getCapabilities} |
| 57 | */ |
| 58 | public static final int CAPABILITY_CALL_PROVIDER = 0x2; |
| 59 | |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame^] | 60 | /** |
| 61 | * Flag indicating that this {@code PhoneAccount} represents built-in PSTN SIM subscription. |
| 62 | * <p> |
| 63 | * Only the android framework can set this capability on a phone account. |
| 64 | */ |
| 65 | public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; |
| 66 | |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 67 | private final PhoneAccount mAccount; |
| 68 | private final Uri mHandle; |
| 69 | private final int mCapabilities; |
| 70 | private final int mIconResId; |
| 71 | private final String mLabel; |
| 72 | private final String mShortDescription; |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 73 | private boolean mVideoCallingSupported; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 74 | |
| 75 | public PhoneAccountMetadata( |
| 76 | PhoneAccount account, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 77 | Uri handle, |
| 78 | int capabilities, |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 79 | int iconResId, |
| 80 | String label, |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 81 | String shortDescription, |
| 82 | boolean supportsVideoCalling) { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 83 | mAccount = account; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 84 | mHandle = handle; |
| 85 | mCapabilities = capabilities; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 86 | mIconResId = iconResId; |
| 87 | mLabel = label; |
| 88 | mShortDescription = shortDescription; |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 89 | mVideoCallingSupported = supportsVideoCalling; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * The {@code PhoneAccount} to which this metadata pertains. |
| 94 | * |
| 95 | * @return A {@code PhoneAccount}. |
| 96 | */ |
| 97 | public PhoneAccount getAccount() { |
| 98 | return mAccount; |
| 99 | } |
| 100 | |
| 101 | /** |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 102 | * The handle (e.g., a phone number) associated with this {@code PhoneAccount}. This represents |
| 103 | * the destination from which outgoing calls using this {@code PhoneAccount} will appear to |
| 104 | * come, if applicable, and the destination to which incoming calls using this |
| 105 | * {@code PhoneAccount} may be addressed. |
| 106 | * |
| 107 | * @return A handle expressed as a {@code Uri}, for example, a phone number. |
| 108 | */ |
| 109 | public Uri getHandle() { |
| 110 | return mHandle; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * The capabilities of this {@code PhoneAccount}. |
| 115 | * |
| 116 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
| 117 | */ |
| 118 | public int getCapabilities() { |
| 119 | return mCapabilities; |
| 120 | } |
| 121 | |
| 122 | /** |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 123 | * A short string label describing a {@code PhoneAccount}. |
| 124 | * |
| 125 | * @return A label for this {@code PhoneAccount}. |
| 126 | */ |
| 127 | public String getLabel() { |
| 128 | return mLabel; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * A short paragraph describing a {@code PhoneAccount}. |
| 133 | * |
| 134 | * @return A description for this {@code PhoneAccount}. |
| 135 | */ |
| 136 | public String getShortDescription() { |
| 137 | return mShortDescription; |
| 138 | } |
| 139 | |
| 140 | /** |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 141 | * The icon resource ID for the icon of this {@code PhoneAccount}. |
| 142 | * |
| 143 | * @return A resource ID. |
| 144 | */ |
| 145 | public int getIconResId() { |
| 146 | return mIconResId; |
| 147 | } |
| 148 | |
| 149 | /** |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 150 | * An icon to represent this {@code PhoneAccount} in a user interface. |
| 151 | * |
| 152 | * @return An icon for this {@code PhoneAccount}. |
| 153 | */ |
| 154 | public Drawable getIcon(Context context) { |
| 155 | return getIcon(context, mIconResId); |
| 156 | } |
| 157 | |
| 158 | private Drawable getIcon(Context context, int resId) { |
| 159 | Context packageContext; |
| 160 | try { |
| 161 | packageContext = context.createPackageContext( |
| 162 | mAccount.getComponentName().getPackageName(), 0); |
| 163 | } catch (PackageManager.NameNotFoundException e) { |
| 164 | Log.w(this, "Cannot find package %s", mAccount.getComponentName().getPackageName()); |
| 165 | return null; |
| 166 | } |
| 167 | try { |
| 168 | return packageContext.getResources().getDrawable(resId); |
| 169 | } catch (MissingResourceException e) { |
| 170 | Log.e(this, e, "Cannot find icon %d in package %s", |
| 171 | resId, mAccount.getComponentName().getPackageName()); |
| 172 | return null; |
| 173 | } |
| 174 | } |
| 175 | |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 176 | /** |
| 177 | * Determines whether this {@code PhoneAccount} supports video calling. |
| 178 | * |
| 179 | * @return {@code true} if this {@code PhoneAccount} supports video calling. |
| 180 | */ |
| 181 | public boolean isVideoCallingSupported() { |
| 182 | return mVideoCallingSupported; |
| 183 | } |
| 184 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 185 | // |
| 186 | // Parcelable implementation |
| 187 | // |
| 188 | |
| 189 | @Override |
| 190 | public int describeContents() { |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public void writeToParcel(Parcel out, int flags) { |
| 196 | out.writeParcelable(mAccount, 0); |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 197 | out.writeParcelable(mHandle, 0); |
| 198 | out.writeInt(mCapabilities); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 199 | out.writeInt(mIconResId); |
| 200 | out.writeString(mLabel); |
| 201 | out.writeString(mShortDescription); |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 202 | out.writeInt(mVideoCallingSupported ? 1 : 0); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | public static final Creator<PhoneAccountMetadata> CREATOR |
| 206 | = new Creator<PhoneAccountMetadata>() { |
| 207 | @Override |
| 208 | public PhoneAccountMetadata createFromParcel(Parcel in) { |
| 209 | return new PhoneAccountMetadata(in); |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public PhoneAccountMetadata[] newArray(int size) { |
| 214 | return new PhoneAccountMetadata[size]; |
| 215 | } |
| 216 | }; |
| 217 | |
| 218 | private PhoneAccountMetadata(Parcel in) { |
| 219 | mAccount = in.readParcelable(getClass().getClassLoader()); |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 220 | mHandle = in.readParcelable(getClass().getClassLoader()); |
| 221 | mCapabilities = in.readInt(); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 222 | mIconResId = in.readInt(); |
| 223 | mLabel = in.readString(); |
| 224 | mShortDescription = in.readString(); |
| Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 225 | mVideoCallingSupported = in.readInt() == 1; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 226 | } |
| 227 | } |