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

Commit af76755f authored by Joanne Chung's avatar Joanne Chung
Browse files

Update ContentCaptureContext to have a token information

In order to support auto translation, we need to give information to
content capture service to let the app can use this information to
find the Activity which needed to be translated.

It's not safe to provide an activity token to the client app directly
even if it is a privilege app. They can use this activity token to
access many activity/windows related functions. We create a new token
for use for content capture and translation. This token will be used
get the target Activity for translation new APIs.

This change focuses on the Content capture API change, the API change
about translation will be done in the next change,

Bug: 177789967
Test: manual. Make sure cc service can get the information.
Test: atest android.view.contentcapture.ContentCaptureContextTest
Test: atest CtsContentCaptureServiceTestCases

Change-Id: Ife8096a8bd1e71ce4e686d95043e347222ad7ee6
parent ea5f0427
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -954,6 +954,9 @@ package android.app.admin {
package android.app.assist {
  public class ActivityId {
  }
  public static class AssistStructure.ViewNode {
    ctor public AssistStructure.ViewNode();
  }
@@ -13996,6 +13999,7 @@ package android.view.contentcapture {
  public final class ContentCaptureContext implements android.os.Parcelable {
    method @Nullable public android.content.ComponentName getActivityComponent();
    method @Nullable public android.app.assist.ActivityId getActivityId();
    method public int getDisplayId();
    method public int getFlags();
    method @Nullable public android.view.contentcapture.ContentCaptureSessionId getParentSessionId();
+9 −0
Original line number Diff line number Diff line
@@ -544,6 +544,15 @@ package android.app.admin {

}

package android.app.assist {

  public class ActivityId {
    method public int getTaskId();
    method @Nullable public android.os.IBinder getToken();
  }

}

package android.app.blob {

  public class BlobStoreManager {
+10 −2
Original line number Diff line number Diff line
@@ -803,6 +803,7 @@ public class Activity extends ContextThemeWrapper
    @UnsupportedAppUsage
    private IBinder mToken;
    private IBinder mAssistToken;
    private IBinder mShareableActivityToken;
    @UnsupportedAppUsage
    private int mIdent;
    @UnsupportedAppUsage
@@ -1210,7 +1211,7 @@ public class Activity extends ContextThemeWrapper
                    if (window != null) {
                        cm.updateWindowAttributes(window.getAttributes());
                    }
                    cm.onActivityCreated(mToken, getComponentName());
                    cm.onActivityCreated(mToken, mShareableActivityToken, getComponentName());
                    break;
                case CONTENT_CAPTURE_RESUME:
                    cm.onActivityResumed();
@@ -7838,7 +7839,8 @@ public class Activity extends ContextThemeWrapper
            CharSequence title, Activity parent, String id,
            NonConfigurationInstances lastNonConfigurationInstances,
            Configuration config, String referrer, IVoiceInteractor voiceInteractor,
            Window window, ActivityConfigCallback activityConfigCallback, IBinder assistToken) {
            Window window, ActivityConfigCallback activityConfigCallback, IBinder assistToken,
            IBinder shareableActivityToken) {
        attachBaseContext(context);

        mFragments.attachHost(null /*parent*/);
@@ -7860,6 +7862,7 @@ public class Activity extends ContextThemeWrapper
        mInstrumentation = instr;
        mToken = token;
        mAssistToken = assistToken;
        mShareableActivityToken = shareableActivityToken;
        mIdent = ident;
        mApplication = application;
        mIntent = intent;
@@ -7917,6 +7920,11 @@ public class Activity extends ContextThemeWrapper
        return mParent != null ? mParent.getAssistToken() : mAssistToken;
    }

    /** @hide */
    public final IBinder getShareableActivityToken() {
        return mParent != null ? mParent.getShareableActivityToken() : mShareableActivityToken;
    }

    /** @hide */
    @VisibleForTesting
    public final ActivityThread getActivityThread() {
+11 −4
Original line number Diff line number Diff line
@@ -517,6 +517,9 @@ public final class ActivityThread extends ClientTransactionHandler {
        @UnsupportedAppUsage
        public IBinder token;
        public IBinder assistToken;
        // A reusable token for other purposes, e.g. content capture, translation. It shouldn't be
        // used without security checks
        public IBinder shareableActivityToken;
        int ident;
        @UnsupportedAppUsage
        Intent intent;
@@ -604,9 +607,11 @@ public final class ActivityThread extends ClientTransactionHandler {
                PersistableBundle persistentState, List<ResultInfo> pendingResults,
                List<ReferrerIntent> pendingNewIntents, ActivityOptions activityOptions,
                boolean isForward, ProfilerInfo profilerInfo, ClientTransactionHandler client,
                IBinder assistToken, FixedRotationAdjustments fixedRotationAdjustments) {
                IBinder assistToken, FixedRotationAdjustments fixedRotationAdjustments,
                IBinder shareableActivityToken) {
            this.token = token;
            this.assistToken = assistToken;
            this.shareableActivityToken = shareableActivityToken;
            this.ident = ident;
            this.intent = intent;
            this.referrer = referrer;
@@ -3158,10 +3163,12 @@ public final class ActivityThread extends ClientTransactionHandler {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    public final Activity startActivityNow(Activity parent, String id,
            Intent intent, ActivityInfo activityInfo, IBinder token, Bundle state,
        Activity.NonConfigurationInstances lastNonConfigurationInstances, IBinder assistToken) {
            Activity.NonConfigurationInstances lastNonConfigurationInstances, IBinder assistToken,
            IBinder shareableActivityToken) {
        ActivityClientRecord r = new ActivityClientRecord();
            r.token = token;
            r.assistToken = assistToken;
            r.shareableActivityToken = shareableActivityToken;
            r.ident = 0;
            r.intent = intent;
            r.state = state;
@@ -3504,7 +3511,7 @@ public final class ActivityThread extends ClientTransactionHandler {
                        r.ident, app, r.intent, r.activityInfo, title, r.parent,
                        r.embeddedID, r.lastNonConfigurationInstances, config,
                        r.referrer, r.voiceInteractor, window, r.configCallback,
                        r.assistToken);
                        r.assistToken, r.shareableActivityToken);

                if (customIntent != null) {
                    activity.mIntent = customIntent;
+2 −1
Original line number Diff line number Diff line
@@ -1247,7 +1247,8 @@ public class Instrumentation {
                info, title, parent, id,
                (Activity.NonConfigurationInstances)lastNonConfigurationInstance,
                new Configuration(), null /* referrer */, null /* voiceInteractor */,
                null /* window */, null /* activityConfigCallback */, null /*assistToken*/);
                null /* window */, null /* activityConfigCallback */, null /*assistToken*/,
                null /*shareableActivityToken*/);
        return activity;
    }

Loading