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