Convert Integer/Float/Boolean to primitive types

In order to avoid unnecessary auto-boxing/unboxing, these fields to
primitive types in the parsed components.

Fix: 197579270
Test: atest -p core/java/android/content/pm \
        services/core/java/com/android/server/pm
Change-Id: I91a61b38ccbb7242f12859d1db298c3262254a63
This commit is contained in:
Jackal Guo
2021-08-24 10:02:10 +08:00
parent 026512d21d
commit ee5b44c889
9 changed files with 37 additions and 28 deletions

View File

@@ -2097,7 +2097,7 @@ public class ParsingPackageUtils {
pkg.setGwpAsanMode(sa.getInt(R.styleable.AndroidManifestApplication_gwpAsanMode, -1));
pkg.setMemtagMode(sa.getInt(R.styleable.AndroidManifestApplication_memtagMode, -1));
if (sa.hasValue(R.styleable.AndroidManifestApplication_nativeHeapZeroInitialized)) {
Boolean v = sa.getBoolean(
final boolean v = sa.getBoolean(
R.styleable.AndroidManifestApplication_nativeHeapZeroInitialized, false);
pkg.setNativeHeapZeroInitialized(
v ? ApplicationInfo.ZEROINIT_ENABLED : ApplicationInfo.ZEROINIT_DISABLED);

View File

@@ -41,6 +41,8 @@ public class ParsingUtils {
public static final int DEFAULT_MIN_SDK_VERSION = 1;
public static final int DEFAULT_TARGET_SDK_VERSION = 0;
public static final int NOT_SET = -1;
@Nullable
public static String buildClassName(String pkg, CharSequence clsSeq) {
if (clsSeq == null || clsSeq.length() <= 0) {

View File

@@ -18,6 +18,7 @@ package android.content.pm.parsing.component;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE_PER_TASK;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
import static android.content.pm.parsing.ParsingUtils.NOT_SET;
import static android.content.pm.parsing.component.ComponentParseUtils.flag;
import android.annotation.NonNull;
@@ -269,15 +270,15 @@ public class ParsedActivityUtils {
activity, tag, null, pkg, sa, 0, useRoundIcon, input,
R.styleable.AndroidManifestActivityAlias_banner,
R.styleable.AndroidManifestActivityAlias_description,
null /*directBootAwareAttr*/,
NOT_SET /*directBootAwareAttr*/,
R.styleable.AndroidManifestActivityAlias_enabled,
R.styleable.AndroidManifestActivityAlias_icon,
R.styleable.AndroidManifestActivityAlias_label,
R.styleable.AndroidManifestActivityAlias_logo,
R.styleable.AndroidManifestActivityAlias_name,
null /*processAttr*/,
NOT_SET /*processAttr*/,
R.styleable.AndroidManifestActivityAlias_roundIcon,
null /*splitNameAttr*/,
NOT_SET /*splitNameAttr*/,
R.styleable.AndroidManifestActivityAlias_attributionTags);
if (result.isError()) {
return result;

View File

@@ -16,8 +16,9 @@
package android.content.pm.parsing.component;
import static android.content.pm.parsing.ParsingUtils.NOT_SET;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.Property;
import android.content.pm.parsing.ParsingPackage;
@@ -41,9 +42,8 @@ class ParsedComponentUtils {
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
static <Component extends ParsedComponent> ParseResult<Component> parseComponent(
Component component, String tag, ParsingPackage pkg, TypedArray array,
boolean useRoundIcon, ParseInput input, int bannerAttr,
@Nullable Integer descriptionAttr, int iconAttr, int labelAttr, int logoAttr,
int nameAttr, int roundIconAttr) {
boolean useRoundIcon, ParseInput input, int bannerAttr, int descriptionAttr,
int iconAttr, int labelAttr, int logoAttr, int nameAttr, int roundIconAttr) {
String name = array.getNonConfigurationString(nameAttr, 0);
if (TextUtils.isEmpty(name)) {
return input.error(tag + " does not specify android:name");
@@ -81,7 +81,7 @@ class ParsedComponentUtils {
component.setBanner(bannerVal);
}
if (descriptionAttr != null) {
if (descriptionAttr != NOT_SET) {
component.setDescriptionRes(array.getResourceId(descriptionAttr, 0));
}

View File

@@ -16,15 +16,17 @@
package android.content.pm.parsing.component;
import static android.content.pm.parsing.ParsingUtils.NOT_SET;
import android.annotation.NonNull;
import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.result.ParseInput;
import android.content.pm.parsing.result.ParseResult;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import com.android.internal.R;
import android.content.pm.parsing.result.ParseInput;
import android.content.pm.parsing.result.ParseResult;
import org.xmlpull.v1.XmlPullParserException;
@@ -46,7 +48,7 @@ public class ParsedInstrumentationUtils {
ParseResult<ParsedInstrumentation> result = ParsedComponentUtils.parseComponent(
instrumentation, tag, pkg, sa, useRoundIcon, input,
R.styleable.AndroidManifestInstrumentation_banner,
null /*descriptionAttr*/,
NOT_SET /*descriptionAttr*/,
R.styleable.AndroidManifestInstrumentation_icon,
R.styleable.AndroidManifestInstrumentation_label,
R.styleable.AndroidManifestInstrumentation_logo,

View File

@@ -16,8 +16,9 @@
package android.content.pm.parsing.component;
import static android.content.pm.parsing.ParsingUtils.NOT_SET;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.IntentFilter;
import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.ParsingUtils;
@@ -45,11 +46,10 @@ class ParsedMainComponentUtils {
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
static <Component extends ParsedMainComponent> ParseResult<Component> parseMainComponent(
Component component, String tag, String[] separateProcesses, ParsingPackage pkg,
TypedArray array, int flags, boolean useRoundIcon, ParseInput input,
int bannerAttr, int descriptionAttr, @Nullable Integer directBootAwareAttr,
@Nullable Integer enabledAttr, int iconAttr, int labelAttr, int logoAttr, int nameAttr,
@Nullable Integer processAttr, int roundIconAttr, @Nullable Integer splitNameAttr,
@Nullable Integer attributionTagsAttr) {
TypedArray array, int flags, boolean useRoundIcon, ParseInput input, int bannerAttr,
int descriptionAttr, int directBootAwareAttr, int enabledAttr, int iconAttr,
int labelAttr, int logoAttr, int nameAttr, int processAttr, int roundIconAttr,
int splitNameAttr, int attributionTagsAttr) {
ParseResult<Component> result = ParsedComponentUtils.parseComponent(component, tag, pkg,
array, useRoundIcon, input, bannerAttr, descriptionAttr, iconAttr, labelAttr,
logoAttr, nameAttr, roundIconAttr);
@@ -57,18 +57,18 @@ class ParsedMainComponentUtils {
return result;
}
if (directBootAwareAttr != null) {
if (directBootAwareAttr != NOT_SET) {
component.setDirectBootAware(array.getBoolean(directBootAwareAttr, false));
if (component.isDirectBootAware()) {
pkg.setPartiallyDirectBootAware(true);
}
}
if (enabledAttr != null) {
if (enabledAttr != NOT_SET) {
component.setEnabled(array.getBoolean(enabledAttr, true));
}
if (processAttr != null) {
if (processAttr != NOT_SET) {
CharSequence processName;
if (pkg.getTargetSdkVersion() >= Build.VERSION_CODES.FROYO) {
processName = array.getNonConfigurationString(processAttr,
@@ -91,11 +91,11 @@ class ParsedMainComponentUtils {
component.setProcessName(processNameResult.getResult());
}
if (splitNameAttr != null) {
if (splitNameAttr != NOT_SET) {
component.setSplitName(array.getNonConfigurationString(splitNameAttr, 0));
}
if (attributionTagsAttr != null) {
if (attributionTagsAttr != NOT_SET) {
final String attributionTags = array.getNonConfigurationString(attributionTagsAttr, 0);
if (attributionTags != null) {
component.setAttributionTags(attributionTags.split("\\|"));

View File

@@ -16,6 +16,8 @@
package android.content.pm.parsing.component;
import static android.content.pm.parsing.ParsingUtils.NOT_SET;
import android.annotation.NonNull;
import android.content.pm.PermissionInfo;
import android.content.pm.parsing.ParsingPackage;
@@ -163,7 +165,7 @@ public class ParsedPermissionUtils {
result = ParsedComponentUtils.parseComponent(
permission, tag, pkg, sa, useRoundIcon, input,
R.styleable.AndroidManifestPermissionTree_banner,
null /*descriptionAttr*/,
NOT_SET /*descriptionAttr*/,
R.styleable.AndroidManifestPermissionTree_icon,
R.styleable.AndroidManifestPermissionTree_label,
R.styleable.AndroidManifestPermissionTree_logo,

View File

@@ -101,7 +101,7 @@ public class ParsedProcessUtils {
proc.setGwpAsanMode(sa.getInt(R.styleable.AndroidManifestProcess_gwpAsanMode, -1));
proc.setMemtagMode(sa.getInt(R.styleable.AndroidManifestProcess_memtagMode, -1));
if (sa.hasValue(R.styleable.AndroidManifestProcess_nativeHeapZeroInitialized)) {
Boolean v = sa.getBoolean(
final boolean v = sa.getBoolean(
R.styleable.AndroidManifestProcess_nativeHeapZeroInitialized, false);
proc.setNativeHeapZeroInitialized(
v ? ApplicationInfo.ZEROINIT_ENABLED : ApplicationInfo.ZEROINIT_DISABLED);

View File

@@ -16,6 +16,8 @@
package android.content.pm.parsing.result;
import static android.content.pm.parsing.ParsingUtils.NOT_SET;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
@@ -62,7 +64,7 @@ public class ParseTypeImpl implements ParseInput, ParseResult<Object> {
private ArrayMap<Long, String> mDeferredErrors = null;
private String mPackageName;
private Integer mTargetSdkVersion;
private int mTargetSdkVersion = NOT_SET;
/**
* Specifically for {@link PackageManager#getPackageArchiveInfo(String, int)} where
@@ -119,7 +121,7 @@ public class ParseTypeImpl implements ParseInput, ParseResult<Object> {
// how many APKs they're going through.
mDeferredErrors.erase();
}
mTargetSdkVersion = null;
mTargetSdkVersion = NOT_SET;
return this;
}
@@ -139,7 +141,7 @@ public class ParseTypeImpl implements ParseInput, ParseResult<Object> {
if (DEBUG_THROW_ALL_ERRORS) {
return error(parseError);
}
if (mTargetSdkVersion != null) {
if (mTargetSdkVersion != NOT_SET) {
if (mDeferredErrors != null && mDeferredErrors.containsKey(deferredError)) {
// If the map already contains the key, that means it's already been checked and
// found to be disabled. Otherwise it would've failed when mTargetSdkVersion was