Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 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 | |
| 17 | package android.service.intelligence; |
| 18 | |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 24 | import java.io.PrintWriter; |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 25 | import java.util.UUID; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 26 | |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 27 | // TODO(b/111276913): add javadocs / implement equals/hashcode/string |
| 28 | /** @hide */ |
| 29 | @SystemApi |
| 30 | public final class InteractionSessionId implements Parcelable { |
| 31 | |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 32 | private final @NonNull String mValue; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 33 | |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 34 | /** |
| 35 | * Creates a new instance. |
| 36 | * |
| 37 | * @hide |
| 38 | */ |
| 39 | public InteractionSessionId() { |
| 40 | this(UUID.randomUUID().toString()); |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 43 | /** |
| 44 | * Creates a new instance. |
| 45 | * |
| 46 | * @param value The internal value. |
| 47 | * |
| 48 | * @hide |
| 49 | */ |
| 50 | public InteractionSessionId(@NonNull String value) { |
| 51 | mValue = value; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @hide |
| 56 | */ |
| 57 | public String getValue() { |
| 58 | return mValue; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public int hashCode() { |
| 63 | final int prime = 31; |
| 64 | int result = 1; |
| 65 | result = prime * result + ((mValue == null) ? 0 : mValue.hashCode()); |
| 66 | return result; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean equals(Object obj) { |
| 71 | if (this == obj) return true; |
| 72 | if (obj == null) return false; |
| 73 | if (getClass() != obj.getClass()) return false; |
| 74 | final InteractionSessionId other = (InteractionSessionId) obj; |
| 75 | if (mValue == null) { |
| 76 | if (other.mValue != null) return false; |
| 77 | } else if (!mValue.equals(other.mValue)) { |
| 78 | return false; |
| 79 | } |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | /** |
Marcin Oczeretko | 3876242 | 2018-11-07 14:20:56 +0000 | [diff] [blame] | 84 | * {@inheritDoc} |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 85 | * |
| 86 | * <p><b>NOTE: </b>this method is only useful for debugging purposes and is not guaranteed to |
| 87 | * be stable, hence it should not be used to identify the session. |
| 88 | */ |
| 89 | @Override |
| 90 | public String toString() { |
| 91 | return mValue; |
Felipe Leme | e348dc3 | 2018-11-05 12:35:29 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** @hide */ |
| 95 | // TODO(b/111276913): dump to proto as well |
| 96 | public void dump(PrintWriter pw) { |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 97 | pw.print(mValue); |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public int describeContents() { |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void writeToParcel(Parcel parcel, int flags) { |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 107 | parcel.writeString(mValue); |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | public static final Parcelable.Creator<InteractionSessionId> CREATOR = |
| 111 | new Parcelable.Creator<InteractionSessionId>() { |
| 112 | |
| 113 | @Override |
| 114 | public InteractionSessionId createFromParcel(Parcel parcel) { |
Felipe Leme | a7bdb14 | 2018-11-05 16:29:29 -0800 | [diff] [blame] | 115 | return new InteractionSessionId(parcel.readString()); |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public InteractionSessionId[] newArray(int size) { |
| 120 | return new InteractionSessionId[size]; |
| 121 | } |
| 122 | }; |
| 123 | } |