From 50077b01ac2a01e5983d35660422f0a3b9f74c80 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Thu, 6 Apr 2023 16:27:11 -0700 Subject: 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 --- .../java/com/android/server/autofill/Session.java | 2 +- .../com/android/server/autofill/ui/AutoFillUI.java | 11 +++++---- .../com/android/server/autofill/ui/FillUi.java | 26 +++++++++++++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 3bd4547dd3e6..b2e8ffcd8fca 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -4277,7 +4277,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState getUiForShowing().showFillUi(filledId, response, filterText, mService.getServicePackageName(), mComponentName, - targetLabel, targetIcon, this, id, mCompatMode); + targetLabel, targetIcon, this, userId, id, mCompatMode); synchronized (mLock) { mPresentationStatsEventLogger.maybeSetCountShown( diff --git a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java index 829161037832..a6318186f2d5 100644 --- a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java +++ b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java @@ -23,6 +23,7 @@ import static com.android.server.autofill.Helper.sVerbose; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UserIdInt; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -196,17 +197,19 @@ public final class AutoFillUI { * @param serviceLabel label of autofill service * @param serviceIcon icon of autofill service * @param callback identifier for the caller + * @param userId the user associated wit the session * @param sessionId id of the autofill session * @param compatMode whether the app is being autofilled in compatibility mode. */ public void showFillUi(@NonNull AutofillId focusedId, @NonNull FillResponse response, @Nullable String filterText, @Nullable String servicePackageName, @NonNull ComponentName componentName, @NonNull CharSequence serviceLabel, - @NonNull Drawable serviceIcon, @NonNull AutoFillUiCallback callback, int sessionId, - boolean compatMode) { + @NonNull Drawable serviceIcon, @NonNull AutoFillUiCallback callback, + @UserIdInt int userId, int sessionId, boolean compatMode) { if (sDebug) { 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 .newLogMaker(MetricsEvent.AUTOFILL_FILL_UI, componentName, servicePackageName, @@ -221,7 +224,7 @@ public final class AutoFillUI { return; } hideAllUiThread(callback); - mFillUi = new FillUi(mContext, response, focusedId, + mFillUi = new FillUi(mContext, userId, response, focusedId, filterText, mOverlayControl, serviceLabel, serviceIcon, mUiModeMgr.isNightMode(), new FillUi.Callback() { diff --git a/services/autofill/java/com/android/server/autofill/ui/FillUi.java b/services/autofill/java/com/android/server/autofill/ui/FillUi.java index 76f4505bbb4a..30d2fe40158b 100644 --- a/services/autofill/java/com/android/server/autofill/ui/FillUi.java +++ b/services/autofill/java/com/android/server/autofill/ui/FillUi.java @@ -22,12 +22,15 @@ import static com.android.server.autofill.Helper.sVerbose; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.UserIdInt; import android.content.Context; import android.content.IntentSender; import android.content.pm.PackageManager; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.hardware.display.DisplayManager; +import android.os.UserManager; import android.service.autofill.Dataset; import android.service.autofill.Dataset.DatasetFieldFilter; import android.service.autofill.FillResponse; @@ -36,6 +39,7 @@ import android.util.PluralsMessageFormatter; import android.util.Slog; import android.util.TypedValue; import android.view.ContextThemeWrapper; +import android.view.Display; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -57,9 +61,12 @@ import android.widget.RemoteViews; import android.widget.TextView; import com.android.internal.R; +import com.android.server.LocalServices; import com.android.server.UiThread; import com.android.server.autofill.AutofillManagerService; import com.android.server.autofill.Helper; +import com.android.server.pm.UserManagerInternal; +import com.android.server.utils.Slogf; import java.io.PrintWriter; import java.util.ArrayList; @@ -133,13 +140,29 @@ final class FillUi { 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 OverlayControl overlayControl, @NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon, boolean nightMode, @NonNull Callback callback) { if (sVerbose) Slog.v(TAG, "nightMode: " + nightMode); mThemeId = nightMode ? THEME_ID_DARK : THEME_ID_LIGHT; 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); 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("mContentHeight: "); pw.println(mContentHeight); 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); switch (mThemeId) { case THEME_ID_DARK: -- cgit v1.2.3-59-g8ed1b