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

Commit 54eae8e0 authored by Felipe Leme's avatar Felipe Leme Committed by Automerger Merge Worker
Browse files

Merge "Fixed SaveUi on Autofill for visible background users." into udc-dev...

Merge "Fixed SaveUi on Autofill for visible background users." into udc-dev am: 0d5d3093 am: d039f7bf

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



Change-Id: I4aafeb697a0d6bf67580e2ff7a469b548b52a330
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f0ccc201 d039f7bf
Loading
Loading
Loading
Loading
+1 −6
Original line number Original line Diff line number Diff line
@@ -79,11 +79,6 @@ import static com.android.server.autofill.SaveEventLogger.SAVE_UI_SHOWN_REASON_O
import static com.android.server.autofill.SaveEventLogger.SAVE_UI_SHOWN_REASON_REQUIRED_ID_CHANGE;
import static com.android.server.autofill.SaveEventLogger.SAVE_UI_SHOWN_REASON_REQUIRED_ID_CHANGE;
import static com.android.server.autofill.SaveEventLogger.SAVE_UI_SHOWN_REASON_TRIGGER_ID_SET;
import static com.android.server.autofill.SaveEventLogger.SAVE_UI_SHOWN_REASON_TRIGGER_ID_SET;
import static com.android.server.autofill.SaveEventLogger.SAVE_UI_SHOWN_REASON_UNKNOWN;
import static com.android.server.autofill.SaveEventLogger.SAVE_UI_SHOWN_REASON_UNKNOWN;
import static com.android.server.autofill.SessionCommittedEventLogger.CommitReason;
import static com.android.server.autofill.SessionCommittedEventLogger.COMMIT_REASON_ACTIVITY_FINISHED;
import static com.android.server.autofill.SessionCommittedEventLogger.COMMIT_REASON_VIEW_CHANGED;
import static com.android.server.autofill.SessionCommittedEventLogger.COMMIT_REASON_VIEW_CLICKED;
import static com.android.server.autofill.SessionCommittedEventLogger.COMMIT_REASON_VIEW_COMMITTED;
import static com.android.server.autofill.SessionCommittedEventLogger.COMMIT_REASON_SESSION_DESTROYED;
import static com.android.server.autofill.SessionCommittedEventLogger.COMMIT_REASON_SESSION_DESTROYED;
import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS;
import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_RECEIVER_EXTRAS;
import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE;
import static com.android.server.wm.ActivityTaskManagerInternal.ASSIST_KEY_STRUCTURE;
@@ -3406,7 +3401,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                final long saveUiDisplayStartTimestamp = SystemClock.elapsedRealtime();
                final long saveUiDisplayStartTimestamp = SystemClock.elapsedRealtime();
                getUiForShowing().showSaveUi(serviceLabel, serviceIcon,
                getUiForShowing().showSaveUi(serviceLabel, serviceIcon,
                        mService.getServicePackageName(), saveInfo, this,
                        mService.getServicePackageName(), saveInfo, this,
                        mComponentName, this, mPendingSaveUi, isUpdate, mCompatMode,
                        mComponentName, this, userId, mPendingSaveUi, isUpdate, mCompatMode,
                        response.getShowSaveDialogIcon());
                        response.getShowSaveDialogIcon());
                mSaveEventLogger.maybeSetLatencySaveUiDisplayMillis(
                mSaveEventLogger.maybeSetLatencySaveUiDisplayMillis(
                    SystemClock.elapsedRealtime()- saveUiDisplayStartTimestamp);
                    SystemClock.elapsedRealtime()- saveUiDisplayStartTimestamp);
+5 −4
Original line number Original line Diff line number Diff line
@@ -325,11 +325,12 @@ public final class AutoFillUI {
    public void showSaveUi(@NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
    public void showSaveUi(@NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
            @Nullable String servicePackageName, @NonNull SaveInfo info,
            @Nullable String servicePackageName, @NonNull SaveInfo info,
            @NonNull ValueFinder valueFinder, @NonNull ComponentName componentName,
            @NonNull ValueFinder valueFinder, @NonNull ComponentName componentName,
            @NonNull AutoFillUiCallback callback, @NonNull PendingUi pendingSaveUi,
            @NonNull AutoFillUiCallback callback, @UserIdInt int userId,
            boolean isUpdate, boolean compatMode, boolean showServiceIcon) {
            @NonNull PendingUi pendingSaveUi, boolean isUpdate, boolean compatMode,
            boolean showServiceIcon) {
        if (sVerbose) {
        if (sVerbose) {
            Slog.v(TAG, "showSaveUi(update=" + isUpdate + ") for " + componentName.toShortString()
            Slog.v(TAG, "showSaveUi(update=" + isUpdate + ") for " + componentName.toShortString()
                    + ": " + info);
                    + " and user " + userId + ": " + info);
        }
        }
        int numIds = 0;
        int numIds = 0;
        numIds += info.getRequiredIds() == null ? 0 : info.getRequiredIds().length;
        numIds += info.getRequiredIds() == null ? 0 : info.getRequiredIds().length;
@@ -349,7 +350,7 @@ public final class AutoFillUI {
            }
            }
            hideAllUiThread(callback);
            hideAllUiThread(callback);
            mSaveUiCallback = callback;
            mSaveUiCallback = callback;
            mSaveUi = new SaveUi(mContext, pendingSaveUi, serviceLabel, serviceIcon,
            mSaveUi = new SaveUi(mContext, userId, pendingSaveUi, serviceLabel, serviceIcon,
                    servicePackageName, componentName, info, valueFinder, mOverlayControl,
                    servicePackageName, componentName, info, valueFinder, mOverlayControl,
                    new SaveUi.OnSaveListener() {
                    new SaveUi.OnSaveListener() {
                @Override
                @Override
+68 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.server.autofill.ui;

import static com.android.server.autofill.Helper.sDebug;

import android.annotation.UserIdInt;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.UserManager;
import android.view.Display;

import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;
import com.android.server.utils.Slogf;

/**
 * Helper for display-related needs.
 */
final class DisplayHelper {

    private static final String TAG = "AutofillDisplayHelper";

    private static final UserManagerInternal sUmi = LocalServices
            .getService(UserManagerInternal.class);

    /**
     * Gets a context with the proper display id set for the given user.
     *
     * <p>For most cases it will return the provided context, but on devices that
     * {@link UserManager#isVisibleBackgroundUsersEnabled() support visible background users}, it
     * will return a context with the display the user started visible on.
     */
    static Context getDisplayContext(Context context, @UserIdInt int userId) {
        if (!UserManager.isVisibleBackgroundUsersEnabled()) {
            return context;
        }
        int displayId = sUmi.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) {
            Slogf.wtf(TAG, "Could not get display with id %d (which is associated with user %d; "
                    + "FillUi operations will probably fail", displayId, userId);
            return context;
        }

        return context.createDisplayContext(display);
    }

    private DisplayHelper() {
        throw new UnsupportedOperationException("Contains only static methods");
    }
}
+2 −23
Original line number Original line Diff line number Diff line
@@ -29,8 +29,6 @@ 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;
@@ -39,7 +37,6 @@ 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;
@@ -61,12 +58,9 @@ 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;
@@ -140,29 +134,14 @@ final class FillUi {
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
    }
    }


    FillUi(@NonNull Context context, @UserIdInt int userId, @NonNull FillResponse response,
    FillUi(@NonNull Context systemContext, @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;

        Context context = DisplayHelper.getDisplayContext(systemContext, userId);
        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);


+3 −1
Original line number Original line Diff line number Diff line
@@ -21,6 +21,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.app.Dialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.ComponentName;
@@ -172,12 +173,13 @@ final class SaveUi {


    private boolean mDestroyed;
    private boolean mDestroyed;


    SaveUi(@NonNull Context context, @NonNull PendingUi pendingUi,
    SaveUi(@NonNull Context systemContext, @UserIdInt int userId, @NonNull PendingUi pendingUi,
           @NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
           @NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon,
           @Nullable String servicePackageName, @NonNull ComponentName componentName,
           @Nullable String servicePackageName, @NonNull ComponentName componentName,
           @NonNull SaveInfo info, @NonNull ValueFinder valueFinder,
           @NonNull SaveInfo info, @NonNull ValueFinder valueFinder,
           @NonNull OverlayControl overlayControl, @NonNull OnSaveListener listener,
           @NonNull OverlayControl overlayControl, @NonNull OnSaveListener listener,
           boolean nightMode, boolean isUpdate, boolean compatMode, boolean showServiceIcon) {
           boolean nightMode, boolean isUpdate, boolean compatMode, boolean showServiceIcon) {
        Context context = DisplayHelper.getDisplayContext(systemContext, userId);
        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;
        mPendingUi = pendingUi;
        mPendingUi = pendingUi;