OSDN Git Service

Don't override targetVers with minCode
authorColin Cross <ccross@android.com>
Mon, 18 Jun 2018 18:47:45 +0000 (11:47 -0700)
committerColin Cross <ccross@android.com>
Mon, 18 Jun 2018 19:58:11 +0000 (12:58 -0700)
If a package contains minSdkVersion="Q" targetSdkVersion="25",
targetCode will be initialized to "Q" when reading minCode,
but targetVers will be set to "25".  targetCode overrides
targetVers, so this results in the computed targetSdkVersion
being "Q".  If minSdkVersion were instead "28", the computed
targetSdkVersion would be "Q".

Make the computed targetSdkVersion consistent by leaving
targetCode and targetVers unset while parsing minSdkVersion,
and then setting them to minCode and minVers if there is
no targetSdkVersion attribute.

Bug: 110167203
Bug: 110353795
Test: install DeviceHealthChecks, verify targetSdk=25
Change-Id: I9547e9b4720543f0c892cbf4de92888c8eead44f

core/java/android/content/pm/PackageParser.java

index 0e74d9e..a22f6d6 100644 (file)
@@ -96,8 +96,8 @@ import com.android.internal.util.ArrayUtils;
 import com.android.internal.util.XmlUtils;
 
 import libcore.io.IoUtils;
-
 import libcore.util.EmptyArray;
+
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -2340,10 +2340,10 @@ public class PackageParser {
                             com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
                     if (val != null) {
                         if (val.type == TypedValue.TYPE_STRING && val.string != null) {
-                            targetCode = minCode = val.string.toString();
+                            minCode = val.string.toString();
                         } else {
                             // If it's not a string, it's an integer.
-                            targetVers = minVers = val.data;
+                            minVers = val.data;
                         }
                     }
 
@@ -2359,6 +2359,9 @@ public class PackageParser {
                             // If it's not a string, it's an integer.
                             targetVers = val.data;
                         }
+                    } else {
+                        targetVers = minVers;
+                        targetCode = minCode;
                     }
 
                     sa.recycle();