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 | */ |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame] | 16 | package android.view.contentcapture; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 17 | |
Felipe Leme | be002d8 | 2019-01-23 10:22:32 -0800 | [diff] [blame] | 18 | import static android.view.contentcapture.ContentCaptureHelper.getSanitizedString; |
| 19 | |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 21 | import android.annotation.NonNull; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 22 | import android.annotation.Nullable; |
| 23 | import android.annotation.SystemApi; |
Felipe Leme | 19652c0 | 2019-02-04 13:01:29 -0800 | [diff] [blame] | 24 | import android.annotation.TestApi; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 27 | import android.util.Log; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 28 | import android.view.autofill.AutofillId; |
| 29 | |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 30 | import com.android.internal.util.Preconditions; |
| 31 | |
| 32 | import java.io.PrintWriter; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 33 | import java.lang.annotation.Retention; |
| 34 | import java.lang.annotation.RetentionPolicy; |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 35 | import java.util.ArrayList; |
| 36 | import java.util.List; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 37 | |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 38 | /** @hide */ |
| 39 | @SystemApi |
Felipe Leme | 19652c0 | 2019-02-04 13:01:29 -0800 | [diff] [blame] | 40 | @TestApi |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 41 | public final class ContentCaptureEvent implements Parcelable { |
| 42 | |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 43 | private static final String TAG = ContentCaptureEvent.class.getSimpleName(); |
| 44 | |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 45 | /** @hide */ |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 46 | public static final int TYPE_SESSION_FINISHED = -2; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 47 | /** @hide */ |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 48 | public static final int TYPE_SESSION_STARTED = -1; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 49 | |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 50 | /** |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 51 | * Called when a node has been added to the screen and is visible to the user. |
| 52 | * |
| 53 | * <p>The metadata of the node is available through {@link #getViewNode()}. |
| 54 | */ |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 55 | public static final int TYPE_VIEW_APPEARED = 1; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 58 | * Called when one or more nodes have been removed from the screen and is not visible to the |
| 59 | * user anymore. |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 60 | * |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 61 | * <p>To get the id(s), first call {@link #getIds()} - if it returns {@code null}, then call |
| 62 | * {@link #getId()}. |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 63 | */ |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 64 | public static final int TYPE_VIEW_DISAPPEARED = 2; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Called when the text of a node has been changed. |
| 68 | * |
| 69 | * <p>The id of the node is available through {@link #getId()}, and the new text is |
| 70 | * available through {@link #getText()}. |
| 71 | */ |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 72 | public static final int TYPE_VIEW_TEXT_CHANGED = 3; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 73 | |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 74 | /** |
Felipe Leme | 544b39c | 2019-02-22 09:26:29 -0800 | [diff] [blame] | 75 | * Called before events (such as {@link #TYPE_VIEW_APPEARED} and/or |
| 76 | * {@link #TYPE_VIEW_DISAPPEARED}) representing a view hierarchy are sent. |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 77 | * |
| 78 | * <p><b>NOTE</b>: there is no guarantee this event will be sent. For example, it's not sent |
| 79 | * if the initial view hierarchy doesn't initially have any view that's important for content |
| 80 | * capture. |
| 81 | */ |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 82 | public static final int TYPE_VIEW_TREE_APPEARING = 4; |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 83 | |
| 84 | /** |
Felipe Leme | 544b39c | 2019-02-22 09:26:29 -0800 | [diff] [blame] | 85 | * Called after events (such as {@link #TYPE_VIEW_APPEARED} and/or |
| 86 | * {@link #TYPE_VIEW_DISAPPEARED}) representing a view hierarchy were sent. |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 87 | * |
| 88 | * <p><b>NOTE</b>: there is no guarantee this event will be sent. For example, it's not sent |
| 89 | * if the initial view hierarchy doesn't initially have any view that's important for content |
| 90 | * capture. |
| 91 | */ |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 92 | public static final int TYPE_VIEW_TREE_APPEARED = 5; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 93 | |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 94 | /** |
| 95 | * Called after a call to |
| 96 | * {@link ContentCaptureSession#setContentCaptureContext(ContentCaptureContext)}. |
| 97 | * |
| 98 | * <p>The passed context is available through {@link #getContentCaptureContext()}. |
| 99 | */ |
| 100 | public static final int TYPE_CONTEXT_UPDATED = 6; |
| 101 | |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 102 | /** |
| 103 | * Called after the session is ready, typically after the activity resumed and the |
| 104 | * initial views appeared |
| 105 | */ |
| 106 | public static final int TYPE_SESSION_RESUMED = 7; |
| 107 | |
| 108 | /** |
| 109 | * Called after the session is paused, typically after the activity paused and the |
| 110 | * views disappeared. |
| 111 | */ |
| 112 | public static final int TYPE_SESSION_PAUSED = 8; |
| 113 | |
| 114 | |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 115 | /** @hide */ |
| 116 | @IntDef(prefix = { "TYPE_" }, value = { |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 117 | TYPE_VIEW_APPEARED, |
| 118 | TYPE_VIEW_DISAPPEARED, |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 119 | TYPE_VIEW_TEXT_CHANGED, |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 120 | TYPE_VIEW_TREE_APPEARING, |
| 121 | TYPE_VIEW_TREE_APPEARED, |
| 122 | TYPE_CONTEXT_UPDATED, |
| 123 | TYPE_SESSION_PAUSED, |
| 124 | TYPE_SESSION_RESUMED |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 125 | }) |
| 126 | @Retention(RetentionPolicy.SOURCE) |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 127 | public @interface EventType{} |
| 128 | |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 129 | private final @NonNull String mSessionId; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 130 | private final int mType; |
| 131 | private final long mEventTime; |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 132 | private @Nullable AutofillId mId; |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 133 | private @Nullable ArrayList<AutofillId> mIds; |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 134 | private @Nullable ViewNode mNode; |
| 135 | private @Nullable CharSequence mText; |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 136 | private @Nullable String mParentSessionId; |
| 137 | private @Nullable ContentCaptureContext mClientContext; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 138 | |
| 139 | /** @hide */ |
Felipe Leme | 21e8dcb | 2019-01-18 09:09:45 -0800 | [diff] [blame] | 140 | public ContentCaptureEvent(@NonNull String sessionId, int type, long eventTime) { |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 141 | mSessionId = sessionId; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 142 | mType = type; |
| 143 | mEventTime = eventTime; |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** @hide */ |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 147 | public ContentCaptureEvent(@NonNull String sessionId, int type) { |
Felipe Leme | 21e8dcb | 2019-01-18 09:09:45 -0800 | [diff] [blame] | 148 | this(sessionId, type, System.currentTimeMillis()); |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /** @hide */ |
| 152 | public ContentCaptureEvent setAutofillId(@NonNull AutofillId id) { |
| 153 | mId = Preconditions.checkNotNull(id); |
| 154 | return this; |
| 155 | } |
| 156 | |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 157 | /** @hide */ |
| 158 | public ContentCaptureEvent setAutofillIds(@NonNull ArrayList<AutofillId> ids) { |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 159 | mIds = Preconditions.checkNotNull(ids); |
Felipe Leme | 0129769 | 2019-01-29 18:16:23 -0800 | [diff] [blame] | 160 | return this; |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Adds an autofill id to the this event, merging the single id into a list if necessary. |
Felipe Leme | 2ca5dfe | 2019-02-05 12:22:50 -0800 | [diff] [blame] | 165 | * |
| 166 | * @hide |
| 167 | */ |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 168 | public ContentCaptureEvent addAutofillId(@NonNull AutofillId id) { |
Felipe Leme | 2ca5dfe | 2019-02-05 12:22:50 -0800 | [diff] [blame] | 169 | Preconditions.checkNotNull(id); |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 170 | if (mIds == null) { |
| 171 | mIds = new ArrayList<>(); |
| 172 | if (mId == null) { |
| 173 | Log.w(TAG, "addAutofillId(" + id + ") called without an initial id"); |
| 174 | } else { |
| 175 | mIds.add(mId); |
| 176 | mId = null; |
| 177 | } |
| 178 | } |
| 179 | mIds.add(id); |
| 180 | return this; |
| 181 | } |
| 182 | |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Used by {@link #TYPE_SESSION_STARTED} and {@link #TYPE_SESSION_FINISHED}. |
| 185 | * |
| 186 | * @hide |
| 187 | */ |
| 188 | public ContentCaptureEvent setParentSessionId(@NonNull String parentSessionId) { |
| 189 | mParentSessionId = parentSessionId; |
| 190 | return this; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Used by {@link #TYPE_SESSION_STARTED} and {@link #TYPE_SESSION_FINISHED}. |
| 195 | * |
| 196 | * @hide |
| 197 | */ |
| 198 | public ContentCaptureEvent setClientContext(@NonNull ContentCaptureContext clientContext) { |
| 199 | mClientContext = clientContext; |
| 200 | return this; |
| 201 | } |
| 202 | |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 203 | /** @hide */ |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 204 | @NonNull |
| 205 | public String getSessionId() { |
| 206 | return mSessionId; |
| 207 | } |
| 208 | |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 209 | /** |
| 210 | * Used by {@link #TYPE_SESSION_STARTED} and {@link #TYPE_SESSION_FINISHED}. |
| 211 | * |
| 212 | * @hide |
| 213 | */ |
| 214 | @Nullable |
| 215 | public String getParentSessionId() { |
| 216 | return mParentSessionId; |
| 217 | } |
| 218 | |
| 219 | /** |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 220 | * Gets the {@link ContentCaptureContext} set calls to |
| 221 | * {@link ContentCaptureSession#setContentCaptureContext(ContentCaptureContext)}. |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 222 | * |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 223 | * <p>Only set on {@link #TYPE_CONTEXT_UPDATED} events. |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 224 | */ |
| 225 | @Nullable |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 226 | public ContentCaptureContext getContentCaptureContext() { |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 227 | return mClientContext; |
| 228 | } |
| 229 | |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 230 | /** @hide */ |
| 231 | @NonNull |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 232 | public ContentCaptureEvent setViewNode(@NonNull ViewNode node) { |
| 233 | mNode = Preconditions.checkNotNull(node); |
| 234 | return this; |
| 235 | } |
| 236 | |
| 237 | /** @hide */ |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 238 | @NonNull |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 239 | public ContentCaptureEvent setText(@Nullable CharSequence text) { |
| 240 | mText = text; |
| 241 | return this; |
| 242 | } |
| 243 | |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 244 | /** |
| 245 | * Gets the type of the event. |
| 246 | * |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 247 | * @return one of {@link #TYPE_VIEW_APPEARED}, {@link #TYPE_VIEW_DISAPPEARED}, |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 248 | * {@link #TYPE_VIEW_TEXT_CHANGED}, {@link #TYPE_VIEW_TREE_APPEARING}, |
| 249 | * {@link #TYPE_VIEW_TREE_APPEARED}, {@link #TYPE_CONTEXT_UPDATED}, |
| 250 | * {@link #TYPE_SESSION_RESUMED}, or {@link #TYPE_SESSION_PAUSED}. |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 251 | */ |
| 252 | public @EventType int getType() { |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 253 | return mType; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /** |
Felipe Leme | aa5088e | 2018-12-10 14:53:58 -0800 | [diff] [blame] | 257 | * Gets when the event was generated, in millis since epoch. |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 258 | */ |
| 259 | public long getEventTime() { |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 260 | return mEventTime; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 264 | * Gets the whole metadata of the node associated with the event. |
| 265 | * |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 266 | * <p>Only set on {@link #TYPE_VIEW_APPEARED} events. |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 267 | */ |
| 268 | @Nullable |
| 269 | public ViewNode getViewNode() { |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 270 | return mNode; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Gets the {@link AutofillId} of the node associated with the event. |
| 275 | * |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 276 | * <p>Only set on {@link #TYPE_VIEW_DISAPPEARED} (when the event contains just one node - if |
| 277 | * it contains more than one, this method returns {@code null} and the actual ids should be |
| 278 | * retrived by {@link #getIds()}) and {@link #TYPE_VIEW_TEXT_CHANGED} events. |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 279 | */ |
| 280 | @Nullable |
| 281 | public AutofillId getId() { |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 282 | return mId; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /** |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 286 | * Gets the {@link AutofillId AutofillIds} of the nodes associated with the event. |
| 287 | * |
| 288 | * <p>Only set on {@link #TYPE_VIEW_DISAPPEARED}, when the event contains more than one node |
| 289 | * (if it contains just one node, it's returned by {@link #getId()} instead. |
| 290 | */ |
| 291 | @Nullable |
| 292 | public List<AutofillId> getIds() { |
| 293 | return mIds; |
| 294 | } |
| 295 | |
| 296 | /** |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 297 | * Gets the current text of the node associated with the event. |
| 298 | * |
| 299 | * <p>Only set on {@link #TYPE_VIEW_TEXT_CHANGED} events. |
| 300 | */ |
| 301 | @Nullable |
| 302 | public CharSequence getText() { |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 303 | return mText; |
| 304 | } |
| 305 | |
| 306 | /** @hide */ |
| 307 | public void dump(@NonNull PrintWriter pw) { |
| 308 | pw.print("type="); pw.print(getTypeAsString(mType)); |
| 309 | pw.print(", time="); pw.print(mEventTime); |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 310 | if (mId != null) { |
| 311 | pw.print(", id="); pw.print(mId); |
| 312 | } |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 313 | if (mIds != null) { |
| 314 | pw.print(", ids="); pw.print(mIds); |
| 315 | } |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 316 | if (mNode != null) { |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 317 | pw.print(", mNode.id="); pw.print(mNode.getAutofillId()); |
| 318 | } |
| 319 | if (mSessionId != null) { |
| 320 | pw.print(", sessionId="); pw.print(mSessionId); |
| 321 | } |
| 322 | if (mParentSessionId != null) { |
| 323 | pw.print(", parentSessionId="); pw.print(mParentSessionId); |
| 324 | } |
| 325 | if (mText != null) { |
Felipe Leme | be002d8 | 2019-01-23 10:22:32 -0800 | [diff] [blame] | 326 | pw.print(", text="); pw.println(getSanitizedString(mText)); |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 327 | } |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 328 | if (mClientContext != null) { |
| 329 | pw.print(", context="); mClientContext.dump(pw); pw.println(); |
| 330 | |
| 331 | } |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 334 | @Override |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 335 | public String toString() { |
| 336 | final StringBuilder string = new StringBuilder("ContentCaptureEvent[type=") |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 337 | .append(getTypeAsString(mType)); |
Felipe Leme | e127c9a | 2019-01-04 14:56:38 -0800 | [diff] [blame] | 338 | string.append(", session=").append(mSessionId); |
| 339 | if (mType == TYPE_SESSION_STARTED && mParentSessionId != null) { |
| 340 | string.append(", parent=").append(mParentSessionId); |
| 341 | } |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 342 | if (mId != null) { |
| 343 | string.append(", id=").append(mId); |
| 344 | } |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 345 | if (mIds != null) { |
| 346 | string.append(", ids=").append(mIds); |
| 347 | } |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 348 | if (mNode != null) { |
| 349 | final String className = mNode.getClassName(); |
| 350 | if (mNode != null) { |
| 351 | string.append(", class=").append(className); |
| 352 | } |
| 353 | string.append(", id=").append(mNode.getAutofillId()); |
| 354 | } |
Felipe Leme | be002d8 | 2019-01-23 10:22:32 -0800 | [diff] [blame] | 355 | if (mText != null) { |
| 356 | string.append(", text=").append(getSanitizedString(mText)); |
| 357 | } |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 358 | if (mClientContext != null) { |
| 359 | string.append(", context=").append(mClientContext); |
| 360 | } |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 361 | return string.append(']').toString(); |
| 362 | } |
| 363 | |
| 364 | @Override |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 365 | public int describeContents() { |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | @Override |
| 370 | public void writeToParcel(Parcel parcel, int flags) { |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 371 | parcel.writeString(mSessionId); |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 372 | parcel.writeInt(mType); |
| 373 | parcel.writeLong(mEventTime); |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 374 | parcel.writeParcelable(mId, flags); |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 375 | parcel.writeTypedList(mIds); |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 376 | ViewNode.writeToParcel(parcel, mNode, flags); |
| 377 | parcel.writeCharSequence(mText); |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 378 | if (mType == TYPE_SESSION_STARTED || mType == TYPE_SESSION_FINISHED) { |
| 379 | parcel.writeString(mParentSessionId); |
| 380 | } |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 381 | if (mType == TYPE_SESSION_STARTED || mType == TYPE_CONTEXT_UPDATED) { |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 382 | parcel.writeParcelable(mClientContext, flags); |
| 383 | } |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 386 | public static final @android.annotation.NonNull Parcelable.Creator<ContentCaptureEvent> CREATOR = |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 387 | new Parcelable.Creator<ContentCaptureEvent>() { |
| 388 | |
| 389 | @Override |
Felipe Leme | ce6877b | 2019-02-28 09:02:26 -0800 | [diff] [blame] | 390 | @NonNull |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 391 | public ContentCaptureEvent createFromParcel(Parcel parcel) { |
Felipe Leme | fc24bea | 2018-12-18 13:19:01 -0800 | [diff] [blame] | 392 | final String sessionId = parcel.readString(); |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 393 | final int type = parcel.readInt(); |
| 394 | final long eventTime = parcel.readLong(); |
Felipe Leme | 21e8dcb | 2019-01-18 09:09:45 -0800 | [diff] [blame] | 395 | final ContentCaptureEvent event = new ContentCaptureEvent(sessionId, type, eventTime); |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 396 | final AutofillId id = parcel.readParcelable(null); |
| 397 | if (id != null) { |
| 398 | event.setAutofillId(id); |
| 399 | } |
Felipe Leme | 48f363c | 2019-01-17 10:53:46 -0800 | [diff] [blame] | 400 | final ArrayList<AutofillId> ids = parcel.createTypedArrayList(AutofillId.CREATOR); |
| 401 | if (ids != null) { |
| 402 | event.setAutofillIds(ids); |
| 403 | } |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 404 | final ViewNode node = ViewNode.readFromParcel(parcel); |
| 405 | if (node != null) { |
| 406 | event.setViewNode(node); |
| 407 | } |
| 408 | event.setText(parcel.readCharSequence()); |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 409 | if (type == TYPE_SESSION_STARTED || type == TYPE_SESSION_FINISHED) { |
| 410 | event.setParentSessionId(parcel.readString()); |
| 411 | } |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 412 | if (type == TYPE_SESSION_STARTED || type == TYPE_CONTEXT_UPDATED) { |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 413 | event.setClientContext(parcel.readParcelable(null)); |
| 414 | } |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 415 | return event; |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | @Override |
Felipe Leme | ce6877b | 2019-02-28 09:02:26 -0800 | [diff] [blame] | 419 | @NonNull |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 420 | public ContentCaptureEvent[] newArray(int size) { |
| 421 | return new ContentCaptureEvent[size]; |
| 422 | } |
| 423 | }; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 424 | |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 425 | /** @hide */ |
| 426 | public static String getTypeAsString(@EventType int type) { |
| 427 | switch (type) { |
Felipe Leme | 87a9dc9 | 2018-12-18 14:28:07 -0800 | [diff] [blame] | 428 | case TYPE_SESSION_STARTED: |
| 429 | return "SESSION_STARTED"; |
| 430 | case TYPE_SESSION_FINISHED: |
| 431 | return "SESSION_FINISHED"; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 432 | case TYPE_SESSION_RESUMED: |
| 433 | return "SESSION_RESUMED"; |
| 434 | case TYPE_SESSION_PAUSED: |
| 435 | return "SESSION_PAUSED"; |
Felipe Leme | 88eae3b | 2018-11-07 15:11:56 -0800 | [diff] [blame] | 436 | case TYPE_VIEW_APPEARED: |
| 437 | return "VIEW_APPEARED"; |
| 438 | case TYPE_VIEW_DISAPPEARED: |
| 439 | return "VIEW_DISAPPEARED"; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 440 | case TYPE_VIEW_TEXT_CHANGED: |
| 441 | return "VIEW_TEXT_CHANGED"; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 442 | case TYPE_VIEW_TREE_APPEARING: |
Felipe Leme | 544b39c | 2019-02-22 09:26:29 -0800 | [diff] [blame] | 443 | return "VIEW_TREE_APPEARING"; |
Felipe Leme | b0da18f | 2019-02-22 15:10:02 -0800 | [diff] [blame] | 444 | case TYPE_VIEW_TREE_APPEARED: |
Felipe Leme | 544b39c | 2019-02-22 09:26:29 -0800 | [diff] [blame] | 445 | return "VIEW_TREE_APPEARED"; |
Felipe Leme | 4eecbe6 | 2019-02-11 17:50:17 -0800 | [diff] [blame] | 446 | case TYPE_CONTEXT_UPDATED: |
| 447 | return "CONTEXT_UPDATED"; |
Felipe Leme | 7a53408 | 2018-11-05 15:03:04 -0800 | [diff] [blame] | 448 | default: |
| 449 | return "UKNOWN_TYPE: " + type; |
| 450 | } |
| 451 | } |
Felipe Leme | 1dfa9a0 | 2018-10-17 17:24:37 -0700 | [diff] [blame] | 452 | } |