Merge "Fix pattern lock for accessibility" into mnc-dev
diff --git a/core/java/com/android/internal/widget/LockPatternView.java b/core/java/com/android/internal/widget/LockPatternView.java
index a709bb8e..9211eaa 100644
--- a/core/java/com/android/internal/widget/LockPatternView.java
+++ b/core/java/com/android/internal/widget/LockPatternView.java
@@ -94,7 +94,7 @@
      */
     private static final float DRAG_THRESHHOLD = 0.0f;
     public static final int VIRTUAL_BASE_VIEW_ID = 1;
-    public static final boolean DEBUG_A11Y = true;
+    public static final boolean DEBUG_A11Y = false;
     private static final String TAG = "LockPatternView";
 
     private OnPatternListener mOnPatternListener;
@@ -568,9 +568,11 @@
 
     @Override
     protected boolean dispatchHoverEvent(MotionEvent event) {
-        // Give TouchHelper first right of refusal
-        boolean handled = mExploreByTouchHelper.dispatchHoverEvent(event);
-        return super.dispatchHoverEvent(event) || handled;
+        // Dispatch to onHoverEvent first so mPatternInProgress is up to date when the
+        // helper gets the event.
+        boolean handled = super.dispatchHoverEvent(event);
+        handled |= mExploreByTouchHelper.dispatchHoverEvent(event);
+        return handled;
     }
 
     /**
@@ -877,7 +879,7 @@
                 return true;
             case MotionEvent.ACTION_CANCEL:
                 if (mPatternInProgress) {
-                    mPatternInProgress = false;
+                    setPatternInProgress(false);
                     resetPattern();
                     notifyPatternCleared();
                 }
@@ -892,6 +894,11 @@
         return false;
     }
 
+    private void setPatternInProgress(boolean progress) {
+        mPatternInProgress = progress;
+        mExploreByTouchHelper.invalidateRoot();
+    }
+
     private void handleActionMove(MotionEvent event) {
         // Handle all recent motion events so we don't skip any cells even when the device
         // is busy...
@@ -905,7 +912,7 @@
             Cell hitCell = detectAndAddHit(x, y);
             final int patternSize = mPattern.size();
             if (hitCell != null && patternSize == 1) {
-                mPatternInProgress = true;
+                setPatternInProgress(true);
                 notifyPatternStarted();
             }
             // note current x and y for rubber banding of in progress patterns
@@ -963,7 +970,7 @@
     private void handleActionUp() {
         // report pattern detected
         if (!mPattern.isEmpty()) {
-            mPatternInProgress = false;
+            setPatternInProgress(false);
             cancelLineAnimations();
             notifyPatternDetected();
             invalidate();
@@ -994,11 +1001,11 @@
         final float y = event.getY();
         final Cell hitCell = detectAndAddHit(x, y);
         if (hitCell != null) {
-            mPatternInProgress = true;
+            setPatternInProgress(true);
             mPatternDisplayMode = DisplayMode.Correct;
             notifyPatternStarted();
         } else if (mPatternInProgress) {
-            mPatternInProgress = false;
+            setPatternInProgress(false);
             notifyPatternCleared();
         }
         if (hitCell != null) {
@@ -1315,6 +1322,9 @@
         @Override
         protected void getVisibleVirtualViews(IntArray virtualViewIds) {
             if (DEBUG_A11Y) Log.v(TAG, "getVisibleVirtualViews(len=" + virtualViewIds.size() + ")");
+            if (!mPatternInProgress) {
+                return;
+            }
             for (int i = VIRTUAL_BASE_VIEW_ID; i < VIRTUAL_BASE_VIEW_ID + 9; i++) {
                 if (!mItems.containsKey(i)) {
                     VirtualViewContainer item = new VirtualViewContainer(getTextForVirtualView(i));
@@ -1337,6 +1347,16 @@
         }
 
         @Override
+        public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
+            super.onPopulateAccessibilityEvent(host, event);
+            if (!mPatternInProgress) {
+                CharSequence contentDescription = getContext().getText(
+                        com.android.internal.R.string.lockscreen_access_pattern_area);
+                event.setContentDescription(contentDescription);
+            }
+        }
+
+        @Override
         protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfo node) {
             if (DEBUG_A11Y) Log.v(TAG, "onPopulateNodeForVirtualView(view=" + virtualViewId + ")");
 
@@ -1345,10 +1365,14 @@
             node.setText(getTextForVirtualView(virtualViewId));
             node.setContentDescription(getTextForVirtualView(virtualViewId));
 
-            if (isClickable(virtualViewId)) {
-                // Mark this node of interest by making it clickable.
-                node.addAction(AccessibilityAction.ACTION_CLICK);
-                node.setClickable(isClickable(virtualViewId));
+            if (mPatternInProgress) {
+                node.setFocusable(true);
+
+                if (isClickable(virtualViewId)) {
+                    // Mark this node of interest by making it clickable.
+                    node.addAction(AccessibilityAction.ACTION_CLICK);
+                    node.setClickable(isClickable(virtualViewId));
+                }
             }
 
             // Compute bounds for this object
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index a45a0fa..d9fa287 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1919,6 +1919,8 @@
             Cell <xliff:g id="cell_index" example="3">%1$s</xliff:g> added</string>
     <!-- Accessibility description sent when user completes drawing a pattern. [CHAR LIMIT=NONE] -->
     <string name="lockscreen_access_pattern_detected">Pattern completed</string>
+    <!-- Accessibility description of the unlock pattern area. [CHAR_LIMIT=none] -->
+    <string name="lockscreen_access_pattern_area" msgid="">Pattern area.</string>
 
     <!-- Accessibility description sent when user changes the current lock screen widget. [CHAR_LIMIT=none] -->
     <string name="keyguard_accessibility_widget_changed">%1$s. Widget %2$d of %3$d.</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 8070986..ee61944 100755
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2310,6 +2310,8 @@
   <java-symbol type="plurals" name="selected_count" />
   <java-symbol type="drawable" name="ic_dialog_alert_material" />
 
+  <java-symbol type="string" name="lockscreen_access_pattern_area" />
+
   <java-symbol type="bool" name="allow_stacked_button_bar" />
   <java-symbol type="bool" name="config_eap_sim_based_auth_supported" />
 
diff --git a/packages/Keyguard/res/layout/keyguard_pattern_view.xml b/packages/Keyguard/res/layout/keyguard_pattern_view.xml
index 09c01de..ccb9af9 100644
--- a/packages/Keyguard/res/layout/keyguard_pattern_view.xml
+++ b/packages/Keyguard/res/layout/keyguard_pattern_view.xml
@@ -63,9 +63,6 @@
                 android:layout_marginStart="8dip"
                 android:layout_gravity="center_horizontal"
                 android:gravity="center"
-                android:contentDescription="@string/keyguard_accessibility_pattern_area"
-                android:focusable="true"
-                android:focusableInTouchMode="true"
                 android:clipChildren="false"
                 android:clipToPadding="false" />
 
diff --git a/packages/Keyguard/res/values/strings.xml b/packages/Keyguard/res/values/strings.xml
index 748129c..cba122f 100644
--- a/packages/Keyguard/res/values/strings.xml
+++ b/packages/Keyguard/res/values/strings.xml
@@ -101,7 +101,7 @@
     <!-- Accessibility description of the password lock. [CHAR_LIMIT=none] -->
     <string name="keyguard_accessibility_password_unlock">Password unlock.</string>
     <!-- Accessibility description of the unlock pattern area. [CHAR_LIMIT=none] -->
-    <string name="keyguard_accessibility_pattern_area">Pattern area.</string>
+    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">Pattern area.</string>
     <!-- Accessibility description of the unlock slide area. [CHAR_LIMIT=none] -->
     <string name="keyguard_accessibility_slide_area">Slide area.</string>
     <!-- Accessibility description of the PIN password view. [CHAR_LIMIT=none] -->