1 /*
2  * Copyright (C) 2023 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 com.android.server.pm.pkg;
18 
19 import android.annotation.CurrentTimeMillisLong;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.content.ComponentName;
23 
24 import com.android.internal.util.AnnotationValidations;
25 import com.android.internal.util.DataClass;
26 
27 import java.nio.file.Path;
28 import java.util.List;
29 
30 /**
31  * Information about the state of an archived app. All fields are gathered at the time of
32  * archival.
33  *
34  * @hide
35  */
36 @DataClass(genEqualsHashCode = true, genToString = true)
37 public class ArchiveState {
38 
39     /**
40      * Information about main activities.
41      *
42      * <p> This list has at least one entry. In the vast majority of cases, this list has only one
43      * entry.
44      */
45     @NonNull
46     private final List<ArchiveActivityInfo> mActivityInfos;
47 
48     /**
49      * Corresponds to android:label of the installer responsible for the unarchival of the app.
50      * Stored in the installer's locale .
51      */
52     @NonNull
53     private final String mInstallerTitle;
54 
55     /**
56      * The time at which the app was archived for the user.  Units are as per
57      * {@link System#currentTimeMillis()}.
58      */
59     private final @CurrentTimeMillisLong long mArchiveTimeMillis;
60 
61     /**
62      * Creates a new ArchiveState.
63      *
64      * @param activityInfos
65      *   Information about main activities.
66      *
67      *   <p> This list has at least one entry. In the vast majority of cases, this list has only one
68      *   entry.
69      * @param installerTitle
70      *   Corresponds to android:label of the installer responsible for the unarchival of the app.
71      *   Stored in the installer's locale .*
72      */
ArchiveState( @onNull List<ArchiveActivityInfo> activityInfos, @NonNull String installerTitle)73     public ArchiveState(
74             @NonNull List<ArchiveActivityInfo> activityInfos,
75             @NonNull String installerTitle) {
76         this(activityInfos, installerTitle, System.currentTimeMillis());
77     }
78 
79 
80     /**
81      * Information about a main activity of an archived app.
82      */
83     @DataClass(genEqualsHashCode = true, genToString = true)
84     public static class ArchiveActivityInfo {
85         /**
86          * Corresponds to the activity's android:label in the app's locale.
87          */
88         @NonNull
89         private final String mTitle;
90 
91         /**
92          * The component name of the original activity (pre-archival).
93          */
94         @NonNull
95         private final ComponentName mOriginalComponentName;
96 
97         /**
98          * The path to the stored icon of the activity in the app's locale. Null if the app does
99          * not define any icon (default icon would be shown on the launcher).
100          */
101         @Nullable
102         private final Path mIconBitmap;
103 
104         /**
105          * See {@link #mIconBitmap}. Only set if the app defined a monochrome icon.
106          */
107         @Nullable
108         private final Path mMonochromeIconBitmap;
109 
110 
111 
112         // Code below generated by codegen v1.0.23.
113         //
114         // DO NOT MODIFY!
115         // CHECKSTYLE:OFF Generated code
116         //
117         // To regenerate run:
118         // $ codegen $ANDROID_BUILD_TOP/frameworks/base/services/core/java/com/android/server/pm/pkg/ArchiveState.java
119         //
120         // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
121         //   Settings > Editor > Code Style > Formatter Control
122         //@formatter:off
123 
124 
125         /**
126          * Creates a new ArchiveActivityInfo.
127          *
128          * @param title
129          *   Corresponds to the activity's android:label in the app's locale.
130          * @param originalComponentName
131          *   The component name of the original activity (pre-archival).
132          * @param iconBitmap
133          *   The path to the stored icon of the activity in the app's locale. Null if the app does
134          *   not define any icon (default icon would be shown on the launcher).
135          * @param monochromeIconBitmap
136          *   See {@link #mIconBitmap}. Only set if the app defined a monochrome icon.
137          */
138         @DataClass.Generated.Member
ArchiveActivityInfo( @onNull String title, @NonNull ComponentName originalComponentName, @Nullable Path iconBitmap, @Nullable Path monochromeIconBitmap)139         public ArchiveActivityInfo(
140                 @NonNull String title,
141                 @NonNull ComponentName originalComponentName,
142                 @Nullable Path iconBitmap,
143                 @Nullable Path monochromeIconBitmap) {
144             this.mTitle = title;
145             AnnotationValidations.validate(
146                     NonNull.class, null, mTitle);
147             this.mOriginalComponentName = originalComponentName;
148             AnnotationValidations.validate(
149                     NonNull.class, null, mOriginalComponentName);
150             this.mIconBitmap = iconBitmap;
151             this.mMonochromeIconBitmap = monochromeIconBitmap;
152 
153             // onConstructed(); // You can define this method to get a callback
154         }
155 
156         /**
157          * Corresponds to the activity's android:label in the app's locale.
158          */
159         @DataClass.Generated.Member
getTitle()160         public @NonNull String getTitle() {
161             return mTitle;
162         }
163 
164         /**
165          * The component name of the original activity (pre-archival).
166          */
167         @DataClass.Generated.Member
getOriginalComponentName()168         public @NonNull ComponentName getOriginalComponentName() {
169             return mOriginalComponentName;
170         }
171 
172         /**
173          * The path to the stored icon of the activity in the app's locale. Null if the app does
174          * not define any icon (default icon would be shown on the launcher).
175          */
176         @DataClass.Generated.Member
getIconBitmap()177         public @Nullable Path getIconBitmap() {
178             return mIconBitmap;
179         }
180 
181         /**
182          * See {@link #mIconBitmap}. Only set if the app defined a monochrome icon.
183          */
184         @DataClass.Generated.Member
getMonochromeIconBitmap()185         public @Nullable Path getMonochromeIconBitmap() {
186             return mMonochromeIconBitmap;
187         }
188 
189         @Override
190         @DataClass.Generated.Member
toString()191         public String toString() {
192             // You can override field toString logic by defining methods like:
193             // String fieldNameToString() { ... }
194 
195             return "ArchiveActivityInfo { " +
196                     "title = " + mTitle + ", " +
197                     "originalComponentName = " + mOriginalComponentName + ", " +
198                     "iconBitmap = " + mIconBitmap + ", " +
199                     "monochromeIconBitmap = " + mMonochromeIconBitmap +
200             " }";
201         }
202 
203         @Override
204         @DataClass.Generated.Member
equals(@ullable Object o)205         public boolean equals(@Nullable Object o) {
206             // You can override field equality logic by defining either of the methods like:
207             // boolean fieldNameEquals(ArchiveActivityInfo other) { ... }
208             // boolean fieldNameEquals(FieldType otherValue) { ... }
209 
210             if (this == o) return true;
211             if (o == null || getClass() != o.getClass()) return false;
212             @SuppressWarnings("unchecked")
213             ArchiveActivityInfo that = (ArchiveActivityInfo) o;
214             //noinspection PointlessBooleanExpression
215             return true
216                     && java.util.Objects.equals(mTitle, that.mTitle)
217                     && java.util.Objects.equals(mOriginalComponentName, that.mOriginalComponentName)
218                     && java.util.Objects.equals(mIconBitmap, that.mIconBitmap)
219                     && java.util.Objects.equals(mMonochromeIconBitmap, that.mMonochromeIconBitmap);
220         }
221 
222         @Override
223         @DataClass.Generated.Member
hashCode()224         public int hashCode() {
225             // You can override field hashCode logic by defining methods like:
226             // int fieldNameHashCode() { ... }
227 
228             int _hash = 1;
229             _hash = 31 * _hash + java.util.Objects.hashCode(mTitle);
230             _hash = 31 * _hash + java.util.Objects.hashCode(mOriginalComponentName);
231             _hash = 31 * _hash + java.util.Objects.hashCode(mIconBitmap);
232             _hash = 31 * _hash + java.util.Objects.hashCode(mMonochromeIconBitmap);
233             return _hash;
234         }
235 
236         @DataClass.Generated(
237                 time = 1701471309832L,
238                 codegenVersion = "1.0.23",
239                 sourceFile = "frameworks/base/services/core/java/com/android/server/pm/pkg/ArchiveState.java",
240                 inputSignatures = "private final @android.annotation.NonNull java.lang.String mTitle\nprivate final @android.annotation.NonNull android.content.ComponentName mOriginalComponentName\nprivate final @android.annotation.Nullable java.nio.file.Path mIconBitmap\nprivate final @android.annotation.Nullable java.nio.file.Path mMonochromeIconBitmap\nclass ArchiveActivityInfo extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true)")
241         @Deprecated
__metadata()242         private void __metadata() {}
243 
244 
245         //@formatter:on
246         // End of generated code
247 
248     }
249 
250 
251 
252 
253 
254     // Code below generated by codegen v1.0.23.
255     //
256     // DO NOT MODIFY!
257     // CHECKSTYLE:OFF Generated code
258     //
259     // To regenerate run:
260     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/services/core/java/com/android/server/pm/pkg/ArchiveState.java
261     //
262     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
263     //   Settings > Editor > Code Style > Formatter Control
264     //@formatter:off
265 
266 
267     /**
268      * Creates a new ArchiveState.
269      *
270      * @param activityInfos
271      *   Information about main activities.
272      *
273      *   <p> This list has at least one entry. In the vast majority of cases, this list has only one
274      *   entry.
275      * @param installerTitle
276      *   Corresponds to android:label of the installer responsible for the unarchival of the app.
277      *   Stored in the installer's locale .
278      * @param archiveTimeMillis
279      *   The time at which the app was archived for the user.  Units are as per
280      *   {@link System#currentTimeMillis()}.
281      */
282     @DataClass.Generated.Member
ArchiveState( @onNull List<ArchiveActivityInfo> activityInfos, @NonNull String installerTitle, @CurrentTimeMillisLong long archiveTimeMillis)283     public ArchiveState(
284             @NonNull List<ArchiveActivityInfo> activityInfos,
285             @NonNull String installerTitle,
286             @CurrentTimeMillisLong long archiveTimeMillis) {
287         this.mActivityInfos = activityInfos;
288         AnnotationValidations.validate(
289                 NonNull.class, null, mActivityInfos);
290         this.mInstallerTitle = installerTitle;
291         AnnotationValidations.validate(
292                 NonNull.class, null, mInstallerTitle);
293         this.mArchiveTimeMillis = archiveTimeMillis;
294         AnnotationValidations.validate(
295                 CurrentTimeMillisLong.class, null, mArchiveTimeMillis);
296 
297         // onConstructed(); // You can define this method to get a callback
298     }
299 
300     /**
301      * Information about main activities.
302      *
303      * <p> This list has at least one entry. In the vast majority of cases, this list has only one
304      * entry.
305      */
306     @DataClass.Generated.Member
getActivityInfos()307     public @NonNull List<ArchiveActivityInfo> getActivityInfos() {
308         return mActivityInfos;
309     }
310 
311     /**
312      * Corresponds to android:label of the installer responsible for the unarchival of the app.
313      * Stored in the installer's locale .
314      */
315     @DataClass.Generated.Member
getInstallerTitle()316     public @NonNull String getInstallerTitle() {
317         return mInstallerTitle;
318     }
319 
320     /**
321      * The time at which the app was archived for the user.  Units are as per
322      * {@link System#currentTimeMillis()}.
323      */
324     @DataClass.Generated.Member
getArchiveTimeMillis()325     public @CurrentTimeMillisLong long getArchiveTimeMillis() {
326         return mArchiveTimeMillis;
327     }
328 
329     @Override
330     @DataClass.Generated.Member
toString()331     public String toString() {
332         // You can override field toString logic by defining methods like:
333         // String fieldNameToString() { ... }
334 
335         return "ArchiveState { " +
336                 "activityInfos = " + mActivityInfos + ", " +
337                 "installerTitle = " + mInstallerTitle + ", " +
338                 "archiveTimeMillis = " + mArchiveTimeMillis +
339         " }";
340     }
341 
342     @Override
343     @DataClass.Generated.Member
equals(@ullable Object o)344     public boolean equals(@Nullable Object o) {
345         // You can override field equality logic by defining either of the methods like:
346         // boolean fieldNameEquals(ArchiveState other) { ... }
347         // boolean fieldNameEquals(FieldType otherValue) { ... }
348 
349         if (this == o) return true;
350         if (o == null || getClass() != o.getClass()) return false;
351         @SuppressWarnings("unchecked")
352         ArchiveState that = (ArchiveState) o;
353         //noinspection PointlessBooleanExpression
354         return true
355                 && java.util.Objects.equals(mActivityInfos, that.mActivityInfos)
356                 && java.util.Objects.equals(mInstallerTitle, that.mInstallerTitle)
357                 && mArchiveTimeMillis == that.mArchiveTimeMillis;
358     }
359 
360     @Override
361     @DataClass.Generated.Member
hashCode()362     public int hashCode() {
363         // You can override field hashCode logic by defining methods like:
364         // int fieldNameHashCode() { ... }
365 
366         int _hash = 1;
367         _hash = 31 * _hash + java.util.Objects.hashCode(mActivityInfos);
368         _hash = 31 * _hash + java.util.Objects.hashCode(mInstallerTitle);
369         _hash = 31 * _hash + Long.hashCode(mArchiveTimeMillis);
370         return _hash;
371     }
372 
373     @DataClass.Generated(
374             time = 1701471309853L,
375             codegenVersion = "1.0.23",
376             sourceFile = "frameworks/base/services/core/java/com/android/server/pm/pkg/ArchiveState.java",
377             inputSignatures = "private final @android.annotation.NonNull java.util.List<com.android.server.pm.pkg.ArchiveActivityInfo> mActivityInfos\nprivate final @android.annotation.NonNull java.lang.String mInstallerTitle\nprivate final @android.annotation.CurrentTimeMillisLong long mArchiveTimeMillis\nclass ArchiveState extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true)")
378     @Deprecated
__metadata()379     private void __metadata() {}
380 
381 
382     //@formatter:on
383     // End of generated code
384 
385 }
386