Search in sources :

Example 6 with PermissionGroupInfo

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

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

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

the class Pm method runListPermissionGroups.

/**
     * 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);
    }
}
Also used : PermissionGroupInfo(android.content.pm.PermissionGroupInfo) RemoteException(android.os.RemoteException)

Example 8 with PermissionGroupInfo

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

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

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

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

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

the class AppOpsDetails method refreshUi.

private boolean refreshUi() {
    if (mPackageInfo == null) {
        return false;
    }
    setAppLabelAndIcon(mPackageInfo);
    Resources res = getActivity().getResources();
    mOperationsSection.removeAllViews();
    String lastPermGroup = "";
    boolean isPlatformSigned = isPlatformSigned();
    for (AppOpsState.OpsTemplate tpl : AppOpsState.ALL_TEMPLATES) {
        /* If we are platform signed, only show the root switch, this
             * one is safe to toggle while other permission-based ones could
             * certainly cause system-wide problems
             */
        if (isPlatformSigned && tpl != AppOpsState.SU_TEMPLATE) {
            continue;
        }
        List<AppOpsState.AppOpEntry> entries = mState.buildState(tpl, mPackageInfo.applicationInfo.uid, mPackageInfo.packageName);
        for (final AppOpsState.AppOpEntry entry : entries) {
            final AppOpsManager.OpEntry firstOp = entry.getOpEntry(0);
            final View view = mInflater.inflate(R.layout.app_ops_details_item, mOperationsSection, false);
            mOperationsSection.addView(view);
            String perm = AppOpsManager.opToPermission(firstOp.getOp());
            if (perm != null) {
                try {
                    PermissionInfo pi = mPm.getPermissionInfo(perm, 0);
                    if (pi.group != null && !lastPermGroup.equals(pi.group)) {
                        lastPermGroup = pi.group;
                        PermissionGroupInfo pgi = mPm.getPermissionGroupInfo(pi.group, 0);
                        if (pgi.icon != 0) {
                            ((ImageView) view.findViewById(R.id.op_icon)).setImageDrawable(pgi.loadIcon(mPm));
                        }
                    }
                } catch (NameNotFoundException e) {
                }
            }
            ((TextView) view.findViewById(R.id.op_name)).setText(entry.getSwitchText(mState));
            ((TextView) view.findViewById(R.id.op_counts)).setText(entry.getCountsText(res));
            ((TextView) view.findViewById(R.id.op_time)).setText(entry.getTimeText(res, true));
            Spinner sp = (Spinner) view.findViewById(R.id.spinnerWidget);
            sp.setVisibility(View.GONE);
            Switch sw = (Switch) view.findViewById(R.id.switchWidget);
            sw.setVisibility(View.GONE);
            final int switchOp = AppOpsManager.opToSwitch(firstOp.getOp());
            int mode = mAppOps.checkOpNoThrow(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName());
            sp.setSelection(modeToPosition(mode));
            sp.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {

                boolean firstMode = true;

                @Override
                public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
                    if (firstMode) {
                        firstMode = false;
                        return;
                    }
                    mAppOps.setMode(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName(), positionToMode(position));
                }

                @Override
                public void onNothingSelected(AdapterView<?> parentView) {
                // Do nothing
                }
            });
            sw.setChecked(mAppOps.checkOpNoThrow(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName()) == AppOpsManager.MODE_ALLOWED);
            sw.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {

                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    mAppOps.setMode(switchOp, entry.getPackageOps().getUid(), entry.getPackageOps().getPackageName(), isChecked ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
                }
            });
            if (AppOpsManager.isStrictOp(switchOp)) {
                sp.setVisibility(View.VISIBLE);
            } else {
                sw.setVisibility(View.VISIBLE);
            }
        }
    }
    return true;
}
Also used : Spinner(android.widget.Spinner) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AppOpsManager(android.app.AppOpsManager) PermissionInfo(android.content.pm.PermissionInfo) Switch(android.widget.Switch) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) Resources(android.content.res.Resources) CompoundButton(android.widget.CompoundButton)

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