1 /* 2 * Copyright (C) 2023 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.platform.helpers; 18 19 import android.app.Instrumentation; 20 21 import androidx.test.uiautomator.By; 22 import androidx.test.uiautomator.BySelector; 23 import androidx.test.uiautomator.UiObject2; 24 25 /** Bluetooth Setting Helper class for Android Auto platform functional tests */ 26 public class SettingsBluetoothHelperImpl extends AbstractStandardAppHelper 27 implements IAutoBluetoothSettingsHelper { 28 29 private static final String LOG_TAG = SettingHelperImpl.class.getSimpleName(); 30 SettingsBluetoothHelperImpl(Instrumentation instr)31 public SettingsBluetoothHelperImpl(Instrumentation instr) { 32 super(instr); 33 } 34 35 /** {@inheritDoc} */ 36 @Override pressBluetoothToggleOnDevice(String deviceName)37 public void pressBluetoothToggleOnDevice(String deviceName) { 38 39 /** 40 * Note: this method currently does not select strictly within the passed-in device name. 41 */ 42 BySelector toggleSelector = 43 getUiElementFromConfig(AutomotiveConfigConstants.TOGGLE_DEVICE_BLUETOOTH); 44 45 UiObject2 toggleButton = getSpectatioUiUtil().findUiObject(toggleSelector); 46 47 getSpectatioUiUtil() 48 .validateUiObject(toggleButton, AutomotiveConfigConstants.TOGGLE_DEVICE_BLUETOOTH); 49 getSpectatioUiUtil().clickAndWait(toggleButton); 50 } 51 52 /** {@inheritDoc} */ 53 @Override pressDevice(String deviceName)54 public void pressDevice(String deviceName) { 55 56 BySelector nameField = By.text(deviceName); 57 BySelector clickable = By.hasDescendant(By.hasDescendant(nameField)); 58 UiObject2 clickableDevice = getSpectatioUiUtil().findUiObject(clickable); 59 getSpectatioUiUtil() 60 .validateUiObject(clickableDevice, "Viewgroup ancestor of " + deviceName); 61 getSpectatioUiUtil().clickAndWait(clickableDevice); 62 } 63 64 /** {@inheritDoc} */ 65 @Override getDeviceSummary()66 public String getDeviceSummary() { 67 68 BySelector statusSelector = 69 getUiElementFromConfig(AutomotiveConfigConstants.DEVICE_HEADER_SUMMARY); 70 UiObject2 statusField = getSpectatioUiUtil().findUiObject(statusSelector); 71 getSpectatioUiUtil() 72 .validateUiObject(statusField, AutomotiveConfigConstants.DEVICE_HEADER_SUMMARY); 73 return statusField.getText(); 74 } 75 76 /** {@inheritDoc} */ 77 @Override isConnected()78 public boolean isConnected() { 79 // Recall that a connected device will show 'Disconnected' 80 return !getDeviceSummary().contains("Disconnected"); 81 } 82 83 /** {@inheritDoc} */ 84 @Override pressForget()85 public void pressForget() { 86 BySelector forgetSelector = 87 getUiElementFromConfig(AutomotiveConfigConstants.DEVICE_FORGET_BUTTON); 88 UiObject2 forgetButton = getSpectatioUiUtil().findUiObject(forgetSelector); 89 getSpectatioUiUtil() 90 .validateUiObject(forgetButton, AutomotiveConfigConstants.DEVICE_FORGET_BUTTON); 91 getSpectatioUiUtil().clickAndWait(forgetButton); 92 } 93 94 /** {@inheritDoc} */ 95 @Override pressConnectionToggle()96 public void pressConnectionToggle() { 97 BySelector connectionSelector = 98 getUiElementFromConfig(AutomotiveConfigConstants.DEVICE_CONNECTION_BUTTON); 99 UiObject2 connectionButton = getSpectatioUiUtil().findUiObject(connectionSelector); 100 getSpectatioUiUtil() 101 .validateUiObject( 102 connectionButton, AutomotiveConfigConstants.DEVICE_CONNECTION_BUTTON); 103 getSpectatioUiUtil().clickAndWait(connectionButton); 104 } 105 106 /** {@inheritDoc} */ 107 @Override goBackToBluetoothSettings()108 public void goBackToBluetoothSettings() { 109 BySelector connectionSelector = 110 getUiElementFromConfig(AutomotiveConfigConstants.DEVICE_CONNECTION_BACK_BUTTON); 111 UiObject2 connectionButton = getSpectatioUiUtil().findUiObject(connectionSelector); 112 getSpectatioUiUtil() 113 .validateUiObject( 114 connectionButton, AutomotiveConfigConstants.DEVICE_CONNECTION_BACK_BUTTON); 115 getSpectatioUiUtil().clickAndWait(connectionButton); 116 } 117 118 /** {@inheritDoc} */ 119 @Override getPackage()120 public String getPackage() { 121 return getPackageFromConfig(AutomotiveConfigConstants.SETTINGS_PACKAGE); 122 } 123 124 /** {@inheritDoc} */ 125 @Override getLauncherName()126 public String getLauncherName() { 127 throw new UnsupportedOperationException("Operation not supported."); 128 } 129 130 /** {@inheritDoc} */ 131 @Override dismissInitialDialogs()132 public void dismissInitialDialogs() { 133 // Nothing to dismiss 134 } 135 } 136