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

Commit 11353c8d authored by Felipe Leme's avatar Felipe Leme
Browse files

Added cmd to change number of visible datasets on Autofill dataset picker.

Bug: 73796644

Test: adb shell cmd autofill set max_visible_datasets 5
Test: adb shell cmd autofill get max_visible_datasets

Change-Id: I3d86ada028354a4329c054c773d12bc7913fd61d
parent 0ec75bea
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.content.Context.AUTOFILL_MANAGER_SERVICE;
import static com.android.server.autofill.Helper.bundleToString;
import static com.android.server.autofill.Helper.sDebug;
import static com.android.server.autofill.Helper.sPartitionMaxCount;
import static com.android.server.autofill.Helper.sVisibleDatasetsMaxCount;
import static com.android.server.autofill.Helper.sVerbose;

import android.annotation.NonNull;
@@ -462,6 +463,24 @@ public final class AutofillManagerService extends SystemService {
        }
    }

    // Called by Shell command.
    public int getMaxVisibleDatasets() {
        mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG);

        synchronized (mLock) {
            return sVisibleDatasetsMaxCount;
        }
    }

    // Called by Shell command.
    public void setMaxVisibleDatasets(int max) {
        mContext.enforceCallingPermission(MANAGE_AUTO_FILL, TAG);
        Slog.i(TAG, "setMaxVisibleDatasets(): " + max);
        synchronized (mLock) {
            sVisibleDatasetsMaxCount = max;
        }
    }

    // Called by Shell command.
    public void getScore(@Nullable String algorithmName, @NonNull String value1,
            @NonNull String value2, @NonNull RemoteCallback callback) {
@@ -1009,6 +1028,7 @@ public final class AutofillManagerService extends SystemService {
                    pw.print("Verbose mode: "); pw.println(sVerbose);
                    pw.print("Disabled users: "); pw.println(mDisabledUsers);
                    pw.print("Max partitions per session: "); pw.println(sPartitionMaxCount);
                    pw.print("Max visible datasets: "); pw.println(sVisibleDatasetsMaxCount);
                    pw.println("User data constraints: "); UserData.dumpConstraints(prefix, pw);
                    final int size = mServicesCache.size();
                    pw.print("Cached services: ");
+20 −0
Original line number Diff line number Diff line
@@ -77,12 +77,18 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
            pw.println("  get max_partitions");
            pw.println("    Gets the maximum number of partitions per session.");
            pw.println("");
            pw.println("  get max_visible_datasets");
            pw.println("    Gets the maximum number of visible datasets in the UI.");
            pw.println("");
            pw.println("  set log_level [off | debug | verbose]");
            pw.println("    Sets the Autofill log level.");
            pw.println("");
            pw.println("  set max_partitions number");
            pw.println("    Sets the maximum number of partitions per session.");
            pw.println("");
            pw.println("  set max_visible_datasets number");
            pw.println("    Sets the maximum number of visible datasets in the UI.");
            pw.println("");
            pw.println("  list sessions [--user USER_ID]");
            pw.println("    Lists all pending sessions.");
            pw.println("");
@@ -105,6 +111,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
                return getLogLevel(pw);
            case "max_partitions":
                return getMaxPartitions(pw);
            case "max_visible_datasets":
                return getMaxVisibileDatasets(pw);
            case "fc_score":
                return getFieldClassificationScore(pw);
            default:
@@ -121,6 +129,8 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
                return setLogLevel(pw);
            case "max_partitions":
                return setMaxPartitions();
            case "max_visible_datasets":
                return setMaxVisibileDatasets();
            default:
                pw.println("Invalid set: " + what);
                return -1;
@@ -173,6 +183,16 @@ public final class AutofillManagerServiceShellCommand extends ShellCommand {
        return 0;
    }

    private int getMaxVisibileDatasets(PrintWriter pw) {
        pw.println(mService.getMaxVisibleDatasets());
        return 0;
    }

    private int setMaxVisibileDatasets() {
        mService.setMaxVisibleDatasets(Integer.parseInt(getNextArgRequired()));
        return 0;
    }

    private int getFieldClassificationScore(PrintWriter pw) {
        final String nextArg = getNextArgRequired();
        final String algorithm, value1;
+7 −0
Original line number Diff line number Diff line
@@ -61,6 +61,13 @@ public final class Helper {
     */
    static int sPartitionMaxCount = 10;

    /**
     * Maximum number of visible datasets in the dataset picker UI.
     *
     * <p>Can be modified using {@code cmd autofill set max_visible_datasets}.
     */
    public static int sVisibleDatasetsMaxCount = 3;

    private Helper() {
        throw new UnsupportedOperationException("contains static members only");
    }
+4 −4
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import com.android.internal.R;
import com.android.server.UiThread;
import com.android.server.autofill.Helper;

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

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
@@ -69,8 +71,6 @@ import java.util.stream.Collectors;
final class FillUi {
    private static final String TAG = "FillUi";

    private static final int VISIBLE_OPTIONS_MAX_COUNT = 3;

    private static final TypedValue sTempTypedValue = new TypedValue();

    public static final class AutofillFrameLayout extends FrameLayout {
@@ -375,7 +375,7 @@ final class FillUi {
                    }
                    requestShowFillUi();
                }
                if (mAdapter.getCount() > VISIBLE_OPTIONS_MAX_COUNT) {
                if (mAdapter.getCount() > sVisibleDatasetsMaxCount) {
                    mListView.setVerticalScrollBarEnabled(true);
                    mListView.onVisibilityAggregated(true);
                } else {
@@ -475,7 +475,7 @@ final class FillUi {
                    changed = true;
                }
                // Update the width to fit only the first items up to max count
                if (i < VISIBLE_OPTIONS_MAX_COUNT) {
                if (i < sVisibleDatasetsMaxCount) {
                    final int clampedMeasuredHeight = Math.min(view.getMeasuredHeight(), maxSize.y);
                    final int newContentHeight = mContentHeight + clampedMeasuredHeight;
                    if (newContentHeight != mContentHeight) {