Search in sources :

Example 26 with PermissionGroupInfo

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

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 27 with PermissionGroupInfo

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

the class AppSecurityPermissions method extractPerms.

private void extractPerms(PackageInfo info, Set<MyPermissionInfo> permSet, PackageInfo installedPkgInfo) {
    String[] strList = info.requestedPermissions;
    int[] flagsList = info.requestedPermissionsFlags;
    if ((strList == null) || (strList.length == 0)) {
        return;
    }
    for (int i = 0; i < strList.length; i++) {
        String permName = strList[i];
        try {
            PermissionInfo tmpPermInfo = mPm.getPermissionInfo(permName, 0);
            if (tmpPermInfo == null) {
                continue;
            }
            int existingIndex = -1;
            if (installedPkgInfo != null && installedPkgInfo.requestedPermissions != null) {
                for (int j = 0; j < installedPkgInfo.requestedPermissions.length; j++) {
                    if (permName.equals(installedPkgInfo.requestedPermissions[j])) {
                        existingIndex = j;
                        break;
                    }
                }
            }
            final int existingFlags = existingIndex >= 0 ? installedPkgInfo.requestedPermissionsFlags[existingIndex] : 0;
            if (!isDisplayablePermission(tmpPermInfo, flagsList[i], existingFlags)) {
                // to see, so skip it.
                continue;
            }
            final String origGroupName = tmpPermInfo.group;
            String groupName = origGroupName;
            if (groupName == null) {
                groupName = tmpPermInfo.packageName;
                tmpPermInfo.group = groupName;
            }
            MyPermissionGroupInfo group = mPermGroups.get(groupName);
            if (group == null) {
                PermissionGroupInfo grp = null;
                if (origGroupName != null) {
                    grp = mPm.getPermissionGroupInfo(origGroupName, 0);
                }
                if (grp != null) {
                    group = new MyPermissionGroupInfo(grp);
                } else {
                    // We could be here either because the permission
                    // didn't originally specify a group or the group it
                    // gave couldn't be found.  In either case, we consider
                    // its group to be the permission's package name.
                    tmpPermInfo.group = tmpPermInfo.packageName;
                    group = mPermGroups.get(tmpPermInfo.group);
                    if (group == null) {
                        group = new MyPermissionGroupInfo(tmpPermInfo);
                    }
                    group = new MyPermissionGroupInfo(tmpPermInfo);
                }
                mPermGroups.put(tmpPermInfo.group, group);
            }
            final boolean newPerm = installedPkgInfo != null && (existingFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0;
            MyPermissionInfo myPerm = new MyPermissionInfo(tmpPermInfo);
            myPerm.mNewReqFlags = flagsList[i];
            myPerm.mExistingReqFlags = existingFlags;
            // This is a new permission if the app is already installed and
            // doesn't currently hold this permission.
            myPerm.mNew = newPerm;
            permSet.add(myPerm);
        } catch (NameNotFoundException e) {
            Log.i(TAG, "Ignoring unknown permission:" + permName);
        }
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PermissionGroupInfo(android.content.pm.PermissionGroupInfo)

Example 28 with PermissionGroupInfo

use of android.content.pm.PermissionGroupInfo in project smartmodule by carozhu.

the class AppInfoUtil method getUsesPermission.

/**
	 * Get the App's All use Permission
	 * 
	 * @param packageName
	 * @return the use Permissions by ArrayList<MyPermission> permissions
	 */
public ArrayList<MyPermission> getUsesPermission(String packageName) {
    ArrayList<MyPermission> myPerms = new ArrayList<MyPermission>();
    try {
        PackageManager packageManager = c.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
        String[] usesPermissionsArray = packageInfo.requestedPermissions;
        for (int i = 0; i < usesPermissionsArray.length; i++) {
            MyPermission permi = new MyPermission();
            String usesPermissionName = usesPermissionsArray[i];
            permi.setPermissionName(usesPermissionName);
            System.out.println("usesPermissionName=" + usesPermissionName);
            PermissionInfo permissionInfo = packageManager.getPermissionInfo(usesPermissionName, 0);
            PermissionGroupInfo permissionGroupInfo = packageManager.getPermissionGroupInfo(permissionInfo.group, 0);
            permi.setPermissionGroup(permissionGroupInfo.loadLabel(packageManager).toString());
            System.out.println("permissionGroup=" + permissionGroupInfo.loadLabel(packageManager).toString());
            String permissionLabel = permissionInfo.loadLabel(packageManager).toString();
            permi.setPermissionLabel(permissionLabel);
            System.out.println("permissionLabel=" + permissionLabel);
            String permissionDescription = permissionInfo.loadDescription(packageManager).toString();
            permi.setPermissionDescription(permissionDescription);
            System.out.println("permissionDescription=" + permissionDescription);
            System.out.println("===========================================");
            myPerms.add(permi);
        }
        return myPerms;
    } catch (Exception e) {
    }
    return myPerms;
}
Also used : PackageManager(android.content.pm.PackageManager) PermissionInfo(android.content.pm.PermissionInfo) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

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