1 /*
2  * Copyright (C) 2021 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.om;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import com.android.internal.util.DataClass;
25 
26 import java.util.Objects;
27 
28 /**
29  * A key used to uniquely identify a Runtime Resource Overlay (RRO).
30  * <!-- For applications -->
31  *
32  * <p>An overlay always belongs to a package and have a mandatory name associated with it. The name
33  * helps uniquely identify a particular overlay within a package.
34  *
35  * <!-- For OverlayManagerService, it isn't public part and hidden by HTML comment. -->
36  * <!--
37  * <p>An overlay always belongs to a package and may optionally have a name associated with it. The
38  * name helps uniquely identify a particular overlay within a package.
39  * -->
40  *
41  * @see OverlayInfo#getOverlayIdentifier()
42  * @see OverlayManagerTransaction.Builder#unregisterFabricatedOverlay(OverlayIdentifier)
43  */
44 @DataClass(genConstructor = false, genBuilder = false, genHiddenBuilder = false,
45         genEqualsHashCode = true, genToString = false)
46 public final class OverlayIdentifier implements Parcelable {
47     /**
48      * The package name containing or owning the overlay.
49      *
50      * @hide
51      */
52     @Nullable private final String mPackageName;
53 
54     /**
55      * The unique name within the package of the overlay.
56      *
57      * @hide
58      */
59     @Nullable private final String mOverlayName;
60 
61     /**
62      * Creates an identifier from a package and unique name within the package.
63      *
64      * @param packageName the package containing or owning the overlay
65      * @param overlayName the unique name of the overlay within the package
66      * @hide
67      */
OverlayIdentifier(@onNull String packageName, @Nullable String overlayName)68     public OverlayIdentifier(@NonNull String packageName, @Nullable String overlayName) {
69         mPackageName = packageName;
70         mOverlayName = overlayName;
71     }
72 
73     /**
74      * Creates an identifier for an overlay without a name.
75      *
76      * @param packageName the package containing or owning the overlay
77      * @hide
78      */
OverlayIdentifier(@onNull String packageName)79     public OverlayIdentifier(@NonNull String packageName) {
80         mPackageName = packageName;
81         mOverlayName = null;
82     }
83 
84     /**
85      * {@inheritDoc}
86      * @hide
87      */
88     @Override
toString()89     public String toString() {
90         return mOverlayName == null ? mPackageName : mPackageName + ":" + mOverlayName;
91     }
92 
93     /** @hide */
94     @NonNull
fromString(@onNull String text)95     public static OverlayIdentifier fromString(@NonNull String text) {
96         final String[] parts = text.split(":", 2);
97         if (parts.length == 2) {
98             return new OverlayIdentifier(parts[0], parts[1]);
99         } else {
100             return new OverlayIdentifier(parts[0]);
101         }
102     }
103 
104 
105 
106     // Code below generated by codegen v1.0.23.
107     //
108     // DO NOT MODIFY!
109     // CHECKSTYLE:OFF Generated code
110     //
111     // To regenerate run:
112     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/om/OverlayIdentifier.java
113     //
114     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
115     //   Settings > Editor > Code Style > Formatter Control
116     //@formatter:off
117 
118 
119     /**
120      * Retrieves the package name containing or owning the overlay.
121      *
122      * @hide
123      */
124     @DataClass.Generated.Member
getPackageName()125     public @Nullable String getPackageName() {
126         return mPackageName;
127     }
128 
129     /**
130      * Retrieves the unique name within the package of the overlay.
131      *
132      * @hide
133      */
134     @DataClass.Generated.Member
getOverlayName()135     public @Nullable String getOverlayName() {
136         return mOverlayName;
137     }
138 
139     /**
140      * {@inheritDoc}
141      * @hide
142      */
143     @Override
144     @DataClass.Generated.Member
equals(@ullable Object o)145     public boolean equals(@Nullable Object o) {
146         // You can override field equality logic by defining either of the methods like:
147         // boolean fieldNameEquals(OverlayIdentifier other) { ... }
148         // boolean fieldNameEquals(FieldType otherValue) { ... }
149 
150         if (this == o) return true;
151         if (o == null || getClass() != o.getClass()) return false;
152         @SuppressWarnings("unchecked")
153         OverlayIdentifier that = (OverlayIdentifier) o;
154         //noinspection PointlessBooleanExpression
155         return true
156                 && Objects.equals(mPackageName, that.mPackageName)
157                 && Objects.equals(mOverlayName, that.mOverlayName);
158     }
159 
160     /**
161      * {@inheritDoc}
162      * @hide
163      */
164     @Override
165     @DataClass.Generated.Member
hashCode()166     public int hashCode() {
167         // You can override field hashCode logic by defining methods like:
168         // int fieldNameHashCode() { ... }
169 
170         int _hash = 1;
171         _hash = 31 * _hash + Objects.hashCode(mPackageName);
172         _hash = 31 * _hash + Objects.hashCode(mOverlayName);
173         return _hash;
174     }
175 
176     /**
177      * {@inheritDoc}
178      */
179     @Override
180     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)181     public void writeToParcel(@NonNull Parcel dest, int flags) {
182         // You can override field parcelling by defining methods like:
183         // void parcelFieldName(Parcel dest, int flags) { ... }
184 
185         byte flg = 0;
186         if (mPackageName != null) flg |= 0x1;
187         if (mOverlayName != null) flg |= 0x2;
188         dest.writeByte(flg);
189         if (mPackageName != null) dest.writeString(mPackageName);
190         if (mOverlayName != null) dest.writeString(mOverlayName);
191     }
192 
193     /**
194      * {@inheritDoc}
195      */
196     @Override
197     @DataClass.Generated.Member
describeContents()198     public int describeContents() { return 0; }
199 
200     /** @hide */
201     @SuppressWarnings({"unchecked", "RedundantCast"})
202     @DataClass.Generated.Member
OverlayIdentifier(@onNull Parcel in)203     /* package-private */ OverlayIdentifier(@NonNull Parcel in) {
204         // You can override field unparcelling by defining methods like:
205         // static FieldType unparcelFieldName(Parcel in) { ... }
206 
207         byte flg = in.readByte();
208         String packageName = (flg & 0x1) == 0 ? null : in.readString();
209         String overlayName = (flg & 0x2) == 0 ? null : in.readString();
210 
211         this.mPackageName = packageName;
212         this.mOverlayName = overlayName;
213 
214         // onConstructed(); // You can define this method to get a callback
215     }
216 
217     @DataClass.Generated.Member
218     public static final @NonNull Parcelable.Creator<OverlayIdentifier> CREATOR
219             = new Parcelable.Creator<OverlayIdentifier>() {
220         @Override
221         public OverlayIdentifier[] newArray(int size) {
222             return new OverlayIdentifier[size];
223         }
224 
225         @Override
226         public OverlayIdentifier createFromParcel(@NonNull Parcel in) {
227             return new OverlayIdentifier(in);
228         }
229     };
230 
231     @DataClass.Generated(
232             time = 1670404485646L,
233             codegenVersion = "1.0.23",
234             sourceFile = "frameworks/base/core/java/android/content/om/OverlayIdentifier.java",
235             inputSignatures = "private final @android.annotation.Nullable java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mOverlayName\npublic @java.lang.Override java.lang.String toString()\npublic static @android.annotation.NonNull android.content.om.OverlayIdentifier fromString(java.lang.String)\nclass OverlayIdentifier extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=false, genHiddenBuilder=false, genEqualsHashCode=true, genToString=false)")
236     @Deprecated
__metadata()237     private void __metadata() {}
238 
239 
240     //@formatter:on
241     // End of generated code
242 
243 }
244