Skip to content

Commit d8faf74

Browse files
committed
Check whether ChromeVox is ready before attempting to call it.
Calls to performAction will immediately return false if ChromeVox is not loaded. Also adds additional debugging output. Bug: 7328657 Change-Id: I5bd7c69ccc9500cebaa4a8c1bf023794f4eebe2e
1 parent 4574df0 commit d8faf74

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

core/java/android/webkit/AccessibilityInjector.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,26 @@ class AccessibilityInjector {
9696

9797
// Template for JavaScript that performs AndroidVox actions.
9898
private static final String ACCESSIBILITY_ANDROIDVOX_TEMPLATE =
99-
"cvox.AndroidVox.performAction('%1s')";
99+
"(function() {" +
100+
" if ((typeof(cvox) != 'undefined')"+
101+
" && (typeof(cvox.ChromeVox) != 'undefined')" +
102+
" && (typeof(cvox.AndroidVox) != 'undefined')" +
103+
" && cvox.ChromeVox.isActive) {" +
104+
" return cvox.AndroidVox.performAction('%1s');" +
105+
" } else {" +
106+
" return false;" +
107+
" }" +
108+
"})()";
100109

101110
// JS code used to shut down an active AndroidVox instance.
102111
private static final String TOGGLE_CVOX_TEMPLATE =
103-
"javascript:(function() { cvox.ChromeVox.host.activateOrDeactivateChromeVox(%b); })();";
112+
"javascript:(function() {" +
113+
" if ((typeof(cvox) != 'undefined')"+
114+
" && (typeof(cvox.ChromeVox) != 'undefined')" +
115+
" && (typeof(cvox.ChromeVox.host) != 'undefined')) {" +
116+
" cvox.ChromeVox.host.activateOrDeactivateChromeVox(%b);" +
117+
" }" +
118+
"})();";
104119

105120
/**
106121
* Creates an instance of the AccessibilityInjector based on
@@ -787,20 +802,26 @@ private boolean waitForResultTimedLocked(int resultId) {
787802
while (true) {
788803
try {
789804
if (mResultId == resultId) {
805+
if (DEBUG)
806+
Log.w(TAG, "Received CVOX result");
790807
return true;
791808
}
792809
if (mResultId > resultId) {
810+
if (DEBUG)
811+
Log.w(TAG, "Obsolete CVOX result");
793812
return false;
794813
}
795814
final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
796815
waitTimeMillis = RESULT_TIMEOUT - elapsedTimeMillis;
797816
if (waitTimeMillis <= 0) {
817+
if (DEBUG)
818+
Log.w(TAG, "Timed out while waiting for CVOX result");
798819
return false;
799820
}
800821
mResultLock.wait(waitTimeMillis);
801822
} catch (InterruptedException ie) {
802823
if (DEBUG)
803-
Log.w(TAG, "Timed out while waiting for CVOX result");
824+
Log.w(TAG, "Interrupted while waiting for CVOX result");
804825
/* ignore */
805826
}
806827
}
@@ -816,6 +837,8 @@ private boolean waitForResultTimedLocked(int resultId) {
816837
@JavascriptInterface
817838
@SuppressWarnings("unused")
818839
public void onResult(String id, String result) {
840+
if (DEBUG)
841+
Log.w(TAG, "Saw CVOX result of '" + result + "'");
819842
final long resultId;
820843

821844
try {

0 commit comments

Comments
 (0)