Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1480ed10 authored by Abodunrinwa Toki's avatar Abodunrinwa Toki
Browse files

Ensure userId is set in TCEvent.

Part of security fix in I2fdffd8eb4221782cb1f34d2ddbe41dd3d36595c

TCContexts that existed outside a TC session did not have userId
set by the SystemTC. This CL ensures SystemTC always sets the
userId for all TCEvents (and deprecated SelectionEvents).

Bug: 136483597
Test: atest android.view.textclassifier
      Manual test ensuring that ConvActions was logging TCEvent with
      userId.

Change-Id: Ie2a362f8f4758d5dc0390aeb2dbf23f9d78a378e
parent b93dc48c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -409,6 +409,15 @@ public final class SelectionEvent implements Parcelable {
        return mPackageName;
    }

    /**
     * Sets the id of this event's user.
     * <p>
     * Package-private for SystemTextClassifier's use.
     */
    void setUserId(@UserIdInt int userId) {
        mUserId = userId;
    }

    /**
     * Returns the id of this event's user.
     * @hide
+7 −0
Original line number Diff line number Diff line
@@ -151,6 +151,7 @@ public final class SystemTextClassifier implements TextClassifier {
        Utils.checkMainThread();

        try {
            event.setUserId(mUserId);
            mManagerService.onSelectionEvent(mSessionId, event);
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "Error reporting selection event.", e);
@@ -163,6 +164,12 @@ public final class SystemTextClassifier implements TextClassifier {
        Utils.checkMainThread();

        try {
            final TextClassificationContext tcContext = event.getEventContext() == null
                    ? new TextClassificationContext.Builder(mPackageName, WIDGET_TYPE_UNKNOWN)
                            .build()
                    : event.getEventContext();
            tcContext.setUserId(mUserId);
            event.setEventContext(tcContext);
            mManagerService.onTextClassifierEvent(mSessionId, event);
        } catch (RemoteException e) {
            Log.e(LOG_TAG, "Error reporting textclassifier event.", e);
+10 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public abstract class TextClassifierEvent implements Parcelable {
    @Nullable
    private final String[] mEntityTypes;
    @Nullable
    private final TextClassificationContext mEventContext;
    private TextClassificationContext mEventContext;
    @Nullable
    private final String mResultId;
    private final int mEventIndex;
@@ -288,6 +288,15 @@ public abstract class TextClassifierEvent implements Parcelable {
        return mEventContext;
    }

    /**
     * Sets the event context.
     * <p>
     * Package-private for SystemTextClassifier's use.
     */
    void setEventContext(@Nullable TextClassificationContext eventContext) {
        mEventContext = eventContext;
    }

    /**
     * Returns the id of the text classifier result related to this event.
     */
+2 −2
Original line number Diff line number Diff line
@@ -457,12 +457,12 @@ public final class TextClassificationManagerService extends ITextClassifierServi
            Preconditions.checkArgument(userId != UserHandle.USER_NULL, "Null userId");
            final int callingUserId = UserHandle.getCallingUserId();
            if (callingUserId != userId) {
                context.enforceCallingPermission(
                context.enforceCallingOrSelfPermission(
                        android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
                        "Invalid userId. UserId=" + userId + ", CallingUserId=" + callingUserId);
            }
        } catch (Exception e) {
            throw new RemoteException("Invalid request", e,
            throw new RemoteException("Invalid request: " + e.getMessage(), e,
                    /* enableSuppression */ true, /* writableStackTrace */ true);
        }
    }