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.Objects.requireNonNull;
22 
23 import android.annotation.NonNull;
24 import android.annotation.SystemApi;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 
28 import androidx.annotation.RequiresApi;
29 
30 import java.util.Objects;
31 
32 /**
33  * Details of an error that a Safety Source may report to the Safety Center.
34  *
35  * @hide
36  */
37 @SystemApi
38 @RequiresApi(TIRAMISU)
39 public final class SafetySourceErrorDetails implements Parcelable {
40 
41     @NonNull
42     public static final Creator<SafetySourceErrorDetails> CREATOR =
43             new Creator<SafetySourceErrorDetails>() {
44                 @Override
45                 public SafetySourceErrorDetails createFromParcel(Parcel in) {
46                     SafetyEvent safetyEvent = in.readTypedObject(SafetyEvent.CREATOR);
47                     return new SafetySourceErrorDetails(safetyEvent);
48                 }
49 
50                 @Override
51                 public SafetySourceErrorDetails[] newArray(int size) {
52                     return new SafetySourceErrorDetails[0];
53                 }
54             };
55 
56     @NonNull private final SafetyEvent mSafetyEvent;
57 
SafetySourceErrorDetails(@onNull SafetyEvent safetyEvent)58     public SafetySourceErrorDetails(@NonNull SafetyEvent safetyEvent) {
59         mSafetyEvent = requireNonNull(safetyEvent);
60     }
61 
62     /** Returns the safety event associated with this error. */
63     @NonNull
getSafetyEvent()64     public SafetyEvent getSafetyEvent() {
65         return mSafetyEvent;
66     }
67 
68     @Override
equals(Object o)69     public boolean equals(Object o) {
70         if (this == o) return true;
71         if (!(o instanceof SafetySourceErrorDetails)) return false;
72         SafetySourceErrorDetails that = (SafetySourceErrorDetails) o;
73         return mSafetyEvent.equals(that.mSafetyEvent);
74     }
75 
76     @Override
hashCode()77     public int hashCode() {
78         return Objects.hash(mSafetyEvent);
79     }
80 
81     @Override
toString()82     public String toString() {
83         return "SafetySourceErrorDetails{" + "mSafetyEvent=" + mSafetyEvent + '}';
84     }
85 
86     @Override
describeContents()87     public int describeContents() {
88         return 0;
89     }
90 
91     @Override
writeToParcel(@onNull Parcel dest, int flags)92     public void writeToParcel(@NonNull Parcel dest, int flags) {
93         dest.writeTypedObject(mSafetyEvent, flags);
94     }
95 }
96