summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2018-09-07 16:22:38 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2018-09-07 16:22:38 +0000
commit645537e52239eb1eebc31e27b742f22a66c0dc15 (patch)
tree89cf44a8b3351781ffb36dae52974ded45d55072
parentf0c67fb4d21185e136e3a119de70f47409597394 (diff)
parent5429ade944a9afbd8622c88ca68c5811e6eb4468 (diff)
Merge "Fixed findValueLocked() so it fetches values from previous sessions."
-rw-r--r--core/java/android/service/autofill/CharSequenceTransformation.java2
-rw-r--r--services/autofill/java/com/android/server/autofill/Session.java43
-rw-r--r--services/autofill/java/com/android/server/autofill/ViewState.java10
3 files changed, 41 insertions, 14 deletions
diff --git a/core/java/android/service/autofill/CharSequenceTransformation.java b/core/java/android/service/autofill/CharSequenceTransformation.java
index f52ac8505289..fa6bd65c0fd4 100644
--- a/core/java/android/service/autofill/CharSequenceTransformation.java
+++ b/core/java/android/service/autofill/CharSequenceTransformation.java
@@ -78,7 +78,7 @@ public final class CharSequenceTransformation extends InternalTransformation imp
int childViewId) throws Exception {
final StringBuilder converted = new StringBuilder();
final int size = mFields.size();
- if (sDebug) Log.d(TAG, size + " multiple fields on id " + childViewId);
+ if (sDebug) Log.d(TAG, size + " fields on id " + childViewId);
for (Entry<AutofillId, Pair<Pattern, String>> entry : mFields.entrySet()) {
final AutofillId id = entry.getKey();
final Pair<Pattern, String> field = entry.getValue();
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 5b7332d0c636..bd4568568f6d 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -395,16 +395,42 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
* or {@code null} when not found on either of them.
*/
@GuardedBy("mLock")
- private AutofillValue findValueLocked(@NonNull AutofillId id) {
- final ViewState state = mViewStates.get(id);
+ @Nullable
+ private AutofillValue findValueLocked(@NonNull AutofillId autofillId) {
+ final AutofillValue value = findValueFromThisSessionOnlyLocked(autofillId);
+ if (value != null) return value;
+
+ // TODO(b/113281366): rather than explicitly look for previous session, it might be better
+ // to merge the sessions when created (see note on mergePreviousSessionLocked())
+ final ArrayList<Session> previousSessions = mService.getPreviousSessionsLocked(this);
+ if (previousSessions != null) {
+ if (sDebug) {
+ Slog.d(TAG, "findValueLocked(): looking on " + previousSessions.size()
+ + " previous sessions for autofillId " + autofillId);
+ }
+ for (int i = 0; i < previousSessions.size(); i++) {
+ final Session previousSession = previousSessions.get(i);
+ final AutofillValue previousValue = previousSession
+ .findValueFromThisSessionOnlyLocked(autofillId);
+ if (previousValue != null) {
+ return previousValue;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Nullable
+ private AutofillValue findValueFromThisSessionOnlyLocked(@NonNull AutofillId autofillId) {
+ final ViewState state = mViewStates.get(autofillId);
if (state == null) {
- if (sDebug) Slog.d(TAG, "findValueLocked(): no view state for " + id);
+ if (sDebug) Slog.d(TAG, "findValueLocked(): no view state for " + autofillId);
return null;
}
AutofillValue value = state.getCurrentValue();
if (value == null) {
- if (sDebug) Slog.d(TAG, "findValueLocked(): no current value for " + id);
- value = getValueFromContextsLocked(id);
+ if (sDebug) Slog.d(TAG, "findValueLocked(): no current value for " + autofillId);
+ value = getValueFromContextsLocked(autofillId);
}
return value;
}
@@ -1769,15 +1795,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
*/
@GuardedBy("mLock")
@Nullable
- private AutofillValue getValueFromContextsLocked(AutofillId id) {
+ private AutofillValue getValueFromContextsLocked(@NonNull AutofillId autofillId) {
final int numContexts = mContexts.size();
for (int i = numContexts - 1; i >= 0; i--) {
final FillContext context = mContexts.get(i);
- final ViewNode node = Helper.findViewNodeByAutofillId(context.getStructure(), id);
+ final ViewNode node = Helper.findViewNodeByAutofillId(context.getStructure(),
+ autofillId);
if (node != null) {
final AutofillValue value = node.getAutofillValue();
if (sDebug) {
- Slog.d(TAG, "getValueFromContexts(" + id + ") at " + i + ": " + value);
+ Slog.d(TAG, "getValueFromContexts(" + autofillId + ") at " + i + ": " + value);
}
if (value != null && !value.isEmpty()) {
return value;
diff --git a/services/autofill/java/com/android/server/autofill/ViewState.java b/services/autofill/java/com/android/server/autofill/ViewState.java
index bb97e4a97c97..e6cd7e0f6ebd 100644
--- a/services/autofill/java/com/android/server/autofill/ViewState.java
+++ b/services/autofill/java/com/android/server/autofill/ViewState.java
@@ -212,20 +212,20 @@ final class ViewState {
public String toString() {
final StringBuilder builder = new StringBuilder("ViewState: [id=").append(id);
if (mDatasetId != null) {
- builder.append("datasetId:" ).append(mDatasetId);
+ builder.append(", datasetId:" ).append(mDatasetId);
}
builder.append("state:" ).append(getStateAsString());
if (mCurrentValue != null) {
- builder.append("currentValue:" ).append(mCurrentValue);
+ builder.append(", currentValue:" ).append(mCurrentValue);
}
if (mAutofilledValue != null) {
- builder.append("autofilledValue:" ).append(mAutofilledValue);
+ builder.append(", autofilledValue:" ).append(mAutofilledValue);
}
if (mSanitizedValue != null) {
- builder.append("sanitizedValue:" ).append(mSanitizedValue);
+ builder.append(", sanitizedValue:" ).append(mSanitizedValue);
}
if (mVirtualBounds != null) {
- builder.append("virtualBounds:" ).append(mVirtualBounds);
+ builder.append(", virtualBounds:" ).append(mVirtualBounds);
}
return builder.toString();
}