1616
1717package android .webkit ;
1818
19+ import android .accessibilityservice .AccessibilityServiceInfo ;
1920import android .animation .ObjectAnimator ;
2021import android .annotation .Widget ;
2122import android .app .ActivityManager ;
@@ -1738,8 +1739,21 @@ public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
17381739 event .setMaxScrollY (Math .max (convertedContentHeight - adjustedViewHeight , 0 ));
17391740 }
17401741
1741- private boolean isAccessibilityEnabled () {
1742- return AccessibilityManager .getInstance (mContext ).isEnabled ();
1742+ private boolean isAccessibilityInjectionEnabled () {
1743+ final AccessibilityManager manager = AccessibilityManager .getInstance (mContext );
1744+ if (!manager .isEnabled ()) {
1745+ return false ;
1746+ }
1747+
1748+ // Accessibility scripts should be injected only when a speaking service
1749+ // is enabled. This may need to change later to accommodate Braille.
1750+ final List <AccessibilityServiceInfo > services = manager .getEnabledAccessibilityServiceList (
1751+ AccessibilityServiceInfo .FEEDBACK_SPOKEN );
1752+ if (services .isEmpty ()) {
1753+ return false ;
1754+ }
1755+
1756+ return true ;
17431757 }
17441758
17451759 private AccessibilityInjector getAccessibilityInjector () {
@@ -3925,7 +3939,7 @@ private boolean setContentScrollBy(int cx, int cy, boolean animate) {
39253939
39263940 // reset the flag since we set to true in if need after
39273941 // loading is see onPageFinished(Url)
3928- if (isAccessibilityEnabled ()) {
3942+ if (isAccessibilityInjectionEnabled ()) {
39293943 getAccessibilityInjector ().onPageStarted (url );
39303944 }
39313945
@@ -3940,7 +3954,7 @@ private boolean setContentScrollBy(int cx, int cy, boolean animate) {
39403954 /* package */ void onPageFinished (String url ) {
39413955 mZoomManager .onPageFinished (url );
39423956
3943- if (isAccessibilityEnabled ()) {
3957+ if (isAccessibilityInjectionEnabled ()) {
39443958 getAccessibilityInjector ().onPageFinished (url );
39453959 }
39463960 }
@@ -4981,7 +4995,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
49814995 }
49824996
49834997 // See if the accessibility injector needs to handle this event.
4984- if (isAccessibilityEnabled ()
4998+ if (isAccessibilityInjectionEnabled ()
49854999 && getAccessibilityInjector ().handleKeyEventIfNecessary (event )) {
49865000 return true ;
49875001 }
@@ -5088,7 +5102,7 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
50885102 }
50895103
50905104 // See if the accessibility injector needs to handle this event.
5091- if (isAccessibilityEnabled ()
5105+ if (isAccessibilityInjectionEnabled ()
50925106 && getAccessibilityInjector ().handleKeyEventIfNecessary (event )) {
50935107 return true ;
50945108 }
@@ -5339,7 +5353,7 @@ String getSelection() {
53395353 public void onAttachedToWindow () {
53405354 if (mWebView .hasWindowFocus ()) setActive (true );
53415355
5342- if (isAccessibilityEnabled ()) {
5356+ if (isAccessibilityInjectionEnabled ()) {
53435357 getAccessibilityInjector ().addAccessibilityApisIfNecessary ();
53445358 }
53455359
@@ -5352,7 +5366,7 @@ public void onDetachedFromWindow() {
53525366 mZoomManager .dismissZoomPicker ();
53535367 if (mWebView .hasWindowFocus ()) setActive (false );
53545368
5355- if (isAccessibilityEnabled ()) {
5369+ if (isAccessibilityInjectionEnabled ()) {
53565370 getAccessibilityInjector ().removeAccessibilityApisIfNecessary ();
53575371 } else {
53585372 // Ensure the injector is cleared if we're detaching from the window
@@ -7434,7 +7448,7 @@ public void handleMessage(Message msg) {
74347448 break ;
74357449
74367450 case SELECTION_STRING_CHANGED :
7437- if (isAccessibilityEnabled ()) {
7451+ if (isAccessibilityInjectionEnabled ()) {
74387452 getAccessibilityInjector ()
74397453 .handleSelectionChangedIfNecessary ((String ) msg .obj );
74407454 }
0 commit comments