summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/Activity.java83
-rw-r--r--core/java/android/app/ActivityManagerInternal.java6
-rw-r--r--core/java/android/app/ActivityThread.java2
-rw-r--r--core/java/android/service/autofill/AutoFillService.java73
-rw-r--r--core/java/android/service/autofill/IAutoFillAppCallback.aidl3
-rw-r--r--core/java/android/service/autofill/IAutoFillManagerService.aidl7
-rw-r--r--core/java/android/service/autofill/IAutoFillServerCallback.aidl3
-rw-r--r--core/java/android/service/autofill/IAutoFillService.aidl3
-rw-r--r--core/java/android/service/autofill/SaveCallback.java4
-rw-r--r--core/java/android/view/View.java33
-rw-r--r--core/java/android/view/autofill/AutoFillManager.java63
-rw-r--r--core/java/android/view/autofill/AutoFillSession.java118
-rw-r--r--core/java/android/view/autofill/Dataset.java2
-rw-r--r--core/java/android/view/autofill/FillResponse.java15
-rw-r--r--core/java/android/widget/TextView.java5
15 files changed, 212 insertions, 208 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 580bb50811e3..1d84ff57d3c1 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -117,9 +117,8 @@ import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityEvent;
import android.view.autofill.AutoFillId;
-import android.view.autofill.Dataset;
-import android.view.autofill.DatasetField;
-import android.view.autofill.VirtualViewDelegate;
+import android.view.autofill.AutoFillManager;
+import android.view.autofill.AutoFillSession;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.Toolbar;
@@ -848,10 +847,7 @@ public class Activity extends ContextThemeWrapper
private boolean mHasCurrentPermissionsRequest;
@GuardedBy("this")
- private WeakReference<IAutoFillAppCallback> mAutoFillCallback;
-
- @GuardedBy("this")
- private VirtualViewDelegate.Callback mAutoFillDelegateCallback;
+ private AutoFillSession mAutoFillSession;
private static native String getDlWarning();
@@ -1704,76 +1700,17 @@ public class Activity extends ContextThemeWrapper
}
/**
- * Lazily sets the {@link #mAutoFillDelegateCallback}.
- */
- private void setAutoFillDelegateCallback() {
- synchronized (this) {
- if (mAutoFillDelegateCallback == null) {
- mAutoFillDelegateCallback = new VirtualViewDelegate.Callback() {
- // TODO(b/33197203): implement
- };
- }
- }
- }
-
- /**
* Lazily gets the {@link IAutoFillAppCallback} for this activitity.
*
* <p>This callback is used by the {@link AutoFillService} app to auto-fill the activity fields.
*/
- WeakReference<IAutoFillAppCallback> getAutoFillCallback() {
+ IAutoFillAppCallback getAutoFillCallback() {
synchronized (this) {
- if (mAutoFillCallback == null) {
- final IAutoFillAppCallback cb = new IAutoFillAppCallback.Stub() {
- @Override
- public void autoFill(Dataset dataset) throws RemoteException {
- // TODO(b/33197203): must keep the dataset so subsequent calls pass the same
- // dataset.extras to service
- runOnUiThread(() -> {
- final View root = getWindow().getDecorView().getRootView();
- for (DatasetField field : dataset.getFields()) {
- final AutoFillId id = field.getId();
- if (id == null) {
- Log.w(TAG, "autoFill(): null id on " + field);
- continue;
- }
- final int viewId = id.getViewId();
- final View view = root.findViewByAccessibilityIdTraversal(viewId);
- if (view == null) {
- Log.w(TAG, "autoFill(): no View with id " + viewId);
- continue;
- }
-
- // TODO(b/33197203): handle protected value (like credit card)
- if (id.isVirtual()) {
- // Delegate virtual fields to provider.
- setAutoFillDelegateCallback();
- final VirtualViewDelegate mgr = view
- .getAutoFillVirtualViewDelegate(
- mAutoFillDelegateCallback);
- if (mgr == null) {
- Log.w(TAG, "autoFill(): cannot fill virtual " + id
- + "; no auto-fill provider for view "
- + view.getClass());
- continue;
- }
- if (DEBUG_AUTO_FILL) {
- Log.d(TAG, "autoFill(): delegating " + id
- + " to virtual manager " + mgr);
- }
- mgr.autoFill(id.getVirtualChildId(), field.getValue());
- } else {
- // Handle non-virtual fields itself.
- view.autoFill(field.getValue());
- }
- }
- });
- }
- };
- mAutoFillCallback = new WeakReference<IAutoFillAppCallback>(cb);
+ if (mAutoFillSession == null) {
+ mAutoFillSession = new AutoFillSession(this);
}
+ return mAutoFillSession.getCallback();
}
- return mAutoFillCallback;
}
/**
@@ -6067,9 +6004,9 @@ public class Activity extends ContextThemeWrapper
getWindow().peekDecorView().getViewRootImpl().dump(prefix, fd, writer, args);
}
- if (mAutoFillCallback != null) {
- writer.print(prefix); writer.print("mAutoFillCallback: " );
- writer.println(mAutoFillCallback.get());
+ if (mAutoFillSession!= null) {
+ writer.print(prefix); writer.print("mAutoFillSession: " );
+ writer.println(mAutoFillSession);
}
mHandler.getLooper().dump(new PrintWriterPrinter(writer), prefix);
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index 89510d9f2d15..e848080d3e32 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -154,6 +154,12 @@ public abstract class ActivityManagerInternal {
public abstract List<IBinder> getTopVisibleActivities();
/**
+ * Returns the top, focused activity of the currently visible stack, but only if it belongs to
+ * the given UID.
+ */
+ public abstract IBinder getTopVisibleActivity(int uid);
+
+ /**
* Callback for window manager to let activity manager know that docked stack changes its
* minimized state.
*/
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 90fab410610b..9a221251318f 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -2967,7 +2967,7 @@ public final class ActivityThread {
if (!forAutoFill) {
r.activity.onProvideAssistContent(content);
} else if (addAutoFillCallback) {
- IAutoFillAppCallback cb = r.activity.getAutoFillCallback().get();
+ IAutoFillAppCallback cb = r.activity.getAutoFillCallback();
if (cb != null) {
data.putBinder(AutoFillService.KEY_CALLBACK, cb.asBinder());
} else {
diff --git a/core/java/android/service/autofill/AutoFillService.java b/core/java/android/service/autofill/AutoFillService.java
index b5cb8f88c871..1e4f90d1ed07 100644
--- a/core/java/android/service/autofill/AutoFillService.java
+++ b/core/java/android/service/autofill/AutoFillService.java
@@ -89,16 +89,14 @@ public abstract class AutoFillService extends Service {
/**
* Key of the {@link Bundle} passed to methods such as
- * {@link #onSaveRequest(AssistStructure, Bundle, CancellationSignal, SaveCallback)}
- * containing the extras set by
+ * {@link #onSaveRequest(AssistStructure, Bundle, SaveCallback)} containing the extras set by
* {@link android.view.autofill.FillResponse.Builder#setExtras(Bundle)}.
*/
public static final String EXTRA_RESPONSE_EXTRAS = KEY_PREFIX + "RESPONSE_EXTRAS";
/**
* Key of the {@link Bundle} passed to methods such as
- * {@link #onSaveRequest(AssistStructure, Bundle, CancellationSignal, SaveCallback)}
- * containing the extras set by
+ * {@link #onSaveRequest(AssistStructure, Bundle, SaveCallback)} containing the extras set by
* {@link android.view.autofill.Dataset.Builder#setExtras(Bundle)}.
*/
public static final String EXTRA_DATASET_EXTRAS = KEY_PREFIX + "DATASET_EXTRAS";
@@ -134,9 +132,9 @@ public abstract class AutoFillService extends Service {
@Override
public void autoFill(AssistStructure structure, IAutoFillServerCallback callback,
- Bundle extras, int flags) {
+ int flags) {
mHandlerCaller
- .obtainMessageIOOO(MSG_AUTO_FILL_ACTIVITY, flags, structure, extras, callback)
+ .obtainMessageIOO(MSG_AUTO_FILL_ACTIVITY, flags, structure, callback)
.sendToTarget();
}
@@ -179,9 +177,8 @@ public abstract class AutoFillService extends Service {
final SomeArgs args = (SomeArgs) msg.obj;
final int flags = msg.arg1;
final AssistStructure structure = (AssistStructure) args.arg1;
- final Bundle extras = (Bundle) args.arg2;
- final IAutoFillServerCallback callback = (IAutoFillServerCallback) args.arg3;
- requestAutoFill(callback, structure, extras, flags);
+ final IAutoFillServerCallback callback = (IAutoFillServerCallback) args.arg2;
+ requestAutoFill(callback, structure, flags);
break;
} case MSG_AUTHENTICATE_FILL_RESPONSE: {
final int flags = msg.arg1;
@@ -254,8 +251,8 @@ public abstract class AutoFillService extends Service {
* @param cancellationSignal signal for observing cancel requests.
* @param callback object used to notify the result of the request.
*/
- public abstract void onFillRequest(AssistStructure structure,
- Bundle data, CancellationSignal cancellationSignal, FillCallback callback);
+ public abstract void onFillRequest(AssistStructure structure, Bundle data,
+ CancellationSignal cancellationSignal, FillCallback callback);
/**
* Called when user requests service to save the fields of an {@link Activity}.
@@ -267,20 +264,19 @@ public abstract class AutoFillService extends Service {
* @param structure {@link Activity}'s view structure.
* @param data bundle containing additional arguments set by the Android system (currently none)
* or data passed by the service in the {@link FillResponse} that originated this call.
- * @param cancellationSignal signal for observing cancel requests.
* @param callback object used to notify the result of the request.
*/
- public abstract void onSaveRequest(AssistStructure structure,
- Bundle data, CancellationSignal cancellationSignal, SaveCallback callback);
+ public abstract void onSaveRequest(AssistStructure structure, Bundle data,
+ SaveCallback callback);
/**
* Called as result of the user action for a {@link FillResponse} that required authentication.
*
* <p>When the {@link FillResponse} required authentication through
- * {@link android.view.autofill.FillResponse.Builder#requiresCustomAuthentication(Bundle, int)}, this
- * call indicates the user is requesting the service to authenticate him/her (and {@code flags}
- * contains {@link #FLAG_AUTHENTICATION_REQUESTED}), and {@code extras} contains the
- * {@link Bundle} passed to that method.
+ * {@link android.view.autofill.FillResponse.Builder#requiresCustomAuthentication(Bundle, int)},
+ * this call indicates the user is requesting the service to authenticate him/her (and
+ * {@code flags} contains {@link #FLAG_AUTHENTICATION_REQUESTED}), and {@code extras} contains
+ * the {@link Bundle} passed to that method.
*
* <p>When the {@link FillResponse} required authentication through
* {@link android.view.autofill.FillResponse.Builder#requiresFingerprintAuthentication(
@@ -336,27 +332,28 @@ public abstract class AutoFillService extends Service {
}
private void requestAutoFill(IAutoFillServerCallback callback, AssistStructure structure,
- Bundle data, int flags) {
- switch (flags) {
- case AUTO_FILL_FLAG_TYPE_FILL:
- final FillCallback fillCallback = new FillCallback(callback);
- if (DEBUG_PENDING_CALLBACKS) {
- addPendingCallback(fillCallback);
- }
- // TODO(b/33197203): hook up the cancelationSignal
- onFillRequest(structure, data, new CancellationSignal(), fillCallback);
- break;
- case AUTO_FILL_FLAG_TYPE_SAVE:
- final SaveCallback saveCallback = new SaveCallback(callback);
- if (DEBUG_PENDING_CALLBACKS) {
- addPendingCallback(saveCallback);
- }
- // TODO(b/33197203): hook up the cancelationSignal
- onSaveRequest(structure, data, new CancellationSignal(), saveCallback);
- break;
- default:
- Log.w(TAG, "invalid flag on requestAutoFill(): " + flags);
+ int flags) {
+ if (DEBUG) Log.d(TAG, "requestAutoFill(): flags=" + flags);
+
+ if ((flags & AUTO_FILL_FLAG_TYPE_FILL) != 0) {
+ final FillCallback fillCallback = new FillCallback(callback);
+ if (DEBUG_PENDING_CALLBACKS) {
+ addPendingCallback(fillCallback);
+ }
+ // TODO(b/33197203): hook up the cancelationSignal
+ onFillRequest(structure, null, new CancellationSignal(), fillCallback);
+ return;
}
+ if ((flags & AUTO_FILL_FLAG_TYPE_SAVE) != 0) {
+ final SaveCallback saveCallback = new SaveCallback(callback);
+ if (DEBUG_PENDING_CALLBACKS) {
+ addPendingCallback(saveCallback);
+ }
+ onSaveRequest(structure, null, saveCallback);
+ return;
+ }
+
+ Log.w(TAG, "invalid flags on requestAutoFill(): " + flags);
}
private void addPendingCallback(CallbackHelper.Dumpable callback) {
diff --git a/core/java/android/service/autofill/IAutoFillAppCallback.aidl b/core/java/android/service/autofill/IAutoFillAppCallback.aidl
index cc83776e2f57..8c3898ab2b15 100644
--- a/core/java/android/service/autofill/IAutoFillAppCallback.aidl
+++ b/core/java/android/service/autofill/IAutoFillAppCallback.aidl
@@ -25,8 +25,7 @@ import android.view.autofill.Dataset;
*
* @hide
*/
-// TODO(b/33197203): rename methods to make them more consistent with a callback, or rename class
-// itself
+// TODO(b/33197203): rename IAutoFillAppSession
oneway interface IAutoFillAppCallback {
/**
* Auto-fills the activity with the contents of a dataset.
diff --git a/core/java/android/service/autofill/IAutoFillManagerService.aidl b/core/java/android/service/autofill/IAutoFillManagerService.aidl
index ce421072bdc4..ace5411ca0d3 100644
--- a/core/java/android/service/autofill/IAutoFillManagerService.aidl
+++ b/core/java/android/service/autofill/IAutoFillManagerService.aidl
@@ -27,8 +27,9 @@ import android.view.autofill.AutoFillId;
*/
oneway interface IAutoFillManagerService {
- void showAutoFillInput(in AutoFillId id, in Rect boundaries);
+ // Called by AutoFillManager (app).
+ void requestAutoFill(in AutoFillId id, in Rect bounds, int flags);
- // TODO(b/33197203): remove it and refactor onShellCommand
- void requestAutoFill(IBinder activityToken, int userId, in Bundle extras, int flags);
+ // Called by ShellCommand only.
+ void requestAutoFillForUser(int userId, int flags);
}
diff --git a/core/java/android/service/autofill/IAutoFillServerCallback.aidl b/core/java/android/service/autofill/IAutoFillServerCallback.aidl
index 185c8f3a4fb3..f7d5064e9e26 100644
--- a/core/java/android/service/autofill/IAutoFillServerCallback.aidl
+++ b/core/java/android/service/autofill/IAutoFillServerCallback.aidl
@@ -28,8 +28,7 @@ import android.view.autofill.FillResponse;
*
* @hide
*/
-// TODO(b/33197203): rename methods to make them more consistent with a callback, or rename class
-// itself
+// TODO(b/33197203): rename to IAutoFillServerSession
oneway interface IAutoFillServerCallback {
// TODO(b/33197203): document methods
void showResponse(in FillResponse response);
diff --git a/core/java/android/service/autofill/IAutoFillService.aidl b/core/java/android/service/autofill/IAutoFillService.aidl
index fa9786a1be53..3e8087b2a5a2 100644
--- a/core/java/android/service/autofill/IAutoFillService.aidl
+++ b/core/java/android/service/autofill/IAutoFillService.aidl
@@ -27,8 +27,7 @@ import com.android.internal.os.IResultReceiver;
// TODO(b/33197203): document class and methods
oneway interface IAutoFillService {
// TODO(b/33197203): rename method to make them more consistent
- void autoFill(in AssistStructure structure, in IAutoFillServerCallback callback,
- in Bundle extras, int flags);
+ void autoFill(in AssistStructure structure, in IAutoFillServerCallback callback, int flags);
void authenticateFillResponse(in Bundle extras, int flags);
void authenticateDataset(in Bundle extras, int flags);
void onConnected();
diff --git a/core/java/android/service/autofill/SaveCallback.java b/core/java/android/service/autofill/SaveCallback.java
index d5022d85f110..e2fb588db212 100644
--- a/core/java/android/service/autofill/SaveCallback.java
+++ b/core/java/android/service/autofill/SaveCallback.java
@@ -58,7 +58,7 @@ public final class SaveCallback implements Dumpable {
/**
* Notifies the Android System that an
* {@link AutoFillService#onSaveRequest(android.app.assist.AssistStructure, Bundle,
- * android.os.CancellationSignal, SaveCallback)} was successfully fulfilled by the service.
+ * SaveCallback)} was successfully fulfilled by the service.
*
* @param ids ids ({@link ViewNode#getAutoFillId()}) of the fields that were saved.
*
@@ -85,7 +85,7 @@ public final class SaveCallback implements Dumpable {
/**
* Notifies the Android System that an
* {@link AutoFillService#onSaveRequest(android.app.assist.AssistStructure, Bundle,
- * android.os.CancellationSignal, SaveCallback)} could not be fulfilled by the service.
+ * SaveCallback)} could not be fulfilled by the service.
*
* @param message error message to be displayed to the user.
*
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ba9bb67c1546..0657bef2ab69 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -1765,12 +1765,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
int mAccessibilityViewId = NO_ID;
- /**
- * The stable ID of this view for auto-fill purposes.
- */
- private int mAutoFillId = NO_ID;
-
-
private int mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED;
SendViewStateChangedAccessibilityEvent mSendViewStateChangedAccessibilityEvent;
@@ -4045,9 +4039,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* input fields and tags (like {@code id}).
* </ul>
*/
- // TODO(b/33197203) (b/34078930): improve documentation: mention all cases, show examples, etc.
- // In particular, be more specific about webview restrictions
- public static final int AUTO_FILL_FLAG_TYPE_FILL = 0x1;
+ // TODO(b/33197203): cannot conflict with flags defined on AutoFillManager until they're removed
+ // (when save is refactored).
+ public static final int AUTO_FILL_FLAG_TYPE_FILL = 0x10000000;
/**
* Set when the user explicitly asked a {@link android.service.autofill.AutoFillService} to save
@@ -4057,7 +4051,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* (Personally Identifiable Information). For example, the text of password fields should be
* included since that's what's typically saved.
*/
- public static final int AUTO_FILL_FLAG_TYPE_SAVE = 0x2;
+ // TODO(b/33197203): cannot conflict with flags defined on AutoFillManager until they're removed
+ // (when save is refactored).
+ public static final int AUTO_FILL_FLAG_TYPE_SAVE = 0x20000000;
/**
* Set to true when drawing cache is enabled and cannot be created.
@@ -6940,8 +6936,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
if (forAutoFill) {
// The auto-fill id needs to be unique, but its value doesn't matter, so it's better to
// reuse the accessibility id to save space.
- mAutoFillId = getAccessibilityViewId();
- structure.setAutoFillId(mAutoFillId);
+ structure.setAutoFillId(getAccessibilityViewId());
structure.setAutoFillType(getAutoFillType());
}
@@ -7568,20 +7563,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
- * Gets the unique identifier of this view for auto-fill purposes.
- *
- * <p>It's only set after {@link #onProvideAutoFillStructure(ViewStructure, int)} is called.
- *
- * @return The view autofill id or {@link #NO_ID} if
- * {@link #onProvideAutoFillStructure(ViewStructure, int)} was not called yet.
- *
- * @hide
- */
- public int getAutoFillViewId() {
- return mAutoFillId;
- }
-
- /**
* Gets the unique identifier of the window in which this View reseides.
*
* @return The window accessibility id.
diff --git a/core/java/android/view/autofill/AutoFillManager.java b/core/java/android/view/autofill/AutoFillManager.java
index cd9842fa6400..cf56e0e95aae 100644
--- a/core/java/android/view/autofill/AutoFillManager.java
+++ b/core/java/android/view/autofill/AutoFillManager.java
@@ -36,12 +36,16 @@ public final class AutoFillManager {
/**
* Flag used to show the auto-fill UI affordance for a view.
*/
- public static final int FLAG_UPDATE_UI_SHOW = 1 << 0;
+ // TODO(b/33197203): cannot conflict with flags defined on View until they're removed (when
+ // save is refactored).
+ public static final int FLAG_UPDATE_UI_SHOW = 0x1;
/**
* Flag used to hide the auto-fill UI affordance for a view.
*/
- public static final int FLAG_UPDATE_UI_HIDE = 1 << 1;
+ // TODO(b/33197203): cannot conflict with flags defined on View until they're removed (when
+ // save is refactored).
+ public static final int FLAG_UPDATE_UI_HIDE = 0x2;
private final IAutoFillManagerService mService;
@@ -64,11 +68,10 @@ public final class AutoFillManager {
* {@link #FLAG_UPDATE_UI_HIDE}.
*/
public void updateAutoFillInput(View view, int flags) {
- if (DEBUG) {
- Log.v(TAG, "updateAutoFillInput(" + view.getAutoFillViewId() + "): flags=" + flags);
- }
+ final Rect bounds = new Rect();
+ view.getBoundsOnScreen(bounds);
- updateAutoFillInput(view, false, View.NO_ID, null, flags);
+ requestAutoFill(new AutoFillId(view.getAccessibilityViewId()), bounds, flags);
}
/**
@@ -79,56 +82,22 @@ public final class AutoFillManager {
*
* @param parent parent view.
* @param childId id identifying the virtual child inside the parent view.
- * @param boundaries boundaries of the child (inside the parent; could be {@code null} when
+ * @param bounds absolute boundaries of the child in the window (could be {@code null} when
* flag is {@link #FLAG_UPDATE_UI_HIDE}.
* @param flags either {@link #FLAG_UPDATE_UI_SHOW} or
* {@link #FLAG_UPDATE_UI_HIDE}.
*/
- public void updateAutoFillInput(View parent, int childId, @Nullable Rect boundaries,
- int flags) {
- if (DEBUG) {
- Log.v(TAG, "updateAutoFillInput(" + parent.getAutoFillViewId() + ", " + childId
- + "): boundaries=" + boundaries + ", flags=" + flags);
- }
- updateAutoFillInput(parent, true, childId, boundaries, flags);
- }
-
- private void updateAutoFillInput(View view, boolean virtual, int childId, Rect boundaries,
+ public void updateAutoFillInput(View parent, int childId, @Nullable Rect bounds,
int flags) {
- if ((flags & FLAG_UPDATE_UI_SHOW) != 0) {
- final int viewId = view.getAutoFillViewId();
- final AutoFillId id = virtual
- ? new AutoFillId(viewId, childId)
- : new AutoFillId(viewId);
- showAutoFillInput(id, boundaries);
- return;
- }
- // TODO(b/33197203): handle FLAG_UPDATE_UI_HIDE
+ requestAutoFill(new AutoFillId(parent.getAccessibilityViewId(), childId), bounds, flags);
}
- private void showAutoFillInput(AutoFillId id, Rect boundaries) {
- final int autoFillViewId = id.getViewId();
- /*
- * TODO(b/33197203): currently SHOW_AUTO_FILL_BAR is only set once per activity (i.e, when
- * the view does not have an auto-fill id), but it should be called again for views that
- * were not part of the initial auto-fill dataset returned by the service. For example:
- *
- * 1.Activity has 4 fields, `first_name`, `last_name`, and `address`.
- * 2.User taps `first_name`.
- * 3.Service returns a dataset with ids for `first_name` and `last_name`.
- * 4.When user taps `first_name` (again) or `last_name`, flag should not have
- * SHOW_AUTO_FILL_BAR set, but when user taps `address`, it should (since that field was
- * not part of the initial dataset).
- *
- * Similarly, once the activity is auto-filled, the flag logic should be reset (so if the
- * user taps the view again, a new auto-fill request is made)
- */
- if (autoFillViewId != View.NO_ID) {
- return;
+ private void requestAutoFill(AutoFillId id, Rect bounds, int flags) {
+ if (DEBUG) {
+ Log.v(TAG, "requestAutoFill(): id=" + id + ", bounds=" + bounds + ", flags=" + flags);
}
-
try {
- mService.showAutoFillInput(id, boundaries);
+ mService.requestAutoFill(id, bounds, flags);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/core/java/android/view/autofill/AutoFillSession.java b/core/java/android/view/autofill/AutoFillSession.java
new file mode 100644
index 000000000000..eec7a823a841
--- /dev/null
+++ b/core/java/android/view/autofill/AutoFillSession.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2017 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 android.view.autofill;
+
+import static android.view.autofill.Helper.DEBUG;
+
+import android.app.Activity;
+import android.os.RemoteException;
+import android.service.autofill.IAutoFillAppCallback;
+import android.util.Log;
+import android.view.View;
+
+import com.android.internal.annotations.GuardedBy;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * An auto-fill session associated with an activity.
+ *
+ * @hide
+ */
+public final class AutoFillSession {
+
+ private static final String TAG = "AutoFillSession";
+
+ private final IAutoFillAppCallback mCallback = new IAutoFillAppCallback.Stub() {
+ @Override
+ public void autoFill(Dataset dataset) throws RemoteException {
+ final Activity activity = mActivity.get();
+ if (activity == null) {
+ if (DEBUG) Log.d(TAG, "autoFill(): activity already GCed");
+ return;
+ }
+ // TODO(b/33197203): must keep the dataset so subsequent calls pass the same
+ // dataset.extras to service
+ activity.runOnUiThread(() -> {
+ final View root = activity.getWindow().getDecorView().getRootView();
+ for (DatasetField field : dataset.getFields()) {
+ final AutoFillId id = field.getId();
+ if (id == null) {
+ Log.w(TAG, "autoFill(): null id on " + field);
+ continue;
+ }
+ final int viewId = id.getViewId();
+ final View view = root.findViewByAccessibilityIdTraversal(viewId);
+ if (view == null) {
+ Log.w(TAG, "autoFill(): no View with id " + viewId);
+ continue;
+ }
+
+ // TODO(b/33197203): handle protected value (like credit card)
+ if (id.isVirtual()) {
+ // Delegate virtual fields.
+ setAutoFillDelegateCallback();
+ final VirtualViewDelegate delegate = view
+ .getAutoFillVirtualViewDelegate(
+ mAutoFillDelegateCallback);
+ if (delegate == null) {
+ Log.w(TAG, "autoFill(): cannot fill virtual " + id
+ + "; no VirtualViewDelegate for view "
+ + view.getClass());
+ continue;
+ }
+ if (DEBUG) {
+ Log.d(TAG, "autoFill(): delegating " + id
+ + " to VirtualViewDelegate " + delegate);
+ }
+ delegate.autoFill(id.getVirtualChildId(), field.getValue());
+ } else {
+ // Handle non-virtual fields itself.
+ view.autoFill(field.getValue());
+ }
+ }
+ });
+ }
+ };
+
+ private final WeakReference<Activity> mActivity;
+
+ @GuardedBy("this")
+ private VirtualViewDelegate.Callback mAutoFillDelegateCallback;
+
+ public AutoFillSession(Activity activity) {
+ mActivity = new WeakReference<>(activity);
+ }
+
+ public IAutoFillAppCallback getCallback() {
+ return mCallback;
+ }
+
+ /**
+ * Lazily sets the {@link #mAutoFillDelegateCallback}.
+ */
+ private void setAutoFillDelegateCallback() {
+ synchronized (this) {
+ if (mAutoFillDelegateCallback == null) {
+ mAutoFillDelegateCallback = new VirtualViewDelegate.Callback() {
+ // TODO(b/33197203): implement
+ };
+ }
+ }
+ }
+
+}
diff --git a/core/java/android/view/autofill/Dataset.java b/core/java/android/view/autofill/Dataset.java
index b11eecc35e76..18a08f930703 100644
--- a/core/java/android/view/autofill/Dataset.java
+++ b/core/java/android/view/autofill/Dataset.java
@@ -284,7 +284,7 @@ public final class Dataset implements Parcelable {
* Sets a {@link Bundle} that will be passed to subsequent calls to
* {@link android.service.autofill.AutoFillService} methods such as
* {@link android.service.autofill.AutoFillService#onSaveRequest(android.app.assist.AssistStructure,
- * Bundle, android.os.CancellationSignal, android.service.autofill.SaveCallback)}, using
+ * Bundle, android.service.autofill.SaveCallback)}, using
* {@link android.service.autofill.AutoFillService#EXTRA_DATASET_EXTRAS} as the key.
*
* <p>It can be used to keep service state in between calls.
diff --git a/core/java/android/view/autofill/FillResponse.java b/core/java/android/view/autofill/FillResponse.java
index 67eb85a90ab9..48dbb8415ec4 100644
--- a/core/java/android/view/autofill/FillResponse.java
+++ b/core/java/android/view/autofill/FillResponse.java
@@ -149,9 +149,9 @@ import java.util.Set;
* Dataset.Builder#setExtras(Bundle)} methods to pass {@link Bundle}s with service-specific data use
* to identify this response on future calls (like {@link
* android.service.autofill.AutoFillService#onSaveRequest(android.app.assist.AssistStructure,
- * Bundle, android.os.CancellationSignal, android.service.autofill.SaveCallback)}) - such bundles
- * will be available as the {@link android.service.autofill.AutoFillService#EXTRA_RESPONSE_EXTRAS}
- * and {@link android.service.autofill.AutoFillService#EXTRA_DATASET_EXTRAS} extras in that method's
+ * Bundle, android.service.autofill.SaveCallback)}) - such bundles will be available as the
+ * {@link android.service.autofill.AutoFillService#EXTRA_RESPONSE_EXTRAS} and
+ * {@link android.service.autofill.AutoFillService#EXTRA_DATASET_EXTRAS} extras in that method's
* {@code extras} argument.
*/
public final class FillResponse implements Parcelable {
@@ -369,9 +369,8 @@ public final class FillResponse implements Parcelable {
/**
* Adds ids of additional fields that the service would be interested to save (through
* {@link android.service.autofill.AutoFillService#onSaveRequest(
- * android.app.assist.AssistStructure, Bundle, android.os.CancellationSignal,
- * android.service.autofill.SaveCallback)}) but were not indirectly set through {@link
- * #addDataset(Dataset)}.
+ * android.app.assist.AssistStructure, Bundle, android.service.autofill.SaveCallback)})
+ * but were not indirectly set through {@link #addDataset(Dataset)}.
*
* <p>See {@link FillResponse} for examples.
*/
@@ -386,8 +385,8 @@ public final class FillResponse implements Parcelable {
* Sets a {@link Bundle} that will be passed to subsequent calls to {@link
* android.service.autofill.AutoFillService} methods such as {@link
* android.service.autofill.AutoFillService#onSaveRequest(
- * android.app.assist.AssistStructure, Bundle, android.os.CancellationSignal,
- * android.service.autofill.SaveCallback)}, using {@link
+ * android.app.assist.AssistStructure, Bundle, android.service.autofill.SaveCallback)},
+ * using {@link
* android.service.autofill.AutoFillService#EXTRA_RESPONSE_EXTRAS} as the key.
*
* <p>It can be used when to keep service state in between calls.
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 072fe4ad7376..c0bec69ca4d7 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -9030,8 +9030,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
final AutoFillManager afm = mContext.getSystemService(AutoFillManager.class);
if (afm != null) {
if (DEBUG_AUTOFILL) {
- Log.v(LOG_TAG, "onFocusChanged(): id=" + getAutoFillViewId() + ", focused= "
- + focused);
+ Log.v(LOG_TAG, "onFocusChanged(false): id=" + getAccessibilityViewId());
}
afm.updateAutoFillInput(this, AutoFillManager.FLAG_UPDATE_UI_HIDE);
}
@@ -10615,7 +10614,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
protected void viewClicked(InputMethodManager imm) {
final AutoFillManager afm = mContext.getSystemService(AutoFillManager.class);
if (afm != null) {
- if (DEBUG_AUTOFILL) Log.v(LOG_TAG, "viewClicked(): id=" + getAutoFillViewId());
+ if (DEBUG_AUTOFILL) Log.v(LOG_TAG, "viewClicked(): id=" + getAccessibilityViewId());
// TODO(b/33197203): integrate with onFocus and/or move to view?
afm.updateAutoFillInput(this, AutoFillManager.FLAG_UPDATE_UI_SHOW);