Search in sources :

Example 26 with PermissionInfo

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

the class PackageManagerService method generatePermissionInfo.

static PermissionInfo generatePermissionInfo(BasePermission bp, int flags) {
    if (bp.perm != null) {
        return PackageParser.generatePermissionInfo(bp.perm, flags);
    }
    PermissionInfo pi = new PermissionInfo();
    pi.name = bp.name;
    pi.packageName = bp.sourcePackage;
    pi.nonLocalizedLabel = bp.name;
    pi.protectionLevel = bp.protectionLevel;
    return pi;
}
Also used : PermissionInfo(android.content.pm.PermissionInfo)

Example 27 with PermissionInfo

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

the class Pm method doListPermissions.

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

Example 28 with PermissionInfo

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

the class Settings method readPermissionsLPw.

private void readPermissionsLPw(HashMap<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);
                final BasePermission bp = new BasePermission(name, 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 29 with PermissionInfo

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

the class MetaDataTest method testPermissionWithData.

@SmallTest
public void testPermissionWithData() throws Exception {
    ComponentName cn = new ComponentName("foo", "com.android.frameworks.coretests.permission.TEST_GRANTED");
    PermissionInfo pi = mContext.getPackageManager().getPermissionInfo(cn.getClassName(), PackageManager.GET_META_DATA);
    checkMetaData(cn, pi);
    pi = mContext.getPackageManager().getPermissionInfo(cn.getClassName(), 0);
    assertNull("Meta data returned when not requested", pi.metaData);
}
Also used : PermissionInfo(android.content.pm.PermissionInfo) ComponentName(android.content.ComponentName) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 30 with PermissionInfo

use of android.content.pm.PermissionInfo in project DroidPlugin by DroidPluginTeam.

the class MyActivity method getPerms.

private void getPerms() {
    final PackageManager pm = getPackageManager();
    final List<PackageInfo> pkgs = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    new Thread() {

        @Override
        public void run() {
            try {
                StringBuilder sb = new StringBuilder();
                Log.e(TAG, "===========包权限start===========");
                Set<String> ps = new TreeSet<String>();
                for (PackageInfo pkg : pkgs) {
                    if (pkg.permissions != null && pkg.permissions.length > 0) {
                        for (PermissionInfo permission : pkg.permissions) {
                            ps.add(permission.name);
                        }
                    }
                }
                for (String p : ps) {
                    PermissionInfo permission = pm.getPermissionInfo(p, 0);
                    PackageInfo pkg = pm.getPackageInfo(permission.packageName, 0);
                    String re = String.format("<uses-permission android:name=\"%s\"/>", permission.name);
                    String ms = String.format("%s,%s,%s,%s,%s,%s,%s,%s", permission.packageName, pkg.applicationInfo.loadLabel(pm), permission.name, permission.group, permission.protectionLevel, permission.loadLabel(pm), permission.loadDescription(pm), re);
                    sb.append(ms).append("\r\n");
                    Log.e(TAG, "packageName=%s, name=%s group=%s protectionLevel=%s", permission.packageName, permission.name, permission.group, permission.protectionLevel);
                }
                FileWriter w = null;
                try {
                    w = new FileWriter(new File(Environment.getExternalStorageDirectory(), "per.txt"));
                    w.write(sb.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (w != null) {
                        try {
                            w.close();
                        } catch (IOException e) {
                        }
                    }
                }
                Log.e(TAG, "===========包权限end===========");
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }.start();
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) FileWriter(java.io.FileWriter) IOException(java.io.IOException) PackageManager(android.content.pm.PackageManager) PermissionInfo(android.content.pm.PermissionInfo) File(java.io.File)

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