blob: e7c350a12b928110912c855f6b42a3a91bec3cbf [file] [log] [blame]
Felipe Leme1dfa9a02018-10-17 17:24:37 -07001/*
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 Lemeaa5088e2018-12-10 14:53:58 -080017package android.view.contentcapture;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070018
Felipe Lemea7bdb142018-11-05 16:29:29 -080019import android.annotation.NonNull;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
Felipe Lemee348dc32018-11-05 12:35:29 -080023import java.io.PrintWriter;
24
Felipe Leme749b8892018-12-03 16:30:30 -080025/**
26 * Identifier for a Content Capture session.
Felipe Leme749b8892018-12-03 16:30:30 -080027 */
Felipe Lemeaa5088e2018-12-10 14:53:58 -080028public final class ContentCaptureSessionId implements Parcelable {
Felipe Leme1dfa9a02018-10-17 17:24:37 -070029
Felipe Lemea7bdb142018-11-05 16:29:29 -080030 private final @NonNull String mValue;
Felipe Lemee348dc32018-11-05 12:35:29 -080031
Felipe Lemea7bdb142018-11-05 16:29:29 -080032 /**
33 * Creates a new instance.
34 *
Felipe Lemea7bdb142018-11-05 16:29:29 -080035 * @param value The internal value.
36 *
37 * @hide
38 */
Felipe Lemeaa5088e2018-12-10 14:53:58 -080039 public ContentCaptureSessionId(@NonNull String value) {
Felipe Lemea7bdb142018-11-05 16:29:29 -080040 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 Lemeaa5088e2018-12-10 14:53:58 -080063 final ContentCaptureSessionId other = (ContentCaptureSessionId) obj;
Felipe Lemea7bdb142018-11-05 16:29:29 -080064 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 Oczeretko38762422018-11-07 14:20:56 +000073 * {@inheritDoc}
Felipe Lemea7bdb142018-11-05 16:29:29 -080074 *
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 Lemee348dc32018-11-05 12:35:29 -080081 }
82
83 /** @hide */
84 // TODO(b/111276913): dump to proto as well
85 public void dump(PrintWriter pw) {
Felipe Lemea7bdb142018-11-05 16:29:29 -080086 pw.print(mValue);
Felipe Leme1dfa9a02018-10-17 17:24:37 -070087 }
88
89 @Override
90 public int describeContents() {
91 return 0;
92 }
93
94 @Override
95 public void writeToParcel(Parcel parcel, int flags) {
Felipe Lemea7bdb142018-11-05 16:29:29 -080096 parcel.writeString(mValue);
Felipe Leme1dfa9a02018-10-17 17:24:37 -070097 }
98
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070099 public static final @android.annotation.NonNull Parcelable.Creator<ContentCaptureSessionId> CREATOR =
Felipe Lemeaa5088e2018-12-10 14:53:58 -0800100 new Parcelable.Creator<ContentCaptureSessionId>() {
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700101
102 @Override
Felipe Lemece6877b2019-02-28 09:02:26 -0800103 @NonNull
Felipe Lemeaa5088e2018-12-10 14:53:58 -0800104 public ContentCaptureSessionId createFromParcel(Parcel parcel) {
105 return new ContentCaptureSessionId(parcel.readString());
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700106 }
107
108 @Override
Felipe Lemece6877b2019-02-28 09:02:26 -0800109 @NonNull
Felipe Lemeaa5088e2018-12-10 14:53:58 -0800110 public ContentCaptureSessionId[] newArray(int size) {
111 return new ContentCaptureSessionId[size];
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700112 }
113 };
114}