blob: f1281ff010332a52834f28d0c4e853d9f127efef [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 */
Felipe Leme749b8892018-12-03 16:30:30 -080016package android.service.contentcapture;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070017
18import android.annotation.IntDef;
19import android.annotation.NonNull;
20import android.annotation.SystemApi;
21import android.app.TaskInfo;
22import android.content.ComponentName;
23import android.os.Parcel;
24import android.os.Parcelable;
25
Felipe Lemee348dc32018-11-05 12:35:29 -080026import com.android.internal.util.Preconditions;
27
28import java.io.PrintWriter;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070029import java.lang.annotation.Retention;
30import java.lang.annotation.RetentionPolicy;
31
32// TODO(b/111276913): add javadocs / implement Parcelable / implement equals/hashcode/toString
33/** @hide */
34@SystemApi
35public final class InteractionContext implements Parcelable {
36
37 /**
Felipe Lemee348dc32018-11-05 12:35:29 -080038 * Flag used to indicate that the app explicitly disabled content capture for the activity
Felipe Leme1dfa9a02018-10-17 17:24:37 -070039 * (using
Felipe Leme749b8892018-12-03 16:30:30 -080040 * {@link android.view.contentcapture.ContentCaptureManager#setContentCaptureEnabled(boolean)}),
Felipe Leme1dfa9a02018-10-17 17:24:37 -070041 * in which case the service will just receive activity-level events.
42 */
43 public static final int FLAG_DISABLED_BY_APP = 0x1;
44
45 /**
46 * Flag used to indicate that the activity's window is tagged with
47 * {@link android.view.Display#FLAG_SECURE}, in which case the service will just receive
48 * activity-level events.
49 */
50 public static final int FLAG_DISABLED_BY_FLAG_SECURE = 0x2;
51
52 /** @hide */
53 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
54 FLAG_DISABLED_BY_APP,
55 FLAG_DISABLED_BY_FLAG_SECURE
56 })
57 @Retention(RetentionPolicy.SOURCE)
58 @interface ContextCreationFlags{}
59
Felipe Lemee348dc32018-11-05 12:35:29 -080060 // TODO(b/111276913): create new object for taskId + componentName / reuse on other places
61 private final @NonNull ComponentName mComponentName;
62 private final int mTaskId;
63 private final int mDisplayId;
64 private final int mFlags;
65
66
Felipe Leme1dfa9a02018-10-17 17:24:37 -070067 /** @hide */
Felipe Lemee348dc32018-11-05 12:35:29 -080068 public InteractionContext(@NonNull ComponentName componentName, int taskId, int displayId,
69 int flags) {
70 mComponentName = Preconditions.checkNotNull(componentName);
71 mTaskId = taskId;
72 mDisplayId = displayId;
73 mFlags = flags;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070074 }
75
76 /**
77 * Gets the id of the {@link TaskInfo task} associated with this context.
78 */
79 public int getTaskId() {
Felipe Lemee348dc32018-11-05 12:35:29 -080080 return mTaskId;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070081 }
82
83 /**
84 * Gets the activity associated with this context.
85 */
86 public @NonNull ComponentName getActivityComponent() {
Felipe Lemee348dc32018-11-05 12:35:29 -080087 return mComponentName;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070088 }
89
90 /**
91 * Gets the ID of the display associated with this context, as defined by
92 * {G android.hardware.display.DisplayManager#getDisplay(int) DisplayManager.getDisplay()}.
93 */
94 public int getDisplayId() {
Felipe Lemee348dc32018-11-05 12:35:29 -080095 return mDisplayId;
Felipe Leme1dfa9a02018-10-17 17:24:37 -070096 }
97
98 /**
99 * Gets the flags associated with this context.
100 *
101 * @return any combination of {@link #FLAG_DISABLED_BY_FLAG_SECURE} and
102 * {@link #FLAG_DISABLED_BY_APP}.
103 */
104 public @ContextCreationFlags int getFlags() {
Felipe Lemee348dc32018-11-05 12:35:29 -0800105 return mFlags;
106 }
107
108 /**
109 * @hide
110 */
111 // TODO(b/111276913): dump to proto as well
112 public void dump(PrintWriter pw) {
113 pw.print("comp="); pw.print(mComponentName.flattenToShortString());
114 pw.print(", taskId="); pw.print(mTaskId);
115 pw.print(", displayId="); pw.print(mDisplayId);
116 if (mFlags > 0) {
117 pw.print(", flags="); pw.print(mFlags);
118 }
119 }
120
121 @Override
122 public String toString() {
123 return "Context[act=" + mComponentName.flattenToShortString() + ", taskId=" + mTaskId
124 + ", displayId=" + mDisplayId + ", flags=" + mFlags + "]";
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700125 }
126
127 @Override
128 public int describeContents() {
129 return 0;
130 }
131
132 @Override
133 public void writeToParcel(Parcel parcel, int flags) {
Felipe Lemee348dc32018-11-05 12:35:29 -0800134 parcel.writeParcelable(mComponentName, flags);
135 parcel.writeInt(mTaskId);
136 parcel.writeInt(mDisplayId);
137 parcel.writeInt(mFlags);
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700138 }
139
140 public static final Parcelable.Creator<InteractionContext> CREATOR =
141 new Parcelable.Creator<InteractionContext>() {
142
143 @Override
144 public InteractionContext createFromParcel(Parcel parcel) {
Felipe Lemee348dc32018-11-05 12:35:29 -0800145 final ComponentName componentName = parcel.readParcelable(null);
146 final int taskId = parcel.readInt();
147 final int displayId = parcel.readInt();
148 final int flags = parcel.readInt();
149 return new InteractionContext(componentName, taskId, displayId, flags);
Felipe Leme1dfa9a02018-10-17 17:24:37 -0700150 }
151
152 @Override
153 public InteractionContext[] newArray(int size) {
154 return new InteractionContext[size];
155 }
156 };
157}