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;
18 
19 import android.annotation.IntRange;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.Objects;
26 
27 /**
28  * Event object provided when a game task is started.
29  *
30  * This is provided to the Game Service via
31  * {@link GameService#onGameStarted(GameStartedEvent)}. It includes the game's taskId
32  * (see {@link #getTaskId}) that the game's package name (see {@link #getPackageName}).
33  *
34  * @hide
35  */
36 @SystemApi
37 public final class GameStartedEvent implements Parcelable {
38 
39     @NonNull
40     public static final Parcelable.Creator<GameStartedEvent> CREATOR =
41             new Parcelable.Creator<GameStartedEvent>() {
42                 @Override
43                 public GameStartedEvent createFromParcel(Parcel source) {
44                     return new GameStartedEvent(
45                             source.readInt(),
46                             source.readString());
47                 }
48 
49                 @Override
50                 public GameStartedEvent[] newArray(int size) {
51                     return new GameStartedEvent[0];
52                 }
53             };
54 
55     private final int mTaskId;
56     private final String mPackageName;
57 
GameStartedEvent(@ntRangefrom = 0) int taskId, @NonNull String packageName)58     public GameStartedEvent(@IntRange(from = 0) int taskId, @NonNull String packageName) {
59         this.mTaskId = taskId;
60         this.mPackageName = packageName;
61     }
62 
63     @Override
describeContents()64     public int describeContents() {
65         return 0;
66     }
67 
68     @Override
writeToParcel(@onNull Parcel dest, int flags)69     public void writeToParcel(@NonNull Parcel dest, int flags) {
70         dest.writeInt(mTaskId);
71         dest.writeString(mPackageName);
72     }
73 
74     /**
75      * Unique identifier for the task associated with the game.
76      */
77     @IntRange(from = 0)
getTaskId()78     public int getTaskId() {
79         return mTaskId;
80     }
81 
82     /**
83      * The package name for the game.
84      */
85     @NonNull
getPackageName()86     public String getPackageName() {
87         return mPackageName;
88     }
89 
90     @Override
toString()91     public String toString() {
92         return "GameStartedEvent{"
93                 + "mTaskId="
94                 + mTaskId
95                 + ", mPackageName='"
96                 + mPackageName
97                 + "\'}";
98     }
99 
100     @Override
equals(Object o)101     public boolean equals(Object o) {
102         if (this == o) {
103             return true;
104         }
105 
106         if (!(o instanceof GameStartedEvent)) {
107             return false;
108         }
109 
110         GameStartedEvent that = (GameStartedEvent) o;
111         return mTaskId == that.mTaskId
112                 && Objects.equals(mPackageName, that.mPackageName);
113     }
114 
115     @Override
hashCode()116     public int hashCode() {
117         return Objects.hash(mTaskId, mPackageName);
118     }
119 }
120