• 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 com.android.safetycenter;
18 
19 import android.annotation.UserIdInt;
20 import android.safetycenter.SafetySourceData;
21 
22 import java.util.Objects;
23 
24 /**
25  * A key to identify a safety source providing {@link SafetySourceData}; based on the {@code
26  * sourceId} and {@code userId}.
27  *
28  * @hide
29  */
30 // TODO(b/219697341): Look into using AutoValue for this data class.
31 
32 public final class SafetySourceKey {
33 
34     private final String mSourceId;
35     @UserIdInt private final int mUserId;
36 
SafetySourceKey(String sourceId, @UserIdInt int userId)37     private SafetySourceKey(String sourceId, @UserIdInt int userId) {
38         mSourceId = sourceId;
39         mUserId = userId;
40     }
41 
42     /** Creates a {@link SafetySourceKey} for the given {@code sourceId} and {@code userId}. */
of(String sourceId, @UserIdInt int userId)43     public static SafetySourceKey of(String sourceId, @UserIdInt int userId) {
44         return new SafetySourceKey(sourceId, userId);
45     }
46 
47     /** Returns the source id of this {@link SafetySourceKey}. */
getSourceId()48     public String getSourceId() {
49         return mSourceId;
50     }
51 
52     /** Returns the user id of this {@link SafetySourceKey}. */
53     @UserIdInt
getUserId()54     public int getUserId() {
55         return mUserId;
56     }
57 
58     @Override
equals(Object o)59     public boolean equals(Object o) {
60         if (this == o) return true;
61         if (!(o instanceof SafetySourceKey)) return false;
62         SafetySourceKey safetySourceKey = (SafetySourceKey) o;
63         return mSourceId.equals(safetySourceKey.mSourceId) && mUserId == safetySourceKey.mUserId;
64     }
65 
66     @Override
hashCode()67     public int hashCode() {
68         return Objects.hash(mSourceId, mUserId);
69     }
70 
71     @Override
toString()72     public String toString() {
73         return "SafetySourceKey{" + "mSourceId='" + mSourceId + "', mUserId=" + mUserId + '}';
74     }
75 }
76