1 /* 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 17 package com.android.incallui; 18 19 import android.telecom.Connection; 20 import android.telecom.Connection.VideoProvider; 21 import android.telecom.InCallService.VideoCall; 22 import android.telecom.VideoProfile; 23 import android.telecom.VideoProfile.CameraCapabilities; 24 25 /** 26 * Implements the InCallUI VideoCall Callback. 27 */ 28 public class InCallVideoCallCallback extends VideoCall.Callback { 29 30 /** 31 * The call associated with this {@link InCallVideoCallCallback}. 32 */ 33 private Call mCall; 34 35 /** 36 * Creates an instance of the call video client, specifying the call it is related to. 37 * 38 * @param call The call. 39 */ InCallVideoCallCallback(Call call)40 public InCallVideoCallCallback(Call call) { 41 mCall = call; 42 } 43 44 /** 45 * Handles an incoming session modification request. 46 * 47 * @param videoProfile The requested video call profile. 48 */ 49 @Override onSessionModifyRequestReceived(VideoProfile videoProfile)50 public void onSessionModifyRequestReceived(VideoProfile videoProfile) { 51 Log.d(this, " onSessionModifyRequestReceived videoProfile=" + videoProfile); 52 int previousVideoState = VideoUtils.getUnPausedVideoState(mCall.getVideoState()); 53 int newVideoState = VideoUtils.getUnPausedVideoState(videoProfile.getVideoState()); 54 55 boolean wasVideoCall = VideoUtils.isVideoCall(previousVideoState); 56 boolean isVideoCall = VideoUtils.isVideoCall(newVideoState); 57 58 // Check for upgrades to video. 59 if (!wasVideoCall && isVideoCall && previousVideoState != newVideoState) { 60 InCallVideoCallCallbackNotifier.getInstance().upgradeToVideoRequest(mCall, 61 newVideoState); 62 } 63 } 64 65 /** 66 * Handles a session modification response. 67 * 68 * @param status Status of the session modify request. Valid values are 69 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS}, 70 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_FAIL}, 71 * {@link Connection.VideoProvider#SESSION_MODIFY_REQUEST_INVALID} 72 * @param requestedProfile 73 * @param responseProfile The actual profile changes made by the peer device. 74 */ 75 @Override onSessionModifyResponseReceived(int status, VideoProfile requestedProfile, VideoProfile responseProfile)76 public void onSessionModifyResponseReceived(int status, VideoProfile requestedProfile, 77 VideoProfile responseProfile) { 78 Log.d(this, "onSessionModifyResponseReceived status=" + status + " requestedProfile=" 79 + requestedProfile + " responseProfile=" + responseProfile); 80 if (status != VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS) { 81 // Report the reason the upgrade failed as the new session modification state. 82 if (status == VideoProvider.SESSION_MODIFY_REQUEST_TIMED_OUT) { 83 mCall.setSessionModificationState( 84 Call.SessionModificationState.UPGRADE_TO_VIDEO_REQUEST_TIMED_OUT); 85 } else { 86 if (status == VideoProvider.SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE) { 87 mCall.setSessionModificationState( 88 Call.SessionModificationState.REQUEST_REJECTED); 89 } else { 90 mCall.setSessionModificationState( 91 Call.SessionModificationState.REQUEST_FAILED); 92 } 93 } 94 } 95 96 // Finally clear the outstanding request. 97 mCall.setSessionModificationState(Call.SessionModificationState.NO_REQUEST); 98 } 99 100 /** 101 * Handles a call session event. 102 * 103 * @param event The event. 104 */ 105 @Override onCallSessionEvent(int event)106 public void onCallSessionEvent(int event) { 107 InCallVideoCallCallbackNotifier.getInstance().callSessionEvent(event); 108 } 109 110 /** 111 * Handles a change to the peer video dimensions. 112 * 113 * @param width The updated peer video width. 114 * @param height The updated peer video height. 115 */ 116 @Override onPeerDimensionsChanged(int width, int height)117 public void onPeerDimensionsChanged(int width, int height) { 118 InCallVideoCallCallbackNotifier.getInstance().peerDimensionsChanged(mCall, width, height); 119 } 120 121 /** 122 * Handles a change to the video quality of the call. 123 * 124 * @param videoQuality The updated video call quality. 125 */ 126 @Override onVideoQualityChanged(int videoQuality)127 public void onVideoQualityChanged(int videoQuality) { 128 InCallVideoCallCallbackNotifier.getInstance().videoQualityChanged(mCall, videoQuality); 129 } 130 131 /** 132 * Handles a change to the call data usage. No implementation as the in-call UI does not 133 * display data usage. 134 * 135 * @param dataUsage The updated data usage. 136 */ 137 @Override onCallDataUsageChanged(long dataUsage)138 public void onCallDataUsageChanged(long dataUsage) { 139 Log.d(this, "onCallDataUsageChanged: dataUsage = " + dataUsage); 140 InCallVideoCallCallbackNotifier.getInstance().callDataUsageChanged(dataUsage); 141 } 142 143 /** 144 * Handles changes to the camera capabilities. No implementation as the in-call UI does not 145 * make use of camera capabilities. 146 * 147 * @param cameraCapabilities The changed camera capabilities. 148 */ 149 @Override onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities)150 public void onCameraCapabilitiesChanged(CameraCapabilities cameraCapabilities) { 151 if (cameraCapabilities != null) { 152 InCallVideoCallCallbackNotifier.getInstance().cameraDimensionsChanged( 153 mCall, cameraCapabilities.getWidth(), cameraCapabilities.getHeight()); 154 } 155 } 156 } 157