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