Java Code Examples for android.content.pm.PermissionInfo#PROTECTION_SIGNATURE

The following examples show how to use android.content.pm.PermissionInfo#PROTECTION_SIGNATURE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BroadcastQueue.java    From AndroidComponentPlugin with Apache License 2.0 7 votes vote down vote up
/**
 * Return true if all given permissions are signature-only perms.
 */
final boolean isSignaturePerm(String[] perms) {
    if (perms == null) {
        return false;
    }
    IPackageManager pm = AppGlobals.getPackageManager();
    for (int i = perms.length-1; i >= 0; i--) {
        try {
            PermissionInfo pi = pm.getPermissionInfo(perms[i], "android", 0);
            if ((pi.protectionLevel & (PermissionInfo.PROTECTION_MASK_BASE
                    | PermissionInfo.PROTECTION_FLAG_PRIVILEGED))
                    != PermissionInfo.PROTECTION_SIGNATURE) {
                // If this a signature permission and NOT allowed for privileged apps, it
                // is okay...  otherwise, nope!
                return false;
            }
        } catch (RemoteException e) {
            return false;
        }
    }
    return true;
}
 
Example 2
Source File: BroadcastQueue.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Return true if all given permissions are signature-only perms.
 */
final boolean isSignaturePerm(String[] perms) {
    if (perms == null) {
        return false;
    }
    IPackageManager pm = AppGlobals.getPackageManager();
    for (int i = perms.length-1; i >= 0; i--) {
        try {
            PermissionInfo pi = pm.getPermissionInfo(perms[i], "android", 0);
            if ((pi.protectionLevel & (PermissionInfo.PROTECTION_MASK_BASE
                    | PermissionInfo.PROTECTION_FLAG_PRIVILEGED))
                    != PermissionInfo.PROTECTION_SIGNATURE) {
                // If this a signature permission and NOT allowed for privileged apps, it
                // is okay...  otherwise, nope!
                return false;
            }
        } catch (RemoteException e) {
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: BasePermission.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public BasePermission(String _name, String _sourcePackageName, @PermissionType int _type) {
    name = _name;
    sourcePackageName = _sourcePackageName;
    type = _type;
    // Default to most conservative protection level.
    protectionLevel = PermissionInfo.PROTECTION_SIGNATURE;
}
 
Example 4
Source File: PermissionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int adjustPermissionProtectionFlagsLocked(
        int protectionLevel, String packageName, int uid) {
    // Signature permission flags area always reported
    final int protectionLevelMasked = protectionLevel
            & (PermissionInfo.PROTECTION_NORMAL
            | PermissionInfo.PROTECTION_DANGEROUS
            | PermissionInfo.PROTECTION_SIGNATURE);
    if (protectionLevelMasked == PermissionInfo.PROTECTION_SIGNATURE) {
        return protectionLevel;
    }
    // System sees all flags.
    final int appId = UserHandle.getAppId(uid);
    if (appId == Process.SYSTEM_UID || appId == Process.ROOT_UID
            || appId == Process.SHELL_UID) {
        return protectionLevel;
    }
    // Normalize package name to handle renamed packages and static libs
    final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName);
    if (pkg == null) {
        return protectionLevel;
    }
    if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.O) {
        return protectionLevelMasked;
    }
    // Apps that target O see flags for all protection levels.
    final PackageSetting ps = (PackageSetting) pkg.mExtras;
    if (ps == null) {
        return protectionLevel;
    }
    if (ps.getAppId() != appId) {
        return protectionLevel;
    }
    return protectionLevel;
}
 
Example 5
Source File: FakeManifestUtils.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
public static PackageInfo buildFakePackageInfo (PackageInfo info) {
    info.requestedPermissions = new String[]{Manifest.permission.VIBRATE,
            Manifest.permission.READ_PHONE_STATE,
            Manifest.permission.GET_TASKS,
            Manifest.permission.INTERNET,
            Manifest.permission.ACCESS_NETWORK_STATE,
            Manifest.permission.ACCESS_WIFI_STATE,
            info.packageName + ".permission.MIPUSH_RECEIVE"};
    PermissionInfo permissionInfo = new PermissionInfo();
    permissionInfo.protectionLevel = PermissionInfo.PROTECTION_SIGNATURE;
    permissionInfo.name = info.packageName + ".permission.MIPUSH_RECEIVE";
    info.permissions = new PermissionInfo[]{permissionInfo};
    return info;
}
 
Example 6
Source File: Utils.java    From Android-Applications-Info with Apache License 2.0 5 votes vote down vote up
public static String getProtectionLevelString(int level) {
    String protLevel = "????";
    switch (level & PermissionInfo.PROTECTION_MASK_BASE) {
        case PermissionInfo.PROTECTION_DANGEROUS:
            protLevel = "dangerous";
            break;
        case PermissionInfo.PROTECTION_NORMAL:
            protLevel = "normal";
            break;
        case PermissionInfo.PROTECTION_SIGNATURE:
            protLevel = "signature";
            break;
        case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM:
            protLevel = "signatureOrSystem";
            break;
    }
    if ((level & PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0) {
        protLevel += "|system";
    }
    if ((level & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) {
        protLevel += "|development";
    }
    if ((level & PermissionInfo.PROTECTION_FLAG_APPOP) != 0) {
        protLevel += "|appop";
    }
    return protLevel;
}
 
Example 7
Source File: GmailContract.java    From retrowatch with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the installed Gmail app supports querying for label information.
 *
 * @param c an application Context
 * @return true if it's safe to make label API queries
 */
public static boolean canReadLabels(Context c) {
    boolean supported = false;

    try {
        final PackageInfo info = c.getPackageManager().getPackageInfo(PACKAGE,
                PackageManager.GET_PROVIDERS | PackageManager.GET_PERMISSIONS);
        boolean allowRead = false;
        if (info.permissions != null) {
            for (int i = 0, len = info.permissions.length; i < len; i++) {
                final PermissionInfo perm = info.permissions[i];
                if (PERMISSION.equals(perm.name)
                        && perm.protectionLevel < PermissionInfo.PROTECTION_SIGNATURE) {
                    allowRead = true;
                    break;
                }
            }
        }
        if (allowRead && info.providers != null) {
            for (int i = 0, len = info.providers.length; i < len; i++) {
                final ProviderInfo provider = info.providers[i];
                if (AUTHORITY.equals(provider.authority) &&
                        TextUtils.equals(PERMISSION, provider.readPermission)) {
                    supported = true;
                }
            }
        }
    } catch (NameNotFoundException e) {
        // Gmail app not found
    }
    return supported;
}
 
Example 8
Source File: GmailContract.java    From retrowatch with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the installed Gmail app supports querying for label information.
 *
 * @param c an application Context
 * @return true if it's safe to make label API queries
 */
public static boolean canReadLabels(Context c) {
    boolean supported = false;

    try {
        final PackageInfo info = c.getPackageManager().getPackageInfo(PACKAGE,
                PackageManager.GET_PROVIDERS | PackageManager.GET_PERMISSIONS);
        boolean allowRead = false;
        if (info.permissions != null) {
            for (int i = 0, len = info.permissions.length; i < len; i++) {
                final PermissionInfo perm = info.permissions[i];
                if (PERMISSION.equals(perm.name)
                        && perm.protectionLevel < PermissionInfo.PROTECTION_SIGNATURE) {
                    allowRead = true;
                    break;
                }
            }
        }
        if (allowRead && info.providers != null) {
            for (int i = 0, len = info.providers.length; i < len; i++) {
                final ProviderInfo provider = info.providers[i];
                if (AUTHORITY.equals(provider.authority) &&
                        TextUtils.equals(PERMISSION, provider.readPermission)) {
                    supported = true;
                }
            }
        }
    } catch (NameNotFoundException e) {
        // Gmail app not found
    }
    return supported;
}
 
Example 9
Source File: BasePermission.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public boolean isSignature() {
    return (protectionLevel & PermissionInfo.PROTECTION_MASK_BASE) ==
            PermissionInfo.PROTECTION_SIGNATURE;
}
 
Example 10
Source File: DynamicApkParser.java    From Android-plugin-support with MIT License 4 votes vote down vote up
private Permission parsePermission(DynamicApkInfo owner, Resources res,
                                       XmlPullParser parser, AttributeSet attrs, String[] outError)
            throws XmlPullParserException, IOException {
        Permission perm = new Permission(owner);

        TypedArray sa = res.obtainAttributes(attrs,
                Hooks.getStyleableArray("AndroidManifestPermission"));

        if (!parsePackageItemInfo(owner, perm.info, outError,
                "<permission>", sa,
                Hooks.getStyleable("AndroidManifestPermission_name"),
                Hooks.getStyleable("AndroidManifestPermission_label"),
                Hooks.getStyleable("AndroidManifestPermission_icon"),
                Hooks.getStyleable("AndroidManifestPermission_logo"),
                Hooks.getStyleable("AndroidManifestPermission_banner"))) {
            sa.recycle();
            mParseError = 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(
                Hooks.getStyleable("AndroidManifestPermission_permissionGroup"));
        if (perm.info.group != null) {
            perm.info.group = perm.info.group.intern();
        }

        perm.info.descriptionRes = sa.getResourceId(
                Hooks.getStyleable("AndroidManifestPermission_description"),
                0);

        perm.info.protectionLevel = sa.getInt(
                Hooks.getStyleable("AndroidManifestPermission_protectionLevel"),
                PermissionInfo.PROTECTION_NORMAL);

        perm.info.flags = sa.getInt(
                Hooks.getStyleable("AndroidManifestPermission_permissionFlags"), 0);

        sa.recycle();

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

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

        owner.permissions.add(perm);

        return perm;
    }