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