1 /*
2  * Copyright (C) 2022 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.safetycenter;
18 
19 import static android.os.Build.VERSION_CODES.TIRAMISU;
20 
21 import static java.util.Collections.unmodifiableList;
22 import static java.util.Objects.requireNonNull;
23 
24 import android.annotation.NonNull;
25 import android.annotation.SystemApi;
26 import android.os.Parcel;
27 import android.os.Parcelable;
28 import android.text.TextUtils;
29 
30 import androidx.annotation.RequiresApi;
31 
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Objects;
35 
36 /**
37  * A group of related {@link SafetyCenterStaticEntry} objects in the Safety Center.
38  *
39  * @hide
40  */
41 @SystemApi
42 @RequiresApi(TIRAMISU)
43 public final class SafetyCenterStaticEntryGroup implements Parcelable {
44 
45     @NonNull
46     public static final Creator<SafetyCenterStaticEntryGroup> CREATOR =
47             new Creator<SafetyCenterStaticEntryGroup>() {
48                 @Override
49                 public SafetyCenterStaticEntryGroup createFromParcel(Parcel source) {
50                     CharSequence title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
51                     List<SafetyCenterStaticEntry> staticEntries =
52                             source.createTypedArrayList(SafetyCenterStaticEntry.CREATOR);
53                     return new SafetyCenterStaticEntryGroup(title, staticEntries);
54                 }
55 
56                 @Override
57                 public SafetyCenterStaticEntryGroup[] newArray(int size) {
58                     return new SafetyCenterStaticEntryGroup[size];
59                 }
60             };
61 
62     @NonNull private final CharSequence mTitle;
63     @NonNull private final List<SafetyCenterStaticEntry> mStaticEntries;
64 
65     /** Creates a {@link SafetyCenterStaticEntryGroup} with the given title and entries. */
SafetyCenterStaticEntryGroup( @onNull CharSequence title, @NonNull List<SafetyCenterStaticEntry> staticEntries)66     public SafetyCenterStaticEntryGroup(
67             @NonNull CharSequence title, @NonNull List<SafetyCenterStaticEntry> staticEntries) {
68         mTitle = requireNonNull(title);
69         mStaticEntries = unmodifiableList(new ArrayList<>(requireNonNull(staticEntries)));
70     }
71 
72     /** Returns the title that describes this entry group. */
73     @NonNull
getTitle()74     public CharSequence getTitle() {
75         return mTitle;
76     }
77 
78     /** Returns the entries that comprise this entry group. */
79     @NonNull
getStaticEntries()80     public List<SafetyCenterStaticEntry> getStaticEntries() {
81         return mStaticEntries;
82     }
83 
84     @Override
equals(Object o)85     public boolean equals(Object o) {
86         if (this == o) return true;
87         if (!(o instanceof SafetyCenterStaticEntryGroup)) return false;
88         SafetyCenterStaticEntryGroup that = (SafetyCenterStaticEntryGroup) o;
89         return TextUtils.equals(mTitle, that.mTitle)
90                 && Objects.equals(mStaticEntries, that.mStaticEntries);
91     }
92 
93     @Override
hashCode()94     public int hashCode() {
95         return Objects.hash(mTitle, mStaticEntries);
96     }
97 
98     @Override
toString()99     public String toString() {
100         return "SafetyCenterStaticEntryGroup{"
101                 + "mTitle="
102                 + mTitle
103                 + ", mStaticEntries="
104                 + mStaticEntries
105                 + '}';
106     }
107 
108     @Override
describeContents()109     public int describeContents() {
110         return 0;
111     }
112 
113     @Override
writeToParcel(@onNull Parcel dest, int flags)114     public void writeToParcel(@NonNull Parcel dest, int flags) {
115         TextUtils.writeToParcel(mTitle, dest, flags);
116         dest.writeTypedList(mStaticEntries);
117     }
118 }
119