Merge "Minor changes on AutoFill Save UI."

This commit is contained in:
TreeHugger Robot
2017-03-04 10:03:54 +00:00
committed by Android (Google) Code Review
5 changed files with 51 additions and 13 deletions

View File

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

View File

@@ -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.
*/

View File

@@ -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":
@@ -72,7 +74,10 @@ public final class AutoFillManagerServiceShellCommand extends ShellCommand {
pw.println(" Destroy all pending sessions.");
pw.println("");
pw.println(" save [--user USER_ID]");
pw.println(" Request provider to save contents of the top activity. ");
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.");
@@ -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;

View File

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

View File

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