SecuritySettings Spectatio Migration
Test: Locally
Bug: 257956800
Change-Id: I899bde8f1028e12189177cf916b882e48675aea3
diff --git a/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/utils/SpectatioUiUtil.java b/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/utils/SpectatioUiUtil.java
index 2b5a13e..db28371 100644
--- a/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/utils/SpectatioUiUtil.java
+++ b/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/utils/SpectatioUiUtil.java
@@ -219,6 +219,14 @@
return uiObject;
}
+ /** Find and return the UI Objects that matches the given selector */
+ public List<UiObject2> findUiObjects(BySelector selector) {
+ validateSelector(selector, /* action= */ "Find UI Object");
+ List<UiObject2> uiObjects =
+ mDevice.wait(Until.findObjects(selector), LONG_UI_RESPONSE_WAIT_MS);
+ return uiObjects;
+ }
+
/**
* Find the UI Object that matches the given text string.
*
diff --git a/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json b/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json
index c38b102..c071375 100644
--- a/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json
+++ b/libraries/automotive-helpers/auto-default-config/resources/assets/defaultSpectatioConfig.json
@@ -2,7 +2,9 @@
"PACKAGES": {
"DIAL_PACKAGE": "com.android.car.dialer",
"PHONE_ACTIVITY": "com.android.car.dialer/.ui.TelecomActivity",
- "HOME_PACKAGE": "com.android.car.carlauncher"
+ "HOME_PACKAGE": "com.android.car.carlauncher",
+ "SECURITY_SETTINGS_PACKAGE": "com.android.car.settings"
+
},
"ACTIONS": {
"CONTACT_LIST_SCROLL_ACTION" : "USE_BUTTON",
@@ -12,7 +14,9 @@
"CONTACT_DETAILS_SCROLL_ACTION" : "USE_BUTTON",
"CONTACT_DETAILS_SCROLL_DIRECTION" : "VERTICAL",
"APP_LIST_SCROLL_ACTION" : "USE_BUTTON",
- "APP_LIST_SCROLL_DIRECTION" : "VERTICAL"
+ "APP_LIST_SCROLL_DIRECTION" : "VERTICAL",
+ "SECURITY_SCROLL_ACTION": "USE_BUTTON",
+ "SECURITY_SCROLL_DIRECTION": "VERTICAL"
},
"COMMANDS": {
"OPEN_DIAL_PAD_COMMAND": "am start -a android.intent.action.DIAL",
@@ -290,6 +294,72 @@
"TYPE": "RESOURCE_ID",
"VALUE": "car_ui_internal_recycler_view",
"PACKAGE": "com.android.car.carlauncher"
+ },
+ "SECURITY_SETTINGS_TITLE": {
+ "TYPE": "RESOURCE_ID",
+ "VALUE": "car_ui_toolbar_title",
+ "PACKAGE": "com.android.car.settings"
+ },
+ "SECURITY_SETTINGS_LOCK_TYPE_PASSWORD": {
+ "TYPE": "TEXT",
+ "VALUE": "Password"
+ },
+ "SECURITY_SETTINGS_PROFILE_LOCK": {
+ "TYPE": "TEXT",
+ "VALUE": "Profile lock"
+ },
+ "SECURITY_SETTINGS_ENTER_PASSWORD": {
+ "TYPE": "CLASS",
+ "VALUE": "android.widget.EditText"
+ },
+ "SECURITY_SETTINGS_LOCK_TYPE_PIN": {
+ "TYPE": "TEXT",
+ "VALUE": "PIN"
+ },
+ "SECURITY_SETTINGS_CONTINUE_BUTTON": {
+ "TYPE": "TEXT",
+ "VALUE": "Continue"
+ },
+ "SECURITY_SETTINGS_CONFIRM_BUTTON": {
+ "TYPE":"TEXT",
+ "VALUE": "Confirm"
+ },
+ "SECURITY_SETTINGS": {
+ "TYPE":"TEXT",
+ "VALUE": "SECURITY"
+ },
+ "SECURITY_SETTINGS_ENTER_PIN_BUTTON": {
+ "TYPE":"RESOURCE_ID",
+ "VALUE": "key_enter",
+ "PACKAGE": "com.android.car.settings"
+ },
+ "SECURITY_SETTINGS_PIN_PAD": {
+ "TYPE": "RESOURCE_ID",
+ "VALUE": "pin_pad",
+ "PACKAGE": "com.android.car.settings"
+ },
+ "SECURITY_SETTINGS_LOCK_TYPE_NONE": {
+ "TYPE": "TEXT",
+ "VALUE": "None"
+ },
+ "SECURITY_SETTINGS_REMOVE_BUTTON": {
+ "TYPE": "TEXT",
+ "VALUE": "Remove"
+ },
+ "SECURITY_SETTINGS_SCROLLABLE_ELEMENT": {
+ "TYPE": "RESOURCE_ID",
+ "VALUE": "car_ui_recycler_view",
+ "PACKAGE": "com.android.car.settings"
+ },
+ "SECURITY_SCROLL_FORWARD_BUTTON": {
+ "TYPE": "RESOURCE_ID",
+ "VALUE": "car_ui_scrollbar_page_down",
+ "PACKAGE": "com.android.car.settings"
+ },
+ "SECURITY_SCROLL_BACKWARD_BUTTON": {
+ "TYPE": "RESOURCE_ID",
+ "VALUE": "car_ui_scrollbar_page_up",
+ "PACKAGE": "com.android.car.settings"
}
}
}
\ No newline at end of file
diff --git a/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java b/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java
index e435f26..a256481 100644
--- a/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java
+++ b/libraries/automotive-helpers/auto-default-config/src/android/platform/helpers/AutomotiveConfigConstants.java
@@ -92,4 +92,30 @@
public static final String APP_LIST_SCROLL_ELEMENT = "APP_LIST_SCROLL_ELEMENT";
public static final String APP_LIST_SCROLL_ACTION = "APP_LIST_SCROLL_ACTION";
public static final String APP_LIST_SCROLL_DIRECTION = "APP_LIST_SCROLL_DIRECTION";
+ public static final String SECURITY_SETTINGS_SCROLLABLE_ELEMENT =
+ "SECURITY_SETTINGS_SCROLLABLE_ELEMENT";
+ public static final String SECURITY_SETTINGS_REMOVE_BUTTON = "SECURITY_SETTINGS_REMOVE_BUTTON";
+ public static final String SECURITY_SETTINGS_LOCK_TYPE_NONE =
+ "SECURITY_SETTINGS_LOCK_TYPE_NONE";
+ public static final String SECURITY_SETTINGS_PIN_PAD = "SECURITY_SETTINGS_PIN_PAD";
+ public static final String SECURITY_SETTINGS_ENTER_PIN_BUTTON =
+ "SECURITY_SETTINGS_ENTER_PIN_BUTTON";
+ public static final String SECURITY_SETTINGS = "SECURITY_SETTINGS";
+ public static final String SECURITY_SETTINGS_LOCK_TYPE_PASSWORD =
+ "SECURITY_SETTINGS_LOCK_TYPE_PASSWORD";
+ public static final String SECURITY_SETTINGS_PACKAGE = "SECURITY_SETTINGS_PACKAGE";
+ public static final String SECURITY_SETTINGS_TITLE = "SECURITY_SETTINGS_TITLE";
+ public static final String SECURITY_SETTINGS_PROFILE_LOCK = "SECURITY_SETTINGS_PROFILE_LOCK";
+ public static final String SECURITY_SETTINGS_ENTER_PASSWORD =
+ "SECURITY_SETTINGS_ENTER_PASSWORD";
+ public static final String SECURITY_SETTINGS_LOCK_TYPE_PIN = "SECURITY_SETTINGS_LOCK_TYPE_PIN";
+ public static final String SECURITY_SETTINGS_CONTINUE_BUTTON =
+ "SECURITY_SETTINGS_CONTINUE_BUTTON";
+ public static final String SECURITY_SETTINGS_CONFIRM_BUTTON =
+ "SECURITY_SETTINGS_CONFIRM_BUTTON";
+ public static final String SECURITY_SETTINGS_CHOOSE_LOCK_TYPE = "Choose a lock type";
+ public static final String SECURITY_SCROLL_FORWARD_BUTTON = "SECURITY_SCROLL_FORWARD_BUTTON";
+ public static final String SECURITY_SCROLL_BACKWARD_BUTTON = "SECURITY_SCROLL_BACKWARD_BUTTON";
+ public static final String SECURITY_SCROLL_ACTION = "SECURITY_SCROLL_ACTION";
+ public static final String SECURITY_SCROLL_DIRECTION = "SECURITY_SCROLL_DIRECTION";
}
diff --git a/libraries/automotive-helpers/settings-app-helper/Android.bp b/libraries/automotive-helpers/settings-app-helper/Android.bp
index b34d0af..ebc5970 100644
--- a/libraries/automotive-helpers/settings-app-helper/Android.bp
+++ b/libraries/automotive-helpers/settings-app-helper/Android.bp
@@ -20,14 +20,15 @@
java_library {
name: "automotive-settings-app-helper",
- libs: [
- "ub-uiautomator",
- "app-helpers-auto-interfaces",
- "automotive-utility-helper",
- "android.car-system-stubs",
- ],
+
static_libs: [
- "androidx.test.runner",
+ "ub-uiautomator",
+ "spectatio-lib",
+ "app-helpers-auto-interfaces",
+ "android-support-annotations",
+ "automotive-config-lib",
+ "android.car-system-stubs",
+ "automotive-utility-helper",
"automotive-standard-app-helper",
],
srcs: ["src/**/*.java"],
diff --git a/libraries/automotive-helpers/settings-app-helper/src/android/platform/helpers/SettingsSecurityHelperImpl.java b/libraries/automotive-helpers/settings-app-helper/src/android/platform/helpers/SettingsSecurityHelperImpl.java
index b52ef52..6c4b2ac 100644
--- a/libraries/automotive-helpers/settings-app-helper/src/android/platform/helpers/SettingsSecurityHelperImpl.java
+++ b/libraries/automotive-helpers/settings-app-helper/src/android/platform/helpers/SettingsSecurityHelperImpl.java
@@ -1,15 +1,43 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package android.platform.helpers;
import android.app.Instrumentation;
+import android.platform.helpers.exceptions.UnknownUiException;
+import android.platform.spectatio.exceptions.MissingUiElementException;
import android.support.test.uiautomator.By;
+import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.UiObject2;
-import android.os.SystemClock;
import java.util.List;
-public class SettingsSecurityHelperImpl extends AbstractAutoStandardAppHelper
+/** Helper class for functional tests of Security settings */
+public class SettingsSecurityHelperImpl extends AbstractStandardAppHelper
implements IAutoSecuritySettingsHelper {
- private static final int UI_RESPONSE_WAIT_MS = 1000;
+
+ private enum ScrollActions {
+ USE_BUTTON,
+ USE_GESTURE;
+ }
+
+ private enum ScrollDirection {
+ VERTICAL,
+ HORIZONTAL;
+ }
public SettingsSecurityHelperImpl(Instrumentation instr) {
super(instr);
@@ -18,21 +46,30 @@
/** {@inheritDoc} */
@Override
public String getPackage() {
- return getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE);
+ return getPackageFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_PACKAGE);
+ }
+
+ @Override
+ public void dismissInitialDialogs() {
+ // Nothing to dismiss
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String getLauncherName() {
+ throw new UnsupportedOperationException("Operation not supported.");
}
/** {@inheritDoc} */
@Override
public void setLockByPassword(String password) {
openChooseLockTypeMenu();
- UiObject2 password_menu =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.LOCK_TYPE_PASSWORD));
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), password_menu);
+ BySelector password_menuSelector =
+ getUiElementFromConfig(
+ AutomotiveConfigConstants.SECURITY_SETTINGS_LOCK_TYPE_PASSWORD);
+ UiObject2 password_menu = getSpectatioUiUtil().findUiObject(password_menuSelector);
+ getSpectatioUiUtil().clickAndWait(password_menu);
+ getSpectatioUiUtil().wait5Seconds();
typePasswordOnTextEditor(password);
pressEnter();
typePasswordOnTextEditor(password);
@@ -40,47 +77,77 @@
}
private void openChooseLockTypeMenu() {
- SystemClock.sleep(UI_RESPONSE_WAIT_MS);
- List<UiObject2> titles =
- findUiObjects(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.TITLE));
- if (titles == null || titles.isEmpty()) {
- throw new RuntimeException("Unable to find Setting title");
- }
+ getSpectatioUiUtil().wait5Seconds();
+ BySelector titlesSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_TITLE);
+ List<UiObject2> titles = getSpectatioUiUtil().findUiObjects(titlesSelector);
+ validateUiObject(titles, AutomotiveConfigConstants.SECURITY_SETTINGS_TITLE);
UiObject2 title = titles.get(titles.size() - 1);
if (title != null
&& title.getText()
.equalsIgnoreCase(
- getResourceValue(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.CHOOSE_LOCK_TYPE))) {
+ AutomotiveConfigConstants.SECURITY_SETTINGS_CHOOSE_LOCK_TYPE)) {
// CHOOSE_LOCK_TYPE is already open
return;
}
- UiObject2 profileLockMenu =
- scrollAndFindUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.PROFILE_LOCK));
- if (profileLockMenu == null) {
- throw new RuntimeException("Unable to find Choose a lock type menu.");
+ try {
+ BySelector profileLockMenuSelector =
+ getUiElementFromConfig(
+ AutomotiveConfigConstants.SECURITY_SETTINGS_PROFILE_LOCK);
+ ScrollActions scrollAction =
+ ScrollActions.valueOf(
+ getActionFromConfig(AutomotiveConfigConstants.SECURITY_SCROLL_ACTION));
+ UiObject2 profileLockMenu = null;
+ switch (scrollAction) {
+ case USE_BUTTON:
+ BySelector forwardButtonSelector =
+ getUiElementFromConfig(
+ AutomotiveConfigConstants.SECURITY_SCROLL_FORWARD_BUTTON);
+ BySelector backwardButtonSelector =
+ getUiElementFromConfig(
+ AutomotiveConfigConstants.SECURITY_SCROLL_BACKWARD_BUTTON);
+ profileLockMenu =
+ getSpectatioUiUtil()
+ .scrollAndFindUiObject(
+ forwardButtonSelector,
+ backwardButtonSelector,
+ profileLockMenuSelector);
+ break;
+ case USE_GESTURE:
+ ScrollDirection scrollDirection =
+ ScrollDirection.valueOf(
+ getActionFromConfig(
+ AutomotiveConfigConstants.SECURITY_SCROLL_DIRECTION));
+ BySelector scrollableElementSelector =
+ getUiElementFromConfig(
+ AutomotiveConfigConstants.SECURITY_SETTINGS_SCROLLABLE_ELEMENT);
+ profileLockMenu =
+ getSpectatioUiUtil()
+ .scrollAndFindUiObject(
+ scrollableElementSelector,
+ profileLockMenuSelector,
+ (scrollDirection == ScrollDirection.VERTICAL));
+ break;
+ default:
+ throw new IllegalStateException(
+ String.format(
+ "Cannot scroll through. Unknown Scroll Action %s.",
+ scrollAction));
+ }
+ validateUiObject(
+ profileLockMenu, String.format("Profile Lock is %s", profileLockMenuSelector));
+ getSpectatioUiUtil().clickAndWait(profileLockMenu);
+ getSpectatioUiUtil().wait5Seconds();
+ } catch (MissingUiElementException ex) {
+ throw new IllegalStateException(String.format("Unable to find Profile Lock Menu."));
}
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), profileLockMenu);
}
private void typePasswordOnTextEditor(String password) {
- UiObject2 textEditor =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.ENTER_PASSWORD));
+ BySelector textEditorSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_ENTER_PASSWORD);
+ UiObject2 textEditor = getSpectatioUiUtil().findUiObject(textEditorSelector);
+ validateUiObject(textEditor, AutomotiveConfigConstants.SECURITY_SETTINGS_ENTER_PASSWORD);
textEditor.setText(password);
}
@@ -88,32 +155,28 @@
@Override
public void setLockByPin(String pin) {
openChooseLockTypeMenu();
- UiObject2 pin_menu =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.LOCK_TYPE_PIN));
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), pin_menu);
+ BySelector pin_menuSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_LOCK_TYPE_PIN);
+ UiObject2 pin_menu = getSpectatioUiUtil().findUiObject(pin_menuSelector);
+ validateUiObject(pin_menu, AutomotiveConfigConstants.SECURITY_SETTINGS_LOCK_TYPE_PIN);
+ getSpectatioUiUtil().clickAndWait(pin_menu);
+ getSpectatioUiUtil().wait5Seconds();
selectPinOnPinPad(pin);
- UiObject2 continue_button =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.CONTINUE_BUTTON));
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), continue_button);
+ BySelector continue_buttonSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_CONTINUE_BUTTON);
+ UiObject2 continue_button = getSpectatioUiUtil().findUiObject(continue_buttonSelector);
+ validateUiObject(
+ continue_button, AutomotiveConfigConstants.SECURITY_SETTINGS_CONTINUE_BUTTON);
+ getSpectatioUiUtil().clickAndWait(continue_button);
+ getSpectatioUiUtil().wait5Seconds();
selectPinOnPinPad(pin);
- UiObject2 confirm_button =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.CONFIRM_BUTTON));
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), confirm_button);
+ BySelector confirm_buttonSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_CONFIRM_BUTTON);
+ UiObject2 confirm_button = getSpectatioUiUtil().findUiObject(confirm_buttonSelector);
+ validateUiObject(
+ confirm_button, AutomotiveConfigConstants.SECURITY_SETTINGS_CONFIRM_BUTTON);
+ getSpectatioUiUtil().clickAndWait(confirm_button);
+ getSpectatioUiUtil().wait5Seconds();
}
private void selectPinOnPinPad(String pin) {
@@ -121,32 +184,25 @@
for (int i = 0; i < length; i++) {
char c = pin.charAt(i);
UiObject2 number =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- Character.toString(c)));
+ getSpectatioUiUtil()
+ .findUiObject(getUiElementFromConfig(Character.toString(c)));
if (number == null) {
- number = findUiObject(By.text(Character.toString(c)));
+ number = getSpectatioUiUtil().findUiObject(By.text(Character.toString(c)));
}
- if (number == null) {
- throw new RuntimeException(
- "Unable to find number on pin pad: " + Character.toString(c));
- }
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), number);
+ validateUiObject(
+ number,
+ String.format("Unable to find number on pin pad: " + Character.toString(c)));
+ getSpectatioUiUtil().clickAndWait(number);
}
}
/** {@inheritDoc} */
@Override
public void unlockByPassword(String password) {
- UiObject2 textEditor =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.ENTER_PASSWORD));
+ BySelector textEditorSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_ENTER_PASSWORD);
+ UiObject2 textEditor = getSpectatioUiUtil().findUiObject(textEditorSelector);
+ validateUiObject(textEditor, AutomotiveConfigConstants.SECURITY_SETTINGS_ENTER_PASSWORD);
textEditor.setText(password);
pressEnter();
}
@@ -154,21 +210,18 @@
/** {@inheritDoc} */
@Override
public void unlockByPin(String pin) {
+
selectPinOnPinPad(pin);
- UiObject2 enter_button =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.ENTER_PIN_BUTTON));
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), enter_button);
- UiObject2 pinPad =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.PIN_PAD));
+ BySelector enter_buttonSelector =
+ getUiElementFromConfig(
+ AutomotiveConfigConstants.SECURITY_SETTINGS_ENTER_PIN_BUTTON);
+ UiObject2 enter_button = getSpectatioUiUtil().findUiObject(enter_buttonSelector);
+ validateUiObject(
+ enter_button, AutomotiveConfigConstants.SECURITY_SETTINGS_ENTER_PIN_BUTTON);
+ getSpectatioUiUtil().clickAndWait(enter_button);
+ BySelector pinPadSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_PIN_PAD);
+ UiObject2 pinPad = getSpectatioUiUtil().findUiObject(pinPadSelector);
if (pinPad != null) {
throw new RuntimeException("PIN input is not corrected");
}
@@ -178,41 +231,49 @@
@Override
public void removeLock() {
openChooseLockTypeMenu();
- UiObject2 none_menu =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.LOCK_TYPE_NONE));
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), none_menu);
- SystemClock.sleep(UI_RESPONSE_WAIT_MS);
- UiObject2 remove_button =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.REMOVE_BUTTON));
- clickAndWaitForWindowUpdate(
- getApplicationConfig(AutoConfigConstants.SETTINGS_PACKAGE), remove_button);
+ BySelector none_menuSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_LOCK_TYPE_NONE);
+ UiObject2 none_menu = getSpectatioUiUtil().findUiObject(none_menuSelector);
+ validateUiObject(none_menu, AutomotiveConfigConstants.SECURITY_SETTINGS_LOCK_TYPE_NONE);
+ getSpectatioUiUtil().clickAndWait(none_menu);
+ getSpectatioUiUtil().wait5Seconds();
+ BySelector remove_buttonSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_REMOVE_BUTTON);
+ UiObject2 remove_button = getSpectatioUiUtil().findUiObject(remove_buttonSelector);
+ validateUiObject(remove_button, AutomotiveConfigConstants.SECURITY_SETTINGS_REMOVE_BUTTON);
+ getSpectatioUiUtil().clickAndWait(remove_button);
}
/** {@inheritDoc} */
@Override
public boolean isDeviceLocked() {
openChooseLockTypeMenu();
- UiObject2 textEditor =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.ENTER_PASSWORD));
- UiObject2 pinPad =
- findUiObject(
- getResourceFromConfig(
- AutoConfigConstants.SETTINGS,
- AutoConfigConstants.SECURITY_SETTINGS,
- AutoConfigConstants.PIN_PAD));
+ BySelector textEditorSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_ENTER_PASSWORD);
+ UiObject2 textEditor = getSpectatioUiUtil().findUiObject(textEditorSelector);
+
+ BySelector pinPadSelector =
+ getUiElementFromConfig(AutomotiveConfigConstants.SECURITY_SETTINGS_PIN_PAD);
+ UiObject2 pinPad = getSpectatioUiUtil().findUiObject(pinPadSelector);
+
return textEditor != null || pinPad != null;
}
+
+ private void validateUiObject(UiObject2 uiObject, String action) {
+ if (uiObject == null) {
+ throw new UnknownUiException(
+ String.format("Unable to find UI Element for %s.", action));
+ }
+ }
+
+ private void validateUiObject(List<UiObject2> uiObjects, String action) {
+ if (uiObjects == null) {
+ throw new UnknownUiException(
+ String.format("Unable to find UI Element for %s.", action));
+ }
+ }
+
+ private void pressEnter() {
+ mDevice.pressEnter();
+ }
}
diff --git a/tests/automotive/functional/settings/src/android/platform/tests/SecuritySettingTest.java b/tests/automotive/functional/settings/src/android/platform/tests/SecuritySettingTest.java
index 3f09e7a..e549054 100644
--- a/tests/automotive/functional/settings/src/android/platform/tests/SecuritySettingTest.java
+++ b/tests/automotive/functional/settings/src/android/platform/tests/SecuritySettingTest.java
@@ -19,19 +19,19 @@
import static junit.framework.Assert.assertTrue;
import android.platform.helpers.AutoConfigConstants;
-import android.platform.helpers.AutoUtility;
+import android.platform.helpers.HelperAccessor;
import android.platform.helpers.IAutoSecuritySettingsHelper;
import android.platform.helpers.IAutoSettingHelper;
-import android.platform.helpers.HelperAccessor;
+
import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
+
public class SecuritySettingTest {
private static final String PASSWORD = "test4fun";
private static final String PIN = "1013";
@@ -44,11 +44,6 @@
mSettingHelper = new HelperAccessor<>(IAutoSettingHelper.class);
}
- @BeforeClass
- public static void exitSuw() {
- AutoUtility.exitSuw();
- }
-
@Before
public void openSecuritySettingFacet() {
mSettingHelper.get().openSetting(AutoConfigConstants.SECURITY_SETTINGS);