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 
isIncomingVideoCall(Call call)48     public static boolean isIncomingVideoCall(Call call) {
49         if (!VideoUtils.isVideoCall(call)) {
50             return false;
51         }
52         final int state = call.getState();
53         return (state == Call.State.INCOMING) || (state == Call.State.CALL_WAITING);
54     }
55 
isActiveVideoCall(Call call)56     public static boolean isActiveVideoCall(Call call) {
57         return VideoUtils.isVideoCall(call) && call.getState() == Call.State.ACTIVE;
58     }
59 
isOutgoingVideoCall(Call call)60     public static boolean isOutgoingVideoCall(Call call) {
61         if (!VideoUtils.isVideoCall(call)) {
62             return false;
63         }
64         final int state = call.getState();
65         return Call.State.isDialing(state) || state == Call.State.CONNECTING
66                 || state == Call.State.SELECT_PHONE_ACCOUNT;
67     }
68 
isAudioCall(Call call)69     public static boolean isAudioCall(Call call) {
70         if (!CompatUtils.isVideoCompatible()) {
71             return true;
72         }
73 
74         return call != null && VideoProfile.isAudioOnly(call.getVideoState());
75     }
76 
77     // TODO (ims-vt) Check if special handling is needed for CONF calls.
canVideoPause(Call call)78     public static boolean canVideoPause(Call call) {
79         return isVideoCall(call) && call.getState() == Call.State.ACTIVE;
80     }
81 
makeVideoPauseProfile(Call call)82     public static VideoProfile makeVideoPauseProfile(Call call) {
83         Preconditions.checkNotNull(call);
84         Preconditions.checkState(!VideoProfile.isAudioOnly(call.getVideoState()));
85         return new VideoProfile(getPausedVideoState(call.getVideoState()));
86     }
87 
makeVideoUnPauseProfile(Call call)88     public static VideoProfile makeVideoUnPauseProfile(Call call) {
89         Preconditions.checkNotNull(call);
90         return new VideoProfile(getUnPausedVideoState(call.getVideoState()));
91     }
92 
getUnPausedVideoState(int videoState)93     public static int getUnPausedVideoState(int videoState) {
94         return videoState & (~VideoProfile.STATE_PAUSED);
95     }
96 
getPausedVideoState(int videoState)97     public static int getPausedVideoState(int videoState) {
98         return videoState | VideoProfile.STATE_PAUSED;
99     }
100 
101 }
102