[RoleManagerTest][Wear]Use text selector for some buttons

The resource selectors are not alwalys working well for Wear's Compose
based UI, so we're here using text selectors, which work well.

Bug: 312618575
Test: atest RoleManagerTest
Merged-In: I9355c44d196061398015858c96f51bc78f8e4374
Change-Id: I9355c44d196061398015858c96f51bc78f8e4374
diff --git a/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java b/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java
index c4fa9be..001a761 100644
--- a/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java
+++ b/tests/cts/role/src/android/app/role/cts/RoleManagerTest.java
@@ -129,6 +129,17 @@
     private static final boolean sIsWatch = sPackageManager.hasSystemFeature(
             PackageManager.FEATURE_WATCH);
 
+    // TODO(b/327528959): consider using resource selectors for Wear too, once the underlying
+    // issue is handled.
+    private static final BySelector NEGATIVE_BUTTON_SELECTOR =
+            sIsWatch ? By.text("Cancel") : By.res("android:id/button2");
+    private static final BySelector POSITIVE_BUTTON_SELECTOR =
+            sIsWatch ? By.text("Set as default") : By.res("android:id/button1");
+    private static final BySelector DONT_ASK_AGAIN_TOGGLE_SELECTOR =
+            sIsWatch
+                    ? By.text("Don\u2019t ask again")
+                    : By.res("com.android.permissioncontroller:id/dont_ask_again");
+
     @Rule
     public DisableAnimationRule mDisableAnimationRule = new DisableAnimationRule();
 
@@ -295,7 +306,7 @@
 
         TestUtils.waitUntil("Find and respond to request role UI", () -> {
             requestRole(ROLE_NAME);
-            UiObject2 cancelButton = waitFindObjectOrNull(By.res("android:id/button2"));
+            UiObject2 cancelButton = waitFindObjectOrNull(NEGATIVE_BUTTON_SELECTOR);
             if (cancelButton == null) {
                 // Dialog not found, try again later.
                 return false;
@@ -331,7 +342,7 @@
 
         TestUtils.waitUntil("Find and respond to request role UI", () -> {
             requestRole(ROLE_NAME);
-            UiObject2 cancelButton = waitFindObjectOrNull(By.res("android:id/button2"));
+            UiObject2 cancelButton = waitFindObjectOrNull(NEGATIVE_BUTTON_SELECTOR);
             if (cancelButton == null) {
                 // Dialog not found, try again later.
                 return false;
@@ -401,10 +412,9 @@
 
     @Nullable
     private UiObject2 findDontAskAgainCheck(boolean expected) throws UiObjectNotFoundException {
-        BySelector selector = By.res("com.android.permissioncontroller:id/dont_ask_again");
         return expected
-                ? waitFindObject(selector)
-                : waitFindObjectOrNull(selector, UNEXPECTED_TIMEOUT_MILLIS);
+                ? waitFindObject(DONT_ASK_AGAIN_TOGGLE_SELECTOR)
+                : waitFindObjectOrNull(DONT_ASK_AGAIN_TOGGLE_SELECTOR, UNEXPECTED_TIMEOUT_MILLIS);
     }
 
     @Nullable
@@ -415,7 +425,7 @@
     @NonNull
     private Pair<Integer, Intent> clickButtonAndWaitForResult(boolean positive)
             throws InterruptedException, UiObjectNotFoundException {
-        waitFindObject(By.res(positive ? "android:id/button1" : "android:id/button2")).click();
+        waitFindObject(positive ? POSITIVE_BUTTON_SELECTOR : NEGATIVE_BUTTON_SELECTOR).click();
         return waitForResult();
     }
 
@@ -478,7 +488,7 @@
                 .putExtra(Intent.EXTRA_PACKAGE_NAME, APP_28_PACKAGE_NAME)
                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
         waitFindObject(By.text(APP_28_LABEL)).click();
-        waitFindObject(By.res("android:id/button1")).click();
+        waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
 
         // TODO(b/149037075): Use TelecomManager.getDefaultDialerPackage() once the bug is fixed.
         //TelecomManager telecomManager = sContext.getSystemService(TelecomManager.class);
@@ -499,7 +509,7 @@
                 .putExtra(Intent.EXTRA_PACKAGE_NAME, APP_28_PACKAGE_NAME)
                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
         waitFindObject(By.text(APP_28_LABEL)).click();
-        waitFindObject(By.res("android:id/button1")).click();
+        waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
 
         TestUtils.waitUntil("App is not set as default sms app", () -> Objects.equals(
                 Telephony.Sms.getDefaultSmsPackage(sContext), APP_28_PACKAGE_NAME));
@@ -551,7 +561,7 @@
                 .putExtra(Intent.EXTRA_PACKAGE_NAME, APP_PACKAGE_NAME)
                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
         waitFindObject(By.text(APP_LABEL)).click();
-        waitFindObject(By.res("android:id/button1")).click();
+        waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
 
         // TODO(b/149037075): Use TelecomManager.getDefaultDialerPackage() once the bug is fixed.
         //TelecomManager telecomManager = sContext.getSystemService(TelecomManager.class);
@@ -597,7 +607,7 @@
                 .putExtra(Intent.EXTRA_PACKAGE_NAME, APP_PACKAGE_NAME)
                 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
         waitFindObject(By.text(APP_LABEL)).click();
-        waitFindObject(By.res("android:id/button1")).click();
+        waitFindObject(POSITIVE_BUTTON_SELECTOR).click();
 
         TestUtils.waitUntil("App is not set as default sms app", () -> Objects.equals(
                 Telephony.Sms.getDefaultSmsPackage(sContext), APP_PACKAGE_NAME));