1 /* 2 * Copyright (C) 2016 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.telecom.Call; 20 import android.telecom.Connection; 21 import android.telecom.ConnectionRequest; 22 import android.telecom.PhoneAccount; 23 import android.telecom.PhoneAccountHandle; 24 25 import static android.telecom.cts.TestUtils.WAIT_FOR_STATE_CHANGE_TIMEOUT_MS; 26 27 /** 28 * Tests which verify functionality related to {@link android.telecom.Connection}s and 29 * {@link android.telecom.Call}s with the 30 * {@link android.telecom.Connection#PROPERTY_IS_EXTERNAL_CALL} and 31 * {@link android.telecom.Call.Details#PROPERTY_IS_EXTERNAL_CALL} properties, respectively, set. 32 */ 33 public class ExternalCallTest extends BaseTelecomTestWithMockServices { 34 public static final int CONNECTION_PROPERTIES = Connection.PROPERTY_IS_EXTERNAL_CALL; 35 public static final int CONNECTION_CAPABILITIES = Connection.CAPABILITY_CAN_PULL_CALL; 36 37 private Call mCall; 38 private MockConnection mConnection; 39 private MockInCallService mInCallService; 40 41 @Override 42 protected void setUp() throws Exception { 43 super.setUp(); 44 if (mShouldTestTelecom) { 45 PhoneAccount account = setupConnectionService( 46 new MockConnectionService() { 47 @Override 48 public Connection onCreateOutgoingConnection( 49 PhoneAccountHandle connectionManagerPhoneAccount, 50 ConnectionRequest request) { 51 Connection connection = super.onCreateOutgoingConnection( 52 connectionManagerPhoneAccount, 53 request); 54 mConnection = (MockConnection) connection; 55 // Modify the connection object created with local values. 56 connection.setConnectionCapabilities(CONNECTION_CAPABILITIES); 57 connection.setConnectionProperties(CONNECTION_PROPERTIES); 58 59 lock.release(); 60 return connection; 61 } 62 }, FLAG_REGISTER | FLAG_ENABLE); 63 64 placeAndVerifyCall(); 65 verifyConnectionForOutgoingCall(); 66 67 mInCallService = mInCallCallbacks.getService(); 68 mCall = mInCallService.getLastCall(); 69 70 assertCallState(mCall, Call.STATE_DIALING); 71 assertCallProperties(mCall, Call.Details.PROPERTY_IS_EXTERNAL_CALL); 72 assertCallCapabilities(mCall, Call.Details.CAPABILITY_CAN_PULL_CALL); 73 } 74 } 75 76 /** 77 * Tests that a request to pull an external call via {@link Call#pullExternalCall()} is 78 * communicated to the {@link Connection} via {@link Connection#onPullExternalCall()}. 79 */ 80 public void testPullExternalCall() { 81 if (!mShouldTestTelecom) { 82 return; 83 } 84 85 final TestUtils.InvokeCounter counter = mConnection.getInvokeCounter( 86 MockConnection.ON_PULL_EXTERNAL_CALL); 87 mCall.pullExternalCall(); 88 counter.waitForCount(1, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 89 } 90 91 public void testNonPullableExternalCall() { 92 if (!mShouldTestTelecom) { 93 return; 94 } 95 96 // Remove the pullable attribute of the connection. 97 mConnection.setConnectionCapabilities(0); 98 assertCallCapabilities(mCall, 0); 99 100 final TestUtils.InvokeCounter counter = mConnection.getInvokeCounter( 101 MockConnection.ON_PULL_EXTERNAL_CALL); 102 // Try to pull -- we expect Telecom to absorb the request since the call is not pullable. 103 mCall.pullExternalCall(); 104 counter.waitForCount(0, WAIT_FOR_STATE_CHANGE_TIMEOUT_MS); 105 } 106 } 107