Skip to content

Commit 3003bad

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "Check whether ChromeVox is ready before attempting to call it." into jb-mr1-dev
2 parents 87c6f9a + d8faf74 commit 3003bad

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
@@ -776,20 +791,26 @@ private boolean waitForResultTimedLocked(int resultId) {
776791
while (true) {
777792
try {
778793
if (mResultId == resultId) {
794+
if (DEBUG)
795+
Log.w(TAG, "Received CVOX result");
779796
return true;
780797
}
781798
if (mResultId > resultId) {
799+
if (DEBUG)
800+
Log.w(TAG, "Obsolete CVOX result");
782801
return false;
783802
}
784803
final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
785804
waitTimeMillis = RESULT_TIMEOUT - elapsedTimeMillis;
786805
if (waitTimeMillis <= 0) {
806+
if (DEBUG)
807+
Log.w(TAG, "Timed out while waiting for CVOX result");
787808
return false;
788809
}
789810
mResultLock.wait(waitTimeMillis);
790811
} catch (InterruptedException ie) {
791812
if (DEBUG)
792-
Log.w(TAG, "Timed out while waiting for CVOX result");
813+
Log.w(TAG, "Interrupted while waiting for CVOX result");
793814
/* ignore */
794815
}
795816
}
@@ -805,6 +826,8 @@ private boolean waitForResultTimedLocked(int resultId) {
805826
@JavascriptInterface
806827
@SuppressWarnings("unused")
807828
public void onResult(String id, String result) {
829+
if (DEBUG)
830+
Log.w(TAG, "Saw CVOX result of '" + result + "'");
808831
final long resultId;
809832

810833
try {

0 commit comments

Comments
 (0)