Example usage for android.content.pm PermissionInfo PROTECTION_NORMAL

List of usage examples for android.content.pm PermissionInfo PROTECTION_NORMAL

Introduction

In this page you can find the example usage for android.content.pm PermissionInfo PROTECTION_NORMAL.

Prototype

int PROTECTION_NORMAL

To view the source code for android.content.pm PermissionInfo PROTECTION_NORMAL.

Click Source Link

Document

A normal application value for #protectionLevel , corresponding to the normal value of android.R.attr#protectionLevel .

Usage

From source file:com.android.packageinstaller.GrantActivity.java

/**
 * Filter the permissions in {@code permissions}, keeping only the NORMAL or DANGEROUS
 * permissions./*from w w  w  .  j av  a 2 s .  co  m*/
 *
 * @param permissions the permissions to filter
 * @return A subset of {@code permissions} with only the
 *     NORMAL or DANGEROUS permissions kept
 */
private String[] keepNormalDangerousPermissions(String[] permissions) {
    List<String> result = new ArrayList<String>();
    for (String permission : permissions) {
        try {
            PermissionInfo pInfo = mPm.getPermissionInfo(permission, 0);
            final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
            if ((base != PermissionInfo.PROTECTION_NORMAL) && (base != PermissionInfo.PROTECTION_DANGEROUS)) {
                continue;
            }
            result.add(permission);
        } catch (NameNotFoundException e) {
            // ignore
        }
    }
    return result.toArray(new String[result.size()]);
}

From source file:com.github.michalbednarski.intentslab.PermissionInfoFragment.java

@SuppressLint("InlinedApi")
private static String protectionLevelToString(int protectionLevel) {
    int base = protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    int flags = protectionLevel & PermissionInfo.PROTECTION_MASK_FLAGS;

    // Base//from  w w  w.j a v  a  2 s  .  c  om
    StringBuilder builder = new StringBuilder(base == PermissionInfo.PROTECTION_NORMAL ? "normal"
            : base == PermissionInfo.PROTECTION_DANGEROUS ? "dangerous"
                    : base == PermissionInfo.PROTECTION_SIGNATURE ? "signature"
                            : base == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM ? "signatureOrSystem"
                                    : String.valueOf(base) // If none matched
    );

    // Flags
    if ((flags & PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0) {
        builder.append("|system");
    }
    if ((flags & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) {
        builder.append("|development");
    }

    // Unrecognized flags
    int unknownFlags = flags
            & ~(PermissionInfo.PROTECTION_FLAG_SYSTEM | PermissionInfo.PROTECTION_FLAG_DEVELOPMENT);
    if (unknownFlags != 0) {
        builder.append("|");
        builder.append(unknownFlags);
    }
    return builder.toString();
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@SuppressLint("InlinedApi")
static boolean checkProtectionLevel(PermissionInfo permissionInfo, int protectionFilter) {
    // Skip test if all options are checked
    if ((protectionFilter & PROTECTION_ANY_LEVEL) == PROTECTION_ANY_LEVEL) {
        return true;
    }/*from  w  w  w  .  j  a  va2s . c o m*/

    // Test protectionLevel
    int protectionLevel = permissionInfo.protectionLevel;
    if (protectionLevel == PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM) {
        protectionLevel = PermissionInfo.PROTECTION_SIGNATURE | PermissionInfo.PROTECTION_FLAG_SYSTEM;
    }
    int protectionLevelBase = protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    int protectionLevelFlags = protectionLevel & PermissionInfo.PROTECTION_MASK_FLAGS;

    // Match against our flags
    return ((protectionLevel == PermissionInfo.PROTECTION_NORMAL ? PROTECTION_NORMAL
            : protectionLevel == PermissionInfo.PROTECTION_DANGEROUS ? PROTECTION_DANGEROUS
                    : (((protectionLevelBase == PermissionInfo.PROTECTION_SIGNATURE) ? PROTECTION_SIGNATURE : 0)
                            | (((protectionLevelFlags & PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0)
                                    ? PROTECTION_SYSTEM
                                    : 0)
                            | (((protectionLevelFlags & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0)
                                    ? PROTECTION_DEVELOPMENT
                                    : 0)))
            & protectionFilter) != 0;
}

From source file:org.fdroid.fdroid.privileged.views.AppSecurityPermissions.java

private boolean isDisplayablePermission(PermissionInfo pInfo, int existingReqFlags) {
    final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    final boolean isNormal = base == PermissionInfo.PROTECTION_NORMAL;
    final boolean isDangerous = base == PermissionInfo.PROTECTION_DANGEROUS
            || ((pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_PRE23) != 0);

    // Dangerous and normal permissions are always shown to the user
    // this is matches the permission list in AppDetails
    if (isNormal || isDangerous) {
        return true;
    }//from ww  w  .j a  v a2s  .  c  o  m

    final boolean isDevelopment = (pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0;
    final boolean wasGranted = (existingReqFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0;

    // Development permissions are only shown to the user if they are already
    // granted to the app -- if we are installing an app and they are not
    // already granted, they will not be granted as part of the install.
    return isDevelopment && wasGranted;
}

From source file:android.content.pm.PackageParser.java

private Permission parsePermission(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs,
        String[] outError) throws XmlPullParserException, IOException {
    Permission perm = new Permission(owner);

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestPermission);

    if (!parsePackageItemInfo(owner, perm.info, outError, "<permission>", sa,
            com.android.internal.R.styleable.AndroidManifestPermission_name,
            com.android.internal.R.styleable.AndroidManifestPermission_label,
            com.android.internal.R.styleable.AndroidManifestPermission_icon,
            com.android.internal.R.styleable.AndroidManifestPermission_logo,
            com.android.internal.R.styleable.AndroidManifestPermission_banner)) {
        sa.recycle();/*from   w w  w  . ja  v  a2 s . c om*/
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    // Note: don't allow this value to be a reference to a resource
    // that may change.
    perm.info.group = sa
            .getNonResourceString(com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
    if (perm.info.group != null) {
        perm.info.group = perm.info.group.intern();
    }

    perm.info.descriptionRes = sa
            .getResourceId(com.android.internal.R.styleable.AndroidManifestPermission_description, 0);

    perm.info.protectionLevel = sa.getInt(
            com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
            PermissionInfo.PROTECTION_NORMAL);

    perm.info.flags = sa.getInt(com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);

    sa.recycle();

    if (perm.info.protectionLevel == -1) {
        outError[0] = "<permission> does not specify protectionLevel";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);

    if ((perm.info.protectionLevel & PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
        if ((perm.info.protectionLevel
                & PermissionInfo.PROTECTION_MASK_BASE) != PermissionInfo.PROTECTION_SIGNATURE) {
            outError[0] = "<permission>  protectionLevel specifies a flag but is "
                    + "not based on signature type";
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        }
    }

    if (!parseAllMetaData(res, parser, attrs, "<permission>", perm, outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissions.add(perm);

    return perm;
}

From source file:android.content.pm.PackageParser.java

private Permission parsePermissionTree(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs,
        String[] outError) throws XmlPullParserException, IOException {
    Permission perm = new Permission(owner);

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestPermissionTree);

    if (!parsePackageItemInfo(owner, perm.info, outError, "<permission-tree>", sa,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_logo,
            com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) {
        sa.recycle();// w  w w .  j  a v  a  2 s .c om
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    sa.recycle();

    int index = perm.info.name.indexOf('.');
    if (index > 0) {
        index = perm.info.name.indexOf('.', index + 1);
    }
    if (index < 0) {
        outError[0] = "<permission-tree> name has less than three segments: " + perm.info.name;
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.descriptionRes = 0;
    perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL;
    perm.tree = true;

    if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm, outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissions.add(perm);

    return perm;
}