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

Commit a346ee51 authored by Jon Spivack's avatar Jon Spivack Committed by Automerger Merge Worker
Browse files

Merge "Allow AssistDataRequester to fetch AssistContent without...

Merge "Allow AssistDataRequester to fetch AssistContent without AssistStructure" into sc-dev am: dd934371 am: 8dbc1f9b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14738871

Change-Id: I2a590da835b7c3eb955912c086c5d065d33bfbfc
parents ae4be880 8dbc1f9b
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -779,6 +779,9 @@ public class ActivityManager {
    /** @hide requestType for assist context: generate full AssistStructure for autofill. */
    /** @hide requestType for assist context: generate full AssistStructure for autofill. */
    public static final int ASSIST_CONTEXT_AUTOFILL = 2;
    public static final int ASSIST_CONTEXT_AUTOFILL = 2;


    /** @hide requestType for assist context: generate AssistContent but not AssistStructure. */
    public static final int ASSIST_CONTEXT_CONTENT = 3;

    /** @hide Flag for registerUidObserver: report changes in process state. */
    /** @hide Flag for registerUidObserver: report changes in process state. */
    public static final int UID_OBSERVER_PROCSTATE = 1<<0;
    public static final int UID_OBSERVER_PROCSTATE = 1<<0;


+18 −10
Original line number Original line Diff line number Diff line
@@ -3843,6 +3843,8 @@ public final class ActivityThread extends ClientTransactionHandler
        // - it does not call onProvideAssistData()
        // - it does not call onProvideAssistData()
        // - it needs an IAutoFillCallback
        // - it needs an IAutoFillCallback
        boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL;
        boolean forAutofill = cmd.requestType == ActivityManager.ASSIST_CONTEXT_AUTOFILL;
        // When only the AssistContent is requested, omit the AsssistStructure
        boolean requestedOnlyContent = cmd.requestType == ActivityManager.ASSIST_CONTEXT_CONTENT;


        // TODO: decide if lastSessionId logic applies to autofill sessions
        // TODO: decide if lastSessionId logic applies to autofill sessions
        if (mLastSessionId != cmd.sessionId) {
        if (mLastSessionId != cmd.sessionId) {
@@ -3869,8 +3871,11 @@ public final class ActivityThread extends ClientTransactionHandler
                r.activity.onProvideAssistData(data);
                r.activity.onProvideAssistData(data);
                referrer = r.activity.onProvideReferrer();
                referrer = r.activity.onProvideReferrer();
            }
            }
            if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill) {
            if (cmd.requestType == ActivityManager.ASSIST_CONTEXT_FULL || forAutofill
                    || requestedOnlyContent) {
                if (!requestedOnlyContent) {
                    structure = new AssistStructure(r.activity, forAutofill, cmd.flags);
                    structure = new AssistStructure(r.activity, forAutofill, cmd.flags);
                }
                Intent activityIntent = r.activity.getIntent();
                Intent activityIntent = r.activity.getIntent();
                boolean notSecure = r.window == null ||
                boolean notSecure = r.window == null ||
                        (r.window.getAttributes().flags
                        (r.window.getAttributes().flags
@@ -3892,8 +3897,9 @@ public final class ActivityThread extends ClientTransactionHandler
                    r.activity.onProvideAssistContent(content);
                    r.activity.onProvideAssistContent(content);
                }
                }
            }
            }

        }
        }

        if (!requestedOnlyContent) {
            if (structure == null) {
            if (structure == null) {
                structure = new AssistStructure();
                structure = new AssistStructure();
            }
            }
@@ -3904,6 +3910,8 @@ public final class ActivityThread extends ClientTransactionHandler
            structure.setAcquisitionEndTime(SystemClock.uptimeMillis());
            structure.setAcquisitionEndTime(SystemClock.uptimeMillis());


            mLastAssistStructures.add(new WeakReference<>(structure));
            mLastAssistStructures.add(new WeakReference<>(structure));
        }

        IActivityTaskManager mgr = ActivityTaskManager.getService();
        IActivityTaskManager mgr = ActivityTaskManager.getService();
        try {
        try {
            mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer);
            mgr.reportAssistContextExtras(cmd.requestToken, data, structure, content, referrer);
+33 −23
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.server.am;
package com.android.server.am;


import static android.app.ActivityManager.ASSIST_CONTEXT_CONTENT;
import static android.app.ActivityManager.ASSIST_CONTEXT_FULL;
import static android.app.ActivityManager.ASSIST_CONTEXT_FULL;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.OP_NONE;
import static android.app.AppOpsManager.OP_NONE;
@@ -143,45 +144,47 @@ public class AssistDataRequester extends IAssistDataReceiver.Stub {
     * Request that autofill data be loaded asynchronously. The resulting data will be provided
     * Request that autofill data be loaded asynchronously. The resulting data will be provided
     * through the {@link AssistDataRequesterCallbacks}.
     * through the {@link AssistDataRequesterCallbacks}.
     *
     *
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, int, String,
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, boolean, int,
     * boolean)}.
     * String, boolean)}.
     */
     */
    public void requestAutofillData(List<IBinder> activityTokens, int callingUid,
    public void requestAutofillData(List<IBinder> activityTokens, int callingUid,
            String callingPackage) {
            String callingPackage) {
        requestData(activityTokens, true /* requestAutofillData */,
        requestData(activityTokens, true /* requestAutofillData */,
                true /* fetchData */, false /* fetchScreenshot */,
                true /* fetchData */, false /* fetchScreenshot */,
                true /* allowFetchData */, false /* allowFetchScreenshot */,
                true /* fetchStructure */, true /* allowFetchData */,
                false /* ignoreTopActivityCheck */, callingUid, callingPackage);
                false /* allowFetchScreenshot */, false /* ignoreTopActivityCheck */, callingUid,
                callingPackage);
    }
    }


    /**
    /**
     * Request that assist data be loaded asynchronously. The resulting data will be provided
     * Request that assist data be loaded asynchronously. The resulting data will be provided
     * through the {@link AssistDataRequesterCallbacks}.
     * through the {@link AssistDataRequesterCallbacks}.
     *
     *
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, int, String,
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, boolean, int,
     * boolean)}.
     * String, boolean)}.
     */
     */
    public void requestAssistData(List<IBinder> activityTokens, final boolean fetchData,
    public void requestAssistData(List<IBinder> activityTokens, final boolean fetchData,
            final boolean fetchScreenshot, boolean allowFetchData, boolean allowFetchScreenshot,
            final boolean fetchScreenshot, boolean allowFetchData, boolean allowFetchScreenshot,
            int callingUid, String callingPackage) {
            int callingUid, String callingPackage) {
        requestAssistData(activityTokens, fetchData, fetchScreenshot, allowFetchData,
        requestAssistData(activityTokens, fetchData, fetchScreenshot, true /* fetchStructure */,
                allowFetchScreenshot, false /* ignoreTopActivityCheck */, callingUid,
                allowFetchData, allowFetchScreenshot, false /* ignoreTopActivityCheck */,
                callingPackage);
                callingUid, callingPackage);
    }
    }


    /**
    /**
     * Request that assist data be loaded asynchronously. The resulting data will be provided
     * Request that assist data be loaded asynchronously. The resulting data will be provided
     * through the {@link AssistDataRequesterCallbacks}.
     * through the {@link AssistDataRequesterCallbacks}.
     *
     *
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, int, String,
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, boolean, int,
     * boolean)}.
     * String, boolean)}.
     */
     */
    public void requestAssistData(List<IBinder> activityTokens, final boolean fetchData,
    public void requestAssistData(List<IBinder> activityTokens, final boolean fetchData,
            final boolean fetchScreenshot, boolean allowFetchData, boolean allowFetchScreenshot,
            final boolean fetchScreenshot, final boolean fetchStructure, boolean allowFetchData,
            boolean ignoreTopActivityCheck, int callingUid, String callingPackage) {
            boolean allowFetchScreenshot, boolean ignoreTopActivityCheck, int callingUid,
            String callingPackage) {
        requestData(activityTokens, false /* requestAutofillData */, fetchData, fetchScreenshot,
        requestData(activityTokens, false /* requestAutofillData */, fetchData, fetchScreenshot,
                allowFetchData, allowFetchScreenshot, ignoreTopActivityCheck, callingUid,
                fetchStructure, allowFetchData, allowFetchScreenshot, ignoreTopActivityCheck,
                callingPackage);
                callingUid, callingPackage);
    }
    }


    /**
    /**
@@ -197,6 +200,8 @@ public class AssistDataRequester extends IAssistDataReceiver.Stub {
     * @param fetchScreenshot whether or not to fetch the screenshot, only applies if fetchData is
     * @param fetchScreenshot whether or not to fetch the screenshot, only applies if fetchData is
     *     true, the caller is allowed to fetch the assist data, and the current activity allows
     *     true, the caller is allowed to fetch the assist data, and the current activity allows
     *     assist data to be fetched from it
     *     assist data to be fetched from it
     * @param fetchStructure whether or not to fetch the AssistStructure along with the
     *     AssistContent
     * @param allowFetchData to be joined with other checks, determines whether or not the requester
     * @param allowFetchData to be joined with other checks, determines whether or not the requester
     *     is allowed to fetch the assist data
     *     is allowed to fetch the assist data
     * @param allowFetchScreenshot to be joined with other checks, determines whether or not the
     * @param allowFetchScreenshot to be joined with other checks, determines whether or not the
@@ -205,9 +210,9 @@ public class AssistDataRequester extends IAssistDataReceiver.Stub {
     *     making the request. Used when passing an activity from Recents.
     *     making the request. Used when passing an activity from Recents.
     */
     */
    private void requestData(List<IBinder> activityTokens, final boolean requestAutofillData,
    private void requestData(List<IBinder> activityTokens, final boolean requestAutofillData,
            final boolean fetchData, final boolean fetchScreenshot, boolean allowFetchData,
            final boolean fetchData, final boolean fetchScreenshot, final boolean fetchStructure,
            boolean allowFetchScreenshot, boolean ignoreTopActivityCheck, int callingUid,
            boolean allowFetchData, boolean allowFetchScreenshot, boolean ignoreTopActivityCheck,
            String callingPackage) {
            int callingUid, String callingPackage) {
        // TODO(b/34090158): Known issue, if the assist data is not allowed on the current activity,
        // TODO(b/34090158): Known issue, if the assist data is not allowed on the current activity,
        //                   then no assist data is requested for any of the other activities
        //                   then no assist data is requested for any of the other activities


@@ -246,13 +251,18 @@ public class AssistDataRequester extends IAssistDataReceiver.Stub {
                        Bundle receiverExtras = new Bundle();
                        Bundle receiverExtras = new Bundle();
                        receiverExtras.putInt(KEY_RECEIVER_EXTRA_INDEX, i);
                        receiverExtras.putInt(KEY_RECEIVER_EXTRA_INDEX, i);
                        receiverExtras.putInt(KEY_RECEIVER_EXTRA_COUNT, numActivities);
                        receiverExtras.putInt(KEY_RECEIVER_EXTRA_COUNT, numActivities);
                        boolean result = requestAutofillData
                        boolean result;
                                ? mActivityTaskManager.requestAutofillData(this,
                        if (requestAutofillData) {
                                        receiverExtras, topActivity, 0 /* flags */)
                            result = mActivityTaskManager.requestAutofillData(this, receiverExtras,
                                : mActivityTaskManager.requestAssistContextExtras(
                                    topActivity, 0 /* flags */);
                                        ASSIST_CONTEXT_FULL, this, receiverExtras, topActivity,
                        } else {
                            int requestType = fetchStructure ? ASSIST_CONTEXT_FULL :
                                    ASSIST_CONTEXT_CONTENT;
                            result = mActivityTaskManager.requestAssistContextExtras(
                                        requestType, this, receiverExtras, topActivity,
                                        /* checkActivityIsTop= */ (i == 0)
                                        /* checkActivityIsTop= */ (i == 0)
                                        && !ignoreTopActivityCheck, /* newSessionId= */ i == 0);
                                        && !ignoreTopActivityCheck, /* newSessionId= */ i == 0);
                        }
                        if (result) {
                        if (result) {
                            mPendingDataCount++;
                            mPendingDataCount++;
                        } else if (i == 0) {
                        } else if (i == 0) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -2835,7 +2835,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        List<IBinder> topActivityToken = new ArrayList<>();
        List<IBinder> topActivityToken = new ArrayList<>();
        topActivityToken.add(tokens.getActivityToken());
        topActivityToken.add(tokens.getActivityToken());
        requester.requestAssistData(topActivityToken, true /* fetchData */,
        requester.requestAssistData(topActivityToken, true /* fetchData */,
                false /* fetchScreenshot */, true /* allowFetchData */,
                false /* fetchScreenshot */, false /* fetchStructure */, true /* allowFetchData */,
                false /* allowFetchScreenshot*/, true /* ignoreFocusCheck */,
                false /* allowFetchScreenshot*/, true /* ignoreFocusCheck */,
                Binder.getCallingUid(), callingPackageName);
                Binder.getCallingUid(), callingPackageName);