Refactored ContentCapture sessions to use an int id.
This is an internal change that will save memory:
- ids themselves are smaller (one int vs ~20 chars string)
- can be mapped with SparseArrays
- parcel objects will be smaller
Test: atest CtsContentCaptureServiceTestCases \
FrameworksCoreTests:android.view.contentcapture.ContentCaptureEventTest \
FrameworksCoreTests:android.view.contentcapture.ContentCaptureSessionTest
Fixes: 121197119
Change-Id: I4b4367bd7238400ade385c2bcc4b0595ed0b1c7b
diff --git a/core/java/android/service/contentcapture/ContentCaptureService.java b/core/java/android/service/contentcapture/ContentCaptureService.java
index 7a35b9e..f83090c 100644
--- a/core/java/android/service/contentcapture/ContentCaptureService.java
+++ b/core/java/android/service/contentcapture/ContentCaptureService.java
@@ -17,6 +17,7 @@
import static android.view.contentcapture.ContentCaptureHelper.sDebug;
import static android.view.contentcapture.ContentCaptureHelper.sVerbose;
+import static android.view.contentcapture.ContentCaptureSession.NO_SESSION_ID;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
@@ -36,9 +37,9 @@
import android.os.Looper;
import android.os.RemoteException;
import android.service.autofill.AutofillService;
-import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
+import android.util.SparseIntArray;
import android.view.contentcapture.ContentCaptureCondition;
import android.view.contentcapture.ContentCaptureContext;
import android.view.contentcapture.ContentCaptureEvent;
@@ -117,7 +118,7 @@
}
@Override
- public void onSessionStarted(ContentCaptureContext context, String sessionId, int uid,
+ public void onSessionStarted(ContentCaptureContext context, int sessionId, int uid,
IResultReceiver clientReceiver, int initialState) {
mHandler.sendMessage(obtainMessage(ContentCaptureService::handleOnCreateSession,
ContentCaptureService.this, context, sessionId, uid, clientReceiver,
@@ -125,14 +126,14 @@
}
@Override
- public void onActivitySnapshot(String sessionId, SnapshotData snapshotData) {
+ public void onActivitySnapshot(int sessionId, SnapshotData snapshotData) {
mHandler.sendMessage(
obtainMessage(ContentCaptureService::handleOnActivitySnapshot,
ContentCaptureService.this, sessionId, snapshotData));
}
@Override
- public void onSessionFinished(String sessionId) {
+ public void onSessionFinished(int sessionId) {
mHandler.sendMessage(obtainMessage(ContentCaptureService::handleFinishSession,
ContentCaptureService.this, sessionId));
}
@@ -171,7 +172,7 @@
* <p>This map is populated when an session is started, which is called by the system server
* and can be trusted. Then subsequent calls made by the app are verified against this map.
*/
- private final ArrayMap<String, Integer> mSessionUids = new ArrayMap<>();
+ private final SparseIntArray mSessionUids = new SparseIntArray();
@CallSuper
@Override
@@ -378,7 +379,7 @@
// so we don't need to create a temporary InteractionSessionId for each event.
private void handleOnCreateSession(@NonNull ContentCaptureContext context,
- @NonNull String sessionId, int uid, IResultReceiver clientReceiver, int initialState) {
+ int sessionId, int uid, IResultReceiver clientReceiver, int initialState) {
mSessionUids.put(sessionId, uid);
onCreateContentCaptureSession(context, new ContentCaptureSessionId(sessionId));
@@ -403,27 +404,27 @@
// Most events belong to the same session, so we can keep a reference to the last one
// to avoid creating too many ContentCaptureSessionId objects
- String lastSessionId = null;
+ int lastSessionId = NO_SESSION_ID;
ContentCaptureSessionId sessionId = null;
final List<ContentCaptureEvent> events = parceledEvents.getList();
for (int i = 0; i < events.size(); i++) {
final ContentCaptureEvent event = events.get(i);
if (!handleIsRightCallerFor(event, uid)) continue;
- String sessionIdString = event.getSessionId();
- if (!sessionIdString.equals(lastSessionId)) {
- sessionId = new ContentCaptureSessionId(sessionIdString);
- lastSessionId = sessionIdString;
+ int sessionIdInt = event.getSessionId();
+ if (sessionIdInt != lastSessionId) {
+ sessionId = new ContentCaptureSessionId(sessionIdInt);
+ lastSessionId = sessionIdInt;
}
switch (event.getType()) {
case ContentCaptureEvent.TYPE_SESSION_STARTED:
final ContentCaptureContext clientContext = event.getContentCaptureContext();
clientContext.setParentSessionId(event.getParentSessionId());
- mSessionUids.put(sessionIdString, uid);
+ mSessionUids.put(sessionIdInt, uid);
onCreateContentCaptureSession(clientContext, sessionId);
break;
case ContentCaptureEvent.TYPE_SESSION_FINISHED:
- mSessionUids.remove(sessionIdString);
+ mSessionUids.delete(sessionIdInt);
onDestroyContentCaptureSession(sessionId);
break;
default:
@@ -432,13 +433,12 @@
}
}
- private void handleOnActivitySnapshot(@NonNull String sessionId,
- @NonNull SnapshotData snapshotData) {
+ private void handleOnActivitySnapshot(int sessionId, @NonNull SnapshotData snapshotData) {
onActivitySnapshot(new ContentCaptureSessionId(sessionId), snapshotData);
}
- private void handleFinishSession(@NonNull String sessionId) {
- mSessionUids.remove(sessionId);
+ private void handleFinishSession(int sessionId) {
+ mSessionUids.delete(sessionId);
onDestroyContentCaptureSession(new ContentCaptureSessionId(sessionId));
}
@@ -454,7 +454,7 @@
* Checks if the given {@code uid} owns the session associated with the event.
*/
private boolean handleIsRightCallerFor(@NonNull ContentCaptureEvent event, int uid) {
- final String sessionId;
+ final int sessionId;
switch (event.getType()) {
case ContentCaptureEvent.TYPE_SESSION_STARTED:
case ContentCaptureEvent.TYPE_SESSION_FINISHED:
@@ -463,8 +463,7 @@
default:
sessionId = event.getSessionId();
}
- final Integer rightUid = mSessionUids.get(sessionId);
- if (rightUid == null) {
+ if (mSessionUids.indexOfKey(sessionId) < 0) {
if (sVerbose) {
Log.v(TAG, "handleIsRightCallerFor(" + event + "): no session for " + sessionId
+ ": " + mSessionUids);
@@ -472,6 +471,7 @@
// Just ignore, as the session could have been finished already
return false;
}
+ final int rightUid = mSessionUids.get(sessionId);
if (rightUid != uid) {
Log.e(TAG, "invalid call from UID " + uid + ": session " + sessionId + " belongs to "
+ rightUid);
diff --git a/core/java/android/service/contentcapture/IContentCaptureService.aidl b/core/java/android/service/contentcapture/IContentCaptureService.aidl
index 6be7a80..03e1b78 100644
--- a/core/java/android/service/contentcapture/IContentCaptureService.aidl
+++ b/core/java/android/service/contentcapture/IContentCaptureService.aidl
@@ -35,10 +35,10 @@
oneway interface IContentCaptureService {
void onConnected(IBinder callback, boolean verbose, boolean debug);
void onDisconnected();
- void onSessionStarted(in ContentCaptureContext context, String sessionId, int uid,
+ void onSessionStarted(in ContentCaptureContext context, int sessionId, int uid,
in IResultReceiver clientReceiver, int initialState);
- void onSessionFinished(String sessionId);
- void onActivitySnapshot(String sessionId, in SnapshotData snapshotData);
+ void onSessionFinished(int sessionId);
+ void onActivitySnapshot(int sessionId, in SnapshotData snapshotData);
void onUserDataRemovalRequest(in UserDataRemovalRequest request);
void onActivityEvent(in ActivityEvent event);
}
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index c34613e..4f84fa1 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -86,7 +86,6 @@
import android.sysprop.DisplayProperties;
import android.text.InputType;
import android.text.TextUtils;
-import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.LayoutDirection;
@@ -28578,8 +28577,7 @@
* hierarchy is traversed: value is either the view itself for appearead events, or its
* autofill id for disappeared.
*/
- // TODO(b/121197119): use SparseArray once session id becomes integer
- ArrayMap<String, ArrayList<Object>> mContentCaptureEvents;
+ SparseArray<ArrayList<Object>> mContentCaptureEvents;
/**
* Cached reference to the {@link ContentCaptureManager}.
@@ -28609,9 +28607,9 @@
@NonNull View view, boolean appeared) {
if (mContentCaptureEvents == null) {
// Most of the time there will be just one session, so intial capacity is 1
- mContentCaptureEvents = new ArrayMap<>(1);
+ mContentCaptureEvents = new SparseArray<>(1);
}
- String sessionId = session.getId();
+ int sessionId = session.getId();
// TODO: life would be much easier if we provided a MultiMap implementation somwhere...
ArrayList<Object> events = mContentCaptureEvents.get(sessionId);
if (events == null) {
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 2880e7f..5f60333 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -2811,8 +2811,7 @@
MainContentCaptureSession mainSession = mAttachInfo.mContentCaptureManager
.getMainContentCaptureSession();
for (int i = 0; i < mAttachInfo.mContentCaptureEvents.size(); i++) {
- String sessionId = mAttachInfo.mContentCaptureEvents
- .keyAt(i);
+ int sessionId = mAttachInfo.mContentCaptureEvents.keyAt(i);
mainSession.notifyViewTreeEvent(sessionId, /* started= */ true);
ArrayList<Object> events = mAttachInfo.mContentCaptureEvents
.valueAt(i);
@@ -2827,8 +2826,8 @@
Log.w(mTag, "no content capture session on view: " + view);
continue for_each_event;
}
- String actualId = session.getId().toString();
- if (!actualId.equals(sessionId)) {
+ int actualId = session.getId();
+ if (actualId != sessionId) {
Log.w(mTag, "content capture session mismatch for view (" + view
+ "): was " + sessionId + " before, it's " + actualId + " now");
continue for_each_event;
diff --git a/core/java/android/view/contentcapture/ContentCaptureContext.java b/core/java/android/view/contentcapture/ContentCaptureContext.java
index 5a27e94..a7b0259 100644
--- a/core/java/android/view/contentcapture/ContentCaptureContext.java
+++ b/core/java/android/view/contentcapture/ContentCaptureContext.java
@@ -15,6 +15,8 @@
*/
package android.view.contentcapture;
+import static android.view.contentcapture.ContentCaptureSession.NO_SESSION_ID;
+
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -35,7 +37,6 @@
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-
/**
* Context associated with a {@link ContentCaptureSession}.
*/
@@ -107,7 +108,7 @@
private final int mDisplayId;
// Fields below are set by the service upon "delivery" and are not marshalled in the parcel
- private @Nullable String mParentSessionId;
+ private int mParentSessionId = NO_SESSION_ID;
/** @hide */
public ContentCaptureContext(@Nullable ContentCaptureContext clientContext,
@@ -198,11 +199,12 @@
@SystemApi
@TestApi
public @Nullable ContentCaptureSessionId getParentSessionId() {
- return mParentSessionId == null ? null : new ContentCaptureSessionId(mParentSessionId);
+ return mParentSessionId == NO_SESSION_ID ? null
+ : new ContentCaptureSessionId(mParentSessionId);
}
/** @hide */
- public void setParentSessionId(@NonNull String parentSessionId) {
+ public void setParentSessionId(int parentSessionId) {
mParentSessionId = parentSessionId;
}
@@ -316,7 +318,7 @@
}
pw.print(", taskId="); pw.print(mTaskId);
pw.print(", displayId="); pw.print(mDisplayId);
- if (mParentSessionId != null) {
+ if (mParentSessionId != NO_SESSION_ID) {
pw.print(", parentId="); pw.print(mParentSessionId);
}
if (mFlags > 0) {
@@ -348,7 +350,7 @@
builder.append(", hasExtras");
}
}
- if (mParentSessionId != null) {
+ if (mParentSessionId != NO_SESSION_ID) {
builder.append(", parentId=").append(mParentSessionId);
}
return builder.append(']').toString();
diff --git a/core/java/android/view/contentcapture/ContentCaptureEvent.java b/core/java/android/view/contentcapture/ContentCaptureEvent.java
index 8188e05..bd38629 100644
--- a/core/java/android/view/contentcapture/ContentCaptureEvent.java
+++ b/core/java/android/view/contentcapture/ContentCaptureEvent.java
@@ -16,6 +16,7 @@
package android.view.contentcapture;
import static android.view.contentcapture.ContentCaptureHelper.getSanitizedString;
+import static android.view.contentcapture.ContentCaptureSession.NO_SESSION_ID;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -126,25 +127,25 @@
@Retention(RetentionPolicy.SOURCE)
public @interface EventType{}
- private final @NonNull String mSessionId;
+ private final int mSessionId;
private final int mType;
private final long mEventTime;
private @Nullable AutofillId mId;
private @Nullable ArrayList<AutofillId> mIds;
private @Nullable ViewNode mNode;
private @Nullable CharSequence mText;
- private @Nullable String mParentSessionId;
+ private int mParentSessionId = NO_SESSION_ID;
private @Nullable ContentCaptureContext mClientContext;
/** @hide */
- public ContentCaptureEvent(@NonNull String sessionId, int type, long eventTime) {
+ public ContentCaptureEvent(int sessionId, int type, long eventTime) {
mSessionId = sessionId;
mType = type;
mEventTime = eventTime;
}
/** @hide */
- public ContentCaptureEvent(@NonNull String sessionId, int type) {
+ public ContentCaptureEvent(int sessionId, int type) {
this(sessionId, type, System.currentTimeMillis());
}
@@ -185,7 +186,7 @@
*
* @hide
*/
- public ContentCaptureEvent setParentSessionId(@NonNull String parentSessionId) {
+ public ContentCaptureEvent setParentSessionId(int parentSessionId) {
mParentSessionId = parentSessionId;
return this;
}
@@ -202,7 +203,7 @@
/** @hide */
@NonNull
- public String getSessionId() {
+ public int getSessionId() {
return mSessionId;
}
@@ -212,7 +213,7 @@
* @hide
*/
@Nullable
- public String getParentSessionId() {
+ public int getParentSessionId() {
return mParentSessionId;
}
@@ -357,10 +358,10 @@
if (mNode != null) {
pw.print(", mNode.id="); pw.print(mNode.getAutofillId());
}
- if (mSessionId != null) {
+ if (mSessionId != NO_SESSION_ID) {
pw.print(", sessionId="); pw.print(mSessionId);
}
- if (mParentSessionId != null) {
+ if (mParentSessionId != NO_SESSION_ID) {
pw.print(", parentSessionId="); pw.print(mParentSessionId);
}
if (mText != null) {
@@ -377,7 +378,7 @@
final StringBuilder string = new StringBuilder("ContentCaptureEvent[type=")
.append(getTypeAsString(mType));
string.append(", session=").append(mSessionId);
- if (mType == TYPE_SESSION_STARTED && mParentSessionId != null) {
+ if (mType == TYPE_SESSION_STARTED && mParentSessionId != NO_SESSION_ID) {
string.append(", parent=").append(mParentSessionId);
}
if (mId != null) {
@@ -409,7 +410,7 @@
@Override
public void writeToParcel(Parcel parcel, int flags) {
- parcel.writeString(mSessionId);
+ parcel.writeInt(mSessionId);
parcel.writeInt(mType);
parcel.writeLong(mEventTime);
parcel.writeParcelable(mId, flags);
@@ -417,7 +418,7 @@
ViewNode.writeToParcel(parcel, mNode, flags);
parcel.writeCharSequence(mText);
if (mType == TYPE_SESSION_STARTED || mType == TYPE_SESSION_FINISHED) {
- parcel.writeString(mParentSessionId);
+ parcel.writeInt(mParentSessionId);
}
if (mType == TYPE_SESSION_STARTED || mType == TYPE_CONTEXT_UPDATED) {
parcel.writeParcelable(mClientContext, flags);
@@ -430,7 +431,7 @@
@Override
@NonNull
public ContentCaptureEvent createFromParcel(Parcel parcel) {
- final String sessionId = parcel.readString();
+ final int sessionId = parcel.readInt();
final int type = parcel.readInt();
final long eventTime = parcel.readLong();
final ContentCaptureEvent event = new ContentCaptureEvent(sessionId, type, eventTime);
@@ -448,7 +449,7 @@
}
event.setText(parcel.readCharSequence());
if (type == TYPE_SESSION_STARTED || type == TYPE_SESSION_FINISHED) {
- event.setParentSessionId(parcel.readString());
+ event.setParentSessionId(parcel.readInt());
}
if (type == TYPE_SESSION_STARTED || type == TYPE_CONTEXT_UPDATED) {
event.setClientContext(parcel.readParcelable(null));
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index ed1ca2a..7761038 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -38,7 +38,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
-import java.util.UUID;
+import java.util.Random;
/**
* Session used to notify a system-provided Content Capture service about events associated with
@@ -48,6 +48,11 @@
private static final String TAG = ContentCaptureSession.class.getSimpleName();
+ private static final Random sIdGenerator = new Random();
+
+ /** @hide */
+ public static final int NO_SESSION_ID = 0;
+
/**
* Initial state, when there is no session.
*
@@ -186,7 +191,7 @@
/** @hide */
@Nullable
- protected final String mId;
+ protected final int mId;
private int mState = UNKNOWN_STATE;
@@ -210,13 +215,14 @@
/** @hide */
protected ContentCaptureSession() {
- this(UUID.randomUUID().toString());
+ this(getRandomSessionId());
}
/** @hide */
@VisibleForTesting
- public ContentCaptureSession(@NonNull String id) {
- mId = Preconditions.checkNotNull(id);
+ public ContentCaptureSession(int id) {
+ Preconditions.checkArgument(id != NO_SESSION_ID);
+ mId = id;
}
// Used by ChildCOntentCaptureSession
@@ -241,15 +247,8 @@
}
/** @hide */
- @VisibleForTesting
- public int getIdAsInt() {
- // TODO(b/121197119): use sessionId instead of hashcode once it's changed to int
- return mId.hashCode();
- }
-
- /** @hide */
@NonNull
- public String getId() {
+ public int getId() {
return mId;
}
@@ -415,7 +414,7 @@
// TODO(b/123036895): use a internalNotifyViewsDisappeared that optimizes how the event is
// parcelized
for (long id : virtualIds) {
- internalNotifyViewDisappeared(new AutofillId(hostId, id, getIdAsInt()));
+ internalNotifyViewDisappeared(new AutofillId(hostId, id, mId));
}
}
@@ -464,7 +463,7 @@
public @NonNull AutofillId newAutofillId(@NonNull AutofillId hostId, long virtualChildId) {
Preconditions.checkNotNull(hostId);
Preconditions.checkArgument(hostId.isNonVirtual(), "hostId cannot be virtual: %s", hostId);
- return new AutofillId(hostId, virtualChildId, getIdAsInt());
+ return new AutofillId(hostId, virtualChildId, mId);
}
/**
@@ -480,7 +479,7 @@
@NonNull
public final ViewStructure newVirtualViewStructure(@NonNull AutofillId parentId,
long virtualId) {
- return new ViewNode.ViewStructureImpl(parentId, virtualId, getIdAsInt());
+ return new ViewNode.ViewStructureImpl(parentId, virtualId, mId);
}
boolean isContentCaptureEnabled() {
@@ -511,7 +510,7 @@
@Override
public String toString() {
- return mId;
+ return Integer.toString(mId);
}
/** @hide */
@@ -541,4 +540,12 @@
return "UNKOWN-" + reason;
}
}
+
+ private static int getRandomSessionId() {
+ int id;
+ do {
+ id = sIdGenerator.nextInt();
+ } while (id == NO_SESSION_ID);
+ return id;
+ }
}
diff --git a/core/java/android/view/contentcapture/ContentCaptureSessionId.java b/core/java/android/view/contentcapture/ContentCaptureSessionId.java
index e7c350a..2d350b2 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSessionId.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSessionId.java
@@ -27,7 +27,7 @@
*/
public final class ContentCaptureSessionId implements Parcelable {
- private final @NonNull String mValue;
+ private final @NonNull int mValue;
/**
* Creates a new instance.
@@ -36,14 +36,14 @@
*
* @hide
*/
- public ContentCaptureSessionId(@NonNull String value) {
+ public ContentCaptureSessionId(@NonNull int value) {
mValue = value;
}
/**
* @hide
*/
- public String getValue() {
+ public int getValue() {
return mValue;
}
@@ -51,7 +51,7 @@
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((mValue == null) ? 0 : mValue.hashCode());
+ result = prime * result + mValue;
return result;
}
@@ -61,11 +61,7 @@
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final ContentCaptureSessionId other = (ContentCaptureSessionId) obj;
- if (mValue == null) {
- if (other.mValue != null) return false;
- } else if (!mValue.equals(other.mValue)) {
- return false;
- }
+ if (mValue != other.mValue) return false;
return true;
}
@@ -77,9 +73,10 @@
*/
@Override
public String toString() {
- return mValue;
+ return Integer.toString(mValue);
}
+
/** @hide */
// TODO(b/111276913): dump to proto as well
public void dump(PrintWriter pw) {
@@ -93,16 +90,16 @@
@Override
public void writeToParcel(Parcel parcel, int flags) {
- parcel.writeString(mValue);
+ parcel.writeInt(mValue);
}
- public static final @android.annotation.NonNull Parcelable.Creator<ContentCaptureSessionId> CREATOR =
+ public static final @NonNull Parcelable.Creator<ContentCaptureSessionId> CREATOR =
new Parcelable.Creator<ContentCaptureSessionId>() {
@Override
@NonNull
public ContentCaptureSessionId createFromParcel(Parcel parcel) {
- return new ContentCaptureSessionId(parcel.readString());
+ return new ContentCaptureSessionId(parcel.readInt());
}
@Override
diff --git a/core/java/android/view/contentcapture/IContentCaptureManager.aidl b/core/java/android/view/contentcapture/IContentCaptureManager.aidl
index 15fbaa2..2775029 100644
--- a/core/java/android/view/contentcapture/IContentCaptureManager.aidl
+++ b/core/java/android/view/contentcapture/IContentCaptureManager.aidl
@@ -42,13 +42,13 @@
* {@link IContentCaptureContext#flags}).
*/
void startSession(IBinder activityToken, in ComponentName componentName,
- String sessionId, int flags, in IResultReceiver result);
+ int sessionId, int flags, in IResultReceiver result);
/**
* Marks the end of a session for the calling user identified by
* the corresponding {@code startSession}'s {@code sessionId}.
*/
- void finishSession(String sessionId);
+ void finishSession(int sessionId);
/**
* Returns the content capture service's component name (if enabled and
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index 790b8f9..784cf9c 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -318,7 +318,7 @@
if (!mEvents.isEmpty() && eventType == TYPE_VIEW_DISAPPEARED) {
final ContentCaptureEvent lastEvent = mEvents.get(mEvents.size() - 1);
if (lastEvent.getType() == TYPE_VIEW_DISAPPEARED
- && event.getSessionId().equals(lastEvent.getSessionId())) {
+ && event.getSessionId() == lastEvent.getSessionId()) {
if (sVerbose) {
Log.v(TAG, "Buffering TYPE_VIEW_DISAPPEARED events for session "
+ lastEvent.getSessionId());
@@ -581,37 +581,35 @@
// TODO(b/122454205): refactor "notifyXXXX" methods below to a common "Buffer" object that is
// shared between ActivityContentCaptureSession and ChildContentCaptureSession objects. Such
// change should also get get rid of the "internalNotifyXXXX" methods above
- void notifyChildSessionStarted(@NonNull String parentSessionId,
- @NonNull String childSessionId, @NonNull ContentCaptureContext clientContext) {
+ void notifyChildSessionStarted(int parentSessionId, int childSessionId,
+ @NonNull ContentCaptureContext clientContext) {
sendEvent(new ContentCaptureEvent(childSessionId, TYPE_SESSION_STARTED)
.setParentSessionId(parentSessionId).setClientContext(clientContext),
FORCE_FLUSH);
}
- void notifyChildSessionFinished(@NonNull String parentSessionId,
- @NonNull String childSessionId) {
+ void notifyChildSessionFinished(int parentSessionId, int childSessionId) {
sendEvent(new ContentCaptureEvent(childSessionId, TYPE_SESSION_FINISHED)
.setParentSessionId(parentSessionId), FORCE_FLUSH);
}
- void notifyViewAppeared(@NonNull String sessionId, @NonNull ViewStructureImpl node) {
+ void notifyViewAppeared(int sessionId, @NonNull ViewStructureImpl node) {
sendEvent(new ContentCaptureEvent(sessionId, TYPE_VIEW_APPEARED)
.setViewNode(node.mNode));
}
/** Public because is also used by ViewRootImpl */
- public void notifyViewDisappeared(@NonNull String sessionId, @NonNull AutofillId id) {
+ public void notifyViewDisappeared(int sessionId, @NonNull AutofillId id) {
sendEvent(new ContentCaptureEvent(sessionId, TYPE_VIEW_DISAPPEARED).setAutofillId(id));
}
- void notifyViewTextChanged(@NonNull String sessionId, @NonNull AutofillId id,
- @Nullable CharSequence text) {
+ void notifyViewTextChanged(int sessionId, @NonNull AutofillId id, @Nullable CharSequence text) {
sendEvent(new ContentCaptureEvent(sessionId, TYPE_VIEW_TEXT_CHANGED).setAutofillId(id)
.setText(text));
}
/** Public because is also used by ViewRootImpl */
- public void notifyViewTreeEvent(@NonNull String sessionId, boolean started) {
+ public void notifyViewTreeEvent(int sessionId, boolean started) {
final int type = started ? TYPE_VIEW_TREE_APPEARING : TYPE_VIEW_TREE_APPEARED;
sendEvent(new ContentCaptureEvent(sessionId, type), FORCE_FLUSH);
}
@@ -622,8 +620,7 @@
sendEvent(new ContentCaptureEvent(mId, type), FORCE_FLUSH);
}
- void notifyContextUpdated(@NonNull String sessionId,
- @Nullable ContentCaptureContext context) {
+ void notifyContextUpdated(int sessionId, @Nullable ContentCaptureContext context) {
sendEvent(new ContentCaptureEvent(sessionId, TYPE_CONTEXT_UPDATED)
.setClientContext(context));
}
diff --git a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureEventTest.java b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureEventTest.java
index 2416de1..2008537 100644
--- a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureEventTest.java
+++ b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureEventTest.java
@@ -49,13 +49,15 @@
private static final LocusId ID = new LocusId("WHATEVER");
+ private static final int NO_SESSION_ID = 0;
+
// Not using @Mock because it's final - no need to be fancy here....
private final ContentCaptureContext mClientContext =
new ContentCaptureContext.Builder(ID).build();
@Test
public void testSetAutofillId_null() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
assertThrows(NullPointerException.class, () -> event.setAutofillId(null));
assertThat(event.getId()).isNull();
@@ -64,7 +66,7 @@
@Test
public void testSetAutofillIds_null() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
assertThrows(NullPointerException.class, () -> event.setAutofillIds(null));
assertThat(event.getId()).isNull();
@@ -73,7 +75,7 @@
@Test
public void testAddAutofillId_null() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
assertThrows(NullPointerException.class, () -> event.addAutofillId(null));
assertThat(event.getId()).isNull();
@@ -82,7 +84,7 @@
@Test
public void testSetAutofillId() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
final AutofillId id = new AutofillId(108);
event.setAutofillId(id);
@@ -92,7 +94,7 @@
@Test
public void testSetAutofillIds() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
final AutofillId id = new AutofillId(108);
final ArrayList<AutofillId> ids = new ArrayList<>(1);
@@ -104,7 +106,7 @@
@Test
public void testAddAutofillId() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
final AutofillId id1 = new AutofillId(108);
event.addAutofillId(id1);
@@ -119,7 +121,7 @@
@Test
public void testAddAutofillId_afterSetId() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
final AutofillId id1 = new AutofillId(108);
event.setAutofillId(id1);
@@ -134,7 +136,7 @@
@Test
public void testAddAutofillId_afterSetIds() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
final AutofillId id1 = new AutofillId(108);
final ArrayList<AutofillId> ids = new ArrayList<>(1);
@@ -163,9 +165,9 @@
}
private ContentCaptureEvent newEventForSessionStarted() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_SESSION_STARTED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_SESSION_STARTED)
.setClientContext(mClientContext)
- .setParentSessionId("108");
+ .setParentSessionId(108);
assertThat(event).isNotNull();
return event;
}
@@ -173,8 +175,8 @@
private void assertSessionStartedEvent(ContentCaptureEvent event) {
assertThat(event.getType()).isEqualTo(TYPE_SESSION_STARTED);
assertThat(event.getEventTime()).isAtLeast(MY_EPOCH);
- assertThat(event.getSessionId()).isEqualTo("42");
- assertThat(event.getParentSessionId()).isEqualTo("108");
+ assertThat(event.getSessionId()).isEqualTo(42);
+ assertThat(event.getParentSessionId()).isEqualTo(108);
assertThat(event.getId()).isNull();
assertThat(event.getIds()).isNull();
assertThat(event.getText()).isNull();
@@ -186,17 +188,17 @@
@Test
public void testSessionFinished_directly() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_SESSION_FINISHED)
- .setParentSessionId("108");
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_SESSION_FINISHED)
+ .setParentSessionId(108);
assertThat(event).isNotNull();
assertSessionFinishedEvent(event);
}
@Test
public void testSessionFinished_throughParcel() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_SESSION_FINISHED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_SESSION_FINISHED)
.setClientContext(mClientContext) // should not be writting to parcel
- .setParentSessionId("108");
+ .setParentSessionId(108);
assertThat(event).isNotNull();
final ContentCaptureEvent clone = cloneThroughParcel(event);
assertSessionFinishedEvent(clone);
@@ -205,8 +207,8 @@
private void assertSessionFinishedEvent(ContentCaptureEvent event) {
assertThat(event.getType()).isEqualTo(TYPE_SESSION_FINISHED);
assertThat(event.getEventTime()).isAtLeast(MY_EPOCH);
- assertThat(event.getSessionId()).isEqualTo("42");
- assertThat(event.getParentSessionId()).isEqualTo("108");
+ assertThat(event.getSessionId()).isEqualTo(42);
+ assertThat(event.getParentSessionId()).isEqualTo(108);
assertThat(event.getId()).isNull();
assertThat(event.getIds()).isNull();
assertThat(event.getText()).isNull();
@@ -216,7 +218,7 @@
@Test
public void testContextUpdated_directly() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_CONTEXT_UPDATED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_CONTEXT_UPDATED)
.setClientContext(mClientContext);
assertThat(event).isNotNull();
assertContextUpdatedEvent(event);
@@ -224,7 +226,7 @@
@Test
public void testContextUpdated_throughParcel() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_CONTEXT_UPDATED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_CONTEXT_UPDATED)
.setClientContext(mClientContext);
assertThat(event).isNotNull();
final ContentCaptureEvent clone = cloneThroughParcel(event);
@@ -233,9 +235,9 @@
@Test
public void testMergeEvent_typeViewTextChanged() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_TEXT_CHANGED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_TEXT_CHANGED)
.setText("test");
- final ContentCaptureEvent event2 = new ContentCaptureEvent("43", TYPE_VIEW_TEXT_CHANGED)
+ final ContentCaptureEvent event2 = new ContentCaptureEvent(43, TYPE_VIEW_TEXT_CHANGED)
.setText("empty");
event.mergeEvent(event2);
@@ -244,14 +246,14 @@
@Test
public void testMergeEvent_typeViewDisappeared() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED)
.setAutofillId(new AutofillId(1));
- final ContentCaptureEvent event2 = new ContentCaptureEvent("43", TYPE_VIEW_DISAPPEARED)
+ final ContentCaptureEvent event2 = new ContentCaptureEvent(43, TYPE_VIEW_DISAPPEARED)
.setAutofillId(new AutofillId(2));
final ArrayList<AutofillId> autofillIds = new ArrayList<>();
autofillIds.add(new AutofillId(3));
autofillIds.add(new AutofillId(4));
- final ContentCaptureEvent event3 = new ContentCaptureEvent("17", TYPE_VIEW_DISAPPEARED)
+ final ContentCaptureEvent event3 = new ContentCaptureEvent(17, TYPE_VIEW_DISAPPEARED)
.setAutofillIds(autofillIds);
event.mergeEvent(event2);
@@ -264,24 +266,24 @@
@Test
public void testMergeEvent_typeViewDisappeared_noIds() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED)
.setAutofillId(new AutofillId(1));
- final ContentCaptureEvent event2 = new ContentCaptureEvent("43", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event2 = new ContentCaptureEvent(43, TYPE_VIEW_DISAPPEARED);
assertThrows(IllegalArgumentException.class, () -> event.mergeEvent(event2));
}
@Test
public void testMergeEvent_nullArgument() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED);
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED);
assertThrows(NullPointerException.class, () -> event.mergeEvent(null));
}
@Test
public void testMergeEvent_differentEventTypes() {
- final ContentCaptureEvent event = new ContentCaptureEvent("42", TYPE_VIEW_DISAPPEARED)
+ final ContentCaptureEvent event = new ContentCaptureEvent(42, TYPE_VIEW_DISAPPEARED)
.setText("test").setAutofillId(new AutofillId(1));
- final ContentCaptureEvent event2 = new ContentCaptureEvent("17", TYPE_VIEW_TEXT_CHANGED)
+ final ContentCaptureEvent event2 = new ContentCaptureEvent(17, TYPE_VIEW_TEXT_CHANGED)
.setText("empty").setAutofillId(new AutofillId(2));
event.mergeEvent(event2);
@@ -296,8 +298,8 @@
private void assertContextUpdatedEvent(ContentCaptureEvent event) {
assertThat(event.getType()).isEqualTo(TYPE_CONTEXT_UPDATED);
assertThat(event.getEventTime()).isAtLeast(MY_EPOCH);
- assertThat(event.getSessionId()).isEqualTo("42");
- assertThat(event.getParentSessionId()).isNull();
+ assertThat(event.getSessionId()).isEqualTo(42);
+ assertThat(event.getParentSessionId()).isEqualTo(NO_SESSION_ID);
assertThat(event.getId()).isNull();
assertThat(event.getIds()).isNull();
assertThat(event.getText()).isNull();
diff --git a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java
index 013408e..81ce15a 100644
--- a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java
+++ b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java
@@ -39,9 +39,9 @@
@RunWith(MockitoJUnitRunner.class)
public class ContentCaptureSessionTest {
- private ContentCaptureSession mSession1 = new MyContentCaptureSession("111");
+ private ContentCaptureSession mSession1 = new MyContentCaptureSession(111);
- private ContentCaptureSession mSession2 = new MyContentCaptureSession("2222");
+ private ContentCaptureSession mSession2 = new MyContentCaptureSession(2222);
@Mock
private View mMockView;
@@ -60,12 +60,12 @@
assertThat(childId.getViewId()).isEqualTo(42);
assertThat(childId.getVirtualChildLongId()).isEqualTo(108L);
assertThat(childId.getVirtualChildIntId()).isEqualTo(View.NO_ID);
- assertThat(childId.getSessionId()).isEqualTo(mSession1.getIdAsInt());
+ assertThat(childId.getSessionId()).isEqualTo(mSession1.getId());
}
@Test
public void testNewAutofillId_differentSessions() {
- assertThat(mSession1.getIdAsInt()).isNotSameAs(mSession2.getIdAsInt()); //sanity check
+ assertThat(mSession1.getId()).isNotEqualTo(mSession2.getId()); //sanity check
final AutofillId parentId = new AutofillId(42);
final AutofillId childId1 = mSession1.newAutofillId(parentId, 108L);
final AutofillId childId2 = mSession2.newAutofillId(parentId, 108L);
@@ -117,7 +117,7 @@
// Cannot use @Spy because we need to pass the session id on constructor
private class MyContentCaptureSession extends ContentCaptureSession {
- private MyContentCaptureSession(String id) {
+ private MyContentCaptureSession(int id) {
super(id);
}
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java
index 4a230e7..c88d3ae 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureManagerService.java
@@ -127,7 +127,7 @@
public ContentCaptureManagerService(@NonNull Context context) {
super(context, new FrameworkResourcesServiceNameResolver(context,
com.android.internal.R.string.config_defaultContentCaptureService),
- UserManager.DISALLOW_CONTENT_CAPTURE, /* refreshServiceOnPackageUpdate=*/ false);
+ UserManager.DISALLOW_CONTENT_CAPTURE, /* refreshServiceOnPackageUpdate= */ false);
DeviceConfig.addOnPropertyChangedListener(DeviceConfig.NAMESPACE_CONTENT_CAPTURE,
ActivityThread.currentApplication().getMainExecutor(),
(namespace, key, value) -> onDeviceConfigChange(key, value));
@@ -472,7 +472,7 @@
return false;
}
- final ComponentName serviceComponent = ComponentName.unflattenFromString(serviceName);
+ final ComponentName serviceComponent = ComponentName.unflattenFromString(serviceName);
if (serviceComponent == null) {
Slog.w(mTag, methodName + ": invalid service name: " + serviceName);
return false;
@@ -523,7 +523,7 @@
@Override
public void startSession(@NonNull IBinder activityToken,
- @NonNull ComponentName componentName, @NonNull String sessionId, int flags,
+ @NonNull ComponentName componentName, int sessionId, int flags,
@NonNull IResultReceiver result) {
Preconditions.checkNotNull(activityToken);
Preconditions.checkNotNull(sessionId);
@@ -540,7 +540,7 @@
}
@Override
- public void finishSession(@NonNull String sessionId) {
+ public void finishSession(int sessionId) {
Preconditions.checkNotNull(sessionId);
final int userId = UserHandle.getCallingUserId();
@@ -627,7 +627,7 @@
boolean showHistory = true;
if (args != null) {
for (String arg : args) {
- switch(arg) {
+ switch (arg) {
case "--no-history":
showHistory = false;
break;
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
index 5934344..665d3df 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCapturePerUserService.java
@@ -17,6 +17,7 @@
package com.android.server.contentcapture;
import static android.service.contentcapture.ContentCaptureService.setClientState;
+import static android.view.contentcapture.ContentCaptureSession.NO_SESSION_ID;
import static android.view.contentcapture.ContentCaptureSession.STATE_DISABLED;
import static android.view.contentcapture.ContentCaptureSession.STATE_DUPLICATED_ID;
import static android.view.contentcapture.ContentCaptureSession.STATE_INTERNAL_ERROR;
@@ -49,8 +50,8 @@
import android.service.contentcapture.ContentCaptureServiceInfo;
import android.service.contentcapture.IContentCaptureServiceCallback;
import android.service.contentcapture.SnapshotData;
-import android.util.ArrayMap;
import android.util.Slog;
+import android.util.SparseArray;
import android.view.contentcapture.UserDataRemovalRequest;
import com.android.internal.annotations.GuardedBy;
@@ -75,8 +76,7 @@
private static final String TAG = ContentCapturePerUserService.class.getSimpleName();
@GuardedBy("mLock")
- private final ArrayMap<String, ContentCaptureServerSession> mSessions =
- new ArrayMap<>();
+ private final SparseArray<ContentCaptureServerSession> mSessions = new SparseArray<>();
/**
* Reference to the remote service.
@@ -223,9 +223,8 @@
// TODO(b/119613670): log metrics
@GuardedBy("mLock")
public void startSessionLocked(@NonNull IBinder activityToken,
- @NonNull ActivityPresentationInfo activityPresentationInfo,
- @NonNull String sessionId, int uid, int flags,
- @NonNull IResultReceiver clientReceiver) {
+ @NonNull ActivityPresentationInfo activityPresentationInfo, int sessionId, int uid,
+ int flags, @NonNull IResultReceiver clientReceiver) {
if (activityPresentationInfo == null) {
Slog.w(TAG, "basic activity info is null");
setClientState(clientReceiver, STATE_DISABLED | STATE_INTERNAL_ERROR,
@@ -315,7 +314,7 @@
// TODO(b/119613670): log metrics
@GuardedBy("mLock")
- public void finishSessionLocked(@NonNull String sessionId) {
+ public void finishSessionLocked(int sessionId) {
if (!isEnabledLocked()) {
return;
}
@@ -379,8 +378,8 @@
@GuardedBy("mLock")
public boolean sendActivityAssistDataLocked(@NonNull IBinder activityToken,
@NonNull Bundle data) {
- final String id = getSessionId(activityToken);
- if (id != null) {
+ final int id = getSessionId(activityToken);
+ if (id != NO_SESSION_ID) {
final ContentCaptureServerSession session = mSessions.get(id);
final Bundle assistData = data.getBundle(ASSIST_KEY_DATA);
final AssistStructure assistStructure = data.getParcelable(ASSIST_KEY_STRUCTURE);
@@ -396,7 +395,7 @@
}
@GuardedBy("mLock")
- public void removeSessionLocked(@NonNull String sessionId) {
+ public void removeSessionLocked(int sessionId) {
mSessions.remove(sessionId);
}
@@ -481,7 +480,7 @@
mRemoteService.dump(prefix2, pw);
}
- if (mSessions.isEmpty()) {
+ if (mSessions.size() == 0) {
pw.print(prefix); pw.println("no sessions");
} else {
final int sessionsSize = mSessions.size();
@@ -499,14 +498,14 @@
* Returns the session id associated with the given activity.
*/
@GuardedBy("mLock")
- private String getSessionId(@NonNull IBinder activityToken) {
+ private int getSessionId(@NonNull IBinder activityToken) {
for (int i = 0; i < mSessions.size(); i++) {
ContentCaptureServerSession session = mSessions.valueAt(i);
if (session.isActivitySession(activityToken)) {
return mSessions.keyAt(i);
}
}
- return null;
+ return NO_SESSION_ID;
}
/**
diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java
index 9b2c05f..1ad66d8 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java
@@ -16,6 +16,7 @@
package com.android.server.contentcapture;
import static android.service.contentcapture.ContentCaptureService.setClientState;
+import static android.view.contentcapture.ContentCaptureSession.NO_SESSION_ID;
import static android.view.contentcapture.ContentCaptureSession.STATE_ACTIVE;
import static android.view.contentcapture.ContentCaptureSession.STATE_DISABLED;
import static android.view.contentcapture.ContentCaptureSession.STATE_SERVICE_RESURRECTED;
@@ -57,7 +58,7 @@
/**
* Canonical session id.
*/
- private final String mId;
+ private final int mId;
/**
* UID of the app whose contents is being captured.
@@ -66,11 +67,12 @@
ContentCaptureServerSession(@NonNull IBinder activityToken,
@NonNull ContentCapturePerUserService service, @NonNull ComponentName appComponentName,
- @NonNull IResultReceiver sessionStateReceiver,
- int taskId, int displayId, @NonNull String sessionId, int uid, int flags) {
+ @NonNull IResultReceiver sessionStateReceiver, int taskId, int displayId, int sessionId,
+ int uid, int flags) {
+ Preconditions.checkArgument(sessionId != NO_SESSION_ID);
mActivityToken = activityToken;
mService = service;
- mId = Preconditions.checkNotNull(sessionId);
+ mId = sessionId;
mUid = uid;
mContentCaptureContext = new ContentCaptureContext(/* clientContext= */ null,
appComponentName, taskId, displayId, flags);
diff --git a/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java b/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java
index 0afe252..3fa3fdf 100644
--- a/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java
+++ b/services/contentcapture/java/com/android/server/contentcapture/RemoteContentCaptureService.java
@@ -98,9 +98,8 @@
* Called by {@link ContentCaptureServerSession} to generate a call to the
* {@link RemoteContentCaptureService} to indicate the session was created.
*/
- public void onSessionStarted(@Nullable ContentCaptureContext context,
- @NonNull String sessionId, int uid, @NonNull IResultReceiver clientReceiver,
- int initialState) {
+ public void onSessionStarted(@Nullable ContentCaptureContext context, int sessionId, int uid,
+ @NonNull IResultReceiver clientReceiver, int initialState) {
scheduleAsyncRequest(
(s) -> s.onSessionStarted(context, sessionId, uid, clientReceiver, initialState));
}
@@ -109,15 +108,14 @@
* Called by {@link ContentCaptureServerSession} to generate a call to the
* {@link RemoteContentCaptureService} to indicate the session was finished.
*/
- public void onSessionFinished(@NonNull String sessionId) {
+ public void onSessionFinished(int sessionId) {
scheduleAsyncRequest((s) -> s.onSessionFinished(sessionId));
}
/**
* Called by {@link ContentCaptureServerSession} to send snapshot data to the service.
*/
- public void onActivitySnapshotRequest(@NonNull String sessionId,
- @NonNull SnapshotData snapshotData) {
+ public void onActivitySnapshotRequest(int sessionId, @NonNull SnapshotData snapshotData) {
scheduleAsyncRequest((s) -> s.onActivitySnapshot(sessionId, snapshotData));
}