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.content.Context;
     20 import android.media.AudioManager;
     21 import android.os.Bundle;
     22 import android.telecom.CallAudioState;
     23 import android.telecom.TelecomManager;
     24 import android.telephony.TelephonyManager;
     25 
     26 /**
     27  * Verifies the behavior of Telecom during various outgoing call flows.
     28  */
     29 public class OutgoingCallTest extends BaseTelecomTestWithMockServices {
     30 
     31     @Override
     32     protected void setUp() throws Exception {
     33         super.setUp();
     34         NewOutgoingCallBroadcastReceiver.reset();
     35         if (mShouldTestTelecom) {
     36             setupConnectionService(null, FLAG_REGISTER | FLAG_ENABLE);
     37         }
     38     }
     39 
     40     /* TODO: Need to send some commands to the UserManager via adb to do setup
     41     public void testDisallowOutgoingCallsForSecondaryUser() {
     42     } */
     43 
     44     /* TODO: Need to figure out a way to mock emergency calls without adb root
     45     public void testOutgoingCallBroadcast_isSentForAllCalls() {
     46     } */
     47 
     48     /**
     49      * Verifies that providing the EXTRA_START_CALL_WITH_SPEAKERPHONE extra starts the call with
     50      * speakerphone automatically enabled.
     51      *
     52      * @see {@link TelecomManager#EXTRA_START_CALL_WITH_SPEAKERPHONE}
     53      */
     54     public void testStartCallWithSpeakerphoneTrue_SpeakerphoneOnInCall() {
     55         if (!mShouldTestTelecom) {
     56             return;
     57         }
     58 
     59         final Bundle extras = new Bundle();
     60         extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
     61         placeAndVerifyCall(extras);
     62         verifyConnectionForOutgoingCall();
     63         assertAudioRoute(mInCallCallbacks.getService(), CallAudioState.ROUTE_SPEAKER);
     64     }
     65 
     66     public void testStartCallWithSpeakerphoneFalse_SpeakerphoneOffInCall() {
     67         if (!mShouldTestTelecom) {
     68             return;
     69         }
     70 
     71         final Bundle extras = new Bundle();
     72         extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false);
     73         placeAndVerifyCall(extras);
     74         verifyConnectionForOutgoingCall();
     75         if (mInCallCallbacks.getService().getCallAudioState().getSupportedRouteMask() ==
     76                 CallAudioState.ROUTE_SPEAKER) {
     77             return; // Do not verify if the only available route is speaker.
     78         }
     79         assertNotAudioRoute(mInCallCallbacks.getService(), CallAudioState.ROUTE_SPEAKER);
     80     }
     81 
     82     public void testStartCallWithSpeakerphoneNotProvided_SpeakerphoneOffByDefault() {
     83         if (!mShouldTestTelecom) {
     84             return;
     85         }
     86 
     87         AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
     88 
     89         placeAndVerifyCall();
     90         verifyConnectionForOutgoingCall();
     91         if (mInCallCallbacks.getService().getCallAudioState().getSupportedRouteMask() ==
     92                 CallAudioState.ROUTE_SPEAKER) {
     93             return; // Do not verify if the only available route is speaker.
     94         }
     95         assertNotAudioRoute(mInCallCallbacks.getService(), CallAudioState.ROUTE_SPEAKER);
     96     }
     97 
     98     public void testPhoneStateListenerInvokedOnOutgoingCall() throws Exception {
     99         if (!mShouldTestTelecom) {
    100             return;
    101         }
    102 
    103         placeAndVerifyCall();
    104         verifyConnectionForOutgoingCall();
    105         String expectedNumber = connectionService.outgoingConnections.get(0)
    106                 .getAddress().getSchemeSpecificPart();
    107         verifyPhoneStateListenerCallbacksForCall(TelephonyManager.CALL_STATE_OFFHOOK,
    108                 expectedNumber);
    109     }
    110 }
    111