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