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

Commit 6f32fefe 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 am: a346ee51

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

Change-Id: If89920975ee5942ebfd441c3b70574f203ffb6a8
parents 665a7807 a346ee51
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -779,6 +779,9 @@ public class ActivityManager {
    /** @hide requestType for assist context: generate full AssistStructure for autofill. */
    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. */
    public static final int UID_OBSERVER_PROCSTATE = 1<<0;

+18 −10
Original line number Diff line number Diff line
@@ -3843,6 +3843,8 @@ public final class ActivityThread extends ClientTransactionHandler
        // - it does not call onProvideAssistData()
        // - it needs an IAutoFillCallback
        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
        if (mLastSessionId != cmd.sessionId) {
@@ -3869,8 +3871,11 @@ public final class ActivityThread extends ClientTransactionHandler
                r.activity.onProvideAssistData(data);
                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);
                }
                Intent activityIntent = r.activity.getIntent();
                boolean notSecure = r.window == null ||
                        (r.window.getAttributes().flags
@@ -3892,8 +3897,9 @@ public final class ActivityThread extends ClientTransactionHandler
                    r.activity.onProvideAssistContent(content);
                }
            }

        }

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

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

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

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.AppOpsManager.MODE_ALLOWED;
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
     * through the {@link AssistDataRequesterCallbacks}.
     *
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, int, String,
     * boolean)}.
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, boolean, int,
     * String, boolean)}.
     */
    public void requestAutofillData(List<IBinder> activityTokens, int callingUid,
            String callingPackage) {
        requestData(activityTokens, true /* requestAutofillData */,
                true /* fetchData */, false /* fetchScreenshot */,
                true /* allowFetchData */, false /* allowFetchScreenshot */,
                false /* ignoreTopActivityCheck */, callingUid, callingPackage);
                true /* fetchStructure */, true /* allowFetchData */,
                false /* allowFetchScreenshot */, false /* ignoreTopActivityCheck */, callingUid,
                callingPackage);
    }

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

    /**
     * Request that assist data be loaded asynchronously. The resulting data will be provided
     * through the {@link AssistDataRequesterCallbacks}.
     *
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, int, String,
     * boolean)}.
     * See {@link #requestData(List, boolean, boolean, boolean, boolean, boolean, boolean, int,
     * String, boolean)}.
     */
    public void requestAssistData(List<IBinder> activityTokens, final boolean fetchData,
            final boolean fetchScreenshot, boolean allowFetchData, boolean allowFetchScreenshot,
            boolean ignoreTopActivityCheck, int callingUid, String callingPackage) {
            final boolean fetchScreenshot, final boolean fetchStructure, boolean allowFetchData,
            boolean allowFetchScreenshot, boolean ignoreTopActivityCheck, int callingUid,
            String callingPackage) {
        requestData(activityTokens, false /* requestAutofillData */, fetchData, fetchScreenshot,
                allowFetchData, allowFetchScreenshot, ignoreTopActivityCheck, callingUid,
                callingPackage);
                fetchStructure, allowFetchData, allowFetchScreenshot, ignoreTopActivityCheck,
                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
     *     true, the caller is allowed to fetch the assist data, and the current activity allows
     *     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
     *     is allowed to fetch the assist data
     * @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.
     */
    private void requestData(List<IBinder> activityTokens, final boolean requestAutofillData,
            final boolean fetchData, final boolean fetchScreenshot, boolean allowFetchData,
            boolean allowFetchScreenshot, boolean ignoreTopActivityCheck, int callingUid,
            String callingPackage) {
            final boolean fetchData, final boolean fetchScreenshot, final boolean fetchStructure,
            boolean allowFetchData, boolean allowFetchScreenshot, boolean ignoreTopActivityCheck,
            int callingUid, String callingPackage) {
        // 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

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