• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import android.text.TextUtils;
28 
29 import androidx.annotation.RequiresApi;
30 
31 import java.util.Objects;
32 
33 /**
34  * Details of an error that the Safety Center should display to the user.
35  *
36  * @hide
37  */
38 @SystemApi
39 @RequiresApi(TIRAMISU)
40 public final class SafetyCenterErrorDetails implements Parcelable {
41 
42     @NonNull
43     public static final Creator<SafetyCenterErrorDetails> CREATOR =
44             new Creator<SafetyCenterErrorDetails>() {
45                 @Override
46                 public SafetyCenterErrorDetails createFromParcel(Parcel in) {
47                     CharSequence errorMessage =
48                             TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
49                     return new SafetyCenterErrorDetails(errorMessage);
50                 }
51 
52                 @Override
53                 public SafetyCenterErrorDetails[] newArray(int size) {
54                     return new SafetyCenterErrorDetails[0];
55                 }
56             };
57 
58     @NonNull private final CharSequence mErrorMessage;
59 
60     /** Creates a {@link SafetyCenterErrorDetails} with a given error message. */
SafetyCenterErrorDetails(@onNull CharSequence errorMessage)61     public SafetyCenterErrorDetails(@NonNull CharSequence errorMessage) {
62         mErrorMessage = requireNonNull(errorMessage);
63     }
64 
65     /** Returns an error message to display to the user. */
66     @NonNull
getErrorMessage()67     public CharSequence getErrorMessage() {
68         return mErrorMessage;
69     }
70 
71     @Override
equals(Object o)72     public boolean equals(Object o) {
73         if (this == o) return true;
74         if (!(o instanceof SafetyCenterErrorDetails)) return false;
75         SafetyCenterErrorDetails that = (SafetyCenterErrorDetails) o;
76         return TextUtils.equals(mErrorMessage, that.mErrorMessage);
77     }
78 
79     @Override
hashCode()80     public int hashCode() {
81         return Objects.hash(mErrorMessage);
82     }
83 
84     @Override
toString()85     public String toString() {
86         return "SafetyCenterErrorDetails{" + "mErrorMessage=" + mErrorMessage + '}';
87     }
88 
89     @Override
describeContents()90     public int describeContents() {
91         return 0;
92     }
93 
94     @Override
writeToParcel(@onNull Parcel dest, int flags)95     public void writeToParcel(@NonNull Parcel dest, int flags) {
96         TextUtils.writeToParcel(mErrorMessage, dest, flags);
97     }
98 }
99