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

Commit 185de726 authored by Felipe Leme's avatar Felipe Leme
Browse files

Add support for url_bar sanitization on autofill compat mode.

Browsers typically use a standard class (like EditView) to hold the URL of the
page being loaded, and the content of that view is sanitized in the initial
autofill request. So, when running in compat mode, we need a mechanism to let
services tell which view contains the URL, so we can convert its contents to
a sanitized webScheme + webDomain pair or properties.

Test: manual verification
Fixes: 72994424

Change-Id: I8be5f3533d6c31f81f28036dc51d5de10a528079
parent 90f285ba
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1469,6 +1469,7 @@ package android {
    field public static final deprecated int unfocusedMonthDateColor = 16843588; // 0x1010344
    field public static final int unselectedAlpha = 16843278; // 0x101020e
    field public static final int updatePeriodMillis = 16843344; // 0x1010250
    field public static final int urlBarResourceId = 16844164; // 0x1010584
    field public static final int use32bitAbi = 16844053; // 0x1010515
    field public static final int useDefaultMargins = 16843641; // 0x1010379
    field public static final int useIntrinsicSizeAsMinimum = 16843536; // 0x1010310
+12 −8
Original line number Diff line number Diff line
@@ -1298,6 +1298,17 @@ public class AssistStructure implements Parcelable {
            return mWebDomain;
        }

        /**
         * @hide
         */
        public void setWebDomain(@Nullable String domain) {
            if (domain == null) return;

            final Uri uri = Uri.parse(domain);
            mWebScheme = uri.getScheme();
            mWebDomain = uri.getHost();
        }

        /**
         * Returns the scheme of the HTML document represented by this view.
         *
@@ -1870,14 +1881,7 @@ public class AssistStructure implements Parcelable {

        @Override
        public void setWebDomain(@Nullable String domain) {
            if (domain == null) {
                mNode.mWebScheme = null;
                mNode.mWebDomain = null;
                return;
            }
            Uri uri = Uri.parse(domain);
            mNode.mWebScheme = uri.getScheme();
            mNode.mWebDomain = uri.getHost();
            mNode.setWebDomain(domain);
        }

        @Override
+25 −10
Original line number Diff line number Diff line
@@ -32,12 +32,12 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
import android.util.Xml;

import com.android.internal.R;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;

import com.android.internal.util.XmlUtils;

import org.xmlpull.v1.XmlPullParser;
@@ -80,7 +80,7 @@ public final class AutofillServiceInfo {
    private final String mSettingsActivity;

    @Nullable
    private final Map<String, Long> mCompatibilityPackages;
    private final Map<String, Pair<Long, String>> mCompatibilityPackages;

    public AutofillServiceInfo(Context context, ComponentName comp, int userHandle)
            throws PackageManager.NameNotFoundException {
@@ -118,7 +118,7 @@ public final class AutofillServiceInfo {
        }

        String settingsActivity = null;
        Map<String, Long> compatibilityPackages = null;
        Map<String, Pair<Long, String>> compatibilityPackages = null;

        try {
            final Resources resources = context.getPackageManager().getResourcesForApplication(
@@ -154,9 +154,10 @@ public final class AutofillServiceInfo {
        mCompatibilityPackages = compatibilityPackages;
    }

    private Map<String, Long> parseCompatibilityPackages(XmlPullParser parser, Resources resources)
    private Map<String, Pair<Long, String>> parseCompatibilityPackages(XmlPullParser parser,
            Resources resources)
            throws IOException, XmlPullParserException {
        Map<String, Long> compatibilityPackages = null;
        Map<String, Pair<Long, String>> compatibilityPackages = null;

        final int outerDepth = parser.getDepth();
        int type;
@@ -200,11 +201,13 @@ public final class AutofillServiceInfo {
                    } else {
                        maxVersionCode = Long.MAX_VALUE;
                    }
                    final String urlBarResourceId = cpAttributes.getString(
                            R.styleable.AutofillService_CompatibilityPackage_urlBarResourceId);

                    if (compatibilityPackages == null) {
                        compatibilityPackages = new ArrayMap<>();
                    }
                    compatibilityPackages.put(name, maxVersionCode);
                    compatibilityPackages.put(name, new Pair<>(maxVersionCode, urlBarResourceId));
                } finally {
                    XmlUtils.skipCurrentTag(parser);
                    if (cpAttributes != null) {
@@ -226,16 +229,28 @@ public final class AutofillServiceInfo {
        return mSettingsActivity;
    }

    @Nullable
    public boolean isCompatibilityModeRequested(String packageName, long versionCode) {
        if (mCompatibilityPackages == null) {
            return false;
        }
        final Long maxVersionCode = mCompatibilityPackages.get(packageName);
        if (maxVersionCode == null) {
        final Pair<Long, String> pair = mCompatibilityPackages.get(packageName);
        if (pair == null) {
            return false;
        }
        return versionCode <= maxVersionCode;
        return versionCode <= pair.first;
    }

    /**
     * Gets the resource id of the URL bar for a package. Used in compat mode
     */
    // TODO: return a list of strings instead
    @Nullable
    public String getUrlBarResourceId(String packageName) {
        if (mCompatibilityPackages == null) {
            return null;
        }
        final Pair<Long, String> pair = mCompatibilityPackages.get(packageName);
        return pair == null ? null : pair.second;
    }

    @Override
+0 −24
Original line number Diff line number Diff line
@@ -177,30 +177,6 @@ public final class FillContext implements Parcelable {
        return foundNodes;
    }

    /**
     * Finds the {@link ViewNode} that has the requested {@code id}, if any.
     *
     * @hide
     */
    @Nullable public ViewNode findViewNodeByAutofillId(@NonNull AutofillId id) {
        final LinkedList<ViewNode> nodesToProcess = new LinkedList<>();
        final int numWindowNodes = mStructure.getWindowNodeCount();
        for (int i = 0; i < numWindowNodes; i++) {
            nodesToProcess.add(mStructure.getWindowNodeAt(i).getRootViewNode());
        }
        while (!nodesToProcess.isEmpty()) {
            final ViewNode node = nodesToProcess.removeFirst();
            if (id.equals(node.getAutofillId())) {
                return node;
            }
            for (int i = 0; i < node.getChildCount(); i++) {
                nodesToProcess.addLast(node.getChildAt(i));
            }
        }

        return null;
    }

    public static final Parcelable.Creator<FillContext> CREATOR =
            new Parcelable.Creator<FillContext>() {
        @Override
+3 −2
Original line number Diff line number Diff line
@@ -1407,7 +1407,8 @@ public final class AutofillManager {

            mSessionId = mService.startSession(client.autofillClientGetActivityToken(),
                    mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(),
                    mCallback != null, flags, client.autofillClientGetComponentName());
                    mCallback != null, flags, client.autofillClientGetComponentName(),
                    isCompatibilityModeEnabledLocked());
            if (mSessionId != NO_SESSION) {
                mState = STATE_ACTIVE;
            }
@@ -1474,7 +1475,7 @@ public final class AutofillManager {
                        client.autofillClientGetActivityToken(),
                        mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(),
                        mCallback != null, flags, client.autofillClientGetComponentName(),
                        mSessionId, action);
                        mSessionId, action, isCompatibilityModeEnabledLocked());
                if (newId != mSessionId) {
                    if (sDebug) Log.d(TAG, "Session restarted: " + mSessionId + "=>" + newId);
                    mSessionId = newId;
Loading