1 /* 2 * Copyright (C) 2018 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 static org.junit.Assert.assertEquals; 20 import static org.mockito.ArgumentMatchers.any; 21 import static org.mockito.ArgumentMatchers.anyInt; 22 import static org.mockito.ArgumentMatchers.eq; 23 import static org.mockito.Mockito.doNothing; 24 import static org.mockito.Mockito.verify; 25 import static org.mockito.Mockito.when; 26 27 import android.os.IBinder; 28 import android.telecom.VideoProfile; 29 import android.test.suitebuilder.annotation.SmallTest; 30 31 import com.android.internal.telecom.IVideoProvider; 32 import com.android.server.telecom.Analytics; 33 import com.android.server.telecom.Call; 34 import com.android.server.telecom.CurrentUserProxy; 35 import com.android.server.telecom.TelecomSystem; 36 import com.android.server.telecom.VideoProviderProxy; 37 38 import org.junit.After; 39 import org.junit.Before; 40 import org.junit.Test; 41 import org.mockito.ArgumentCaptor; 42 import org.mockito.Mock; 43 import org.mockito.MockitoAnnotations; 44 45 public class VideoProviderProxyTest extends TelecomTestCase { 46 47 private TelecomSystem.SyncRoot mLock; 48 private VideoProviderProxy mVideoProviderProxy; 49 @Mock private IVideoProvider mVideoProvider; 50 @Mock private IBinder mIBinder; 51 @Mock private Call mCall; 52 @Mock private Analytics.CallInfo mCallInfo; 53 @Mock private CurrentUserProxy mCurrentUserProxy; 54 @Mock private VideoProviderProxy.Listener mListener; 55 56 @Override 57 @Before setUp()58 public void setUp() throws Exception { 59 super.setUp(); 60 MockitoAnnotations.initMocks(this); 61 mLock = new TelecomSystem.SyncRoot() { }; 62 63 when(mVideoProvider.asBinder()).thenReturn(mIBinder); 64 doNothing().when(mIBinder).linkToDeath(any(), anyInt()); 65 when(mCall.getAnalytics()).thenReturn(mCallInfo); 66 doNothing().when(mCallInfo).addVideoEvent(anyInt(), anyInt()); 67 doNothing().when(mCall).maybeEnableSpeakerForVideoUpgrade(anyInt()); 68 mVideoProviderProxy = new VideoProviderProxy(mLock, mVideoProvider, mCall, 69 mCurrentUserProxy); 70 mVideoProviderProxy.addListener(mListener); 71 } 72 73 @Override 74 @After tearDown()75 public void tearDown() throws Exception { 76 super.tearDown(); 77 } 78 79 /** 80 * Tests the case where we receive a request to upgrade to video, except: 81 * 1. Phone account says we support video. 82 * 2. Call says we don't support video. 83 * 84 * Ensures that we send back a response immediately to indicate the call should remain as 85 * audio-only. 86 * @throws Exception 87 */ 88 @SmallTest 89 @Test testReceiveUpgradeRequestWhenLocalDoesntSupportVideo()90 public void testReceiveUpgradeRequestWhenLocalDoesntSupportVideo() throws Exception { 91 // Given a call which supports video at the phone account level, but is not currently 92 // marked as supporting video locally. 93 when(mCall.isLocallyVideoCapable()).thenReturn(false); 94 when(mCall.isVideoCallingSupportedByPhoneAccount()).thenReturn(true); 95 96 // Simulate receiving a request to upgrade to video. 97 mVideoProviderProxy.getVideoCallListenerBinder().receiveSessionModifyRequest( 98 new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL)); 99 100 // Make sure that we send back a response rejecting the request. 101 ArgumentCaptor<VideoProfile> capturedProfile = ArgumentCaptor.forClass(VideoProfile.class); 102 verify(mVideoProvider).sendSessionModifyResponse(capturedProfile.capture()); 103 assertEquals(VideoProfile.STATE_AUDIO_ONLY, capturedProfile.getValue().getVideoState()); 104 } 105 106 /** 107 * Tests the case where we receive a request to upgrade to video and video is supported. 108 * @throws Exception 109 */ 110 @SmallTest 111 @Test testReceiveUpgradeRequestWhenVideoIsSupported()112 public void testReceiveUpgradeRequestWhenVideoIsSupported() throws Exception { 113 // Given a call which supports video at the phone account level, and is currently marked as 114 // supporting video locally. 115 when(mCall.isLocallyVideoCapable()).thenReturn(true); 116 when(mCall.isVideoCallingSupportedByPhoneAccount()).thenReturn(true); 117 118 // Simulate receiving a request to upgrade to video. 119 mVideoProviderProxy.getVideoCallListenerBinder().receiveSessionModifyRequest( 120 new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL)); 121 122 // Ensure it gets proxied back to the caller. 123 124 ArgumentCaptor<VideoProfile> capturedProfile = ArgumentCaptor.forClass(VideoProfile.class); 125 verify(mListener).onSessionModifyRequestReceived(any(), capturedProfile.capture()); 126 assertEquals(VideoProfile.STATE_BIDIRECTIONAL, capturedProfile.getValue().getVideoState()); 127 } 128 129 /** 130 * Tests the case where dialer requests an upgrade to video; we should try to change to speaker. 131 * @throws Exception 132 */ 133 @SmallTest 134 @Test testTryToEnableSpeakerOnVideoUpgrade()135 public void testTryToEnableSpeakerOnVideoUpgrade() throws Exception { 136 mVideoProviderProxy.onSendSessionModifyRequest( 137 new VideoProfile(VideoProfile.STATE_AUDIO_ONLY), 138 new VideoProfile(VideoProfile.STATE_BIDIRECTIONAL)); 139 verify(mCall).maybeEnableSpeakerForVideoUpgrade(eq(VideoProfile.STATE_BIDIRECTIONAL)); 140 } 141 } 142