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