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

Commit c3d1c85b authored by Svet Ganov's avatar Svet Ganov
Browse files

Allow custom buttons in autofill UI

Test: added CTS test in topic

bug:36871561

Change-Id: I78ffd8ba33fb982183677fffc587bbf1a077e132
parent 43574b03
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -1068,5 +1068,19 @@ public final class AutofillManager {
                });
            }
        }

        @Override
        public void startIntentSender(IntentSender intentSender) {
            final AutofillManager afm = mAfm.get();
            if (afm != null) {
                afm.mContext.getMainThreadHandler().post(() -> {
                    try {
                        afm.mContext.startIntentSender(intentSender, null, 0, 0, 0);
                    } catch (IntentSender.SendIntentException e) {
                        Log.e(TAG, "startIntentSender() failed for intent:" + intentSender, e);
                    }
                });
            }
        }
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -59,7 +59,12 @@ oneway interface IAutoFillManagerClient {
    void requestHideFillUi(in IBinder windowToken, in AutofillId id);

    /**
     * Nitifies no fill UI will be shown.
     * Notifies no fill UI will be shown.
     */
    void notifyNoFillUi(in IBinder windowToken, in AutofillId id);

    /**
     * Starts the provided intent sender
     */
    void startIntentSender(in IntentSender intentSender);
}
+17 −0
Original line number Diff line number Diff line
@@ -370,6 +370,23 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
    }

    // AutoFillUiCallback
    @Override
    public void startIntentSender(IntentSender intentSender) {
        synchronized (mLock) {
            removeSelfLocked();
        }
        mHandlerCaller.getHandler().post(() -> {
            try {
                synchronized (mLock) {
                    mClient.startIntentSender(intentSender);
                }
            } catch (RemoteException e) {
                Slog.e(TAG, "Error launching auth intent", e);
            }
        });
    }

    public void setAuthenticationResultLocked(Bundle data) {
        if ((mResponseWaitingAuth == null && mDatasetWaitingAuth == null) || data == null) {
            removeSelf();
+8 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ public final class AutoFillUI {
        void requestShowFillUi(AutofillId id, int width, int height,
                IAutofillWindowPresenter presenter);
        void requestHideFillUi(AutofillId id);
        void startIntentSender(IntentSender intentSender);
    }

    public AutoFillUI(@NonNull Context context) {
@@ -201,6 +202,13 @@ public final class AutoFillUI {
                        mCallback.requestHideFillUi(focusedId);
                    }
                }

                @Override
                public void startIntentSender(IntentSender intentSender) {
                    if (mCallback != null) {
                        mCallback.startIntentSender(intentSender);
                    }
                }
            });
        });
    }
+18 −3
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@ package com.android.server.autofill.ui;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.graphics.Rect;
import android.service.autofill.Dataset;
import android.service.autofill.FillResponse;
@@ -55,6 +58,7 @@ final class FillUi {
        void requestShowFillUi(int width, int height,
                IAutofillWindowPresenter windowPresenter);
        void requestHideFillUi();
        void startIntentSender(IntentSender intentSender);
    }

    private final @NonNull AutofillWindowPresenter mWindowPresenter =
@@ -84,13 +88,24 @@ final class FillUi {
        final ViewGroup decor = (ViewGroup) inflater.inflate(
                R.layout.autofill_dataset_picker, null);

        final RemoteViews.OnClickHandler interceptionHandler = new RemoteViews.OnClickHandler() {
            @Override
            public boolean onClickHandler(View view, PendingIntent pendingIntent,
                    Intent fillInIntent) {
                if (pendingIntent != null) {
                    mCallback.startIntentSender(pendingIntent.getIntentSender());
                }
                return true;
            }
        };

        if (response.getAuthentication() != null) {
            mListView = null;
            mAdapter = null;

            final View content;
            try {
                content = response.getPresentation().apply(context, decor);
                content = response.getPresentation().apply(context, decor, interceptionHandler);
                decor.addView(content);
            } catch (RuntimeException e) {
                callback.onCanceled();
@@ -101,7 +116,7 @@ final class FillUi {
            final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            content.measure(widthMeasureSpec, heightMeasureSpec);
            content.setOnClickListener(v -> mCallback.onResponsePicked(response));
            decor.setOnClickListener(v -> mCallback.onResponsePicked(response));
            // TODO(b/33197203 , b/36660292): temporary limiting maximum height and minimum width
            mContentWidth = Math.max(content.getMeasuredWidth(), 1000);
            mContentHeight = Math.min(content.getMeasuredHeight(), 500);
@@ -118,7 +133,7 @@ final class FillUi {
                    final RemoteViews presentation = dataset.getFieldPresentation(index);
                    final View view;
                    try {
                        view = presentation.apply(context, null);
                        view = presentation.apply(context, null, interceptionHandler);
                    } catch (RuntimeException e) {
                        Slog.e(TAG, "Error inflating remote views", e);
                        continue;