Alan Viverette | 3da604b | 2020-06-10 18:34:39 +0000 | [diff] [blame] | 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 | |
| 43 | public ParsedMainComponent() { |
| 44 | } |
| 45 | |
| 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 | |
| 56 | public ParsedMainComponent setProcessName(String processName) { |
| 57 | this.processName = TextUtils.safeIntern(processName); |
| 58 | return this; |
| 59 | } |
| 60 | |
| 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 | */ |
| 69 | public String getClassName() { |
| 70 | return getName(); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int describeContents() { |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 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 | |
| 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 |
| 113 | public String getProcessName() { |
| 114 | return processName; |
| 115 | } |
| 116 | |
| 117 | public boolean isDirectBootAware() { |
| 118 | return directBootAware; |
| 119 | } |
| 120 | |
| 121 | public boolean isEnabled() { |
| 122 | return enabled; |
| 123 | } |
| 124 | |
| 125 | public boolean isExported() { |
| 126 | return exported; |
| 127 | } |
| 128 | |
| 129 | public int getOrder() { |
| 130 | return order; |
| 131 | } |
| 132 | |
| 133 | @Nullable |
| 134 | public String getSplitName() { |
| 135 | return splitName; |
| 136 | } |
| 137 | |
| 138 | public ParsedMainComponent setDirectBootAware(boolean value) { |
| 139 | directBootAware = value; |
| 140 | return this; |
| 141 | } |
| 142 | |
| 143 | public ParsedMainComponent setExported(boolean value) { |
| 144 | exported = value; |
| 145 | return this; |
| 146 | } |
| 147 | |
| 148 | public ParsedMainComponent setSplitName(@Nullable String value) { |
| 149 | splitName = value; |
| 150 | return this; |
| 151 | } |
| 152 | } |