コード例 #1
1
  /** 点击聊天里的红包后,显示的界面 */
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void handleLuckyMoneyReceive() {
    AccessibilityNodeInfo nodeInfo = getService().getRootInActiveWindow();
    if (nodeInfo == null) {
      Log.w(TAG, "rootWindow为空");
      return;
    }

    AccessibilityNodeInfo targetNode = null;

    List<AccessibilityNodeInfo> list = null;
    int event = getConfig().getWechatAfterOpenHongBaoEvent();
    if (event == Config.WX_AFTER_OPEN_HONGBAO) { // 拆红包
      if (getWechatVersion() < USE_ID_MIN_VERSION) {
        list = nodeInfo.findAccessibilityNodeInfosByText("拆红包");
      } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
          if (getWechatVersion() < WECHAT_6_3_11_VERSION) {
            list = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/b2c");
          } else {
            list = nodeInfo.findAccessibilityNodeInfosByViewId("com.tencent.mm:id/b43");
          }
        }
        if (list == null || list.isEmpty()) {
          List<AccessibilityNodeInfo> l = nodeInfo.findAccessibilityNodeInfosByText("给你发了一个红包");
          if (l != null && !l.isEmpty()) {
            AccessibilityNodeInfo p = l.get(0).getParent();
            if (p != null) {
              for (int i = 0; i < p.getChildCount(); i++) {
                AccessibilityNodeInfo node = p.getChild(i);
                if ("android.widget.Button".equals(node.getClassName())) {
                  targetNode = node;
                  break;
                }
              }
            }
          }
        }
      }
    } else if (event == Config.WX_AFTER_OPEN_SEE) { // 看一看
      if (getWechatVersion() < USE_ID_MIN_VERSION) { // 低版本才有 看大家手气的功能
        list = nodeInfo.findAccessibilityNodeInfosByText("看看大家的手气");
      }
    }

    if (list != null && !list.isEmpty()) {
      targetNode = list.get(0);
    }

    if (targetNode != null) {
      final AccessibilityNodeInfo n = targetNode;
      long sDelayTime = getConfig().getWechatOpenDelayTime();
      if (sDelayTime != 0) {
        getHandler()
            .postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
                  }
                },
                sDelayTime);
      } else {
        n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
      }
    }
  }
コード例 #2
0
 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));
       }
     }
   }
 }
コード例 #3
0
 @LargeTest
 public void testObjectContract() throws Exception {
   final long startTimeMillis = SystemClock.uptimeMillis();
   try {
     // find a view and make sure it is not focused
     AccessibilityNodeInfo button =
         mUiTestAutomationBridge.findAccessibilityNodeInfoByViewIdInActiveWindow(R.id.button5);
     assertNotNull(button);
     AccessibilityNodeInfo parent = button.getParent();
     final int childCount = parent.getChildCount();
     for (int i = 0; i < childCount; i++) {
       AccessibilityNodeInfo child = parent.getChild(i);
       assertNotNull(child);
       if (child.equals(button)) {
         assertEquals(
             "Equal objects must have same hasCode.", button.hashCode(), child.hashCode());
         return;
       }
     }
     fail("Parent's children do not have the info whose parent is the parent.");
   } finally {
     if (DEBUG) {
       final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
       Log.i(LOG_TAG, "testObjectContract: " + elapsedTimeMillis + "ms");
     }
   }
 }
コード例 #4
0
  public boolean generateHongbaoMsg(AccessibilityNodeInfo node) {
    try {
      AccessibilityNodeInfo hongbaoNode = node.getParent();
      String hongbaoContent = hongbaoNode.getChild(0).getText().toString();

      if (hongbaoContent == null) return false;

      AccessibilityNodeInfo messageNode = hongbaoNode.getParent();

      String[] hongbaoInfo = getSenderContentDescriptionFromNode(messageNode);

      String cur = this.getSignature(hongbaoInfo[0], hongbaoContent, hongbaoInfo[1]);
      String last = this.toString();
      Log.e("Test", "curSignature=" + cur);
      Log.e("Test", "lastSignature=" + last);

      if (cur.equals(last)) return false;

      this.sender = hongbaoInfo[0];
      this.time = hongbaoInfo[1];
      this.content = hongbaoContent;
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #5
0
  private AccessibilityNodeInfo findNodeRegularRecursive(
      UiSelector subSelector, AccessibilityNodeInfo fromNode, int index) {

    if (subSelector.isMatchFor(fromNode, index)) {
      if (DEBUG) {
        Log.d(LOG_TAG, formatLog(String.format("%s", subSelector.dumpToString(false))));
      }
      if (subSelector.isLeaf()) {
        return fromNode;
      }
      if (subSelector.hasChildSelector()) {
        mLogIndent++; // next selector
        subSelector = subSelector.getChildSelector();
        if (subSelector == null) {
          Log.e(LOG_TAG, "Error: A child selector without content");
          return null; // there is an implementation fault
        }
      } else if (subSelector.hasParentSelector()) {
        mLogIndent++; // next selector
        subSelector = subSelector.getParentSelector();
        if (subSelector == null) {
          Log.e(LOG_TAG, "Error: A parent selector without content");
          return null; // there is an implementation fault
        }
        // the selector requested we start at this level from
        // the parent node from the one we just matched
        fromNode = fromNode.getParent();
        if (fromNode == null) return null;
      }
    }

    int childCount = fromNode.getChildCount();
    boolean hasNullChild = false;
    for (int i = 0; i < childCount; i++) {
      AccessibilityNodeInfo childNode = fromNode.getChild(i);
      if (childNode == null) {
        Log.w(
            LOG_TAG,
            String.format("AccessibilityNodeInfo returned a null child (%d of %d)", i, childCount));
        if (!hasNullChild) {
          Log.w(LOG_TAG, String.format("parent = %s", fromNode.toString()));
        }
        hasNullChild = true;
        continue;
      }
      if (!childNode.isVisibleToUser()) {
        if (VERBOSE)
          Log.v(LOG_TAG, String.format("Skipping invisible child: %s", childNode.toString()));
        continue;
      }
      AccessibilityNodeInfo retNode = findNodeRegularRecursive(subSelector, childNode, i);
      if (retNode != null) {
        return retNode;
      }
    }
    return null;
  }
コード例 #6
0
  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;
  }
コード例 #7
0
  @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");
      }
    }
  }
コード例 #8
0
 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;
 }
コード例 #9
0
 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;
 }
コード例 #10
0
 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;
 }
コード例 #11
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;
 }
コード例 #12
0
 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;
 }
コード例 #13
0
  private AccessibilityNodeInfo findNodePatternRecursive(
      UiSelector subSelector,
      AccessibilityNodeInfo fromNode,
      int index,
      UiSelector originalPattern) {

    if (subSelector.isMatchFor(fromNode, index)) {
      if (subSelector.isLeaf()) {
        if (mPatternIndexer == 0) {
          if (DEBUG)
            Log.d(LOG_TAG, formatLog(String.format("%s", subSelector.dumpToString(false))));
          return fromNode;
        } else {
          if (DEBUG)
            Log.d(LOG_TAG, formatLog(String.format("%s", subSelector.dumpToString(false))));
          mPatternCounter++; // count the pattern matched
          mPatternIndexer--; // decrement until zero for the instance requested

          // At a leaf selector within a group and still not instance matched
          // then reset the  selector to continue search from current position
          // in the accessibility tree for the next pattern match up until the
          // pattern index hits 0.
          subSelector = originalPattern;
          // starting over with next pattern search so reset to parent level
          mLogIndent = mLogParentIndent;
        }
      } else {
        if (DEBUG) Log.d(LOG_TAG, formatLog(String.format("%s", subSelector.dumpToString(false))));

        if (subSelector.hasChildSelector()) {
          mLogIndent++; // next selector
          subSelector = subSelector.getChildSelector();
          if (subSelector == null) {
            Log.e(LOG_TAG, "Error: A child selector without content");
            return null;
          }
        } else if (subSelector.hasParentSelector()) {
          mLogIndent++; // next selector
          subSelector = subSelector.getParentSelector();
          if (subSelector == null) {
            Log.e(LOG_TAG, "Error: A parent selector without content");
            return null;
          }
          fromNode = fromNode.getParent();
          if (fromNode == null) return null;
        }
      }
    }

    int childCount = fromNode.getChildCount();
    boolean hasNullChild = false;
    for (int i = 0; i < childCount; i++) {
      AccessibilityNodeInfo childNode = fromNode.getChild(i);
      if (childNode == null) {
        Log.w(
            LOG_TAG,
            String.format("AccessibilityNodeInfo returned a null child (%d of %d)", i, childCount));
        if (!hasNullChild) {
          Log.w(LOG_TAG, String.format("parent = %s", fromNode.toString()));
        }
        hasNullChild = true;
        continue;
      }
      if (!childNode.isVisibleToUser()) {
        if (DEBUG)
          Log.d(LOG_TAG, String.format("Skipping invisible child: %s", childNode.toString()));
        continue;
      }
      AccessibilityNodeInfo retNode =
          findNodePatternRecursive(subSelector, childNode, i, originalPattern);
      if (retNode != null) {
        return retNode;
      }
    }
    return null;
  }