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.service.games.testing;
18 
19 
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import androidx.annotation.IntDef;
24 import androidx.annotation.NonNull;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 import java.util.Objects;
29 
30 public final class GameSessionEventInfo implements Parcelable {
31     @NonNull
32     public static final Parcelable.Creator<GameSessionEventInfo> CREATOR =
33             new Parcelable.Creator<GameSessionEventInfo>() {
34                 @Override
35                 public GameSessionEventInfo createFromParcel(Parcel source) {
36                     return new GameSessionEventInfo(
37                             source.readString(),
38                             source.readInt(),
39                             source.readInt());
40                 }
41 
42                 @Override
43                 public GameSessionEventInfo[] newArray(int size) {
44                     return new GameSessionEventInfo[0];
45                 }
46             };
47 
48     @IntDef(value = {
49         GAME_SESSION_EVENT_CREATED,
50         GAME_SESSION_EVENT_DESTROYED,
51     })
52     @Retention(RetentionPolicy.SOURCE)
53     public @interface GameSessionEvent {}
54 
55     public static final int GAME_SESSION_EVENT_CREATED = 1;
56     public static final int GAME_SESSION_EVENT_DESTROYED = 2;
57 
58     private final String mGamePackageName;
59     private final int mTaskId;
60     @GameSessionEvent
61     private final int mEvent;
62 
create( String gamePackageName, int taskId, @GameSessionEvent int event)63     public static GameSessionEventInfo create(
64             String gamePackageName,
65             int taskId,
66             @GameSessionEvent int event) {
67         return new GameSessionEventInfo(gamePackageName, taskId, event);
68     }
69 
GameSessionEventInfo(String gamePackageName, int taskId, @GameSessionEvent int event)70     private GameSessionEventInfo(String gamePackageName, int taskId, @GameSessionEvent int event) {
71         mGamePackageName = gamePackageName;
72         mTaskId = taskId;
73         mEvent = event;
74     }
75 
76     @Override
describeContents()77     public int describeContents() {
78         return 0;
79     }
80 
81     @Override
writeToParcel(@onNull Parcel dest, int flags)82     public void writeToParcel(@NonNull Parcel dest, int flags) {
83         dest.writeString(mGamePackageName);
84         dest.writeInt(mTaskId);
85         dest.writeInt(mEvent);
86     }
87 
88     @Override
equals(Object o)89     public boolean equals(Object o) {
90         if (this == o) return true;
91         if (!(o instanceof GameSessionEventInfo)) return false;
92         GameSessionEventInfo that = (GameSessionEventInfo) o;
93         return mTaskId == that.mTaskId && mEvent == that.mEvent && Objects.equals(
94                 mGamePackageName, that.mGamePackageName);
95     }
96 
97     @Override
hashCode()98     public int hashCode() {
99         return Objects.hash(mGamePackageName, mTaskId, mEvent);
100     }
101 
102     @Override
toString()103     public String toString() {
104         return "GameSessionEventInfo{"
105                 + "mGamePackageName='"
106                 + mGamePackageName
107                 + '\''
108                 + ", mTaskId="
109                 + mTaskId
110                 + ", mEvent="
111                 + mEvent
112                 + '}';
113     }
114 }
115