Improved AutoFill Save workflow.

Currently, the onProvideAutoFillStructure() methods can be called
twice: to auto-fill an activity and to save the activity's data
in the service.

The problem with this approach is that when the save workflow is
called, the activity might have been gone. Hence, a proper approach
is to keep the initial AssistStructure data in the system_service
memory, watch for view changes, and then passed the new structure
back to the AutoFillService.

A side effect of this change is that we need another way to determine
if the view is sanitized or not. For "standard" views, that will be
defined based on whether the view content come from a resource or not,
but that logic is not implemented yet (for now, all views will be
considered sanitized, except for TextView passwords). For "custom"
views (such as WebView), this logic is responsibility of the view
implementation, through the newChild() method, which now takes a
flag (whose value could be AUTO_FILL_FLAG_SANITIZED for sanitized
views).

The SaveCallback.onSuccess() method was simplified: it does
not need a list of saved ids anymore the auto-fill UI will not use it
anymore.

Another side effect is that the Save notification is gone - until
it's attached again, it can be test by using:

    adb shell cmd autofill save

Finally, hook AutoFillUI on ACTION_CLOSE_SYSTEM_DIALOGS events.

BUG: 33269702
BUG: 31001899
Test: manual verification
Test: CtsAutoFillServiceTestCases passes
Change-Id: I907a7e21d1b3cd1ab6dec3a08d144a52655da46f
diff --git a/core/java/android/view/autofill/AutoFillManager.java b/core/java/android/view/autofill/AutoFillManager.java
index cf56e0e..f2f522d 100644
--- a/core/java/android/view/autofill/AutoFillManager.java
+++ b/core/java/android/view/autofill/AutoFillManager.java
@@ -36,15 +36,11 @@
     /**
      * Flag used to show the auto-fill UI affordance for a view.
      */
-    // 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.
      */
-    // 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;
@@ -71,7 +67,7 @@
         final Rect bounds = new Rect();
         view.getBoundsOnScreen(bounds);
 
-        requestAutoFill(new AutoFillId(view.getAccessibilityViewId()), bounds, flags);
+        requestAutoFill(getAutoFillId(view), bounds, flags);
     }
 
     /**
@@ -92,7 +88,30 @@
         requestAutoFill(new AutoFillId(parent.getAccessibilityViewId(), childId), bounds, flags);
     }
 
+    /**
+     * Notifies the framework that the value of a view changed.
+     * @param view view whose value was updated
+     * @param value new value.
+     */
+    public void onValueChanged(View view, AutoFillValue value) {
+        // TODO(b/33197203): optimize it by not calling service when the view does not belong to
+        // the session.
+        final AutoFillId id = getAutoFillId(view);
+        if (DEBUG) Log.v(TAG, "onValueChanged(): id=" + id + ", value=" + value);
+        try {
+            mService.onValueChanged(id, value);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    private AutoFillId getAutoFillId(View view) {
+        return new AutoFillId(view.getAccessibilityViewId());
+    }
+
     private void requestAutoFill(AutoFillId id, Rect bounds, int flags) {
+        // TODO(b/33197203): optimize it by not calling service when the view does not belong to
+        // the session.
         if (DEBUG) {
             Log.v(TAG, "requestAutoFill(): id=" + id + ", bounds=" + bounds + ", flags=" + flags);
         }