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

Commit bcf5b69c authored by Winson Chiu's avatar Winson Chiu
Browse files

Correctly parse minSdk even when targetSdk is a codename

The code that assigned target to min if min was not specified was
only checking for min codenames, but if the manifest specified a
numerical minSdkVersion, that is valid and would incorrectly prevent
the package from installing.

Bug: 237059024

Test: mts-tradefed > mts-eng-only -m ApkInApexTest

Change-Id: I3a2b9baa82ebb8ca9031c9fa128ce12bff17226e
parent 07943a5b
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -542,14 +542,17 @@ public class ApkLiteParseUtils {

                int minVer = DEFAULT_MIN_SDK_VERSION;
                String minCode = null;
                boolean minAssigned = false;
                int targetVer = DEFAULT_TARGET_SDK_VERSION;
                String targetCode = null;

                if (!TextUtils.isEmpty(minSdkVersionString)) {
                    try {
                        minVer = Integer.parseInt(minSdkVersionString);
                        minAssigned = true;
                    } catch (NumberFormatException ignored) {
                        minCode = minSdkVersionString;
                        minAssigned = !TextUtils.isEmpty(minCode);
                    }
                }

@@ -558,7 +561,7 @@ public class ApkLiteParseUtils {
                        targetVer = Integer.parseInt(targetSdkVersionString);
                    } catch (NumberFormatException ignored) {
                        targetCode = targetSdkVersionString;
                        if (minCode == null) {
                        if (!minAssigned) {
                            minCode = targetCode;
                        }
                    }
+4 −1
Original line number Diff line number Diff line
@@ -1540,6 +1540,7 @@ public class ParsingPackageUtils {
            try {
                int minVers = ParsingUtils.DEFAULT_MIN_SDK_VERSION;
                String minCode = null;
                boolean minAssigned = false;
                int targetVers = ParsingUtils.DEFAULT_TARGET_SDK_VERSION;
                String targetCode = null;
                int maxVers = Integer.MAX_VALUE;
@@ -1548,9 +1549,11 @@ public class ParsingPackageUtils {
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        minCode = val.string.toString();
                        minAssigned = !TextUtils.isEmpty(minCode);
                    } else {
                        // If it's not a string, it's an integer.
                        minVers = val.data;
                        minAssigned = true;
                    }
                }

@@ -1558,7 +1561,7 @@ public class ParsingPackageUtils {
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = val.string.toString();
                        if (minCode == null) {
                        if (!minAssigned) {
                            minCode = targetCode;
                        }
                    } else {