1 /*
2  * Copyright (C) 2020 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.app.search;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.Objects;
26 
27 /**
28  * The id for an search session. See {@link SearchSession}.
29  *
30  * @hide
31  */
32 @SystemApi
33 public final class SearchSessionId implements Parcelable {
34 
35     private final String mId;
36     private final int mUserId;
37 
38     /**
39      * Creates a new id for a search session.
40      *
41      * @hide
42      */
SearchSessionId(@onNull final String id, final int userId)43     public SearchSessionId(@NonNull final String id, final int userId) {
44         mId = id;
45         mUserId = userId;
46     }
47 
SearchSessionId(Parcel p)48     private SearchSessionId(Parcel p) {
49         mId = p.readString();
50         mUserId = p.readInt();
51     }
52 
53     /**
54      * @hide
55      */
getUserId()56     public int getUserId() {
57         return mUserId;
58     }
59 
60     @Override
equals(@ullable Object o)61     public boolean equals(@Nullable Object o) {
62         if (!getClass().equals(o != null ? o.getClass() : null)) return false;
63 
64         SearchSessionId other = (SearchSessionId) o;
65         return mId.equals(other.mId) && mUserId == other.mUserId;
66     }
67 
68     @Override
toString()69     public @NonNull String toString() {
70         return mId + "," + mUserId;
71     }
72 
73     @Override
hashCode()74     public int hashCode() {
75         return Objects.hash(mId, mUserId);
76     }
77 
78     @Override
describeContents()79     public int describeContents() {
80         return 0;
81     }
82 
83     @Override
writeToParcel(@onNull Parcel dest, int flags)84     public void writeToParcel(@NonNull Parcel dest, int flags) {
85         dest.writeString(mId);
86         dest.writeInt(mUserId);
87     }
88 
89     public static final @NonNull Creator<SearchSessionId> CREATOR =
90             new Creator<SearchSessionId>() {
91                 public SearchSessionId createFromParcel(Parcel parcel) {
92                     return new SearchSessionId(parcel);
93                 }
94 
95                 public SearchSessionId[] newArray(int size) {
96                     return new SearchSessionId[size];
97                 }
98             };
99 }
100