Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a1f01675 authored by William Loh's avatar William Loh
Browse files

Introduce maxSdkVersion attribute for the permission tag

If the maxSdkVersion attribute is defined on the permission tag
the permission will not be created if the API level is higher than
the maxSdkVersion level.

Bug: 223902327
Test: Added permission tag with maxSdkVersion attribute on test apk &&
 and checked the existance of the permission with &&
 adb shell pm list permissions
Change-Id: I00a8a0102943b0df3302bc5df5d26c92ece1d3a2
parent baa34227
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2084,6 +2084,11 @@
        <attr name="protectionLevel" />
        <attr name="permissionFlags" />
        <attr name="knownCerts" />
        <!-- Optional: specify the maximum version of the Android OS for which the
             application wishes to create the permission.  When running on a version
             of Android higher than the number given here, the permission will not
             be created.  -->
        <attr name="maxSdkVersion" />
    </declare-styleable>

    <!-- The <code>permission-group</code> tag declares a logical grouping of
+7 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.pm.parsing.result.ParseResult;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.os.Build;
import android.util.ArrayMap;
import android.util.Slog;

@@ -53,8 +54,7 @@ public class ParsedPermissionUtils {
        String tag = "<" + parser.getName() + ">";
        ParseResult<ParsedPermissionImpl> result;

        TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestPermission);
        try {
        try (TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestPermission)) {
            result = ParsedComponentUtils.parseComponent(
                    permission, tag, pkg, sa, useRoundIcon, input,
                    R.styleable.AndroidManifestPermission_banner,
@@ -68,6 +68,11 @@ public class ParsedPermissionUtils {
                return input.error(result);
            }

            int maxSdkVersion = sa.getInt(R.styleable.AndroidManifestPermission_maxSdkVersion, -1);
            if ((maxSdkVersion != -1) && (maxSdkVersion < Build.VERSION.SDK_INT)) {
                return input.success(null);
            }

            if (sa.hasValue(
                    R.styleable.AndroidManifestPermission_backgroundPermission)) {
                if ("android".equals(packageName)) {
@@ -135,8 +140,6 @@ public class ParsedPermissionUtils {
                            + " restricted: " + permission.getName());
                }
            }
        } finally {
            sa.recycle();
        }

        permission.setProtectionLevel(
+5 −1
Original line number Diff line number Diff line
@@ -1245,7 +1245,11 @@ public class ParsingPackageUtils {
        if (result.isError()) {
            return input.error(result);
        }
        return input.success(pkg.addPermission(result.getResult()));
        ParsedPermission permission = result.getResult();
        if (permission != null) {
            pkg.addPermission(permission);
        }
        return input.success(pkg);
    }

    private static ParseResult<ParsingPackage> parsePermissionTree(ParseInput input,