public static ArrayList<ApkPermission> permissions(
      Context context, ArrayList<String> permissionArray) {
    PackageManager pm = context.getPackageManager();

    CharSequence csPermissionGroupLabel;
    CharSequence csPermissionLabel;
    List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(0);
    ArrayList<ApkPermission> list = new ArrayList<>();

    if (permissionArray != null) {
      for (int i = 0; i != permissionArray.size(); i++) {
        String permission = permissionArray.get(i);

        for (PermissionGroupInfo pgi : lstGroups) {
          try {
            List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0);
            for (PermissionInfo pi : lstPermissions) {
              if (pi.name.equals(permission)) {
                csPermissionLabel = pi.loadLabel(pm);
                csPermissionGroupLabel = pgi.loadLabel(pm);
                list.add(
                    new ApkPermission(
                        csPermissionGroupLabel.toString(), csPermissionLabel.toString()));
              }
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      }
      Collections.sort(
          list,
          new Comparator<ApkPermission>() {
            @Override
            public int compare(ApkPermission lhs, ApkPermission rhs) {
              return lhs.getName().compareTo(rhs.getName());
            }
          });
    }

    return list;
  }
Example #2
0
 public static void printAllPermission(Context context) {
   PackageManager pm = context.getPackageManager();
   CharSequence csPermissionGroupLabel;
   CharSequence csPermissionLabel;
   List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(PackageManager.GET_PERMISSIONS);
   for (PermissionGroupInfo pgi : lstGroups) {
     csPermissionGroupLabel = pgi.loadLabel(pm);
     Log.d(
         "ldx", "PermissionGroup: " + pgi.name + "  [" + csPermissionGroupLabel.toString() + "]");
     try {
       List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0);
       for (PermissionInfo pi : lstPermissions) {
         csPermissionLabel = pi.loadLabel(pm);
         Log.d(
             "ldx", "     PermissionChild" + pi.name + "  [" + csPermissionLabel.toString() + "]");
       }
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main3);
    mPm = getPackageManager();
    Intent i = getIntent();
    String title = i.getStringExtra("title");
    final String PackageName = title.substring(8);

    ExpandableListView list = (ExpandableListView) findViewById(R.id.permissionList);
    mGroupData = new ArrayList<Map<String, String>>();
    mChildData = new ArrayList<List<Map<String, String>>>();
    String permissionName;
    String applicationLabel;
    String packageName;
    PackageInfo pi = null;
    ApplicationInfo ai = null;
    applicationLabel = PackageName;
    int packageVersionCode;
    String packageVersionName;
    String AppName;
    Drawable icon;
    long lastUpdate;
    int system;
    int install;

    try {
      pi = mPm.getPackageInfo(PackageName, PackageManager.GET_META_DATA);

      try {
        icon = mPm.getApplicationIcon(PackageName); // ///icon  빼기

      } catch (PackageManager.NameNotFoundException e) {
        icon = mPm.getDefaultActivityIcon();
      }

      ImageView imageView = (ImageView) findViewById(android.R.id.icon);
      imageView.setImageDrawable(icon);

      AppName = pi.packageName;
      packageVersionCode = pi.versionCode;
      packageVersionName = pi.versionName;
      Log.v("XXXX7", "name:     " + packageVersionName);

      ai = mPm.getApplicationInfo(PackageName, PackageManager.GET_META_DATA); // //라벨 빼오기
      String labelName = mPm.getApplicationLabel(ai).toString();

      ((TextView) findViewById(R.id.curAppName)).setText(labelName); // Appname layout 연결
      ((TextView) findViewById(R.id.packagea)).setText(AppName); // Appname layout 연결
      ((TextView) findViewById(R.id.curAppversion))
          .setText(packageVersionCode + " / " + packageVersionName);

    } catch (Exception ex) {
      packageVersionCode = 0;
      packageVersionName = "n/a";
      // Log.e("PM", "Error fetching app version");
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////

    manageButton = (ImageButton) findViewById(R.id.application_detail_manage_button);
    manageButton.setImageResource(R.drawable.ic_menu_manage);
    manageButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (Build.VERSION.SDK_INT >= 9) {
              try {
                Intent i = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
                i.addCategory(Intent.CATEGORY_DEFAULT);
                i.setData(Uri.parse("package:" + PackageName));
                startActivity(i);
              } catch (ActivityNotFoundException anfe) {
                Intent i = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
                i.addCategory(Intent.CATEGORY_DEFAULT);
                startActivity(i);
              }
            } else {
              Toast.makeText(
                      MarketPlay.this,
                      context.getText(R.string.application_detail_manager_unavailable),
                      Toast.LENGTH_LONG)
                  .show();
            }
          }
        });

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////
    try {
      pi = mPm.getPackageInfo(PackageName, PackageManager.GET_PERMISSIONS);

    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }

    mChildData.clear();
    mGroupData.clear();

    //        int count = 0;
    //        try {
    //            for (String key : pi.requestedPermissions) {
    //                if (key.startsWith("android.permission.")) count++;
    //            }
    //            curGroupMap.put(NAME, applicationLabel + "(" + count + ")");
    //            Log.v("XXXX7", "count :     " + count);
    //        } catch (NullPointerException e) {
    //            curGroupMap.put(NAME, applicationLabel + "(" + 0 + ")");
    //            Log.v("XXXX7", "///count :     " + count);
    //        }
    //        curGroupMap.put(DESCRIPTION, packageVersionName);
    //        Log.v("XXXX7", "Description  :     " + packageVersionName);
    //        curGroupMap.put(PACKAGENAME, PackageName);
    //        Log.v("XXXX7", "packageName  :     " + PackageName);
    //
    //        mGroupData.add(curGroupMap);

    Log.v("1", "" + mChildData);

    Log.v("2", "" + mChildData);
    try {
      Log.v("3", "" + mChildData);
      if (pi.requestedPermissions != null) {
        for (String key : pi.requestedPermissions) {
          try {
            if (!(key.startsWith("android.permission."))) continue;
            Log.d("BBB", key);
            PermissionInfo pinfo = mPm.getPermissionInfo(key, PackageManager.GET_META_DATA);
            Map<String, String> curGroupMap = new HashMap<String, String>();
            Map<String, String> curChildMap = new HashMap<String, String>();
            List<Map<String, String>> children = new ArrayList<Map<String, String>>();
            CharSequence label = pinfo.loadLabel(mPm);
            CharSequence desc = pinfo.loadDescription(mPm);

            curGroupMap.put(NAME, (label == null) ? pinfo.name : label.toString());
            Log.d("AAA", label.toString());
            curGroupMap.put(SECURITYLEVEL, String.valueOf(pinfo.protectionLevel));
            curChildMap.put(PERMISSION, key);
            curChildMap.put(DESCRIPTION, (desc == null) ? "" : desc.toString());
            curChildMap.put(SECURITYLEVEL, String.valueOf(pinfo.protectionLevel));
            children.add(curChildMap);

            mGroupData.add(curGroupMap);
            Log.d("CCC", "" + mGroupData);
            mChildData.add(children);
            Log.d("DDD", "" + mChildData);

          } catch (PackageManager.NameNotFoundException e) {
            Log.i(TAG, "Ignoring unknown permission ");
            continue;
          }
        }
      } else {
        ((TextView) findViewById(R.id.iff)).setText(" App 의 요구 권한 이 없습니다 ^^  ");

        //                mGroupData.add(curGroupMap);
        //                mChildData.add(children);
      }
    } catch (NullPointerException e) {
      Log.i(TAG, "Ignoring unknown permission ");
    }

    //        SimpleAdapter adapter = new SimpleAdapter(this, children,
    // R.layout.permission_list_item, new String[]{"", "Name", "Description"}, new
    // int[]{R.id.listviewpermissiontext, R.id.text1, R.id.text2});
    //        if (pi.requestedPermissions != null) {
    //            permissionList = (ListView) findViewById(R.id.permissionList);
    //            permissionList.setAdapter(adapter);
    //        } else {
    //            ((TextView) findViewById(R.id.iff)).setText(" App 의 요구 권한 이 없습니다 ^^  ");
    //        }

    PermissionAdapter mAdapter =
        new PermissionAdapter(
            MarketPlay.this,
            mGroupData,
            R.layout.marketplay_item,
            new String[] {NAME},
            new int[] {R.id.text1},
            mChildData,
            R.layout.marketplay_item_child,
            new String[] {DESCRIPTION, PERMISSION},
            new int[] {R.id.text1, R.id.text2});

    list.setAdapter(mAdapter);

    Log.v("BBB", "" + mChildData);

    // permissionList = (ListView)findViewById(R.id.permissionL);
    // permissionList.setAdapter(adapter);    ///권한들 .. layout

  }
Example #4
0
  private void doListPermissions(
      ArrayList<String> groupList,
      boolean groups,
      boolean labels,
      boolean summary,
      int startProtectionLevel,
      int endProtectionLevel)
      throws RemoteException {
    for (int i = 0; i < groupList.size(); i++) {
      String groupName = groupList.get(i);
      String prefix = "";
      if (groups) {
        if (i > 0) System.out.println("");
        if (groupName != null) {
          PermissionGroupInfo pgi = mPm.getPermissionGroupInfo(groupName, 0);
          if (summary) {
            Resources res = getResources(pgi);
            if (res != null) {
              System.out.print(loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel) + ": ");
            } else {
              System.out.print(pgi.name + ": ");
            }
          } else {
            System.out.println((labels ? "+ " : "") + "group:" + pgi.name);
            if (labels) {
              System.out.println("  package:" + pgi.packageName);
              Resources res = getResources(pgi);
              if (res != null) {
                System.out.println("  label:" + loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel));
                System.out.println(
                    "  description:"
                        + loadText(pgi, pgi.descriptionRes, pgi.nonLocalizedDescription));
              }
            }
          }
        } else {
          System.out.println(((labels && !summary) ? "+ " : "") + "ungrouped:");
        }
        prefix = "  ";
      }
      List<PermissionInfo> ps = mPm.queryPermissionsByGroup(groupList.get(i), 0);
      int count = ps.size();
      boolean first = true;
      for (int p = 0; p < count; p++) {
        PermissionInfo pi = ps.get(p);
        if (groups && groupName == null && pi.group != null) {
          continue;
        }
        final int base = pi.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
        if (base < startProtectionLevel || base > endProtectionLevel) {
          continue;
        }
        if (summary) {
          if (first) {
            first = false;
          } else {
            System.out.print(", ");
          }
          Resources res = getResources(pi);
          if (res != null) {
            System.out.print(loadText(pi, pi.labelRes, pi.nonLocalizedLabel));
          } else {
            System.out.print(pi.name);
          }
        } else {
          System.out.println(prefix + (labels ? "+ " : "") + "permission:" + pi.name);
          if (labels) {
            System.out.println(prefix + "  package:" + pi.packageName);
            Resources res = getResources(pi);
            if (res != null) {
              System.out.println(
                  prefix + "  label:" + loadText(pi, pi.labelRes, pi.nonLocalizedLabel));
              System.out.println(
                  prefix
                      + "  description:"
                      + loadText(pi, pi.descriptionRes, pi.nonLocalizedDescription));
            }
            System.out.println(
                prefix
                    + "  protectionLevel:"
                    + PermissionInfo.protectionToString(pi.protectionLevel));
          }
        }
      }

      if (summary) {
        System.out.println("");
      }
    }
  }