blob: 667193b14113a30a473c4277daf707c9b9a42a61 [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
17package android.service.intelligence;
18
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;
Felipe Lemea7bdb142018-11-05 16:29:29 -080025import java.util.UUID;
Felipe Lemee348dc32018-11-05 12:35:29 -080026
Felipe Leme1dfa9a02018-10-17 17:24:37 -070027// TODO(b/111276913): add javadocs / implement equals/hashcode/string
28/** @hide */
29@SystemApi
30public final class InteractionSessionId implements Parcelable {
31
Felipe Lemea7bdb142018-11-05 16:29:29 -080032 private final @NonNull String mValue;
Felipe Lemee348dc32018-11-05 12:35:29 -080033
Felipe Lemea7bdb142018-11-05 16:29:29 -080034 /**
35 * Creates a new instance.
36 *
37 * @hide
38 */
39 public InteractionSessionId() {
40 this(UUID.randomUUID().toString());
Felipe Lemee348dc32018-11-05 12:35:29 -080041 }
42
Felipe Lemea7bdb142018-11-05 16:29:29 -080043 /**
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 Oczeretko38762422018-11-07 14:20:56 +000084 * {@inheritDoc}
Felipe Lemea7bdb142018-11-05 16:29:29 -080085 *
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 Lemee348dc32018-11-05 12:35:29 -080092 }
93
94 /** @hide */
95 // TODO(b/111276913): dump to proto as well
96 public void dump(PrintWriter pw) {
Felipe Lemea7bdb142018-11-05 16:29:29 -080097 pw.print(mValue);
Felipe Leme1dfa9a02018-10-17 17:24:37 -070098 }
99
100 @Override
101 public int describeContents() {
102 return 0;
103 }
104
105 @Override
106 public void writeToParcel(Parcel parcel, int flags) {
Felipe Lemea7bdb142018-11-05 16:29:29 -0800107 parcel.writeString(mValue);
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700108 }
109
110 public static final Parcelable.Creator<InteractionSessionId> CREATOR =
111 new Parcelable.Creator<InteractionSessionId>() {
112
113 @Override
114 public InteractionSessionId createFromParcel(Parcel parcel) {
Felipe Lemea7bdb142018-11-05 16:29:29 -0800115 return new InteractionSessionId(parcel.readString());
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700116 }
117
118 @Override
119 public InteractionSessionId[] newArray(int size) {
120 return new InteractionSessionId[size];
121 }
122 };
123}