Search in sources :

Example 16 with PermissionInfo

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

the class Settings method writePermissionLPr.

void writePermissionLPr(XmlSerializer serializer, BasePermission bp) throws XmlPullParserException, java.io.IOException {
    if (bp.sourcePackage != null) {
        serializer.startTag(null, TAG_ITEM);
        serializer.attribute(null, ATTR_NAME, bp.name);
        serializer.attribute(null, "package", bp.sourcePackage);
        if (bp.protectionLevel != PermissionInfo.PROTECTION_NORMAL) {
            serializer.attribute(null, "protection", Integer.toString(bp.protectionLevel));
        }
        if (PackageManagerService.DEBUG_SETTINGS)
            Log.v(PackageManagerService.TAG, "Writing perm: name=" + bp.name + " type=" + bp.type);
        if (bp.type == BasePermission.TYPE_DYNAMIC) {
            final PermissionInfo pi = bp.perm != null ? bp.perm.info : bp.pendingInfo;
            if (pi != null) {
                serializer.attribute(null, "type", "dynamic");
                if (pi.icon != 0) {
                    serializer.attribute(null, "icon", Integer.toString(pi.icon));
                }
                if (pi.nonLocalizedLabel != null) {
                    serializer.attribute(null, "label", pi.nonLocalizedLabel.toString());
                }
            }
        }
        if (bp.allowViaWhitelist) {
            serializer.attribute(null, "allowViaWhitelist", Integer.toString(1));
        }
        serializer.endTag(null, TAG_ITEM);
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo)

Example 17 with PermissionInfo

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

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 18 with PermissionInfo

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

the class AppPermissions method loadPermissionGroups.

private void loadPermissionGroups() {
    mGroups.clear();
    if (mPackageInfo.requestedPermissions == null) {
        return;
    }
    final boolean appSupportsRuntimePermissions = appSupportsRuntime(mPackageInfo.applicationInfo);
    for (int i = 0; i < mPackageInfo.requestedPermissions.length; i++) {
        String requestedPerm = mPackageInfo.requestedPermissions[i];
        final PermissionInfo permInfo;
        try {
            permInfo = mContext.getPackageManager().getPermissionInfo(requestedPerm, 0);
        } catch (NameNotFoundException e) {
            Log.w(TAG, "Unknown permission: " + requestedPerm);
            continue;
        }
        String permName = permInfo.name;
        String groupName = permInfo.group != null ? permInfo.group : permName;
        PermissionGroup group = mGroups.get(groupName);
        if (group == null) {
            group = new PermissionGroup();
            mGroups.put(groupName, group);
        }
        final boolean runtime = appSupportsRuntimePermissions && permInfo.protectionLevel == PermissionInfo.PROTECTION_DANGEROUS;
        final boolean granted = (mPackageInfo.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;
        Permission permission = new Permission(runtime, granted);
        group.addPermission(permission, permName);
    }
    // Only care about runtime perms for now.
    for (int i = mGroups.size() - 1; i >= 0; i--) {
        if (!mGroups.valueAt(i).mHasRuntimePermissions) {
            mGroups.removeAt(i);
        }
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 19 with PermissionInfo

use of android.content.pm.PermissionInfo 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)

Example 20 with PermissionInfo

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

the class Settings method readPermissionsLPw.

private void readPermissionsLPw(ArrayMap<String, BasePermission> out, XmlPullParser parser) throws IOException, XmlPullParserException {
    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        final String tagName = parser.getName();
        if (tagName.equals(TAG_ITEM)) {
            final String name = parser.getAttributeValue(null, ATTR_NAME);
            final String sourcePackage = parser.getAttributeValue(null, "package");
            final String ptype = parser.getAttributeValue(null, "type");
            if (name != null && sourcePackage != null) {
                final boolean dynamic = "dynamic".equals(ptype);
                BasePermission bp = out.get(name);
                // If the permission is builtin, do not clobber it.
                if (bp == null || bp.type != BasePermission.TYPE_BUILTIN) {
                    bp = new BasePermission(name.intern(), sourcePackage, dynamic ? BasePermission.TYPE_DYNAMIC : BasePermission.TYPE_NORMAL);
                }
                bp.protectionLevel = readInt(parser, null, "protection", PermissionInfo.PROTECTION_NORMAL);
                bp.protectionLevel = PermissionInfo.fixProtectionLevel(bp.protectionLevel);
                bp.allowViaWhitelist = readInt(parser, null, "allowViaWhitelist", 0) == 1;
                if (dynamic) {
                    PermissionInfo pi = new PermissionInfo();
                    pi.packageName = sourcePackage.intern();
                    pi.name = name.intern();
                    pi.icon = readInt(parser, null, "icon", 0);
                    pi.nonLocalizedLabel = parser.getAttributeValue(null, "label");
                    pi.protectionLevel = bp.protectionLevel;
                    pi.allowViaWhitelist = bp.allowViaWhitelist;
                    bp.pendingInfo = pi;
                }
                out.put(bp.name, bp);
            } else {
                PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: permissions has" + " no name at " + parser.getPositionDescription());
            }
        } else {
            PackageManagerService.reportSettingsProblem(Log.WARN, "Unknown element reading permissions: " + parser.getName() + " at " + parser.getPositionDescription());
        }
        XmlUtils.skipCurrentTag(parser);
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo)

Aggregations

PermissionInfo (android.content.pm.PermissionInfo)43 PermissionGroupInfo (android.content.pm.PermissionGroupInfo)14 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)12 ComponentName (android.content.ComponentName)6 Resources (android.content.res.Resources)6 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 PackageInfo (android.content.pm.PackageInfo)3 PackageManager (android.content.pm.PackageManager)3 PackageParser (android.content.pm.PackageParser)3 AppOpsManager (android.app.AppOpsManager)1 RemoteException (android.os.RemoteException)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