@@ -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