1 /* 2 * Copyright (C) 2017 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.cts.verifier.telecom; 18 19 import android.content.Intent; 20 import android.net.Uri; 21 import android.os.Bundle; 22 import android.telecom.PhoneAccount; 23 import android.telecom.PhoneAccountHandle; 24 import android.telecom.TelecomManager; 25 import android.view.View; 26 import android.widget.Button; 27 import android.widget.ImageView; 28 29 import com.android.cts.verifier.PassFailButtons; 30 import com.android.cts.verifier.R; 31 32 import java.util.List; 33 34 /** 35 * Tests that an outgoing call made from the default dialer on the system is able to connect to 36 * the CtsConnectionService. 37 */ 38 public class OutgoingCallTestActivity extends PassFailButtons.Activity { 39 40 private Button mRegisterAndEnablePhoneAccount; 41 private Button mConfirmPhoneAccountEnabled; 42 private Button mDialOutgoingCall; 43 private Button mConfirmOutgoingCall; 44 45 private ImageView mStep1Status; 46 private ImageView mStep2Status; 47 private ImageView mStep3Status; 48 49 private Uri TEST_DIAL_NUMBER = Uri.fromParts("tel", "5551212", null); 50 51 @Override 52 protected void onCreate(Bundle savedInstanceState) { 53 super.onCreate(savedInstanceState); 54 View view = getLayoutInflater().inflate(R.layout.telecom_outgoing_call, null); 55 setContentView(view); 56 setInfoResources(R.string.telecom_outgoing_call_test, 57 R.string.telecom_outgoing_call_test_info, -1); 58 setPassFailButtonClickListeners(); 59 getPassButton().setEnabled(false); 60 61 mRegisterAndEnablePhoneAccount = view.findViewById( 62 R.id.telecom_outgoing_call_register_enable_phone_account_button); 63 if (mRegisterAndEnablePhoneAccount == null) { 64 finish(); 65 } 66 mRegisterAndEnablePhoneAccount.setOnClickListener(v -> { 67 PhoneAccountUtils.registerTestPhoneAccount(this); 68 PhoneAccount account = PhoneAccountUtils.getPhoneAccount(this); 69 if (account != null) { 70 // Open the phone accounts screen to have the user set CtsConnectionService as 71 // the default. 72 Intent intent = new Intent(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS); 73 startActivity(intent); 74 75 mConfirmPhoneAccountEnabled.setEnabled(true); 76 } else { 77 mStep1Status.setImageResource(R.drawable.fs_error); 78 } 79 }); 80 81 mConfirmPhoneAccountEnabled = view.findViewById(R.id 82 .telecom_outgoing_call_confirm_register_button); 83 if (mConfirmPhoneAccountEnabled == null) { 84 finish(); 85 } 86 mConfirmPhoneAccountEnabled.setOnClickListener(v -> { 87 PhoneAccount account = PhoneAccountUtils.getPhoneAccount(this); 88 PhoneAccountHandle defaultOutgoingAccount = PhoneAccountUtils 89 .getDefaultOutgoingPhoneAccount(this) ; 90 if (account != null && account.isEnabled() && 91 PhoneAccountUtils.TEST_PHONE_ACCOUNT_HANDLE.equals(defaultOutgoingAccount)) { 92 getPassButton().setEnabled(true); 93 mStep1Status.setImageResource(R.drawable.fs_good); 94 mConfirmPhoneAccountEnabled.setEnabled(false); 95 } else { 96 mStep1Status.setImageResource(R.drawable.fs_error); 97 } 98 }); 99 mConfirmPhoneAccountEnabled.setEnabled(false); 100 101 mDialOutgoingCall = view.findViewById(R.id.telecom_outgoing_call_dial_button); 102 if (mDialOutgoingCall == null) { 103 finish(); 104 } 105 mDialOutgoingCall.setOnClickListener(v -> { 106 Intent intent = new Intent(Intent.ACTION_DIAL); 107 intent.setData(TEST_DIAL_NUMBER); 108 startActivity(intent); 109 mStep2Status.setImageResource(R.drawable.fs_good); 110 }); 111 112 mConfirmOutgoingCall = view.findViewById(R.id.telecom_outgoing_call_confirm_button); 113 if (mConfirmOutgoingCall == null) { 114 finish(); 115 } 116 mConfirmOutgoingCall.setOnClickListener(v -> { 117 if (confirmOutgoingCall()) { 118 mStep3Status.setImageResource(R.drawable.fs_good); 119 } else { 120 mStep3Status.setImageResource(R.drawable.fs_error); 121 } 122 PhoneAccountUtils.unRegisterTestPhoneAccount(this); 123 }); 124 125 mStep1Status = view.findViewById(R.id.step_1_status); 126 mStep2Status = view.findViewById(R.id.step_2_status); 127 mStep3Status = view.findViewById(R.id.step_3_status); 128 mStep1Status.setImageResource(R.drawable.fs_indeterminate); 129 mStep2Status.setImageResource(R.drawable.fs_indeterminate); 130 mStep3Status.setImageResource(R.drawable.fs_indeterminate); 131 } 132 133 private boolean confirmOutgoingCall() { 134 if (CtsConnectionService.getConnectionService() == null) { 135 return false; 136 } 137 List<CtsConnection> ongoingConnections = 138 CtsConnectionService.getConnectionService().getConnections(); 139 if (ongoingConnections == null || ongoingConnections.size() != 1) { 140 return false; 141 } 142 CtsConnection outgoingConnection = ongoingConnections.get(0); 143 if (outgoingConnection.isIncomingCall()) { 144 return false; 145 } 146 outgoingConnection.onDisconnect(); 147 return true; 148 } 149 } 150