[atf] Update ATF @369258897
1.Add a flag to indicate whether text character locations should be
requested
2.Add a test for Swtich to make sure retreiving character locations work
as expected

Bug: 185164418
Test: Exsiting and new tests pass
Change-Id: I12ad86b7f162098f52e0d3d27abc748ca6d7f767
diff --git a/Android.bp b/Android.bp
index df0fa15..f96704c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -53,7 +53,7 @@
     tools: ["layoutlib_create"],
     out: ["temp_layoutlib.jar"],
     srcs: [
-        ":atf-prebuilt-367166430{.jar}",
+        ":atf-prebuilt-369258897{.jar}",
         ":core-icu4j-for-host{.jar}",
         ":core-libart-for-host{.jar}",
         ":framework-all{.jar}",
diff --git a/bridge/tests/res/testApp/MyApplication/src/main/res/layout/a11y_test_switch_text_contrast.xml b/bridge/tests/res/testApp/MyApplication/src/main/res/layout/a11y_test_switch_text_contrast.xml
new file mode 100644
index 0000000..db408f1
--- /dev/null
+++ b/bridge/tests/res/testApp/MyApplication/src/main/res/layout/a11y_test_switch_text_contrast.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2021 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.
+  -->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="#FFFFFFFF">
+    <!-- Low contrast, with slightly transparent text -->
+    <Switch
+        android:text="Switch"
+        android:textColor="#3000FFFF"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:minHeight="48dp"
+        android:id="@+id/switch1"
+        tools:layout_editor_absoluteY="191dp"
+        tools:layout_editor_absoluteX="104dp" />
+</LinearLayout>
\ No newline at end of file
diff --git a/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java b/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java
index 6fe9bb5..1359f29 100644
--- a/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java
+++ b/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java
@@ -187,6 +187,28 @@
     }
 
     @Test
+    public void testSwitchTextContrastCheck() throws Exception {
+        render("a11y_test_switch_text_contrast.xml", session -> {
+            ValidatorResult result = getRenderResult(session);
+            List<Issue> textContrast = filter(result.getIssues(), "TextContrastCheck");
+
+            // ATF doesn't count alpha values in a Switch unless image is passed and the character
+            // locations are available.
+            ExpectedLevels expectedLevels = new ExpectedLevels();
+            expectedLevels.expectedErrors = 0;
+            expectedLevels.expectedWarnings = 1; // True only if character locations are available.
+            expectedLevels.expectedVerboses = 2;
+            expectedLevels.expectedFixes = 1;
+            expectedLevels.check(textContrast);
+
+            // Make sure no other errors in the system.
+            textContrast = filter(textContrast, EnumSet.of(Level.ERROR));
+            List<Issue> filtered = filter(result.getIssues(), EnumSet.of(Level.ERROR));
+            checkEquals(filtered, textContrast);
+        });
+    }
+
+    @Test
     public void testTextContrastCheckNoImage() throws Exception {
         render("a11y_test_text_contrast.xml", session -> {
             ValidatorResult result = getRenderResult(session);
@@ -339,6 +361,7 @@
         LayoutValidator.updatePolicy(new Policy(
                 EnumSet.of(Type.ACCESSIBILITY, Type.RENDER),
                 EnumSet.of(Level.ERROR, Level.WARNING, Level.INFO, Level.VERBOSE)));
+        LayoutValidator.setObtainCharacterLocations(true);
 
         LayoutPullParser parser = createParserFromPath(fileName);
         layoutLibCallback.initResources();
diff --git a/validator/resources/strings.properties b/validator/resources/strings.properties
index 8aa1c6e..7b324b9 100644
--- a/validator/resources/strings.properties
+++ b/validator/resources/strings.properties
@@ -82,6 +82,7 @@
 result_message_addendum_opacity_description = Its actual opacity is %1$.2f%%.
 result_message_brief_text_contrast_not_sufficient = Consider increasing this item\'s text foreground to background contrast ratio.
 result_message_textview_contrast_not_sufficient = The item\'s text contrast ratio is %1$.2f. This ratio is based on a text color of <tt>#%2$06X</tt> and background color of <tt>#%3$06X</tt>. Consider increasing this item\'s text contrast ratio to %4$.2f or greater.
+result_message_customized_textview_contrast_not_sufficient = The item\'s text contrast ratio is %1$.2f. This ratio is based on a text color of <tt>#%2$06X</tt> and background color of <tt>#%3$06X</tt>. Consider using colors that result in a contrast ratio greater than the modified ratio of %4$.2f.
 result_message_textview_heuristic_contrast_not_sufficient = The item\'s text contrast ratio is %1$.2f. This ratio is based on an estimated foreground color of <tt>#%2$06X</tt> and an estimated background color of <tt>#%3$06X</tt>. Consider using colors that result in a contrast ratio greater than %4$.2f for small text, or %5$.2f for large text.
 result_message_textview_heuristic_contrast_not_sufficient_when_text_size_available = The item\'s text contrast ratio is %1$.2f. This ratio is based on an estimated foreground color of <tt>#%2$06X</tt> and an estimated background color of <tt>#%3$06X</tt>. Consider increasing this item\'s text contrast ratio to %4$.2f or greater.
 result_message_textview_heuristic_contrast_not_sufficient_confirmed = The item\'s text contrast ratio is %1$.2f. This ratio is based on the provided foreground color of <tt>#%2$06X</tt> and provided background color of <tt>#%3$06X</tt>. Consider using colors that result in a contrast ratio greater than %4$.2f for small text, or %5$.2f for large text.
diff --git a/validator/src/com/android/tools/idea/validator/LayoutValidator.java b/validator/src/com/android/tools/idea/validator/LayoutValidator.java
index 79228fc..572eeb2 100644
--- a/validator/src/com/android/tools/idea/validator/LayoutValidator.java
+++ b/validator/src/com/android/tools/idea/validator/LayoutValidator.java
@@ -42,6 +42,8 @@
 
     private static boolean sSaveCroppedImages = false;
 
+    private static boolean sObtainCharacterLocations = false;
+
     /**
      * @return true if validator is paused. False otherwise.
      */
@@ -71,6 +73,15 @@
     }
 
     /**
+     * Indicates whether text character locations should be requested.
+     *
+     * @param obtainCharacterLocations true if text character locations should be requested.
+     */
+    public static void setObtainCharacterLocations(boolean obtainCharacterLocations) {
+        sObtainCharacterLocations = obtainCharacterLocations;
+    }
+
+    /**
      * Validate the layout using the default policy.
      * Precondition: View must be attached to the window.
      *
@@ -79,7 +90,8 @@
     @NotNull
     public static ValidatorResult validate(@NotNull View view, @Nullable BufferedImage image) {
         if (!sPaused && view.isAttachedToWindow()) {
-            ValidatorHierarchy hierarchy = ValidatorUtil.buildHierarchy(sPolicy, view, image);
+            ValidatorHierarchy hierarchy =
+                    ValidatorUtil.buildHierarchy(sPolicy, view, image, sObtainCharacterLocations);
             return ValidatorUtil.generateResults(sPolicy, hierarchy);
         }
         // TODO: Add non-a11y layout validation later.
@@ -96,7 +108,7 @@
     public static ValidatorHierarchy buildHierarchy(
             @NotNull View view, @Nullable BufferedImage image) {
         if (!sPaused && view.isAttachedToWindow()) {
-            return ValidatorUtil.buildHierarchy(sPolicy, view, image);
+            return ValidatorUtil.buildHierarchy(sPolicy, view, image, sObtainCharacterLocations);
         }
         return new ValidatorHierarchy();
     }
diff --git a/validator/src/com/android/tools/idea/validator/ValidatorUtil.java b/validator/src/com/android/tools/idea/validator/ValidatorUtil.java
index b576d3e..8f29d85 100644
--- a/validator/src/com/android/tools/idea/validator/ValidatorUtil.java
+++ b/validator/src/com/android/tools/idea/validator/ValidatorUtil.java
@@ -28,8 +28,6 @@
 import com.android.tools.layoutlib.annotations.NotNull;
 import com.android.tools.layoutlib.annotations.Nullable;
 
-import org.jsoup.Jsoup;
-
 import android.view.View;
 
 import java.awt.image.BufferedImage;
@@ -46,13 +44,11 @@
 
 import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheck;
 import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckPreset;
-import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult;
 import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult.AccessibilityCheckResultType;
 import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheck;
 import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheckResult;
 import com.google.android.apps.common.testing.accessibility.framework.Parameters;
 import com.google.android.apps.common.testing.accessibility.framework.checks.EditableContentDescCheck;
-import com.google.android.apps.common.testing.accessibility.framework.checks.RedundantDescriptionCheck;
 import com.google.android.apps.common.testing.accessibility.framework.checks.TextContrastCheck;
 import com.google.android.apps.common.testing.accessibility.framework.checks.TouchTargetSizeCheck;
 import com.google.android.apps.common.testing.accessibility.framework.strings.StringManager;
@@ -104,12 +100,14 @@
      * @param policy policy to apply for the hierarchy
      * @param view root view to build hierarchy from
      * @param image screenshot image that matches the view
+     * @param obtainCharacterLocations whether text character locations should be requested
      * @return The hierarchical data required for running the ATF checks.
      */
     public static ValidatorHierarchy buildHierarchy(
             @NotNull ValidatorData.Policy policy,
             @NotNull View view,
-            @Nullable BufferedImage image) {
+            @Nullable BufferedImage image,
+            boolean obtainCharacterLocations) {
         ValidatorHierarchy hierarchy = new ValidatorHierarchy();
         if (!policy.mTypes.contains(Type.ACCESSIBILITY)) {
             return hierarchy;
@@ -122,6 +120,7 @@
         hierarchy.mView = AccessibilityHierarchyAndroid
                 .newBuilder(view)
                 .setViewOriginMap(builder.mSrcMap)
+                .setObtainCharacterLocations(obtainCharacterLocations)
                 .setCustomViewBuilder(new CustomViewBuilderAndroid() {
                     @Override
                     public Class<?> getClassByName(