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

Commit f4537dcf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Minor changes on AutoFill Save UI."

parents 3056c611 de4d4c20
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -40,13 +40,6 @@
            android:singleLine="true">
        </TextView>

        <TextView
            android:id="@+id/autofill_save_subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="invisible">
        </TextView>

        <Space
            android:layout_width="0dp"
            android:layout_height="0dp"
@@ -64,6 +57,13 @@

    </LinearLayout>

    <TextView
        android:id="@+id/autofill_save_subtitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="invisible" >
    </TextView>

    <com.android.internal.widget.ButtonBarLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
+7 −0
Original line number Diff line number Diff line
@@ -247,6 +247,13 @@ public final class AutoFillManagerService extends SystemService {
        }
    }

    // Called by Shell command.
    public void setSaveTimeout(int timeout) {
        Slog.i(TAG, "setSaveTimeout("  + timeout + ")");
        mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        mUi.setSaveTimeout(timeout);
    }

    /**
     * Removes a cached service for a given user.
     */
+18 −1
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ public final class AutoFillManagerServiceShellCommand extends ShellCommand {
        switch (cmd) {
            case "save":
                return requestSave();
            case "set":
                return requestSet();
            case "list":
                return requestList(pw);
            case "destroy":
@@ -74,6 +76,9 @@ public final class AutoFillManagerServiceShellCommand extends ShellCommand {
            pw.println("  save [--user USER_ID]");
            pw.println("    Request provider to save contents of the top activity.");
            pw.println("");
            pw.println("  set save_timeout MS");
            pw.println("    Sets how long (in ms) the save snack bar is shown.");
            pw.println("");
            pw.println("  reset");
            pw.println("    Reset all pending sessions and cached service connections.");
            pw.println("");
@@ -86,6 +91,18 @@ public final class AutoFillManagerServiceShellCommand extends ShellCommand {
        return 0;
    }

    private int requestSet() {
        final String type = getNextArgRequired();
        switch (type) {
            case "save_timeout":
                mService.setSaveTimeout(Integer.parseInt(getNextArgRequired()));
                break;
            default:
                throw new IllegalArgumentException("Invalid 'set' type: " + type);
        }
        return 0;
    }

    private int requestDestroy(PrintWriter pw) {
        if (!isNextArgSessions(pw)) {
            return -1;
+17 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.service.autofill.FillResponse;
import android.service.autofill.SaveInfo;
import android.text.TextUtils;
import android.util.Slog;
import android.text.format.DateUtils;
import android.view.autofill.AutoFillId;
import android.widget.Toast;

@@ -44,6 +45,8 @@ import java.io.PrintWriter;
public final class AutoFillUI {
    private static final String TAG = "AutoFillUI";

    private static final int MAX_SAVE_TIMEOUT_MS = (int) (30 * DateUtils.SECOND_IN_MILLIS);

    private final Handler mHandler = UiThread.getHandler();
    private final @NonNull Context mContext;

@@ -53,6 +56,8 @@ public final class AutoFillUI {
    private @Nullable AutoFillUiCallback mCallback;
    private @Nullable IBinder mWindowToken;

    private int mSaveTimeoutMs = (int) (5 * DateUtils.SECOND_IN_MILLIS);

    public interface AutoFillUiCallback {
        void authenticate(@NonNull IntentSender intent);
        void fill(@NonNull Dataset dataset);
@@ -206,7 +211,7 @@ public final class AutoFillUI {
                        }
                    }
                }
            });
            }, mSaveTimeoutMs);
        });
    }

@@ -217,11 +222,22 @@ public final class AutoFillUI {
        mHandler.post(this::hideAllUiThread);
    }

    public void setSaveTimeout(int timeout) {
        if (timeout > MAX_SAVE_TIMEOUT_MS) {
            throw new IllegalArgumentException("Maximum value is " + MAX_SAVE_TIMEOUT_MS + "ms");
        }
        if (timeout <= 0) {
            throw new IllegalArgumentException("Must be a positive value");
        }
        mSaveTimeoutMs = timeout;
    }

    public void dump(PrintWriter pw) {
        pw.println("AufoFill UI");
        final String prefix = "  ";
        pw.print(prefix); pw.print("showsFillUi: "); pw.println(mFillUi != null);
        pw.print(prefix); pw.print("showsSaveUi: "); pw.println(mSaveUi != null);
        pw.print(prefix); pw.print("save timeout: "); pw.println(mSaveTimeoutMs);
    }

    @android.annotation.UiThread
+2 −4
Original line number Diff line number Diff line
@@ -42,8 +42,6 @@ final class SaveUi {
        void onCancel(IntentSender listener);
    }

    private static final long LIFETIME_MILLIS = 5 * DateUtils.SECOND_IN_MILLIS;

    private final Handler mHandler = UiThread.getHandler();

    private final @NonNull Dialog mDialog;
@@ -53,7 +51,7 @@ final class SaveUi {
    private boolean mDestroyed;

    SaveUi(@NonNull Context context, @NonNull CharSequence providerLabel, @NonNull SaveInfo info,
            @NonNull OnSaveListener listener) {
            @NonNull OnSaveListener listener, int lifeTimeMs) {
        mListener = listener;

        final LayoutInflater inflater = LayoutInflater.from(context);
@@ -119,7 +117,7 @@ final class SaveUi {

        mDialog.show();

        mHandler.postDelayed(() -> mListener.onCancel(null), LIFETIME_MILLIS);
        mHandler.postDelayed(() -> mListener.onCancel(null), lifeTimeMs);
    }

    void destroy() {