blob: 84119472ca3242a426d8522853053e7ed5a2ab06 [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 Leme749b8892018-12-03 16:30:30 -080017package android.service.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.annotation.SystemApi;
21import android.os.Parcel;
22import android.os.Parcelable;
23
Felipe Lemee348dc32018-11-05 12:35:29 -080024import java.io.PrintWriter;
25
Felipe Leme749b8892018-12-03 16:30:30 -080026/**
27 * Identifier for a Content Capture session.
28 *
29 * @hide
30 */
Felipe Leme1dfa9a02018-10-17 17:24:37 -070031@SystemApi
32public final class InteractionSessionId implements Parcelable {
33
Felipe Lemea7bdb142018-11-05 16:29:29 -080034 private final @NonNull String mValue;
Felipe Lemee348dc32018-11-05 12:35:29 -080035
Felipe Lemea7bdb142018-11-05 16:29:29 -080036 /**
37 * Creates a new instance.
38 *
Felipe Lemea7bdb142018-11-05 16:29:29 -080039 * @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 Oczeretko38762422018-11-07 14:20:56 +000077 * {@inheritDoc}
Felipe Lemea7bdb142018-11-05 16:29:29 -080078 *
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 Lemee348dc32018-11-05 12:35:29 -080085 }
86
87 /** @hide */
88 // TODO(b/111276913): dump to proto as well
89 public void dump(PrintWriter pw) {
Felipe Lemea7bdb142018-11-05 16:29:29 -080090 pw.print(mValue);
Felipe Leme1dfa9a02018-10-17 17:24:37 -070091 }
92
93 @Override
94 public int describeContents() {
95 return 0;
96 }
97
98 @Override
99 public void writeToParcel(Parcel parcel, int flags) {
Felipe Lemea7bdb142018-11-05 16:29:29 -0800100 parcel.writeString(mValue);
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700101 }
102
103 public static final Parcelable.Creator<InteractionSessionId> CREATOR =
104 new Parcelable.Creator<InteractionSessionId>() {
105
106 @Override
107 public InteractionSessionId createFromParcel(Parcel parcel) {
Felipe Lemea7bdb142018-11-05 16:29:29 -0800108 return new InteractionSessionId(parcel.readString());
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700109 }
110
111 @Override
112 public InteractionSessionId[] newArray(int size) {
113 return new InteractionSessionId[size];
114 }
115 };
116}