Search in sources :

Example 21 with PermissionGroupInfo

use of android.content.pm.PermissionGroupInfo in project platform_frameworks_base by android.

the class PackageManagerShellCommand method runListPermissions.

private int runListPermissions() throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    boolean labels = false;
    boolean groups = false;
    boolean userOnly = false;
    boolean summary = false;
    boolean dangerousOnly = false;
    String opt;
    while ((opt = getNextOption()) != null) {
        switch(opt) {
            case "-d":
                dangerousOnly = true;
                break;
            case "-f":
                labels = true;
                break;
            case "-g":
                groups = true;
                break;
            case "-s":
                groups = true;
                labels = true;
                summary = true;
                break;
            case "-u":
                userOnly = true;
                break;
            default:
                pw.println("Error: Unknown option: " + opt);
                return 1;
        }
    }
    final ArrayList<String> groupList = new ArrayList<String>();
    if (groups) {
        final List<PermissionGroupInfo> infos = mInterface.getAllPermissionGroups(0).getList();
        final int count = infos.size();
        for (int i = 0; i < count; i++) {
            groupList.add(infos.get(i).name);
        }
        groupList.add(null);
    } else {
        final String grp = getNextArg();
        groupList.add(grp);
    }
    if (dangerousOnly) {
        pw.println("Dangerous Permissions:");
        pw.println("");
        doListPermissions(groupList, groups, labels, summary, PermissionInfo.PROTECTION_DANGEROUS, PermissionInfo.PROTECTION_DANGEROUS);
        if (userOnly) {
            pw.println("Normal Permissions:");
            pw.println("");
            doListPermissions(groupList, groups, labels, summary, PermissionInfo.PROTECTION_NORMAL, PermissionInfo.PROTECTION_NORMAL);
        }
    } else if (userOnly) {
        pw.println("Dangerous and Normal Permissions:");
        pw.println("");
        doListPermissions(groupList, groups, labels, summary, PermissionInfo.PROTECTION_NORMAL, PermissionInfo.PROTECTION_DANGEROUS);
    } else {
        pw.println("All Permissions:");
        pw.println("");
        doListPermissions(groupList, groups, labels, summary, -10000, 10000);
    }
    return 0;
}
Also used : ArrayList(java.util.ArrayList) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) PrintWriter(java.io.PrintWriter)

Example 22 with PermissionGroupInfo

use of android.content.pm.PermissionGroupInfo in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerShellCommand method doListPermissions.

private void doListPermissions(ArrayList<String> groupList, boolean groups, boolean labels, boolean summary, int startProtectionLevel, int endProtectionLevel) throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    final int groupCount = groupList.size();
    for (int i = 0; i < groupCount; i++) {
        String groupName = groupList.get(i);
        String prefix = "";
        if (groups) {
            if (i > 0) {
                pw.println("");
            }
            if (groupName != null) {
                PermissionGroupInfo pgi = mInterface.getPermissionGroupInfo(groupName, 0);
                if (summary) {
                    Resources res = getResources(pgi);
                    if (res != null) {
                        pw.print(loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel) + ": ");
                    } else {
                        pw.print(pgi.name + ": ");
                    }
                } else {
                    pw.println((labels ? "+ " : "") + "group:" + pgi.name);
                    if (labels) {
                        pw.println("  package:" + pgi.packageName);
                        Resources res = getResources(pgi);
                        if (res != null) {
                            pw.println("  label:" + loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel));
                            pw.println("  description:" + loadText(pgi, pgi.descriptionRes, pgi.nonLocalizedDescription));
                        }
                    }
                }
            } else {
                pw.println(((labels && !summary) ? "+ " : "") + "ungrouped:");
            }
            prefix = "  ";
        }
        List<PermissionInfo> ps = mInterface.queryPermissionsByGroup(groupList.get(i), 0).getList();
        final 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 {
                    pw.print(", ");
                }
                Resources res = getResources(pi);
                if (res != null) {
                    pw.print(loadText(pi, pi.labelRes, pi.nonLocalizedLabel));
                } else {
                    pw.print(pi.name);
                }
            } else {
                pw.println(prefix + (labels ? "+ " : "") + "permission:" + pi.name);
                if (labels) {
                    pw.println(prefix + "  package:" + pi.packageName);
                    Resources res = getResources(pi);
                    if (res != null) {
                        pw.println(prefix + "  label:" + loadText(pi, pi.labelRes, pi.nonLocalizedLabel));
                        pw.println(prefix + "  description:" + loadText(pi, pi.descriptionRes, pi.nonLocalizedDescription));
                    }
                    pw.println(prefix + "  protectionLevel:" + PermissionInfo.protectionToString(pi.protectionLevel));
                }
            }
        }
        if (summary) {
            pw.println("");
        }
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) Resources(android.content.res.Resources) PrintWriter(java.io.PrintWriter)

Example 23 with PermissionGroupInfo

use of android.content.pm.PermissionGroupInfo in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerShellCommand method runListPermissionGroups.

private int runListPermissionGroups() throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    final List<PermissionGroupInfo> pgs = mInterface.getAllPermissionGroups(0).getList();
    final int count = pgs.size();
    for (int p = 0; p < count; p++) {
        final PermissionGroupInfo pgi = pgs.get(p);
        pw.print("permission group:");
        pw.println(pgi.name);
    }
    return 0;
}
Also used : PermissionGroupInfo(android.content.pm.PermissionGroupInfo) PrintWriter(java.io.PrintWriter)

Example 24 with PermissionGroupInfo

use of android.content.pm.PermissionGroupInfo in project android_frameworks_base by ResurrectionRemix.

the class PackageManagerShellCommand method doListPermissions.

private void doListPermissions(ArrayList<String> groupList, boolean groups, boolean labels, boolean summary, int startProtectionLevel, int endProtectionLevel) throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    final int groupCount = groupList.size();
    for (int i = 0; i < groupCount; i++) {
        String groupName = groupList.get(i);
        String prefix = "";
        if (groups) {
            if (i > 0) {
                pw.println("");
            }
            if (groupName != null) {
                PermissionGroupInfo pgi = mInterface.getPermissionGroupInfo(groupName, 0);
                if (summary) {
                    Resources res = getResources(pgi);
                    if (res != null) {
                        pw.print(loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel) + ": ");
                    } else {
                        pw.print(pgi.name + ": ");
                    }
                } else {
                    pw.println((labels ? "+ " : "") + "group:" + pgi.name);
                    if (labels) {
                        pw.println("  package:" + pgi.packageName);
                        Resources res = getResources(pgi);
                        if (res != null) {
                            pw.println("  label:" + loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel));
                            pw.println("  description:" + loadText(pgi, pgi.descriptionRes, pgi.nonLocalizedDescription));
                        }
                    }
                }
            } else {
                pw.println(((labels && !summary) ? "+ " : "") + "ungrouped:");
            }
            prefix = "  ";
        }
        List<PermissionInfo> ps = mInterface.queryPermissionsByGroup(groupList.get(i), 0).getList();
        final 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 {
                    pw.print(", ");
                }
                Resources res = getResources(pi);
                if (res != null) {
                    pw.print(loadText(pi, pi.labelRes, pi.nonLocalizedLabel));
                } else {
                    pw.print(pi.name);
                }
            } else {
                pw.println(prefix + (labels ? "+ " : "") + "permission:" + pi.name);
                if (labels) {
                    pw.println(prefix + "  package:" + pi.packageName);
                    Resources res = getResources(pi);
                    if (res != null) {
                        pw.println(prefix + "  label:" + loadText(pi, pi.labelRes, pi.nonLocalizedLabel));
                        pw.println(prefix + "  description:" + loadText(pi, pi.descriptionRes, pi.nonLocalizedDescription));
                    }
                    pw.println(prefix + "  protectionLevel:" + PermissionInfo.protectionToString(pi.protectionLevel));
                }
            }
        }
        if (summary) {
            pw.println("");
        }
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) Resources(android.content.res.Resources) PrintWriter(java.io.PrintWriter)

Example 25 with PermissionGroupInfo

use of android.content.pm.PermissionGroupInfo in project android_frameworks_base by crdroidandroid.

the class PackageManagerShellCommand method runListPermissions.

private int runListPermissions() throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    boolean labels = false;
    boolean groups = false;
    boolean userOnly = false;
    boolean summary = false;
    boolean dangerousOnly = false;
    String opt;
    while ((opt = getNextOption()) != null) {
        switch(opt) {
            case "-d":
                dangerousOnly = true;
                break;
            case "-f":
                labels = true;
                break;
            case "-g":
                groups = true;
                break;
            case "-s":
                groups = true;
                labels = true;
                summary = true;
                break;
            case "-u":
                userOnly = true;
                break;
            default:
                pw.println("Error: Unknown option: " + opt);
                return 1;
        }
    }
    final ArrayList<String> groupList = new ArrayList<String>();
    if (groups) {
        final List<PermissionGroupInfo> infos = mInterface.getAllPermissionGroups(0).getList();
        final int count = infos.size();
        for (int i = 0; i < count; i++) {
            groupList.add(infos.get(i).name);
        }
        groupList.add(null);
    } else {
        final String grp = getNextArg();
        groupList.add(grp);
    }
    if (dangerousOnly) {
        pw.println("Dangerous Permissions:");
        pw.println("");
        doListPermissions(groupList, groups, labels, summary, PermissionInfo.PROTECTION_DANGEROUS, PermissionInfo.PROTECTION_DANGEROUS);
        if (userOnly) {
            pw.println("Normal Permissions:");
            pw.println("");
            doListPermissions(groupList, groups, labels, summary, PermissionInfo.PROTECTION_NORMAL, PermissionInfo.PROTECTION_NORMAL);
        }
    } else if (userOnly) {
        pw.println("Dangerous and Normal Permissions:");
        pw.println("");
        doListPermissions(groupList, groups, labels, summary, PermissionInfo.PROTECTION_NORMAL, PermissionInfo.PROTECTION_DANGEROUS);
    } else {
        pw.println("All Permissions:");
        pw.println("");
        doListPermissions(groupList, groups, labels, summary, -10000, 10000);
    }
    return 0;
}
Also used : ArrayList(java.util.ArrayList) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) PrintWriter(java.io.PrintWriter)

Aggregations

PermissionGroupInfo (android.content.pm.PermissionGroupInfo)28 PermissionInfo (android.content.pm.PermissionInfo)14 PrintWriter (java.io.PrintWriter)12 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)11 ArrayList (java.util.ArrayList)8 Resources (android.content.res.Resources)6 PackageInfo (android.content.pm.PackageInfo)2 PackageManager (android.content.pm.PackageManager)2 RemoteException (android.os.RemoteException)2 AppOpsManager (android.app.AppOpsManager)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 Spinner (android.widget.Spinner)1 Switch (android.widget.Switch)1 TextView (android.widget.TextView)1 VPackage (com.lody.virtual.server.pm.parser.VPackage)1 PluginPackageParser (com.morgoo.droidplugin.pm.parser.PluginPackageParser)1 MyPermission (com.smartandroid.sa.entity.MyPermission)1