1 /* Copyright (c) 2014, The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 package com.android.incallui; 30 31 import android.telecom.VideoProfile; 32 33 import com.google.common.base.Preconditions; 34 35 public class CallUtils { 36 isVideoCall(Call call)37 public static boolean isVideoCall(Call call) { 38 return call != null && isVideoCall(call.getVideoState()); 39 } 40 isVideoCall(int videoState)41 public static boolean isVideoCall(int videoState) { 42 return VideoProfile.isTransmissionEnabled(videoState) 43 || VideoProfile.isReceptionEnabled(videoState); 44 } 45 isIncomingVideoCall(Call call)46 public static boolean isIncomingVideoCall(Call call) { 47 if (!CallUtils.isVideoCall(call)) { 48 return false; 49 } 50 final int state = call.getState(); 51 return (state == Call.State.INCOMING) || (state == Call.State.CALL_WAITING); 52 } 53 isActiveVideoCall(Call call)54 public static boolean isActiveVideoCall(Call call) { 55 return CallUtils.isVideoCall(call) && call.getState() == Call.State.ACTIVE; 56 } 57 isOutgoingVideoCall(Call call)58 public static boolean isOutgoingVideoCall(Call call) { 59 if (!CallUtils.isVideoCall(call)) { 60 return false; 61 } 62 final int state = call.getState(); 63 return Call.State.isDialing(state) || state == Call.State.CONNECTING 64 || state == Call.State.SELECT_PHONE_ACCOUNT; 65 } 66 isAudioCall(Call call)67 public static boolean isAudioCall(Call call) { 68 return call != null && VideoProfile.isAudioOnly(call.getVideoState()); 69 } 70 71 // TODO (ims-vt) Check if special handling is needed for CONF calls. canVideoPause(Call call)72 public static boolean canVideoPause(Call call) { 73 return isVideoCall(call) && call.getState() == Call.State.ACTIVE; 74 } 75 makeVideoPauseProfile(Call call)76 public static VideoProfile makeVideoPauseProfile(Call call) { 77 Preconditions.checkNotNull(call); 78 Preconditions.checkState(!VideoProfile.isAudioOnly(call.getVideoState())); 79 return new VideoProfile(getPausedVideoState(call.getVideoState())); 80 } 81 makeVideoUnPauseProfile(Call call)82 public static VideoProfile makeVideoUnPauseProfile(Call call) { 83 Preconditions.checkNotNull(call); 84 return new VideoProfile(getUnPausedVideoState(call.getVideoState())); 85 } 86 getUnPausedVideoState(int videoState)87 public static int getUnPausedVideoState(int videoState) { 88 return videoState & (~VideoProfile.STATE_PAUSED); 89 } 90 getPausedVideoState(int videoState)91 public static int getPausedVideoState(int videoState) { 92 return videoState | VideoProfile.STATE_PAUSED; 93 } 94 95 } 96