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 package com.android.server.pm;
17 
18 import android.annotation.UserIdInt;
19 
20 /**
21  * Representation of a {@link UserManagerInternal.UserVisibilityListener} event.
22  */
23 public final class UserVisibilityChangedEvent {
24 
25     public @UserIdInt int userId;
26     public boolean visible;
27 
UserVisibilityChangedEvent(@serIdInt int userId, boolean visible)28     UserVisibilityChangedEvent(@UserIdInt int userId, boolean visible) {
29         this.userId = userId;
30         this.visible = visible;
31     }
32 
33     @Override
hashCode()34     public int hashCode() {
35         final int prime = 31;
36         int result = 1;
37         result = prime * result + userId;
38         result = prime * result + (visible ? 1231 : 1237);
39         return result;
40     }
41 
42     @Override
equals(Object obj)43     public boolean equals(Object obj) {
44         if (this == obj) return true;
45         if (obj == null) return false;
46         if (getClass() != obj.getClass()) return false;
47         UserVisibilityChangedEvent other = (UserVisibilityChangedEvent) obj;
48         if (userId != other.userId) return false;
49         if (visible != other.visible) return false;
50         return true;
51     }
52 
53     @Override
toString()54     public String toString() {
55         return userId + ":" + (visible ? "visible" : "invisible");
56     }
57 
58     /**
59      * Factory method.
60      */
onVisible(@serIdInt int userId)61     public static UserVisibilityChangedEvent onVisible(@UserIdInt int userId) {
62         return new UserVisibilityChangedEvent(userId, /* visible= */ true);
63     }
64 
65     /**
66      * Factory method.
67      */
onInvisible(@serIdInt int userId)68     public static UserVisibilityChangedEvent onInvisible(@UserIdInt int userId) {
69         return new UserVisibilityChangedEvent(userId, /* visible= */ false);
70     }
71 }
72