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

Commit 50077b01 authored by Felipe Leme's avatar Felipe Leme
Browse files

Initial fix on Autofill for visible background users.

It needs to set the proper display in the FillUI context, otherwise
WindowManager doesn't allow the AutofillPopupDialog to be anchored to
the activity being autofilled.

Test: atest --user-type secondary_user_on_secondary_display CtsAutoFillServiceTestCases:android.autofillservice.cts.dropdown.LoginActivityTest#testAutofill_oneDataset
Test: atest CtsAutoFillServiceTestCases # on phone
Bug: 271031908

Change-Id: Ifa9a69101168888afccfc9f63aa8a4eb92a93108
parent 209dc315
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -4277,7 +4277,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState


        getUiForShowing().showFillUi(filledId, response, filterText,
        getUiForShowing().showFillUi(filledId, response, filterText,
                mService.getServicePackageName(), mComponentName,
                mService.getServicePackageName(), mComponentName,
                targetLabel, targetIcon, this, id, mCompatMode);
                targetLabel, targetIcon, this, userId, id, mCompatMode);


        synchronized (mLock) {
        synchronized (mLock) {
            mPresentationStatsEventLogger.maybeSetCountShown(
            mPresentationStatsEventLogger.maybeSetCountShown(
+7 −4
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.server.autofill.Helper.sVerbose;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -196,17 +197,19 @@ public final class AutoFillUI {
     * @param serviceLabel label of autofill service
     * @param serviceLabel label of autofill service
     * @param serviceIcon icon of autofill service
     * @param serviceIcon icon of autofill service
     * @param callback identifier for the caller
     * @param callback identifier for the caller
     * @param userId the user associated wit the session
     * @param sessionId id of the autofill session
     * @param sessionId id of the autofill session
     * @param compatMode whether the app is being autofilled in compatibility mode.
     * @param compatMode whether the app is being autofilled in compatibility mode.
     */
     */
    public void showFillUi(@NonNull AutofillId focusedId, @NonNull FillResponse response,
    public void showFillUi(@NonNull AutofillId focusedId, @NonNull FillResponse response,
            @Nullable String filterText, @Nullable String servicePackageName,
            @Nullable String filterText, @Nullable String servicePackageName,
            @NonNull ComponentName componentName, @NonNull CharSequence serviceLabel,
            @NonNull ComponentName componentName, @NonNull CharSequence serviceLabel,
            @NonNull Drawable serviceIcon, @NonNull AutoFillUiCallback callback, int sessionId,
            @NonNull Drawable serviceIcon, @NonNull AutoFillUiCallback callback,
            boolean compatMode) {
            @UserIdInt int userId, int sessionId, boolean compatMode) {
        if (sDebug) {
        if (sDebug) {
            final int size = filterText == null ? 0 : filterText.length();
            final int size = filterText == null ? 0 : filterText.length();
            Slog.d(TAG, "showFillUi(): id=" + focusedId + ", filter=" + size + " chars");
            Slog.d(TAG, "showFillUi(): id=" + focusedId + ", filter=" + size + " chars, userId="
                    + userId);
        }
        }
        final LogMaker log = Helper
        final LogMaker log = Helper
                .newLogMaker(MetricsEvent.AUTOFILL_FILL_UI, componentName, servicePackageName,
                .newLogMaker(MetricsEvent.AUTOFILL_FILL_UI, componentName, servicePackageName,
@@ -221,7 +224,7 @@ public final class AutoFillUI {
                return;
                return;
            }
            }
            hideAllUiThread(callback);
            hideAllUiThread(callback);
            mFillUi = new FillUi(mContext, response, focusedId,
            mFillUi = new FillUi(mContext, userId, response, focusedId,
                    filterText, mOverlayControl, serviceLabel, serviceIcon,
                    filterText, mOverlayControl, serviceLabel, serviceIcon,
                    mUiModeMgr.isNightMode(),
                    mUiModeMgr.isNightMode(),
                    new FillUi.Callback() {
                    new FillUi.Callback() {
+25 −1
Original line number Original line Diff line number Diff line
@@ -22,12 +22,15 @@ import static com.android.server.autofill.Helper.sVerbose;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.Context;
import android.content.Context;
import android.content.IntentSender;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
import android.os.UserManager;
import android.service.autofill.Dataset;
import android.service.autofill.Dataset;
import android.service.autofill.Dataset.DatasetFieldFilter;
import android.service.autofill.Dataset.DatasetFieldFilter;
import android.service.autofill.FillResponse;
import android.service.autofill.FillResponse;
@@ -36,6 +39,7 @@ import android.util.PluralsMessageFormatter;
import android.util.Slog;
import android.util.Slog;
import android.util.TypedValue;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
@@ -57,9 +61,12 @@ import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.TextView;


import com.android.internal.R;
import com.android.internal.R;
import com.android.server.LocalServices;
import com.android.server.UiThread;
import com.android.server.UiThread;
import com.android.server.autofill.AutofillManagerService;
import com.android.server.autofill.AutofillManagerService;
import com.android.server.autofill.Helper;
import com.android.server.autofill.Helper;
import com.android.server.pm.UserManagerInternal;
import com.android.server.utils.Slogf;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -133,13 +140,29 @@ final class FillUi {
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
    }
    }


    FillUi(@NonNull Context context, @NonNull FillResponse response,
    FillUi(@NonNull Context context, @UserIdInt int userId, @NonNull FillResponse response,
            @NonNull AutofillId focusedViewId, @Nullable String filterText,
            @NonNull AutofillId focusedViewId, @Nullable String filterText,
            @NonNull OverlayControl overlayControl, @NonNull CharSequence serviceLabel,
            @NonNull OverlayControl overlayControl, @NonNull CharSequence serviceLabel,
            @NonNull Drawable serviceIcon, boolean nightMode, @NonNull Callback callback) {
            @NonNull Drawable serviceIcon, boolean nightMode, @NonNull Callback callback) {
        if (sVerbose) Slog.v(TAG, "nightMode: " + nightMode);
        if (sVerbose) Slog.v(TAG, "nightMode: " + nightMode);
        mThemeId = nightMode ? THEME_ID_DARK : THEME_ID_LIGHT;
        mThemeId = nightMode ? THEME_ID_DARK : THEME_ID_LIGHT;
        mCallback = callback;
        mCallback = callback;

        if (UserManager.isVisibleBackgroundUsersEnabled()) {
            UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class);
            int displayId = umi.getMainDisplayAssignedToUser(userId);
            if (sDebug) {
                Slogf.d(TAG, "Creating context for display %d for user %d", displayId, userId);
            }
            Display display = context.getSystemService(DisplayManager.class).getDisplay(displayId);
            if (display != null) {
                context = context.createDisplayContext(display);
            } else {
                Slogf.d(TAG, "Could not get display with id %d (which is associated with user %d; "
                        + "FillUi operations will probably fail", displayId, userId);
            }
        }

        mFullScreen = isFullScreen(context);
        mFullScreen = isFullScreen(context);
        mContext = new ContextThemeWrapper(context, mThemeId);
        mContext = new ContextThemeWrapper(context, mThemeId);


@@ -774,6 +797,7 @@ final class FillUi {
        pw.print(prefix); pw.print("mContentWidth: "); pw.println(mContentWidth);
        pw.print(prefix); pw.print("mContentWidth: "); pw.println(mContentWidth);
        pw.print(prefix); pw.print("mContentHeight: "); pw.println(mContentHeight);
        pw.print(prefix); pw.print("mContentHeight: "); pw.println(mContentHeight);
        pw.print(prefix); pw.print("mDestroyed: "); pw.println(mDestroyed);
        pw.print(prefix); pw.print("mDestroyed: "); pw.println(mDestroyed);
        pw.print(prefix); pw.print("mContext: "); pw.println(mContext);
        pw.print(prefix); pw.print("theme id: "); pw.print(mThemeId);
        pw.print(prefix); pw.print("theme id: "); pw.print(mThemeId);
        switch (mThemeId) {
        switch (mThemeId) {
            case THEME_ID_DARK:
            case THEME_ID_DARK: