• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 com.android.incallui;
18 
19 import android.telecom.VideoProfile;
20 
21 import com.android.contacts.common.compat.CompatUtils;
22 
23 import com.google.common.base.Preconditions;
24 
25 public class VideoUtils {
26 
isVideoCall(Call call)27     public static boolean isVideoCall(Call call) {
28         return call != null && isVideoCall(call.getVideoState());
29     }
30 
isVideoCall(int videoState)31     public static boolean isVideoCall(int videoState) {
32         if (!CompatUtils.isVideoCompatible()) {
33             return false;
34         }
35 
36         return VideoProfile.isTransmissionEnabled(videoState)
37                 || VideoProfile.isReceptionEnabled(videoState);
38     }
39 
isBidirectionalVideoCall(Call call)40     public static boolean isBidirectionalVideoCall(Call call) {
41         if (!CompatUtils.isVideoCompatible()) {
42             return false;
43         }
44 
45         return VideoProfile.isBidirectional(call.getVideoState());
46     }
47 
isTransmissionEnabled(Call call)48     public static boolean isTransmissionEnabled(Call call) {
49         if (!CompatUtils.isVideoCompatible()) {
50             return false;
51         }
52 
53         return VideoProfile.isTransmissionEnabled(call.getVideoState());
54     }
55 
isIncomingVideoCall(Call call)56     public static boolean isIncomingVideoCall(Call call) {
57         if (!VideoUtils.isVideoCall(call)) {
58             return false;
59         }
60         final int state = call.getState();
61         return (state == Call.State.INCOMING) || (state == Call.State.CALL_WAITING);
62     }
63 
isActiveVideoCall(Call call)64     public static boolean isActiveVideoCall(Call call) {
65         return VideoUtils.isVideoCall(call) && call.getState() == Call.State.ACTIVE;
66     }
67 
isOutgoingVideoCall(Call call)68     public static boolean isOutgoingVideoCall(Call call) {
69         if (!VideoUtils.isVideoCall(call)) {
70             return false;
71         }
72         final int state = call.getState();
73         return Call.State.isDialing(state) || state == Call.State.CONNECTING
74                 || state == Call.State.SELECT_PHONE_ACCOUNT;
75     }
76 
isAudioCall(Call call)77     public static boolean isAudioCall(Call call) {
78         if (!CompatUtils.isVideoCompatible()) {
79             return true;
80         }
81 
82         return call != null && VideoProfile.isAudioOnly(call.getVideoState());
83     }
84 
85     // TODO (ims-vt) Check if special handling is needed for CONF calls.
canVideoPause(Call call)86     public static boolean canVideoPause(Call call) {
87         return isVideoCall(call) && call.getState() == Call.State.ACTIVE;
88     }
89 
makeVideoPauseProfile(Call call)90     public static VideoProfile makeVideoPauseProfile(Call call) {
91         Preconditions.checkNotNull(call);
92         Preconditions.checkState(!VideoProfile.isAudioOnly(call.getVideoState()));
93         return new VideoProfile(getPausedVideoState(call.getVideoState()));
94     }
95 
makeVideoUnPauseProfile(Call call)96     public static VideoProfile makeVideoUnPauseProfile(Call call) {
97         Preconditions.checkNotNull(call);
98         return new VideoProfile(getUnPausedVideoState(call.getVideoState()));
99     }
100 
getUnPausedVideoState(int videoState)101     public static int getUnPausedVideoState(int videoState) {
102         return videoState & (~VideoProfile.STATE_PAUSED);
103     }
104 
getPausedVideoState(int videoState)105     public static int getPausedVideoState(int videoState) {
106         return videoState | VideoProfile.STATE_PAUSED;
107     }
108 
109 }
110