/*
 * Copyright 2014-present Facebook, Inc.
 *
 * 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 com.facebook.litho;

import static android.content.Context.ACCESSIBILITY_SERVICE;

import android.content.Context;
import android.support.v4.view.accessibility.AccessibilityManagerCompat;
import android.view.accessibility.AccessibilityManager;

class AccessibilityUtils {
  private static final boolean ACCESSIBILITY_ENABLED =
      Boolean.getBoolean("is_accessibility_enabled");

  /**
   * @returns True if accessibility touch exploration is currently enabled
   * in the framework.
   */
  public static boolean isAccessibilityEnabled(Context context) {
    final AccessibilityManager manager =
        (AccessibilityManager) context.getSystemService(ACCESSIBILITY_SERVICE);
    return ACCESSIBILITY_ENABLED
        || (manager.isEnabled() && AccessibilityManagerCompat.isTouchExplorationEnabled(manager));
  }
}

@@ -689,16 +689,78 @@
 RVICE;%0A%0A
+import android.accessibilityservice.AccessibilityServiceInfo;%0A
 import a
@@ -809,21 +809,16 @@
 port.v4.
-view.
 accessib
@@ -814,32 +814,39 @@
 v4.accessibility
+service
 .AccessibilityMa
@@ -843,28 +843,86 @@
 sibility
-ManagerCompa
+ServiceInfoCompat;%0Aimport android.view.accessibility.AccessibilityEven
 t;%0Aimpor
@@ -971,16 +971,39 @@
 Manager;
+%0Aimport java.util.List;
 %0A%0Aclass 
@@ -1466,21 +1466,172 @@
 BLED
-%0A        %7C%7C
+ %7C%7C isRunningApplicableAccessibilityService(manager);%0A  %7D%0A%0A  public static boolean isRunningApplicableAccessibilityService(AccessibilityManager manager) %7B%0A    if
  (
+!
 mana
@@ -1649,74 +1649,1072 @@
 ed()
- && AccessibilityManagerCompat.isTouchExplorationEnabled(manager))
+) %7B%0A      return false;%0A    %7D%0A    return manager.isTouchExplorationEnabled()%0A        %7C%7C enabledServiceCanFocusAndRetrieveWindowContent(manager);%0A  %7D%0A%0A  public static boolean enabledServiceCanFocusAndRetrieveWindowContent(%0A      AccessibilityManager manager) %7B%0A    List%3CAccessibilityServiceInfo%3E enabledServices =%0A        manager.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_ALL_MASK);%0A%0A    if (enabledServices == null) %7B%0A      return false;%0A    %7D%0A%0A    for (AccessibilityServiceInfo serviceInfo : enabledServices) %7B%0A      int eventTypes = serviceInfo.eventTypes;%0A      if ((eventTypes & AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED)%0A          != AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) %7B%0A        continue;%0A      %7D%0A      int capabilities = AccessibilityServiceInfoCompat.getCapabilities(serviceInfo);%0A      if ((capabilities & AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT)%0A          == AccessibilityServiceInfo.CAPABILITY_CAN_RETRIEVE_WINDOW_CONTENT) %7B%0A        return true;%0A      %7D%0A    %7D%0A%0A    return false
 ;%0A  

Include accessibility services like SelectToSpeak in isAccessibilityEnabled check