1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.content.pm.parsing.component;
18 
19 import static android.content.pm.parsing.ParsingPackageImpl.sForInternedString;
20 
21 import android.annotation.Nullable;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.text.TextUtils;
25 
26 import com.android.internal.util.DataClass;
27 import com.android.internal.util.Parcelling.BuiltIn.ForInternedString;
28 
29 /** @hide */
30 public class ParsedMainComponent extends ParsedComponent {
31 
32     @Nullable
33     @DataClass.ParcelWith(ForInternedString.class)
34     private String processName;
35     boolean directBootAware;
36     boolean enabled = true;
37     boolean exported;
38     int order;
39 
40     @Nullable
41     String splitName;
42 
ParsedMainComponent()43     public ParsedMainComponent() {
44     }
45 
ParsedMainComponent(ParsedMainComponent other)46     public ParsedMainComponent(ParsedMainComponent other) {
47         super(other);
48         this.processName = other.processName;
49         this.directBootAware = other.directBootAware;
50         this.enabled = other.enabled;
51         this.exported = other.exported;
52         this.order = other.order;
53         this.splitName = other.splitName;
54     }
55 
setProcessName(String processName)56     public ParsedMainComponent setProcessName(String processName) {
57         this.processName = TextUtils.safeIntern(processName);
58         return this;
59     }
60 
setEnabled(boolean enabled)61     public ParsedMainComponent setEnabled(boolean enabled) {
62         this.enabled = enabled;
63         return this;
64     }
65 
66     /**
67      * A main component's name is a class name. This makes code slightly more readable.
68      */
getClassName()69     public String getClassName() {
70         return getName();
71     }
72 
73     @Override
describeContents()74     public int describeContents() {
75         return 0;
76     }
77 
78     @Override
writeToParcel(Parcel dest, int flags)79     public void writeToParcel(Parcel dest, int flags) {
80         super.writeToParcel(dest, flags);
81         sForInternedString.parcel(this.processName, dest, flags);
82         dest.writeBoolean(this.directBootAware);
83         dest.writeBoolean(this.enabled);
84         dest.writeBoolean(this.exported);
85         dest.writeInt(this.order);
86         dest.writeString(this.splitName);
87     }
88 
ParsedMainComponent(Parcel in)89     protected ParsedMainComponent(Parcel in) {
90         super(in);
91         this.processName = sForInternedString.unparcel(in);
92         this.directBootAware = in.readBoolean();
93         this.enabled = in.readBoolean();
94         this.exported = in.readBoolean();
95         this.order = in.readInt();
96         this.splitName = in.readString();
97     }
98 
99     public static final Parcelable.Creator<ParsedMainComponent> CREATOR =
100             new Parcelable.Creator<ParsedMainComponent>() {
101                 @Override
102                 public ParsedMainComponent createFromParcel(Parcel source) {
103                     return new ParsedMainComponent(source);
104                 }
105 
106                 @Override
107                 public ParsedMainComponent[] newArray(int size) {
108                     return new ParsedMainComponent[size];
109                 }
110             };
111 
112     @Nullable
getProcessName()113     public String getProcessName() {
114         return processName;
115     }
116 
isDirectBootAware()117     public boolean isDirectBootAware() {
118         return directBootAware;
119     }
120 
isEnabled()121     public boolean isEnabled() {
122         return enabled;
123     }
124 
isExported()125     public boolean isExported() {
126         return exported;
127     }
128 
getOrder()129     public int getOrder() {
130         return order;
131     }
132 
133     @Nullable
getSplitName()134     public String getSplitName() {
135         return splitName;
136     }
137 
setDirectBootAware(boolean value)138     public ParsedMainComponent setDirectBootAware(boolean value) {
139         directBootAware = value;
140         return this;
141     }
142 
setExported(boolean value)143     public ParsedMainComponent setExported(boolean value) {
144         exported = value;
145         return this;
146     }
147 
setSplitName(@ullable String value)148     public ParsedMainComponent setSplitName(@Nullable String value) {
149         splitName = value;
150         return this;
151     }
152 }
153