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

Commit 7c5169e3 authored by Winson's avatar Winson
Browse files

Split ParsedComponentImpl

Bug: 178218967

Change-Id: Id23554d153b312dce91871b5b45967a7377a3093
parent df08d493
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class ComponentParseUtils {
                || intentInfo.hasAction(Intent.ACTION_SEND_MULTIPLE);
    }

    static <Component extends ParsedComponent> ParseResult<Component> parseAllMetaData(
    static <Component extends ParsedComponentImpl> ParseResult<Component> parseAllMetaData(
            ParsingPackage pkg, Resources res, XmlResourceParser parser, String tag,
            Component component, ParseInput input) throws XmlPullParserException, IOException {
        final int depth = parser.getDepth();
+9 −9
Original line number Diff line number Diff line
@@ -145,17 +145,17 @@ public class ParsedActivity extends ParsedMainComponent {
        alias.setPackageName(target.getPackageName());
        alias.setTargetActivity(targetActivityName);
        alias.configChanges = target.configChanges;
        alias.flags = target.flags;
        alias.setFlags(target.getFlags());
        alias.privateFlags = target.privateFlags;
        alias.icon = target.icon;
        alias.logo = target.logo;
        alias.banner = target.banner;
        alias.labelRes = target.labelRes;
        alias.nonLocalizedLabel = target.nonLocalizedLabel;
        alias.setIcon(target.getIcon());
        alias.setLogo(target.getLogo());
        alias.setBanner(target.getBanner());
        alias.setLabelRes(target.getLabelRes());
        alias.setNonLocalizedLabel(target.getNonLocalizedLabel());
        alias.launchMode = target.launchMode;
        alias.lockTaskLaunchMode = target.lockTaskLaunchMode;
        alias.documentLaunchMode = target.documentLaunchMode;
        alias.descriptionRes = target.descriptionRes;
        alias.setDescriptionRes(target.getDescriptionRes());
        alias.screenOrientation = target.screenOrientation;
        alias.taskAffinity = target.taskAffinity;
        alias.theme = target.theme;
@@ -379,7 +379,7 @@ public class ParsedActivity extends ParsedMainComponent {
        dest.writeString(this.requestedVrComponent);
        dest.writeInt(this.rotationAnimation);
        dest.writeInt(this.colorMode);
        dest.writeBundle(this.metaData);
        dest.writeBundle(this.getMetaData());

        if (windowLayout != null) {
            dest.writeInt(1);
@@ -416,7 +416,7 @@ public class ParsedActivity extends ParsedMainComponent {
        this.requestedVrComponent = in.readString();
        this.rotationAnimation = in.readInt();
        this.colorMode = in.readInt();
        this.metaData = in.readBundle();
        this.setMetaData(in.readBundle());
        if (in.readBoolean()) {
            windowLayout = new ActivityInfo.WindowLayout(in);
        }
+15 −217
Original line number Diff line number Diff line
@@ -16,251 +16,49 @@

package android.content.pm.parsing.component;

import static android.content.pm.parsing.ParsingPackageImpl.sForInternedString;

import static java.util.Collections.emptyMap;

import android.annotation.CallSuper;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.pm.PackageManager.Property;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.android.internal.util.CollectionUtils;
import com.android.internal.util.DataClass;
import com.android.internal.util.Parcelling;
import com.android.internal.util.Parcelling.BuiltIn.ForInternedString;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/** @hide */
public abstract class ParsedComponent implements Parcelable {
public interface ParsedComponent extends Parcelable {

    private static final ParsedIntentInfo.ListParceler sForIntentInfos =
            Parcelling.Cache.getOrCreate(ParsedIntentInfo.ListParceler.class);
    int getBanner();

    @NonNull
    @DataClass.ParcelWith(ForInternedString.class)
    protected String name;
    protected int icon;
    protected int labelRes;
    @Nullable
    protected CharSequence nonLocalizedLabel;
    protected int logo;
    protected int banner;
    protected int descriptionRes;

    // TODO(b/135203078): Replace flags with individual booleans, scoped by subclass
    protected int flags;

    @NonNull
    @DataClass.ParcelWith(ForInternedString.class)
    protected String packageName;

    @Nullable
    @DataClass.PluralOf("intent")
    @DataClass.ParcelWith(ParsedIntentInfo.ListParceler.class)
    protected List<ParsedIntentInfo> intents;

    protected ComponentName componentName;

    @Nullable
    protected Bundle metaData;

    protected Map<String, Property> mProperties = emptyMap();

    ParsedComponent() {

    }

    @SuppressWarnings("IncompleteCopyConstructor")
    public ParsedComponent(ParsedComponent other) {
        this.metaData = other.metaData;
        this.name = other.name;
        this.icon = other.getIcon();
        this.labelRes = other.getLabelRes();
        this.nonLocalizedLabel = other.getNonLocalizedLabel();
        this.logo = other.getLogo();
        this.banner = other.getBanner();

        this.descriptionRes = other.getDescriptionRes();
    ComponentName getComponentName();

        this.flags = other.getFlags();
    int getDescriptionRes();

        this.setPackageName(other.packageName);
        this.intents = new ArrayList<>(other.getIntents());
    }
    int getFlags();

    public void addIntent(ParsedIntentInfo intent) {
        this.intents = CollectionUtils.add(this.intents, intent);
    }

    /** Add a property to the component */
    public void addProperty(@NonNull Property property) {
        this.mProperties = CollectionUtils.add(this.mProperties, property.getName(), property);
    }
    int getIcon();

    @NonNull
    public List<ParsedIntentInfo> getIntents() {
        return intents != null ? intents : Collections.emptyList();
    }

    public ParsedComponent setBanner(int banner) {
        this.banner = banner;
        return this;
    }

    public ParsedComponent setDescriptionRes(int descriptionRes) {
        this.descriptionRes = descriptionRes;
        return this;
    }
    List<ParsedIntentInfo> getIntents();

    public ParsedComponent setFlags(int flags) {
        this.flags = flags;
        return this;
    }
    int getLabelRes();

    public ParsedComponent setIcon(int icon) {
        this.icon = icon;
        return this;
    }
    int getLogo();

    public ParsedComponent setLabelRes(int labelRes) {
        this.labelRes = labelRes;
        return this;
    }

    public ParsedComponent setLogo(int logo) {
        this.logo = logo;
        return this;
    }

    public ParsedComponent setMetaData(Bundle metaData) {
        this.metaData = metaData;
        return this;
    }

    public ParsedComponent setName(String name) {
        this.name = TextUtils.safeIntern(name);
        return this;
    }

    public ParsedComponent setNonLocalizedLabel(CharSequence nonLocalizedLabel) {
        this.nonLocalizedLabel = nonLocalizedLabel;
        return this;
    }

    @CallSuper
    public void setPackageName(@NonNull String packageName) {
        this.packageName = TextUtils.safeIntern(packageName);
        //noinspection ConstantConditions
        this.componentName = null;

        // Note: this method does not edit name (which can point to a class), because this package
        // name change is not changing the package in code, but the identifier used by the system.
    }

    @NonNull
    public ComponentName getComponentName() {
        if (componentName == null) {
            componentName = new ComponentName(getPackageName(), getName());
        }
        return componentName;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeInt(this.getIcon());
        dest.writeInt(this.getLabelRes());
        dest.writeCharSequence(this.getNonLocalizedLabel());
        dest.writeInt(this.getLogo());
        dest.writeInt(this.getBanner());
        dest.writeInt(this.getDescriptionRes());
        dest.writeInt(this.getFlags());
        sForInternedString.parcel(this.packageName, dest, flags);
        sForIntentInfos.parcel(this.getIntents(), dest, flags);
        dest.writeBundle(this.metaData);
        dest.writeMap(this.mProperties);
    }

    protected ParsedComponent(Parcel in) {
        // We use the boot classloader for all classes that we load.
        final ClassLoader boot = Object.class.getClassLoader();
        //noinspection ConstantConditions
        this.name = in.readString();
        this.icon = in.readInt();
        this.labelRes = in.readInt();
        this.nonLocalizedLabel = in.readCharSequence();
        this.logo = in.readInt();
        this.banner = in.readInt();
        this.descriptionRes = in.readInt();
        this.flags = in.readInt();
        //noinspection ConstantConditions
        this.packageName = sForInternedString.unparcel(in);
        this.intents = sForIntentInfos.unparcel(in);
        this.metaData = in.readBundle(boot);
        this.mProperties = in.readHashMap(boot);
    }
    @Nullable
    Bundle getMetaData();

    @NonNull
    public String getName() {
        return name;
    }

    public int getIcon() {
        return icon;
    }

    public int getLabelRes() {
        return labelRes;
    }
    String getName();

    @Nullable
    public CharSequence getNonLocalizedLabel() {
        return nonLocalizedLabel;
    }

    public int getLogo() {
        return logo;
    }

    public int getBanner() {
        return banner;
    }

    public int getDescriptionRes() {
        return descriptionRes;
    }

    public int getFlags() {
        return flags;
    }
    CharSequence getNonLocalizedLabel();

    @NonNull
    public String getPackageName() {
        return packageName;
    }

    @Nullable
    public Bundle getMetaData() {
        return metaData;
    }
    String getPackageName();

    @NonNull
    public Map<String, Property> getProperties() {
        return mProperties;
    }
    Map<String, Property> getProperties();
}
+314 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.content.pm.parsing.component;

import static android.content.pm.parsing.ParsingPackageImpl.sForInternedString;

import static java.util.Collections.emptyMap;

import android.annotation.CallSuper;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.pm.PackageManager.Property;
import android.os.Bundle;
import android.os.Parcel;
import android.text.TextUtils;
import android.util.ArrayMap;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.CollectionUtils;
import com.android.internal.util.DataClass;
import com.android.internal.util.Parcelling;
import com.android.internal.util.Parcelling.BuiltIn.ForInternedString;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/** @hide */
@DataClass(genGetters = true, genSetters = true, genConstructor = false, genBuilder = false)
@DataClass.Suppress({"setComponentName", "setProperties", "setIntents"})
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public abstract class ParsedComponentImpl implements ParsedComponent {

    private static final ParsedIntentInfo.ListParceler sForIntentInfos =
            Parcelling.Cache.getOrCreate(ParsedIntentInfo.ListParceler.class);

    @NonNull
    @DataClass.ParcelWith(ForInternedString.class)
    private String name;
    private int icon;
    private int labelRes;
    @Nullable
    private CharSequence nonLocalizedLabel;
    private int logo;
    private int banner;
    private int descriptionRes;

    // TODO(b/135203078): Replace flags with individual booleans, scoped by subclass
    private int flags;

    @NonNull
    @DataClass.ParcelWith(ForInternedString.class)
    private String packageName;

    @NonNull
    @DataClass.PluralOf("intent")
    @DataClass.ParcelWith(ParsedIntentInfo.ListParceler.class)
    private List<ParsedIntentInfo> intents = Collections.emptyList();

    @Nullable
    private ComponentName componentName;

    @Nullable
    private Bundle metaData;

    @NonNull
    private Map<String, Property> mProperties = emptyMap();

    public ParsedComponentImpl() {

    }

    protected ParsedComponentImpl(ParsedComponentImpl other) {
        this.metaData = other.metaData;
        this.name = other.name;
        this.icon = other.getIcon();
        this.labelRes = other.getLabelRes();
        this.nonLocalizedLabel = other.getNonLocalizedLabel();
        this.logo = other.getLogo();
        this.banner = other.getBanner();
        this.descriptionRes = other.getDescriptionRes();
        this.flags = other.getFlags();
        this.packageName = other.packageName;
        this.componentName = other.componentName;
        this.intents = new ArrayList<>(other.getIntents());
        this.mProperties = new ArrayMap<>();
        this.mProperties.putAll(other.mProperties);
    }

    public void addIntent(ParsedIntentInfo intent) {
        this.intents = CollectionUtils.add(this.intents, intent);
    }

    /** Add a property to the component */
    public void addProperty(@NonNull Property property) {
        this.mProperties = CollectionUtils.add(this.mProperties, property.getName(), property);
    }

    public ParsedComponentImpl setName(String name) {
        this.name = TextUtils.safeIntern(name);
        return this;
    }

    @CallSuper
    public void setPackageName(@NonNull String packageName) {
        this.packageName = TextUtils.safeIntern(packageName);
        //noinspection ConstantConditions
        this.componentName = null;

        // Note: this method does not edit name (which can point to a class), because this package
        // name change is not changing the package in code, but the identifier used by the system.
    }

    @Override
    @NonNull
    public ComponentName getComponentName() {
        if (componentName == null) {
            componentName = new ComponentName(getPackageName(), getName());
        }
        return componentName;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeInt(this.getIcon());
        dest.writeInt(this.getLabelRes());
        dest.writeCharSequence(this.getNonLocalizedLabel());
        dest.writeInt(this.getLogo());
        dest.writeInt(this.getBanner());
        dest.writeInt(this.getDescriptionRes());
        dest.writeInt(this.getFlags());
        sForInternedString.parcel(this.packageName, dest, flags);
        sForIntentInfos.parcel(this.getIntents(), dest, flags);
        dest.writeBundle(this.metaData);
        dest.writeMap(this.mProperties);
    }

    protected ParsedComponentImpl(Parcel in) {
        // We use the boot classloader for all classes that we load.
        final ClassLoader boot = Object.class.getClassLoader();
        //noinspection ConstantConditions
        this.name = in.readString();
        this.icon = in.readInt();
        this.labelRes = in.readInt();
        this.nonLocalizedLabel = in.readCharSequence();
        this.logo = in.readInt();
        this.banner = in.readInt();
        this.descriptionRes = in.readInt();
        this.flags = in.readInt();
        //noinspection ConstantConditions
        this.packageName = sForInternedString.unparcel(in);
        this.intents = sForIntentInfos.unparcel(in);
        this.metaData = in.readBundle(boot);
        this.mProperties = in.readHashMap(boot);
    }



    // Code below generated by codegen v1.0.23.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/component/ParsedComponentImpl.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    @DataClass.Generated.Member
    public @NonNull String getName() {
        return name;
    }

    @DataClass.Generated.Member
    public int getIcon() {
        return icon;
    }

    @DataClass.Generated.Member
    public int getLabelRes() {
        return labelRes;
    }

    @DataClass.Generated.Member
    public @Nullable CharSequence getNonLocalizedLabel() {
        return nonLocalizedLabel;
    }

    @DataClass.Generated.Member
    public int getLogo() {
        return logo;
    }

    @DataClass.Generated.Member
    public int getBanner() {
        return banner;
    }

    @DataClass.Generated.Member
    public int getDescriptionRes() {
        return descriptionRes;
    }

    @DataClass.Generated.Member
    public int getFlags() {
        return flags;
    }

    @DataClass.Generated.Member
    public @NonNull String getPackageName() {
        return packageName;
    }

    @DataClass.Generated.Member
    public @NonNull List<ParsedIntentInfo> getIntents() {
        return intents;
    }

    @DataClass.Generated.Member
    public @Nullable Bundle getMetaData() {
        return metaData;
    }

    @DataClass.Generated.Member
    public @NonNull Map<String,Property> getProperties() {
        return mProperties;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setIcon( int value) {
        icon = value;
        return this;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setLabelRes( int value) {
        labelRes = value;
        return this;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setNonLocalizedLabel(@NonNull CharSequence value) {
        nonLocalizedLabel = value;
        return this;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setLogo( int value) {
        logo = value;
        return this;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setBanner( int value) {
        banner = value;
        return this;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setDescriptionRes( int value) {
        descriptionRes = value;
        return this;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setFlags( int value) {
        flags = value;
        return this;
    }

    @DataClass.Generated.Member
    public @NonNull ParsedComponentImpl setMetaData(@NonNull Bundle value) {
        metaData = value;
        return this;
    }

    @DataClass.Generated(
            time = 1626976992288L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/content/pm/parsing/component/ParsedComponentImpl.java",
            inputSignatures = "private static final  android.content.pm.parsing.component.ParsedIntentInfo.ListParceler sForIntentInfos\nprivate @android.annotation.NonNull @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String name\nprivate  int icon\nprivate  int labelRes\nprivate @android.annotation.Nullable java.lang.CharSequence nonLocalizedLabel\nprivate  int logo\nprivate  int banner\nprivate  int descriptionRes\nprivate  int flags\nprivate @android.annotation.NonNull @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String packageName\nprivate @android.annotation.NonNull @com.android.internal.util.DataClass.PluralOf(\"intent\") @com.android.internal.util.DataClass.ParcelWith(android.content.pm.parsing.component.ParsedIntentInfo.ListParceler.class) java.util.List<android.content.pm.parsing.component.ParsedIntentInfo> intents\nprivate @android.annotation.Nullable android.content.ComponentName componentName\nprivate @android.annotation.Nullable android.os.Bundle metaData\nprivate @android.annotation.NonNull java.util.Map<java.lang.String,android.content.pm.PackageManager.Property> mProperties\npublic  void addIntent(android.content.pm.parsing.component.ParsedIntentInfo)\npublic  void addProperty(android.content.pm.PackageManager.Property)\npublic  android.content.pm.parsing.component.ParsedComponentImpl setName(java.lang.String)\npublic @android.annotation.CallSuper void setPackageName(java.lang.String)\npublic @java.lang.Override @android.annotation.NonNull android.content.ComponentName getComponentName()\npublic @java.lang.Override int describeContents()\npublic @java.lang.Override void writeToParcel(android.os.Parcel,int)\nclass ParsedComponentImpl extends java.lang.Object implements [android.content.pm.parsing.component.ParsedComponent]\n@com.android.internal.util.DataClass(genGetters=true, genSetters=true, genConstructor=false, genBuilder=false)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}
+3 −3
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class ParsedComponentUtils {

    @NonNull
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    static <Component extends ParsedComponent> ParseResult<Component> parseComponent(
    static <Component extends ParsedComponentImpl> ParseResult<Component> parseComponent(
            Component component, String tag, ParsingPackage pkg, TypedArray array,
            boolean useRoundIcon, ParseInput input, int bannerAttr, int descriptionAttr,
            int iconAttr, int labelAttr, int logoAttr, int nameAttr, int roundIconAttr) {
@@ -96,7 +96,7 @@ class ParsedComponentUtils {
        return input.success(component);
    }

    static ParseResult<Bundle> addMetaData(ParsedComponent component, ParsingPackage pkg,
    static ParseResult<Bundle> addMetaData(ParsedComponentImpl component, ParsingPackage pkg,
            Resources resources, XmlResourceParser parser, ParseInput input) {
        ParseResult<Property> result = ParsingPackageUtils.parseMetaData(pkg, component,
                resources, parser, "<meta-data>", input);
@@ -110,7 +110,7 @@ class ParsedComponentUtils {
        return input.success(component.getMetaData());
    }

    static ParseResult<Property> addProperty(ParsedComponent component, ParsingPackage pkg,
    static ParseResult<Property> addProperty(ParsedComponentImpl component, ParsingPackage pkg,
            Resources resources, XmlResourceParser parser, ParseInput input) {
        ParseResult<Property> result = ParsingPackageUtils.parseMetaData(pkg, component,
                resources, parser, "<property>", input);
Loading