Debian Codegraph @

core/java/android/app/assist/ActivityId.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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
17 package android.app.assist;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.annotation.TestApi;
23 import android.os.IBinder;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.service.contentcapture.ContentCaptureService;
27 import android.view.contentcapture.ContentCaptureContext;
28 import android.view.translation.UiTranslationManager;
29
30 import com.android.internal.annotations.Immutable;
31
32 /**
33 * The class is used to identify an instance of an Activity. The system provides this to services
34 * that need to request operations on a specific Activity. For example, the system provides this in
35 * {@link ContentCaptureContext} to {@link ContentCaptureService} which can use it to issue requests
36 * like {@link UiTranslationManager#startTranslation}.
37 *
38 * @hide
39 */
40 @Immutable
41 @SystemApi
42 @TestApi
43 public final class ActivityId implements Parcelable {
44
45 /**
46 * The identifier of the task this activity is in.
47 */
48 private final int mTaskId;
49 /**
50 * The identifier of the activity.
51 */
52 @Nullable
53 private final IBinder mActivityId;
54
55 /**
56 * @hide
57 */
58 @TestApi
59 public ActivityId(int taskId, @Nullable IBinder activityId) {
60 mTaskId = taskId;
61 mActivityId = activityId;
62 }
63
64 /**
65 * @hide
66 */
67 public ActivityId(@NonNull Parcel source) {
68 mTaskId = source.readInt();
69 mActivityId = source.readStrongBinder();
70 }
71
72 /**
73 * The identifier of the task this activity is in.
74 * @hide
75 */
76 @TestApi
77 public int getTaskId() {
78 return mTaskId;
79 }
80
81 /**
82 * The identifier of the activity. In some case, this value may be null, e.g. the child session
83 * of content capture.
84 * @hide
85 */
86 @Nullable
87 @TestApi
88 public IBinder getToken() {
89 return mActivityId;
90 }
91
92 /**
93 * {@inheritDoc}
94 */
95 @Override
96 public int describeContents() {
97 return 0;
98 }
99
100 /**
101 * {@inheritDoc}
102 */
103 @Override
104 public void writeToParcel(@NonNull Parcel dest, int flags) {
105 dest.writeInt(mTaskId);
106 dest.writeStrongBinder(mActivityId);
107 }
108
109 /**
110 * Creates {@link ActivityId} instances from parcels.
111 */
112 @NonNull
113 public static final Parcelable.Creator<ActivityId> CREATOR =
114 new Parcelable.Creator<ActivityId>() {
115 @Override
116 public ActivityId createFromParcel(Parcel parcel) {
117 return new ActivityId(parcel);
118 }
119
120 @Override
121 public ActivityId[] newArray(int size) {
122 return new ActivityId[size];
123 }
124 };
125
126 @Override
127 public String toString() {
128 return "ActivityId { taskId = " + mTaskId + ", activityId = " + mActivityId + " }";
129 }
130
131 @Override
132 public boolean equals(@Nullable Object o) {
133 if (this == o) {
134 return true;
135 }
136 if (o == null || getClass() != o.getClass()) {
137 return false;
138 }
139 ActivityId that = (ActivityId) o;
140 if (mTaskId != that.mTaskId) {
141 return false;
142 }
143 return mActivityId != null
144 ? mActivityId.equals(that.mActivityId)
145 : that.mActivityId == null;
146 }
147
148 @Override
149 public int hashCode() {
150 int result = mTaskId;
151 result = 31 * result + (mActivityId != null ? mActivityId.hashCode() : 0);
152 return result;
153 }
154 }