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 android.telecom.cts; 18 19 import android.net.Uri; 20 import android.telecom.Connection; 21 import android.telecom.VideoProfile; 22 import android.view.Surface; 23 24 import android.telecom.Connection.VideoProvider; 25 26 /** 27 * Implements a mock video provider implementation. 28 */ 29 public class MockVideoProvider extends VideoProvider { 30 public static final String CAMERA_NONE = "none"; 31 public static final String CAMERA_FRONT = "front"; 32 public static final String CAMERA_BACK = "back"; 33 public static final int CAMERA_FRONT_DIMENSIONS = 1024; 34 public static final int CAMERA_BACK_DIMENSIONS = 2048; 35 public static final long DATA_USAGE = 1024; 36 public static final long DATA_USAGE_UNDEFINED = -1; 37 public static final int VIDEO_QUALITY_UNDEFINED = -1; 38 public static final int SESSION_EVENT_UNDEFINED = -1; 39 public static final int PEER_WIDTH_UNDEFINED = -1; 40 public static final int DEVICE_ORIENTATION_UNDEFINED = -1; 41 public static final float ZOOM_UNDEFINED = -1.0f; 42 43 private Uri mPauseImageUri; 44 private String mCameraId = CAMERA_NONE; 45 private MockConnection mMockConnection; 46 private int mDeviceOrientation = DEVICE_ORIENTATION_UNDEFINED; 47 private float mZoom = ZOOM_UNDEFINED; 48 private Surface mPreviewSurface = null; 49 private Surface mDisplaySurface = null; 50 private VideoProfile mSessionModifyResponse = null; 51 MockVideoProvider(MockConnection mockConnection)52 public MockVideoProvider(MockConnection mockConnection) { 53 mMockConnection = mockConnection; 54 } 55 56 @Override onSetCamera(String cameraId)57 public void onSetCamera(String cameraId) { 58 handleCameraChange(cameraId); 59 } 60 61 @Override onSetPreviewSurface(Surface surface)62 public void onSetPreviewSurface(Surface surface) { 63 mPreviewSurface = surface; 64 } 65 66 @Override onSetDisplaySurface(Surface surface)67 public void onSetDisplaySurface(Surface surface) { 68 mDisplaySurface = surface; 69 } 70 71 @Override onSetDeviceOrientation(int rotation)72 public void onSetDeviceOrientation(int rotation) { 73 mDeviceOrientation = rotation; 74 } 75 76 @Override onSetZoom(float value)77 public void onSetZoom(float value) { 78 mZoom = value; 79 } 80 81 /** 82 * Handles a session modification request from the {@link MockInCallService}. Assumes the peer 83 * has accepted the proposed video profile. 84 * 85 * @param fromProfile The video properties prior to the request. 86 * @param toProfile The video properties with the requested changes made. 87 */ 88 @Override onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile)89 public void onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) { 90 super.receiveSessionModifyResponse(Connection.VideoProvider.SESSION_MODIFY_REQUEST_SUCCESS, 91 toProfile, toProfile); 92 mMockConnection.setVideoState(toProfile.getVideoState()); 93 } 94 95 @Override onSendSessionModifyResponse(VideoProfile responseProfile)96 public void onSendSessionModifyResponse(VideoProfile responseProfile) { 97 mSessionModifyResponse = responseProfile; 98 } 99 100 /** 101 * Responds with the current camera capabilities. 102 */ 103 @Override onRequestCameraCapabilities()104 public void onRequestCameraCapabilities() { 105 handleCameraChange(mCameraId); 106 } 107 108 /** 109 * Handles requests to retrieve the connection data usage by returning a fixed usage amount of 110 * {@code 1024} bytes. 111 */ 112 @Override onRequestConnectionDataUsage()113 public void onRequestConnectionDataUsage() { 114 super.setCallDataUsage(DATA_USAGE); 115 } 116 117 @Override onSetPauseImage(Uri uri)118 public void onSetPauseImage(Uri uri) { 119 mPauseImageUri = uri; 120 } 121 122 /** 123 * Handles a change to the current camera selection. Responds by reporting the capabilities of 124 * the camera. 125 */ handleCameraChange(String cameraId)126 private void handleCameraChange(String cameraId) { 127 mCameraId = cameraId; 128 if (CAMERA_FRONT.equals(mCameraId)) { 129 super.changeCameraCapabilities(new VideoProfile.CameraCapabilities( 130 CAMERA_FRONT_DIMENSIONS, CAMERA_FRONT_DIMENSIONS)); 131 } else if (CAMERA_BACK.equals(mCameraId)) { 132 super.changeCameraCapabilities(new VideoProfile.CameraCapabilities( 133 CAMERA_BACK_DIMENSIONS, CAMERA_BACK_DIMENSIONS)); 134 } 135 } 136 137 /** 138 * Sends a mock video quality value from the provider. 139 * 140 * @param videoQuality The video quality. 141 */ sendMockVideoQuality(int videoQuality)142 public void sendMockVideoQuality(int videoQuality) { 143 super.changeVideoQuality(videoQuality); 144 } 145 146 /** 147 * Sends a mock call session event from the provider. 148 * 149 * @param event The call session event. 150 */ sendMockCallSessionEvent(int event)151 public void sendMockCallSessionEvent(int event) { 152 super.handleCallSessionEvent(event); 153 } 154 155 /** 156 * Sends a mock peer width from the provider. 157 * 158 * @param width The peer width. 159 */ sendMockPeerWidth(int width)160 public void sendMockPeerWidth(int width) { 161 super.changePeerDimensions(width, width); 162 } 163 164 /** 165 * Sends a mock session modify request from the provider. 166 * 167 * @param request The requested profile. 168 */ sendMockSessionModifyRequest(VideoProfile request)169 public void sendMockSessionModifyRequest(VideoProfile request) { 170 super.receiveSessionModifyRequest(request); 171 } 172 getDeviceOrientation()173 public int getDeviceOrientation() { 174 return mDeviceOrientation; 175 } 176 getZoom()177 public float getZoom() { 178 return mZoom; 179 } 180 getPreviewSurface()181 public Surface getPreviewSurface() { 182 return mPreviewSurface; 183 } 184 getDisplaySurface()185 public Surface getDisplaySurface() { 186 return mDisplaySurface; 187 } 188 getSessionModifyResponse()189 public VideoProfile getSessionModifyResponse() { 190 return mSessionModifyResponse; 191 } 192 } 193