blob: 899317095ecbf8269d71a3ed5c9083c68ad30033 [file] [log] [blame]
Ihab Awad807fe0a2014-07-09 12:30:52 -07001/*
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
17package android.telecomm;
18
19import android.content.Context;
20import android.content.pm.PackageManager;
21import android.graphics.drawable.Drawable;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070022import android.net.Uri;
Ihab Awad807fe0a2014-07-09 12:30:52 -070023import android.os.Parcel;
24import android.os.Parcelable;
25
Ihab Awad807fe0a2014-07-09 12:30:52 -070026import java.util.MissingResourceException;
27
28/**
29 * Provides user interface description information for a {@code PhoneAccount}.
Ihab Awad94cf4bf2014-07-17 11:21:19 -070030 *
31 * TODO: Per feedback from API Council, rename to "PhoneAccount". See also comment on class
32 * PhoneAccount.
Ihab Awad807fe0a2014-07-09 12:30:52 -070033 */
34public class PhoneAccountMetadata implements Parcelable {
Ihab Awad94cf4bf2014-07-17 11:21:19 -070035
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 Awad7522bbd62014-07-18 15:53:17 -070060 /**
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 Awad94cf4bf2014-07-17 11:21:19 -070067 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 Gunnaa07df82014-07-17 07:50:22 -070073 private boolean mVideoCallingSupported;
Ihab Awad807fe0a2014-07-09 12:30:52 -070074
75 public PhoneAccountMetadata(
76 PhoneAccount account,
Ihab Awad94cf4bf2014-07-17 11:21:19 -070077 Uri handle,
78 int capabilities,
Ihab Awad807fe0a2014-07-09 12:30:52 -070079 int iconResId,
80 String label,
Tyler Gunnaa07df82014-07-17 07:50:22 -070081 String shortDescription,
82 boolean supportsVideoCalling) {
Ihab Awad807fe0a2014-07-09 12:30:52 -070083 mAccount = account;
Ihab Awad94cf4bf2014-07-17 11:21:19 -070084 mHandle = handle;
85 mCapabilities = capabilities;
Ihab Awad807fe0a2014-07-09 12:30:52 -070086 mIconResId = iconResId;
87 mLabel = label;
88 mShortDescription = shortDescription;
Tyler Gunnaa07df82014-07-17 07:50:22 -070089 mVideoCallingSupported = supportsVideoCalling;
Ihab Awad807fe0a2014-07-09 12:30:52 -070090 }
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 Awad94cf4bf2014-07-17 11:21:19 -0700102 * 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 Awad807fe0a2014-07-09 12:30:52 -0700123 * 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 Awad94cf4bf2014-07-17 11:21:19 -0700141 * 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 Awad807fe0a2014-07-09 12:30:52 -0700150 * 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 Gunnaa07df82014-07-17 07:50:22 -0700176 /**
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 Awad807fe0a2014-07-09 12:30:52 -0700185 //
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 Awad94cf4bf2014-07-17 11:21:19 -0700197 out.writeParcelable(mHandle, 0);
198 out.writeInt(mCapabilities);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700199 out.writeInt(mIconResId);
200 out.writeString(mLabel);
201 out.writeString(mShortDescription);
Ihab Awad94cf4bf2014-07-17 11:21:19 -0700202 out.writeInt(mVideoCallingSupported ? 1 : 0);
Ihab Awad807fe0a2014-07-09 12:30:52 -0700203 }
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 Awad94cf4bf2014-07-17 11:21:19 -0700220 mHandle = in.readParcelable(getClass().getClassLoader());
221 mCapabilities = in.readInt();
Ihab Awad807fe0a2014-07-09 12:30:52 -0700222 mIconResId = in.readInt();
223 mLabel = in.readString();
224 mShortDescription = in.readString();
Tyler Gunnaa07df82014-07-17 07:50:22 -0700225 mVideoCallingSupported = in.readInt() == 1;
Ihab Awad807fe0a2014-07-09 12:30:52 -0700226 }
227}