示例#1
0
  /**
   * Lists all of the installed instrumentation, or all for a given package
   *
   * <p>pm list instrumentation [package] [-f]
   */
  private void runListInstrumentation() {
    int flags = 0; // flags != 0 is only used to request meta-data
    boolean showPackage = false;
    String targetPackage = null;

    try {
      String opt;
      while ((opt = nextArg()) != null) {
        if (opt.equals("-f")) {
          showPackage = true;
        } else if (opt.charAt(0) != '-') {
          targetPackage = opt;
        } else {
          System.err.println("Error: Unknown option: " + opt);
          showUsage();
          return;
        }
      }
    } catch (RuntimeException ex) {
      System.err.println("Error: " + ex.toString());
      showUsage();
      return;
    }

    try {
      List<InstrumentationInfo> list = mPm.queryInstrumentation(targetPackage, flags);

      // Sort by target package
      Collections.sort(
          list,
          new Comparator<InstrumentationInfo>() {
            public int compare(InstrumentationInfo o1, InstrumentationInfo o2) {
              return o1.targetPackage.compareTo(o2.targetPackage);
            }
          });

      int count = (list != null) ? list.size() : 0;
      for (int p = 0; p < count; p++) {
        InstrumentationInfo ii = list.get(p);
        System.out.print("instrumentation:");
        if (showPackage) {
          System.out.print(ii.sourceDir);
          System.out.print("=");
        }
        ComponentName cn = new ComponentName(ii.packageName, ii.name);
        System.out.print(cn.flattenToShortString());
        System.out.print(" (target=");
        System.out.print(ii.targetPackage);
        System.out.println(")");
      }
    } catch (RemoteException e) {
      System.err.println(e.toString());
      System.err.println(PM_NOT_RUNNING_ERR);
    }
  }