1616
1717package android .webkit ;
1818
19+ import android .accessibilityservice .AccessibilityServiceInfo ;
1920import android .animation .ObjectAnimator ;
2021import android .annotation .Widget ;
2122import android .app .ActivityManager ;
@@ -1743,8 +1744,21 @@ public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
17431744 event .setMaxScrollY (Math .max (convertedContentHeight - adjustedViewHeight , 0 ));
17441745 }
17451746
1746- private boolean isAccessibilityEnabled () {
1747- return AccessibilityManager .getInstance (mContext ).isEnabled ();
1747+ private boolean isAccessibilityInjectionEnabled () {
1748+ final AccessibilityManager manager = AccessibilityManager .getInstance (mContext );
1749+ if (!manager .isEnabled ()) {
1750+ return false ;
1751+ }
1752+
1753+ // Accessibility scripts should be injected only when a speaking service
1754+ // is enabled. This may need to change later to accommodate Braille.
1755+ final List <AccessibilityServiceInfo > services = manager .getEnabledAccessibilityServiceList (
1756+ AccessibilityServiceInfo .FEEDBACK_SPOKEN );
1757+ if (services .isEmpty ()) {
1758+ return false ;
1759+ }
1760+
1761+ return true ;
17481762 }
17491763
17501764 private AccessibilityInjector getAccessibilityInjector () {
@@ -3930,7 +3944,7 @@ private boolean setContentScrollBy(int cx, int cy, boolean animate) {
39303944
39313945 // reset the flag since we set to true in if need after
39323946 // loading is see onPageFinished(Url)
3933- if (isAccessibilityEnabled ()) {
3947+ if (isAccessibilityInjectionEnabled ()) {
39343948 getAccessibilityInjector ().onPageStarted (url );
39353949 }
39363950
@@ -3945,7 +3959,7 @@ private boolean setContentScrollBy(int cx, int cy, boolean animate) {
39453959 /* package */ void onPageFinished (String url ) {
39463960 mZoomManager .onPageFinished (url );
39473961
3948- if (isAccessibilityEnabled ()) {
3962+ if (isAccessibilityInjectionEnabled ()) {
39493963 getAccessibilityInjector ().onPageFinished (url );
39503964 }
39513965 }
@@ -4986,7 +5000,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
49865000 }
49875001
49885002 // See if the accessibility injector needs to handle this event.
4989- if (isAccessibilityEnabled ()
5003+ if (isAccessibilityInjectionEnabled ()
49905004 && getAccessibilityInjector ().handleKeyEventIfNecessary (event )) {
49915005 return true ;
49925006 }
@@ -5093,7 +5107,7 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
50935107 }
50945108
50955109 // See if the accessibility injector needs to handle this event.
5096- if (isAccessibilityEnabled ()
5110+ if (isAccessibilityInjectionEnabled ()
50975111 && getAccessibilityInjector ().handleKeyEventIfNecessary (event )) {
50985112 return true ;
50995113 }
@@ -5344,7 +5358,7 @@ String getSelection() {
53445358 public void onAttachedToWindow () {
53455359 if (mWebView .hasWindowFocus ()) setActive (true );
53465360
5347- if (isAccessibilityEnabled ()) {
5361+ if (isAccessibilityInjectionEnabled ()) {
53485362 getAccessibilityInjector ().addAccessibilityApisIfNecessary ();
53495363 }
53505364
@@ -5357,7 +5371,7 @@ public void onDetachedFromWindow() {
53575371 mZoomManager .dismissZoomPicker ();
53585372 if (mWebView .hasWindowFocus ()) setActive (false );
53595373
5360- if (isAccessibilityEnabled ()) {
5374+ if (isAccessibilityInjectionEnabled ()) {
53615375 getAccessibilityInjector ().removeAccessibilityApisIfNecessary ();
53625376 } else {
53635377 // Ensure the injector is cleared if we're detaching from the window
@@ -7439,7 +7453,7 @@ public void handleMessage(Message msg) {
74397453 break ;
74407454
74417455 case SELECTION_STRING_CHANGED :
7442- if (isAccessibilityEnabled ()) {
7456+ if (isAccessibilityInjectionEnabled ()) {
74437457 getAccessibilityInjector ()
74447458 .handleSelectionChangedIfNecessary ((String ) msg .obj );
74457459 }
0 commit comments