Merge "Don't allow the keyboard to probe Inline Suggestion content." into rvc-dev am: ea25d217be am: c84181cd16
Change-Id: I99ad7b6915fdde2408c9e049cc3369e52f1bbdb7
This commit is contained in:
@@ -2604,17 +2604,20 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private void updateViewStateAndUiOnValueChangedLocked(AutofillId id, AutofillValue value,
|
private void updateViewStateAndUiOnValueChangedLocked(AutofillId id, AutofillValue value,
|
||||||
ViewState viewState, int flags) {
|
ViewState viewState, int flags) {
|
||||||
viewState.setCurrentValue(value);
|
final String textValue;
|
||||||
|
|
||||||
final String filterText;
|
|
||||||
if (value == null || !value.isText()) {
|
if (value == null || !value.isText()) {
|
||||||
filterText = null;
|
textValue = null;
|
||||||
} else {
|
} else {
|
||||||
final CharSequence text = value.getTextValue();
|
final CharSequence text = value.getTextValue();
|
||||||
// Text should never be null, but it doesn't hurt to check to avoid a
|
// Text should never be null, but it doesn't hurt to check to avoid a
|
||||||
// system crash...
|
// system crash...
|
||||||
filterText = (text == null) ? null : text.toString();
|
textValue = (text == null) ? null : text.toString();
|
||||||
}
|
}
|
||||||
|
updateFilteringStateOnValueChangedLocked(textValue, viewState);
|
||||||
|
|
||||||
|
viewState.setCurrentValue(value);
|
||||||
|
|
||||||
|
final String filterText = textValue;
|
||||||
|
|
||||||
final AutofillValue filledValue = viewState.getAutofilledValue();
|
final AutofillValue filledValue = viewState.getAutofilledValue();
|
||||||
if (filledValue != null) {
|
if (filledValue != null) {
|
||||||
@@ -2645,6 +2648,52 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
getUiForShowing().filterFillUi(filterText, this);
|
getUiForShowing().filterFillUi(filterText, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable filtering of inline suggestions for further text changes in this view if any
|
||||||
|
* character was removed earlier and now any character is being added. Such behaviour may
|
||||||
|
* indicate the IME attempting to probe the potentially sensitive content of inline suggestions.
|
||||||
|
*/
|
||||||
|
@GuardedBy("mLock")
|
||||||
|
private void updateFilteringStateOnValueChangedLocked(@Nullable String newTextValue,
|
||||||
|
ViewState viewState) {
|
||||||
|
if (newTextValue == null) {
|
||||||
|
// Don't just return here, otherwise the IME can circumvent this logic using non-text
|
||||||
|
// values.
|
||||||
|
newTextValue = "";
|
||||||
|
}
|
||||||
|
final AutofillValue currentValue = viewState.getCurrentValue();
|
||||||
|
final String currentTextValue;
|
||||||
|
if (currentValue == null || !currentValue.isText()) {
|
||||||
|
currentTextValue = "";
|
||||||
|
} else {
|
||||||
|
currentTextValue = currentValue.getTextValue().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((viewState.getState() & ViewState.STATE_CHAR_REMOVED) == 0) {
|
||||||
|
if (!containsCharsInOrder(newTextValue, currentTextValue)) {
|
||||||
|
viewState.setState(ViewState.STATE_CHAR_REMOVED);
|
||||||
|
}
|
||||||
|
} else if (!containsCharsInOrder(currentTextValue, newTextValue)) {
|
||||||
|
// Characters were added or replaced.
|
||||||
|
viewState.setState(ViewState.STATE_INLINE_DISABLED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if {@code s1} contains all characters of {@code s2}, in order.
|
||||||
|
*/
|
||||||
|
private static boolean containsCharsInOrder(String s1, String s2) {
|
||||||
|
int prevIndex = -1;
|
||||||
|
for (char ch : s2.toCharArray()) {
|
||||||
|
int index = TextUtils.indexOf(s1, ch, prevIndex + 1);
|
||||||
|
if (index == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
prevIndex = index;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFillReady(@NonNull FillResponse response, @NonNull AutofillId filledId,
|
public void onFillReady(@NonNull FillResponse response, @NonNull AutofillId filledId,
|
||||||
@Nullable AutofillValue value) {
|
@Nullable AutofillValue value) {
|
||||||
@@ -2735,6 +2784,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ViewState currentView = mViewStates.get(mCurrentViewId);
|
||||||
|
if ((currentView.getState() & ViewState.STATE_INLINE_DISABLED) != 0) {
|
||||||
|
response.getDatasets().clear();
|
||||||
|
}
|
||||||
InlineSuggestionsResponse inlineSuggestionsResponse =
|
InlineSuggestionsResponse inlineSuggestionsResponse =
|
||||||
InlineSuggestionFactory.createInlineSuggestionsResponse(
|
InlineSuggestionFactory.createInlineSuggestionsResponse(
|
||||||
inlineSuggestionsRequest.get(), response, filterText, mCurrentViewId,
|
inlineSuggestionsRequest.get(), response, filterText, mCurrentViewId,
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ final class ViewState {
|
|||||||
public static final int STATE_TRIGGERED_AUGMENTED_AUTOFILL = 0x1000;
|
public static final int STATE_TRIGGERED_AUGMENTED_AUTOFILL = 0x1000;
|
||||||
/** Inline suggestions were shown for this View. */
|
/** Inline suggestions were shown for this View. */
|
||||||
public static final int STATE_INLINE_SHOWN = 0x2000;
|
public static final int STATE_INLINE_SHOWN = 0x2000;
|
||||||
|
/** A character was removed from the View value (not by the service). */
|
||||||
|
public static final int STATE_CHAR_REMOVED = 0x4000;
|
||||||
|
/** Showing inline suggestions is not allowed for this View. */
|
||||||
|
public static final int STATE_INLINE_DISABLED = 0x8000;
|
||||||
|
|
||||||
public final AutofillId id;
|
public final AutofillId id;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user