• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.safetycenter;
18 
19 import static android.os.Build.VERSION_CODES.TIRAMISU;
20 
21 import static com.android.safetycenter.internaldata.SafetyCenterIds.toUserFriendlyString;
22 
23 import android.annotation.UserIdInt;
24 import android.safetycenter.SafetySourceIssue;
25 import android.safetycenter.config.SafetySource;
26 import android.safetycenter.config.SafetySourcesGroup;
27 
28 import androidx.annotation.RequiresApi;
29 
30 import com.android.safetycenter.internaldata.SafetyCenterIssueKey;
31 
32 import java.util.Objects;
33 
34 /**
35  * Contains various information about a {@link SafetySourceIssue}.
36  *
37  * @hide
38  */
39 @RequiresApi(TIRAMISU)
40 public final class SafetySourceIssueInfo {
41 
42     private final SafetySourceIssue mSafetySourceIssue;
43     private final SafetySource mSafetySource;
44     private final SafetySourcesGroup mSafetySourcesGroup;
45     private final SafetyCenterIssueKey mSafetyCenterIssueKey;
46 
47     /** Creates a new {@link SafetySourceIssueInfo} instance. */
SafetySourceIssueInfo( SafetySourceIssue safetySourceIssue, SafetySource safetySource, SafetySourcesGroup safetySourcesGroup, @UserIdInt int userId)48     public SafetySourceIssueInfo(
49             SafetySourceIssue safetySourceIssue,
50             SafetySource safetySource,
51             SafetySourcesGroup safetySourcesGroup,
52             @UserIdInt int userId) {
53         mSafetySourceIssue = safetySourceIssue;
54         mSafetySource = safetySource;
55         mSafetySourcesGroup = safetySourcesGroup;
56         mSafetyCenterIssueKey =
57                 SafetyCenterIssueKey.newBuilder()
58                         .setSafetySourceId(safetySource.getId())
59                         .setSafetySourceIssueId(safetySourceIssue.getId())
60                         .setUserId(userId)
61                         .build();
62     }
63 
64     /** Returns the {@link SafetyCenterIssueKey} related to this {@link SafetySourceIssue}. */
getSafetyCenterIssueKey()65     public SafetyCenterIssueKey getSafetyCenterIssueKey() {
66         return mSafetyCenterIssueKey;
67     }
68     /** Returns the {@link SafetySourceIssue}. */
getSafetySourceIssue()69     public SafetySourceIssue getSafetySourceIssue() {
70         return mSafetySourceIssue;
71     }
72 
73     /** Returns the {@link SafetySource} related to this {@link SafetySourceIssue}. */
getSafetySource()74     public SafetySource getSafetySource() {
75         return mSafetySource;
76     }
77 
78     /** Returns the {@link SafetySourcesGroup} related to this {@link SafetySourceIssue}. */
getSafetySourcesGroup()79     public SafetySourcesGroup getSafetySourcesGroup() {
80         return mSafetySourcesGroup;
81     }
82 
83     @Override
equals(Object o)84     public boolean equals(Object o) {
85         if (this == o) return true;
86         if (!(o instanceof SafetySourceIssueInfo)) return false;
87         SafetySourceIssueInfo that = (SafetySourceIssueInfo) o;
88         return mSafetySourceIssue.equals(that.mSafetySourceIssue)
89                 && mSafetySource.equals(that.mSafetySource)
90                 && mSafetySourcesGroup.equals(that.mSafetySourcesGroup)
91                 && mSafetyCenterIssueKey.equals(that.mSafetyCenterIssueKey);
92     }
93 
94     @Override
hashCode()95     public int hashCode() {
96         return Objects.hash(
97                 mSafetySourceIssue, mSafetySource, mSafetySourcesGroup, mSafetyCenterIssueKey);
98     }
99 
100     @Override
toString()101     public String toString() {
102         return "SafetySourceIssueInfo{"
103                 + "mSafetySourceIssue="
104                 + mSafetySourceIssue
105                 + ", mSafetySource="
106                 + mSafetySource
107                 + ", mSafetySourcesGroup="
108                 + mSafetySourcesGroup
109                 + ", mSafetyCenterIssueKey="
110                 + toUserFriendlyString(mSafetyCenterIssueKey)
111                 + '}';
112     }
113 }
114