Search in sources :

Example 31 with PermissionInfo

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

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

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

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());
                }
            }
        }
        serializer.endTag(null, TAG_ITEM);
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo)

Example 33 with PermissionInfo

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

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());
                }
            }
        }
        serializer.endTag(null, TAG_ITEM);
    }
}
Also used : PermissionInfo(android.content.pm.PermissionInfo)

Example 34 with PermissionInfo

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

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);
                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;
                    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)

Example 35 with PermissionInfo

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

the class PackageManagerService method addPermissionLocked.

boolean addPermissionLocked(PermissionInfo info, boolean async) {
    if (info.labelRes == 0 && info.nonLocalizedLabel == null) {
        throw new SecurityException("Label must be specified in permission");
    }
    BasePermission tree = checkPermissionTreeLP(info.name);
    BasePermission bp = mSettings.mPermissions.get(info.name);
    boolean added = bp == null;
    boolean changed = true;
    int fixedLevel = PermissionInfo.fixProtectionLevel(info.protectionLevel);
    if (added) {
        enforcePermissionCapLocked(info, tree);
        bp = new BasePermission(info.name, tree.sourcePackage, BasePermission.TYPE_DYNAMIC);
    } else if (bp.type != BasePermission.TYPE_DYNAMIC) {
        throw new SecurityException("Not allowed to modify non-dynamic permission " + info.name);
    } else {
        if (bp.protectionLevel == fixedLevel && bp.perm.owner.equals(tree.perm.owner) && bp.uid == tree.uid && comparePermissionInfos(bp.perm.info, info)) {
            changed = false;
        }
    }
    bp.protectionLevel = fixedLevel;
    info = new PermissionInfo(info);
    info.protectionLevel = fixedLevel;
    bp.perm = new PackageParser.Permission(tree.perm.owner, info);
    bp.perm.info.packageName = tree.perm.info.packageName;
    bp.uid = tree.uid;
    if (added) {
        mSettings.mPermissions.put(info.name, bp);
    }
    if (changed) {
        if (!async) {
            mSettings.writeLPr();
        } else {
            scheduleWriteSettingsLocked();
        }
    }
    return added;
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) PackageParser(android.content.pm.PackageParser)

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