public boolean ReadyLoad(AccessibilityNodeInfo info) {

    if (info.getChildCount() == 0) {
      if (info.getText() != null && info.getText().toString().contains("已经连接到您的设备")) {
        return true;
      }
    } else {
      for (int i = 0; i < info.getChildCount(); i++) {
        if (info.getChild(i) != null) {
          if (ReadyLoad(info.getChild(i))) {
            return true;
          }
          ;
        }
      }
    }
    return false;
  }
  @LargeTest
  public void testTraverseAllViews() throws Exception {
    final long startTimeMillis = SystemClock.uptimeMillis();
    try {
      // make list of expected nodes
      List<String> classNameAndTextList = new ArrayList<String>();
      classNameAndTextList.add("android.widget.LinearLayout");
      classNameAndTextList.add("android.widget.LinearLayout");
      classNameAndTextList.add("android.widget.LinearLayout");
      classNameAndTextList.add("android.widget.LinearLayout");
      classNameAndTextList.add("android.widget.ButtonButton1");
      classNameAndTextList.add("android.widget.ButtonButton2");
      classNameAndTextList.add("android.widget.ButtonButton3");
      classNameAndTextList.add("android.widget.ButtonButton4");
      classNameAndTextList.add("android.widget.ButtonButton5");
      classNameAndTextList.add("android.widget.ButtonButton6");
      classNameAndTextList.add("android.widget.ButtonButton7");
      classNameAndTextList.add("android.widget.ButtonButton8");
      classNameAndTextList.add("android.widget.ButtonButton9");

      AccessibilityNodeInfo root =
          mUiTestAutomationBridge.findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.root);
      assertNotNull("We must find the existing root.", root);

      Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>();
      fringe.add(root);

      // do a BFS traversal and check nodes
      while (!fringe.isEmpty()) {
        AccessibilityNodeInfo current = fringe.poll();

        CharSequence className = current.getClassName();
        CharSequence text = current.getText();
        String receivedClassNameAndText =
            className.toString() + ((text != null) ? text.toString() : "");
        String expectedClassNameAndText = classNameAndTextList.remove(0);

        assertEquals(
            "Did not get the expected node info",
            expectedClassNameAndText,
            receivedClassNameAndText);

        final int childCount = current.getChildCount();
        for (int i = 0; i < childCount; i++) {
          AccessibilityNodeInfo child = current.getChild(i);
          fringe.add(child);
        }
      }
    } finally {
      if (DEBUG) {
        final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
        Log.i(LOG_TAG, "testTraverseAllViews: " + elapsedTimeMillis + "ms");
      }
    }
  }
 private String accessibilityNodeInfoRecursion(AccessibilityNodeInfo ani) {
   if (ani == null) return null;
   if (ani.getClassName()
           .toString()
           .equals("com.google.android.search.searchplate.SimpleSearchText")
       || ani.getClassName()
               .toString()
               .equals("com.google.android.apps.gsa.searchplate.SimpleSearchText")
           && ani.getText() != null) {
     return ani.getText().toString();
   }
   String result = null;
   for (int i = 0; i < ani.getChildCount(); i++) {
     result = accessibilityNodeInfoRecursion(ani.getChild(i));
     if (result != null) {
       break;
     }
   }
   return result;
 }
 public boolean ReadyID(AccessibilityNodeInfo info) {
   if (info.getChildCount() == 0) {
     if (info != null && info.getClassName().equals("android.widget.EditText")) {
       if (info.hashCode() == mTeamViewData.mIdTextHash) {
         if (!info.getText().toString().trim().equals("-")) {
           mTeamViewData.mIdText = info.getText().toString().replace(" ", "").trim();
           return true;
         }
       }
     }
   } else {
     for (int i = 0; i < info.getChildCount(); i++) {
       if (info.getChild(i) != null) {
         if (ReadyID(info.getChild(i))) {
           return true;
         }
       }
     }
   }
   return false;
 }
 public void recycle(AccessibilityNodeInfo info) {
   if (info.getChildCount() == 0) {
     log("child widget----------------------------" + info.getClassName(), 1);
     log("Text:" + info.getText(), 1);
     log("hash:=" + info.hashCode(), 1);
   } else {
     for (int i = 0; i < info.getChildCount(); i++) {
       if (info.getChild(i) != null) {
         recycle(info.getChild(i));
       }
     }
   }
 }
 public int findIDTextView(AccessibilityNodeInfo info) {
   if (info.getChildCount() == 0) {
     if (info != null && info.getClassName().equals("android.widget.EditText")) {
       if (info.getText().toString().trim().equals("正在激活")) {
         state = STATE_BEGIN;
       }
       if (info.getText().toString().trim().equals("-")) {
         mTeamViewData.mIdTextHash = info.hashCode();
         return info.hashCode();
       }
     }
   } else {
     for (int i = 0; i < info.getChildCount(); i++) {
       if (info.getChild(i) != null) {
         int hash = findIDTextView(info.getChild(i));
         if (hash != 0) {
           return hash;
         }
       }
     }
   }
   return 0;
 }
 private String[] getSenderContentDescriptionFromNode(AccessibilityNodeInfo node) {
   int count = node.getChildCount();
   String[] result = {"unknownSender", "unknownTime"};
   for (int i = 0; i < count; i++) {
     AccessibilityNodeInfo thisNode = node.getChild(i);
     if ("android.widget.ImageView".equals(thisNode.getClassName())) {
       CharSequence contentDescription = thisNode.getContentDescription();
       if (contentDescription != null) result[0] = contentDescription.toString();
     } else if ("android.widget.TextView".equals(thisNode.getClassName())) {
       CharSequence thisNodeText = thisNode.getText();
       if (thisNodeText != null) result[1] = thisNodeText.toString();
     }
   }
   return result;
 }
  @LargeTest
  public void testFindAccessibilityNodeInfoByViewId() throws Exception {
    final long startTimeMillis = SystemClock.uptimeMillis();
    try {
      AccessibilityNodeInfo button =
          mUiTestAutomationBridge.findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
      assertNotNull(button);
      assertEquals(0, button.getChildCount());

      // bounds
      Rect bounds = new Rect();
      button.getBoundsInParent(bounds);
      assertEquals(0, bounds.left);
      assertEquals(0, bounds.top);
      assertEquals(160, bounds.right);
      assertEquals(100, bounds.bottom);

      // char sequence attributes
      assertEquals("com.android.frameworks.coretests", button.getPackageName());
      assertEquals("android.widget.Button", button.getClassName());
      assertEquals("Button5", button.getText());
      assertNull(button.getContentDescription());

      // boolean attributes
      assertTrue(button.isFocusable());
      assertTrue(button.isClickable());
      assertTrue(button.isEnabled());
      assertFalse(button.isFocused());
      assertTrue(button.isClickable());
      assertFalse(button.isPassword());
      assertFalse(button.isSelected());
      assertFalse(button.isCheckable());
      assertFalse(button.isChecked());

      // actions
      assertEquals(ACTION_FOCUS | ACTION_SELECT | ACTION_CLEAR_SELECTION, button.getActions());
    } finally {
      if (DEBUG) {
        final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
        Log.i(LOG_TAG, "testFindAccessibilityNodeInfoByViewId: " + elapsedTimeMillis + "ms");
      }
    }
  }
 public boolean ReadyPCID(AccessibilityNodeInfo info) {
   if (info.getChildCount() == 4) {
     AccessibilityNodeInfo child = info.getChild(0);
     if (child != null
         && child.getChildCount() == 0
         && child.getText() != null
         && child.getText().toString().trim().equals("允许远程支持吗?")) {
       String temp = info.getChild(1).getText().toString();
       int postion = temp.indexOf("to remote support");
       if (temp.contains("Would you like to allow")) {
         mTeamViewData.mPCIDTEXT =
             info.getChild(1).getText().toString().substring(24, postion).replace(" ", "").trim();
         mTeamViewData.rejectButton = info.getChild(2);
         mTeamViewData.allowButton = info.getChild(3);
         return true;
       }
     } else {
       return false;
     }
   }
   return false;
 }
  @LargeTest
  public void testAccessibilityEventGetSource() throws Exception {
    final long startTimeMillis = SystemClock.uptimeMillis();
    try {
      // find a view and make sure it is not focused
      final AccessibilityNodeInfo button =
          mUiTestAutomationBridge.findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
      assertFalse(button.isFocused());

      AccessibilityEvent event =
          mUiTestAutomationBridge.executeCommandAndWaitForAccessibilityEvent(
              new Runnable() {
                @Override
                public void run() {
                  // focus the view
                  assertTrue(button.performAction(ACTION_FOCUS));
                }
              },
              new Predicate<AccessibilityEvent>() {
                @Override
                public boolean apply(AccessibilityEvent event) {
                  return (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED
                      && event.getPackageName().equals(getActivity().getPackageName())
                      && event.getText().get(0).equals(button.getText()));
                }
              },
              TIMEOUT_PROPAGATE_ACCESSIBILITY_EVENT_MILLIS);

      // check the last event
      assertNotNull(event);

      // check that last event source
      AccessibilityNodeInfo source = event.getSource();
      assertNotNull(source);

      // bounds
      Rect buttonBounds = new Rect();
      button.getBoundsInParent(buttonBounds);
      Rect sourceBounds = new Rect();
      source.getBoundsInParent(sourceBounds);

      assertEquals(buttonBounds.left, sourceBounds.left);
      assertEquals(buttonBounds.right, sourceBounds.right);
      assertEquals(buttonBounds.top, sourceBounds.top);
      assertEquals(buttonBounds.bottom, sourceBounds.bottom);

      // char sequence attributes
      assertEquals(button.getPackageName(), source.getPackageName());
      assertEquals(button.getClassName(), source.getClassName());
      assertEquals(button.getText(), source.getText());
      assertSame(button.getContentDescription(), source.getContentDescription());

      // boolean attributes
      assertSame(button.isFocusable(), source.isFocusable());
      assertSame(button.isClickable(), source.isClickable());
      assertSame(button.isEnabled(), source.isEnabled());
      assertNotSame(button.isFocused(), source.isFocused());
      assertSame(button.isLongClickable(), source.isLongClickable());
      assertSame(button.isPassword(), source.isPassword());
      assertSame(button.isSelected(), source.isSelected());
      assertSame(button.isCheckable(), source.isCheckable());
      assertSame(button.isChecked(), source.isChecked());
    } finally {
      if (DEBUG) {
        final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
        Log.i(LOG_TAG, "testAccessibilityEventGetSource: " + elapsedTimeMillis + "ms");
      }
    }
  }