Merge "Initial fix on Autofill for visible background users." into udc-dev

This commit is contained in:
Felipe Leme
2023-04-20 17:13:03 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 6 deletions

View File

@@ -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(

View File

@@ -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() {

View File

@@ -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: