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