blob: 90ed36f19dbfdef8a5c2b7888a4d1d387b991fe7 [file] [log] [blame]
Tyler Gunn7c668b92014-06-27 14:38:28 -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
Tyler Gunnef9f6f92014-09-12 22:16:17 -070017package android.telecom;
Tyler Gunn7c668b92014-06-27 14:38:28 -070018
Tyler Gunn48d02102016-01-08 13:20:25 -080019import android.annotation.IntDef;
Tyler Gunn7c668b92014-06-27 14:38:28 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
Tyler Gunn48d02102016-01-08 13:20:25 -080023import java.lang.annotation.Retention;
24import java.lang.annotation.RetentionPolicy;
25
Tyler Gunn7c668b92014-06-27 14:38:28 -070026/**
27 * Represents attributes of video calls.
28 */
Ihab Awadb19a0bc2014-08-07 19:46:01 -070029public class VideoProfile implements Parcelable {
Tyler Gunn48d02102016-01-08 13:20:25 -080030
31 /** @hide */
32 @Retention(RetentionPolicy.SOURCE)
33 @IntDef({QUALITY_UNKNOWN, QUALITY_HIGH, QUALITY_MEDIUM, QUALITY_LOW, QUALITY_DEFAULT})
34 public @interface VideoQuality {}
35
Tyler Gunn7c668b92014-06-27 14:38:28 -070036 /**
Rekha Kumar07366812015-03-24 16:42:31 -070037 * "Unknown" video quality.
38 * @hide
39 */
40 public static final int QUALITY_UNKNOWN = 0;
41 /**
Tyler Gunn7c668b92014-06-27 14:38:28 -070042 * "High" video quality.
43 */
44 public static final int QUALITY_HIGH = 1;
45
46 /**
47 * "Medium" video quality.
48 */
49 public static final int QUALITY_MEDIUM = 2;
50
51 /**
52 * "Low" video quality.
53 */
54 public static final int QUALITY_LOW = 3;
55
56 /**
57 * Use default video quality.
58 */
59 public static final int QUALITY_DEFAULT = 4;
60
Tyler Gunn48d02102016-01-08 13:20:25 -080061 /** @hide */
62 @Retention(RetentionPolicy.SOURCE)
63 @IntDef(
64 flag = true,
Tyler Gunn9d127732018-03-02 15:45:51 -080065 prefix = { "STATE_" },
Tyler Gunn48d02102016-01-08 13:20:25 -080066 value = {STATE_AUDIO_ONLY, STATE_TX_ENABLED, STATE_RX_ENABLED, STATE_BIDIRECTIONAL,
67 STATE_PAUSED})
68 public @interface VideoState {}
69
Yorke Lee32f24732015-05-12 16:18:03 -070070 /**
Tyler Gunnbc6f12e2015-06-09 14:34:11 -070071 * Used when answering or dialing a call to indicate that the call does not have a video
72 * component.
73 * <p>
74 * Should <b>not</b> be used in comparison checks to determine if a video state represents an
75 * audio-only call.
76 * <p>
77 * The following, for example, is not the correct way to check if a call is audio-only:
78 * <pre>
79 * {@code
80 * // This is the incorrect way to check for an audio-only call.
81 * if (videoState == VideoProfile.STATE_AUDIO_ONLY) {
82 * // Handle audio-only call.
83 * }
84 * }
85 * </pre>
86 * <p>
87 * Instead, use the {@link VideoProfile#isAudioOnly(int)} helper function to check if a
88 * video state represents an audio-only call:
89 * <pre>
90 * {@code
91 * // This is the correct way to check for an audio-only call.
92 * if (VideoProfile.isAudioOnly(videoState)) {
93 * // Handle audio-only call.
94 * }
95 * }
96 * </pre>
Yorke Lee32f24732015-05-12 16:18:03 -070097 */
98 public static final int STATE_AUDIO_ONLY = 0x0;
99
100 /**
101 * Video transmission is enabled.
102 */
103 public static final int STATE_TX_ENABLED = 0x1;
104
105 /**
106 * Video reception is enabled.
107 */
108 public static final int STATE_RX_ENABLED = 0x2;
109
110 /**
111 * Video signal is bi-directional.
112 */
113 public static final int STATE_BIDIRECTIONAL = STATE_TX_ENABLED | STATE_RX_ENABLED;
114
115 /**
116 * Video is paused.
117 */
118 public static final int STATE_PAUSED = 0x4;
119
Tyler Gunn7c668b92014-06-27 14:38:28 -0700120 private final int mVideoState;
121
122 private final int mQuality;
123
124 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700125 * Creates an instance of the VideoProfile
Tyler Gunn7c668b92014-06-27 14:38:28 -0700126 *
127 * @param videoState The video state.
Andrew Lee055e5a22014-07-21 12:14:11 -0700128 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800129 public VideoProfile(@VideoState int videoState) {
Andrew Lee055e5a22014-07-21 12:14:11 -0700130 this(videoState, QUALITY_DEFAULT);
131 }
132
133 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700134 * Creates an instance of the VideoProfile
Andrew Lee055e5a22014-07-21 12:14:11 -0700135 *
136 * @param videoState The video state.
Tyler Gunn7c668b92014-06-27 14:38:28 -0700137 * @param quality The video quality.
138 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800139 public VideoProfile(@VideoState int videoState, @VideoQuality int quality) {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700140 mVideoState = videoState;
141 mQuality = quality;
142 }
143
144 /**
Andrew Lee48332d62014-07-28 14:04:20 -0700145 * The video state of the call.
Yorke Lee32f24732015-05-12 16:18:03 -0700146 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
147 * {@link VideoProfile#STATE_BIDIRECTIONAL},
148 * {@link VideoProfile#STATE_TX_ENABLED},
149 * {@link VideoProfile#STATE_RX_ENABLED},
150 * {@link VideoProfile#STATE_PAUSED}.
Tyler Gunn7c668b92014-06-27 14:38:28 -0700151 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800152 @VideoState
Tyler Gunn7c668b92014-06-27 14:38:28 -0700153 public int getVideoState() {
154 return mVideoState;
155 }
156
157 /**
158 * The desired video quality for the call.
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700159 * Valid values: {@link VideoProfile#QUALITY_HIGH}, {@link VideoProfile#QUALITY_MEDIUM},
160 * {@link VideoProfile#QUALITY_LOW}, {@link VideoProfile#QUALITY_DEFAULT}.
Tyler Gunn7c668b92014-06-27 14:38:28 -0700161 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800162 @VideoQuality
Tyler Gunn7c668b92014-06-27 14:38:28 -0700163 public int getQuality() {
164 return mQuality;
165 }
166
167 /**
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700168 * Responsible for creating VideoProfile objects from deserialized Parcels.
Tyler Gunn7c668b92014-06-27 14:38:28 -0700169 **/
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700170 public static final Parcelable.Creator<VideoProfile> CREATOR =
171 new Parcelable.Creator<VideoProfile> () {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700172 /**
173 * Creates a MediaProfile instances from a parcel.
174 *
175 * @param source The parcel.
176 * @return The MediaProfile.
177 */
178 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700179 public VideoProfile createFromParcel(Parcel source) {
Tyler Gunn7c668b92014-06-27 14:38:28 -0700180 int state = source.readInt();
181 int quality = source.readInt();
182
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700183 ClassLoader classLoader = VideoProfile.class.getClassLoader();
184 return new VideoProfile(state, quality);
Tyler Gunn7c668b92014-06-27 14:38:28 -0700185 }
186
187 @Override
Ihab Awadb19a0bc2014-08-07 19:46:01 -0700188 public VideoProfile[] newArray(int size) {
189 return new VideoProfile[size];
Tyler Gunn7c668b92014-06-27 14:38:28 -0700190 }
191 };
192
193 /**
194 * Describe the kinds of special objects contained in this Parcelable's
195 * marshalled representation.
196 *
197 * @return a bitmask indicating the set of special object types marshalled
198 * by the Parcelable.
199 */
200 @Override
201 public int describeContents() {
202 return 0;
203 }
204
205 /**
206 * Flatten this object in to a Parcel.
207 *
208 * @param dest The Parcel in which the object should be written.
209 * @param flags Additional flags about how the object should be written.
210 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
211 */
212 @Override
213 public void writeToParcel(Parcel dest, int flags) {
214 dest.writeInt(mVideoState);
215 dest.writeInt(mQuality);
216 }
Andrew Lee48332d62014-07-28 14:04:20 -0700217
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700218 @Override
219 public String toString() {
220 StringBuilder sb = new StringBuilder();
221 sb.append("[VideoProfile videoState = ");
Tyler Gunn87b73f32015-06-03 10:09:59 -0700222 sb.append(videoStateToString(mVideoState));
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700223 sb.append(" videoQuality = ");
224 sb.append(mQuality);
225 sb.append("]");
226 return sb.toString();
227 }
228
Andrew Lee48332d62014-07-28 14:04:20 -0700229 /**
Tyler Gunn87b73f32015-06-03 10:09:59 -0700230 * Generates a string representation of a video state.
231 *
232 * @param videoState The video state.
233 * @return String representation of the video state.
234 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800235 public static String videoStateToString(@VideoState int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700236 StringBuilder sb = new StringBuilder();
237 sb.append("Audio");
Andrew Lee48332d62014-07-28 14:04:20 -0700238
Tyler Gunn1aee66f2017-02-21 15:19:43 -0800239 if (videoState == STATE_AUDIO_ONLY) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700240 sb.append(" Only");
241 } else {
242 if (isTransmissionEnabled(videoState)) {
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700243 sb.append(" Tx");
244 }
245
Tyler Gunn87b73f32015-06-03 10:09:59 -0700246 if (isReceptionEnabled(videoState)) {
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700247 sb.append(" Rx");
248 }
249
Tyler Gunn87b73f32015-06-03 10:09:59 -0700250 if (isPaused(videoState)) {
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700251 sb.append(" Pause");
252 }
Tyler Gunnbde0b1e2015-04-24 15:09:58 -0700253 }
Tyler Gunn87b73f32015-06-03 10:09:59 -0700254
255 return sb.toString();
256 }
257
258 /**
259 * Indicates whether the video state is audio only.
Tyler Gunn1aee66f2017-02-21 15:19:43 -0800260 * <p>
261 * Note: Considers only whether either both the {@link #STATE_RX_ENABLED} or
262 * {@link #STATE_TX_ENABLED} bits are off, but not {@link #STATE_PAUSED}.
Tyler Gunn87b73f32015-06-03 10:09:59 -0700263 *
264 * @param videoState The video state.
265 * @return {@code True} if the video state is audio only, {@code false} otherwise.
266 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800267 public static boolean isAudioOnly(@VideoState int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700268 return !hasState(videoState, VideoProfile.STATE_TX_ENABLED)
269 && !hasState(videoState, VideoProfile.STATE_RX_ENABLED);
270 }
271
272 /**
273 * Indicates whether video transmission or reception is enabled for a video state.
274 *
275 * @param videoState The video state.
276 * @return {@code True} if video transmission or reception is enabled, {@code false} otherwise.
277 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800278 public static boolean isVideo(@VideoState int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700279 return hasState(videoState, VideoProfile.STATE_TX_ENABLED)
280 || hasState(videoState, VideoProfile.STATE_RX_ENABLED)
281 || hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL);
282 }
283
284 /**
285 * Indicates whether the video state has video transmission enabled.
286 *
287 * @param videoState The video state.
288 * @return {@code True} if video transmission is enabled, {@code false} otherwise.
289 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800290 public static boolean isTransmissionEnabled(@VideoState int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700291 return hasState(videoState, VideoProfile.STATE_TX_ENABLED);
292 }
293
294 /**
295 * Indicates whether the video state has video reception enabled.
296 *
297 * @param videoState The video state.
298 * @return {@code True} if video reception is enabled, {@code false} otherwise.
299 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800300 public static boolean isReceptionEnabled(@VideoState int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700301 return hasState(videoState, VideoProfile.STATE_RX_ENABLED);
302 }
303
304 /**
305 * Indicates whether the video state is bi-directional.
306 *
307 * @param videoState The video state.
308 * @return {@code True} if the video is bi-directional, {@code false} otherwise.
309 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800310 public static boolean isBidirectional(@VideoState int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700311 return hasState(videoState, VideoProfile.STATE_BIDIRECTIONAL);
312 }
313
314 /**
315 * Indicates whether the video state is paused.
316 *
317 * @param videoState The video state.
318 * @return {@code True} if the video is paused, {@code false} otherwise.
319 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800320 public static boolean isPaused(@VideoState int videoState) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700321 return hasState(videoState, VideoProfile.STATE_PAUSED);
322 }
323
324 /**
325 * Indicates if a specified state is set in a videoState bit-mask.
326 *
327 * @param videoState The video state bit-mask.
328 * @param state The state to check.
329 * @return {@code True} if the state is set.
330 */
Tyler Gunn48d02102016-01-08 13:20:25 -0800331 private static boolean hasState(@VideoState int videoState, @VideoState int state) {
Tyler Gunn87b73f32015-06-03 10:09:59 -0700332 return (videoState & state) == state;
Andrew Lee48332d62014-07-28 14:04:20 -0700333 }
Yorke Lee400470f2015-05-12 13:31:25 -0700334
335 /**
336 * Represents the camera capabilities important to a Video Telephony provider.
337 */
338 public static final class CameraCapabilities implements Parcelable {
339
340 /**
341 * The width of the camera video in pixels.
342 */
343 private final int mWidth;
344
345 /**
346 * The height of the camera video in pixels.
347 */
348 private final int mHeight;
349
350 /**
351 * Whether the camera supports zoom.
352 */
353 private final boolean mZoomSupported;
354
355 /**
356 * The maximum zoom supported by the camera.
357 */
358 private final float mMaxZoom;
359
360 /**
361 * Create a call camera capabilities instance.
362 *
363 * @param width The width of the camera video (in pixels).
364 * @param height The height of the camera video (in pixels).
365 */
366 public CameraCapabilities(int width, int height) {
367 this(width, height, false, 1.0f);
368 }
369
370 /**
371 * Create a call camera capabilities instance that optionally
372 * supports zoom.
373 *
374 * @param width The width of the camera video (in pixels).
375 * @param height The height of the camera video (in pixels).
376 * @param zoomSupported True when camera supports zoom.
377 * @param maxZoom Maximum zoom supported by camera.
378 * @hide
379 */
380 public CameraCapabilities(int width, int height, boolean zoomSupported, float maxZoom) {
381 mWidth = width;
382 mHeight = height;
383 mZoomSupported = zoomSupported;
384 mMaxZoom = maxZoom;
385 }
386
387 /**
388 * Responsible for creating CallCameraCapabilities objects from deserialized Parcels.
389 **/
390 public static final Parcelable.Creator<CameraCapabilities> CREATOR =
391 new Parcelable.Creator<CameraCapabilities> () {
392 /**
393 * Creates a CallCameraCapabilities instances from a parcel.
394 *
395 * @param source The parcel.
396 * @return The CallCameraCapabilities.
397 */
398 @Override
399 public CameraCapabilities createFromParcel(Parcel source) {
400 int width = source.readInt();
401 int height = source.readInt();
402 boolean supportsZoom = source.readByte() != 0;
403 float maxZoom = source.readFloat();
404
405 return new CameraCapabilities(width, height, supportsZoom, maxZoom);
406 }
407
408 @Override
409 public CameraCapabilities[] newArray(int size) {
410 return new CameraCapabilities[size];
411 }
412 };
413
414 /**
415 * Describe the kinds of special objects contained in this Parcelable's
416 * marshalled representation.
417 *
418 * @return a bitmask indicating the set of special object types marshalled
419 * by the Parcelable.
420 */
421 @Override
422 public int describeContents() {
423 return 0;
424 }
425
426 /**
427 * Flatten this object in to a Parcel.
428 *
429 * @param dest The Parcel in which the object should be written.
430 * @param flags Additional flags about how the object should be written.
431 * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
432 */
433 @Override
434 public void writeToParcel(Parcel dest, int flags) {
435 dest.writeInt(getWidth());
436 dest.writeInt(getHeight());
437 dest.writeByte((byte) (isZoomSupported() ? 1 : 0));
438 dest.writeFloat(getMaxZoom());
439 }
440
441 /**
442 * The width of the camera video in pixels.
443 */
444 public int getWidth() {
445 return mWidth;
446 }
447
448 /**
449 * The height of the camera video in pixels.
450 */
451 public int getHeight() {
452 return mHeight;
453 }
454
455 /**
456 * Whether the camera supports zoom.
457 * @hide
458 */
459 public boolean isZoomSupported() {
460 return mZoomSupported;
461 }
462
463 /**
464 * The maximum zoom supported by the camera.
465 * @hide
466 */
467 public float getMaxZoom() {
468 return mMaxZoom;
469 }
470 }
471
Tyler Gunn7c668b92014-06-27 14:38:28 -0700472}