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.server.telecom.tests; 18 19 import org.mockito.Mockito; 20 21 import android.net.Uri; 22 import android.telecom.Connection; 23 import android.telecom.Connection.VideoProvider; 24 import android.telecom.InCallService; 25 import android.telecom.InCallService.VideoCall; 26 import android.telecom.Log; 27 import android.telecom.VideoProfile; 28 import android.view.Surface; 29 30 /** 31 * Provides a mock implementation of a video provider. 32 */ 33 public class MockVideoProvider extends VideoProvider { 34 public static final String CAMERA_NONE = "none"; 35 public static final String CAMERA_FRONT = "front"; 36 public static final String CAMERA_BACK = "back"; 37 public static final int CAMERA_FRONT_DIMENSIONS = 1024; 38 public static final int CAMERA_BACK_DIMENSIONS = 2048; 39 public static final long DATA_USAGE = 1024; 40 public static final int PEER_DIMENSIONS = 4096; 41 public static final int DEVICE_ORIENTATION_UNDEFINED = -1; 42 public static final float ZOOM_UNDEFINED = -1.0f; 43 44 private Surface mPreviewSurface = null; 45 private Surface mDisplaySurface = null; 46 private int mDeviceOrientation = DEVICE_ORIENTATION_UNDEFINED; 47 private float mZoom = ZOOM_UNDEFINED; 48 private VideoProfile mSessionModifyResponse = null; 49 private Uri mPauseImage = null; 50 51 /** 52 * Responds to a request to set the camera by reporting the new camera information via the 53 * {@link #changeCameraCapabilities(VideoProfile.CameraCapabilities)} API. 54 * 55 * @param cameraId The id of the camera (use ids as reported by 56 */ 57 @Override onSetCamera(String cameraId)58 public void onSetCamera(String cameraId) { 59 handleCameraChange(cameraId); 60 } 61 62 /** 63 * Stores the preview surface set via the {@link VideoCall#setPreviewSurface(Surface)} API for 64 * retrieval using {@link #getPreviewSurface()}. 65 * 66 * @param surface The {@link Surface}. 67 */ 68 @Override onSetPreviewSurface(Surface surface)69 public void onSetPreviewSurface(Surface surface) { 70 mPreviewSurface = surface; 71 } 72 73 /** 74 * Stores the display surface set via the {@link VideoCall#setDisplaySurface(Surface)} API for 75 * retrieval using {@link #getDisplaySurface()}. 76 * 77 * @param surface The {@link Surface}. 78 */ 79 @Override onSetDisplaySurface(Surface surface)80 public void onSetDisplaySurface(Surface surface) { 81 mDisplaySurface = surface; 82 } 83 84 /** 85 * Stores the device orientation set via the {@link VideoCall#setDeviceOrientation(int)} API for 86 * retrieval using {@link #getDeviceOrientation()}. 87 * 88 * @param rotation The device orientation, in degrees. 89 */ 90 @Override onSetDeviceOrientation(int rotation)91 public void onSetDeviceOrientation(int rotation) { 92 mDeviceOrientation = rotation; 93 } 94 95 /** 96 * Stores the zoom level set via the {@link VideoCall#setZoom(float)} API for retrieval using 97 * {@link #getZoom()}. 98 * 99 * @param value The camera zoom. 100 */ 101 @Override onSetZoom(float value)102 public void onSetZoom(float value) { 103 mZoom = value; 104 } 105 106 /** 107 * Responds to any incoming session modify request by accepting the requested profile. 108 * 109 * @param fromProfile The video profile prior to the request. 110 * @param toProfile The video profile with the requested changes made. 111 */ 112 @Override onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile)113 public void onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { 114 super.receiveSessionModifyResponse(VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS, 115 fromProfile, toProfile); 116 } 117 118 /** 119 * Stores session modify responses received via the 120 * {@link VideoCall#sendSessionModifyResponse(VideoProfile)} API for retrieval via 121 * {@link #getSessionModifyResponse()}. 122 * 123 * @param responseProfile The response video profile. 124 */ 125 @Override onSendSessionModifyResponse(VideoProfile responseProfile)126 public void onSendSessionModifyResponse(VideoProfile responseProfile) { 127 mSessionModifyResponse = responseProfile; 128 } 129 130 /** 131 * Responds to requests for camera capabilities by reporting the front camera capabilities. 132 */ 133 @Override onRequestCameraCapabilities()134 public void onRequestCameraCapabilities() { 135 handleCameraChange(CAMERA_FRONT); 136 } 137 138 /** 139 * Responds to all requests for data usage by reporting {@link #DATA_USAGE}. 140 */ 141 @Override onRequestConnectionDataUsage()142 public void onRequestConnectionDataUsage() { 143 super.setCallDataUsage(DATA_USAGE); 144 } 145 146 /** 147 * Stores pause image URIs received via the {@link VideoCall#setPauseImage(Uri)} API for 148 * retrieval via {@link #getPauseImage()}. 149 * 150 * @param uri URI of image to display. 151 */ 152 @Override onSetPauseImage(Uri uri)153 public void onSetPauseImage(Uri uri) { 154 mPauseImage = uri; 155 } 156 157 /** 158 * Handles a change to the current camera selection. Responds by reporting the capabilities of 159 * the camera. 160 */ handleCameraChange(String cameraId)161 private void handleCameraChange(String cameraId) { 162 if (CAMERA_FRONT.equals(cameraId)) { 163 super.changeCameraCapabilities(new VideoProfile.CameraCapabilities( 164 CAMERA_FRONT_DIMENSIONS, CAMERA_FRONT_DIMENSIONS)); 165 } else if (CAMERA_BACK.equals(cameraId)) { 166 super.changeCameraCapabilities(new VideoProfile.CameraCapabilities( 167 CAMERA_BACK_DIMENSIONS, CAMERA_BACK_DIMENSIONS)); 168 } 169 } 170 171 /** 172 * Retrieves the last preview surface sent to the provider. 173 * 174 * @return the surface. 175 */ getPreviewSurface()176 public Surface getPreviewSurface() { 177 return mPreviewSurface; 178 } 179 180 /** 181 * Retrieves the last display surface sent to the provider. 182 * 183 * @return the surface. 184 */ getDisplaySurface()185 public Surface getDisplaySurface() { 186 return mDisplaySurface; 187 } 188 189 /** 190 * Retrieves the last device orientation sent to the provider. 191 * 192 * @return the orientation. 193 */ getDeviceOrientation()194 public int getDeviceOrientation() { 195 return mDeviceOrientation; 196 } 197 198 /** 199 * Retrieves the last zoom sent to the provider. 200 * 201 * @return the zoom. 202 */ getZoom()203 public float getZoom() { 204 return mZoom; 205 } 206 207 /** 208 * Retrieves the last session modify response sent to the provider. 209 * 210 * @return the session modify response. 211 */ getSessionModifyResponse()212 public VideoProfile getSessionModifyResponse() { 213 return mSessionModifyResponse; 214 } 215 216 /** 217 * Retrieves the last pause image sent to the provider. 218 * 219 * @return the pause image URI. 220 */ getPauseImage()221 public Uri getPauseImage() { 222 return mPauseImage; 223 } 224 225 /** 226 * Sends a mock session modify request via the provider. 227 */ sendMockSessionModifyRequest()228 public void sendMockSessionModifyRequest() { 229 super.receiveSessionModifyRequest(new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL)); 230 } 231 232 /** 233 * Sends a mock session event via the provider. 234 * 235 * @param event the event. 236 */ sendMockSessionEvent(int event)237 public void sendMockSessionEvent(int event) { 238 super.handleCallSessionEvent(event); 239 } 240 241 /** 242 * Sends a mock peer dimension change via the provider. 243 * 244 * @param width The new width. 245 * @param height The new height. 246 */ sendMockPeerDimensions(int width, int height)247 public void sendMockPeerDimensions(int width, int height) { 248 super.changePeerDimensions(width, height); 249 } 250 251 /** 252 * Sends a mock video quality change via the provider. 253 * 254 * @param videoQuality the video quality. 255 */ sendMockVideoQuality(int videoQuality)256 public void sendMockVideoQuality(int videoQuality) { 257 super.changeVideoQuality(videoQuality); 258 } 259 } 260