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.os.Bundle; 20 import android.telecom.PhoneAccount; 21 import android.view.View; 22 import android.widget.Button; 23 import android.widget.ImageView; 24 25 import com.android.cts.verifier.PassFailButtons; 26 import com.android.cts.verifier.R; 27 28 /** 29 * Tests that a new {@link android.telecom.ConnectionService} be added and its associated 30 * {@link android.telecom.PhoneAccount} enabled using the calling accounts settings screen. 31 */ 32 public class EnablePhoneAccountTestActivity extends PassFailButtons.Activity { 33 34 private Button mRegisterPhoneAccount; 35 private Button mConfirm; 36 private ImageView mStep1Status; 37 private ImageView mStep2Status; 38 39 @Override onCreate(Bundle savedInstanceState)40 protected void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 View view = getLayoutInflater().inflate(R.layout.telecom_enable_phone_account, null); 43 setContentView(view); 44 setInfoResources(R.string.telecom_enable_phone_account_test, 45 R.string.telecom_enable_phone_account_info, -1); 46 setPassFailButtonClickListeners(); 47 getPassButton().setEnabled(false); 48 49 mRegisterPhoneAccount = (Button) view.findViewById( 50 R.id.telecom_enable_phone_account_register_button); 51 mRegisterPhoneAccount.setOnClickListener(v -> { 52 PhoneAccountUtils.registerTestPhoneAccount(this); 53 PhoneAccount account = PhoneAccountUtils.getPhoneAccount(this); 54 if (account != null) { 55 mConfirm.setEnabled(true); 56 mRegisterPhoneAccount.setEnabled(false); 57 mStep1Status.setImageResource(R.drawable.fs_good); 58 } else { 59 mStep1Status.setImageResource(R.drawable.fs_error); 60 } 61 }); 62 63 mConfirm = (Button) view.findViewById(R.id.telecom_enable_phone_account_confirm_button); 64 mConfirm.setOnClickListener(v -> { 65 PhoneAccount account = PhoneAccountUtils.getPhoneAccount(this); 66 if (account != null && account.isEnabled()) { 67 getPassButton().setEnabled(true); 68 mStep2Status.setImageResource(R.drawable.fs_good); 69 mConfirm.setEnabled(false); 70 PhoneAccountUtils.unRegisterTestPhoneAccount(this); 71 } else { 72 mStep2Status.setImageResource(R.drawable.fs_error); 73 } 74 }); 75 mConfirm.setEnabled(false); 76 77 mStep1Status = (ImageView) view.findViewById(R.id.step_1_status); 78 mStep2Status = (ImageView) view.findViewById(R.id.step_2_status); 79 } 80 81 } 82