Example #1
0
  /** Lists all the known permission groups. */
  private void runListPermissionGroups() {
    try {
      List<PermissionGroupInfo> pgs = mPm.getAllPermissionGroups(0);

      int count = pgs.size();
      for (int p = 0; p < count; p++) {
        PermissionGroupInfo pgi = pgs.get(p);
        System.out.print("permission group:");
        System.out.println(pgi.name);
      }
    } catch (RemoteException e) {
      System.err.println(e.toString());
      System.err.println(PM_NOT_RUNNING_ERR);
    }
  }
Example #2
0
  /** Lists all the permissions in a group. */
  private void runListPermissions() {
    try {
      boolean labels = false;
      boolean groups = false;
      boolean userOnly = false;
      boolean summary = false;
      boolean dangerousOnly = false;
      String opt;
      while ((opt = nextOption()) != null) {
        if (opt.equals("-f")) {
          labels = true;
        } else if (opt.equals("-g")) {
          groups = true;
        } else if (opt.equals("-s")) {
          groups = true;
          labels = true;
          summary = true;
        } else if (opt.equals("-u")) {
          userOnly = true;
        } else if (opt.equals("-d")) {
          dangerousOnly = true;
        } else {
          System.err.println("Error: Unknown option: " + opt);
          return;
        }
      }

      String grp = nextOption();
      ArrayList<String> groupList = new ArrayList<String>();
      if (groups) {
        List<PermissionGroupInfo> infos = mPm.getAllPermissionGroups(0);
        for (int i = 0; i < infos.size(); i++) {
          groupList.add(infos.get(i).name);
        }
        groupList.add(null);
      } else {
        groupList.add(grp);
      }

      if (dangerousOnly) {
        System.out.println("Dangerous Permissions:");
        System.out.println("");
        doListPermissions(
            groupList,
            groups,
            labels,
            summary,
            PermissionInfo.PROTECTION_DANGEROUS,
            PermissionInfo.PROTECTION_DANGEROUS);
        if (userOnly) {
          System.out.println("Normal Permissions:");
          System.out.println("");
          doListPermissions(
              groupList,
              groups,
              labels,
              summary,
              PermissionInfo.PROTECTION_NORMAL,
              PermissionInfo.PROTECTION_NORMAL);
        }
      } else if (userOnly) {
        System.out.println("Dangerous and Normal Permissions:");
        System.out.println("");
        doListPermissions(
            groupList,
            groups,
            labels,
            summary,
            PermissionInfo.PROTECTION_NORMAL,
            PermissionInfo.PROTECTION_DANGEROUS);
      } else {
        System.out.println("All Permissions:");
        System.out.println("");
        doListPermissions(groupList, groups, labels, summary, -10000, 10000);
      }
    } catch (RemoteException e) {
      System.err.println(e.toString());
      System.err.println(PM_NOT_RUNNING_ERR);
    }
  }